Skip to content

Commit add1915

Browse files
iMicknlfrenck
authored andcommitted
Improve error message for unsupported hardware in Overkiz (home-assistant#154314)
1 parent 18ef4af commit add1915

File tree

3 files changed

+110
-2
lines changed

3 files changed

+110
-2
lines changed

homeassistant/components/overkiz/config_flow.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,27 @@ async def async_step_cloud(
171171
except TooManyAttemptsBannedException:
172172
errors["base"] = "too_many_attempts"
173173
except UnknownUserException:
174+
# If the user has no supported CozyTouch devices on
175+
# the Overkiz API server. Login will return unknown user.
176+
if user_input[CONF_HUB] in {
177+
Server.ATLANTIC_COZYTOUCH,
178+
Server.SAUTER_COZYTOUCH,
179+
Server.THERMOR_COZYTOUCH,
180+
}:
181+
description_placeholders["unsupported_device"] = "CozyTouch"
174182
# Somfy Protect accounts are not supported since they don't use
175183
# the Overkiz API server. Login will return unknown user.
176-
description_placeholders["unsupported_device"] = "Somfy Protect"
184+
elif user_input[CONF_HUB] in {
185+
Server.SOMFY_AMERICA,
186+
Server.SOMFY_DEVELOPER_MODE,
187+
Server.SOMFY_EUROPE,
188+
Server.SOMFY_OCEANIA,
189+
}:
190+
description_placeholders["unsupported_device"] = "Somfy Protect"
191+
# Fallback for other unknown devices
192+
else:
193+
description_placeholders["unsupported_device"] = "Unknown"
194+
177195
errors["base"] = "unsupported_hardware"
178196
except Exception: # noqa: BLE001
179197
errors["base"] = "unknown"

homeassistant/components/overkiz/strings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"too_many_attempts": "Too many attempts with an invalid token, temporarily banned",
5656
"too_many_requests": "Too many requests, try again later",
5757
"unknown": "[%key:common::config_flow::error::unknown%]",
58-
"unsupported_hardware": "Your {unsupported_device} hardware is not supported by this integration."
58+
"unsupported_hardware": "Your {unsupported_device} hardware is not using the Overkiz platform and can't be supported by this integration."
5959
},
6060
"abort": {
6161
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]",

tests/components/overkiz/test_config_flow.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,96 @@ async def test_form_invalid_auth_cloud(
255255
assert result["errors"] == {"base": error}
256256

257257

258+
@pytest.mark.parametrize(
259+
("side_effect", "description_placeholder", "server"),
260+
[
261+
(UnknownUserException, "CozyTouch", TEST_SERVER_COZYTOUCH),
262+
(UnknownUserException, "Unknown", TEST_SERVER2),
263+
],
264+
)
265+
async def test_form_invalid_hardware_cloud(
266+
hass: HomeAssistant,
267+
side_effect: Exception,
268+
description_placeholder: str,
269+
server: str,
270+
) -> None:
271+
"""Test we handle unsupported hardware (cloud)."""
272+
result = await hass.config_entries.flow.async_init(
273+
DOMAIN, context={"source": config_entries.SOURCE_USER}
274+
)
275+
276+
assert result["type"] is FlowResultType.FORM
277+
278+
result = await hass.config_entries.flow.async_configure(
279+
result["flow_id"],
280+
{"hub": server},
281+
)
282+
283+
assert result["type"] is FlowResultType.FORM
284+
assert result["step_id"] == "cloud"
285+
286+
with patch("pyoverkiz.client.OverkizClient.login", side_effect=side_effect):
287+
result = await hass.config_entries.flow.async_configure(
288+
result["flow_id"],
289+
{"username": TEST_EMAIL, "password": TEST_PASSWORD},
290+
)
291+
292+
await hass.async_block_till_done()
293+
294+
assert result["type"] is FlowResultType.FORM
295+
assert result["errors"] == {"base": "unsupported_hardware"}
296+
assert result["description_placeholders"] == {
297+
"unsupported_device": description_placeholder
298+
}
299+
300+
301+
@pytest.mark.parametrize(
302+
("side_effect", "description_placeholder", "server"),
303+
[
304+
(UnknownUserException, "Somfy Protect", TEST_SERVER),
305+
],
306+
)
307+
async def test_form_invalid_hardware_cloud_local(
308+
hass: HomeAssistant,
309+
side_effect: Exception,
310+
description_placeholder: str,
311+
server: str,
312+
) -> None:
313+
"""Test we handle unsupported hardware (cloud and local)."""
314+
result = await hass.config_entries.flow.async_init(
315+
DOMAIN, context={"source": config_entries.SOURCE_USER}
316+
)
317+
318+
assert result["type"] is FlowResultType.FORM
319+
320+
result = await hass.config_entries.flow.async_configure(
321+
result["flow_id"],
322+
{"hub": server},
323+
)
324+
325+
result = await hass.config_entries.flow.async_configure(
326+
result["flow_id"],
327+
{"api_type": "cloud"},
328+
)
329+
330+
assert result["type"] is FlowResultType.FORM
331+
assert result["step_id"] == "cloud"
332+
333+
with patch("pyoverkiz.client.OverkizClient.login", side_effect=side_effect):
334+
result = await hass.config_entries.flow.async_configure(
335+
result["flow_id"],
336+
{"username": TEST_EMAIL, "password": TEST_PASSWORD},
337+
)
338+
339+
await hass.async_block_till_done()
340+
341+
assert result["type"] is FlowResultType.FORM
342+
assert result["errors"] == {"base": "unsupported_hardware"}
343+
assert result["description_placeholders"] == {
344+
"unsupported_device": description_placeholder
345+
}
346+
347+
258348
@pytest.mark.parametrize(
259349
("side_effect", "error"),
260350
[

0 commit comments

Comments
 (0)