Improve error message for unsupported hardware in Overkiz (#154314)

This commit is contained in:
Mick Vleeshouwer
2025-10-18 23:43:49 +02:00
committed by GitHub
parent 5b1e3ef574
commit 363e5f088c
3 changed files with 110 additions and 2 deletions
@@ -171,9 +171,27 @@ class OverkizConfigFlow(ConfigFlow, domain=DOMAIN):
except TooManyAttemptsBannedException:
errors["base"] = "too_many_attempts"
except UnknownUserException:
# If the user has no supported CozyTouch devices on
# the Overkiz API server. Login will return unknown user.
if user_input[CONF_HUB] in {
Server.ATLANTIC_COZYTOUCH,
Server.SAUTER_COZYTOUCH,
Server.THERMOR_COZYTOUCH,
}:
description_placeholders["unsupported_device"] = "CozyTouch"
# Somfy Protect accounts are not supported since they don't use
# the Overkiz API server. Login will return unknown user.
description_placeholders["unsupported_device"] = "Somfy Protect"
elif user_input[CONF_HUB] in {
Server.SOMFY_AMERICA,
Server.SOMFY_DEVELOPER_MODE,
Server.SOMFY_EUROPE,
Server.SOMFY_OCEANIA,
}:
description_placeholders["unsupported_device"] = "Somfy Protect"
# Fallback for other unknown devices
else:
description_placeholders["unsupported_device"] = "Unknown"
errors["base"] = "unsupported_hardware"
except Exception: # noqa: BLE001
errors["base"] = "unknown"
@@ -55,7 +55,7 @@
"too_many_attempts": "Too many attempts with an invalid token, temporarily banned",
"too_many_requests": "Too many requests, try again later",
"unknown": "[%key:common::config_flow::error::unknown%]",
"unsupported_hardware": "Your {unsupported_device} hardware is not supported by this integration."
"unsupported_hardware": "Your {unsupported_device} hardware is not using the Overkiz platform and can't be supported by this integration."
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]",
@@ -255,6 +255,96 @@ async def test_form_invalid_auth_cloud(
assert result["errors"] == {"base": error}
@pytest.mark.parametrize(
("side_effect", "description_placeholder", "server"),
[
(UnknownUserException, "CozyTouch", TEST_SERVER_COZYTOUCH),
(UnknownUserException, "Unknown", TEST_SERVER2),
],
)
async def test_form_invalid_hardware_cloud(
hass: HomeAssistant,
side_effect: Exception,
description_placeholder: str,
server: str,
) -> None:
"""Test we handle unsupported hardware (cloud)."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{"hub": server},
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "cloud"
with patch("pyoverkiz.client.OverkizClient.login", side_effect=side_effect):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{"username": TEST_EMAIL, "password": TEST_PASSWORD},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {"base": "unsupported_hardware"}
assert result["description_placeholders"] == {
"unsupported_device": description_placeholder
}
@pytest.mark.parametrize(
("side_effect", "description_placeholder", "server"),
[
(UnknownUserException, "Somfy Protect", TEST_SERVER),
],
)
async def test_form_invalid_hardware_cloud_local(
hass: HomeAssistant,
side_effect: Exception,
description_placeholder: str,
server: str,
) -> None:
"""Test we handle unsupported hardware (cloud and local)."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{"hub": server},
)
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{"api_type": "cloud"},
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "cloud"
with patch("pyoverkiz.client.OverkizClient.login", side_effect=side_effect):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{"username": TEST_EMAIL, "password": TEST_PASSWORD},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {"base": "unsupported_hardware"}
assert result["description_placeholders"] == {
"unsupported_device": description_placeholder
}
@pytest.mark.parametrize(
("side_effect", "error"),
[