8000 Warn user if "model" key is missing from Shelly firmware by chemelli74 · Pull Request #71612 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Warn user if "model" key is missing from Shelly firmware #71612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions homeassistant/components/shelly/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ async def async_step_user(
)
except HTTP_CONNECT_ERRORS:
errors["base"] = "cannot_connect"
except KeyError:
errors["base"] = "firmware_not_fully_provisioned"
except Exception: # pylint: disable=broad-except
LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
Expand Down Expand Up @@ -160,6 +162,8 @@ async def async_step_credentials(
errors["base"] = "cannot_connect"
except aioshelly.exceptions.JSONRPCError:
errors["base"] = "cannot_connect"
except KeyError:
errors["base"] = "firmware_not_fully_provisioned"
except Exception: # pylint: disable=broad-except
LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
Expand Down Expand Up @@ -219,6 +223,8 @@ async def async_step_zeroconf(

try:
self.device_info = await validate_input(self.hass, self.host, self.info, {})
except KeyError:
LOGGER.debug("Shelly host %s firmware not fully provisioned", self.host)
except HTTP_CONNECT_ERRORS:
return self.async_abort(reason="cannot_connect")

Expand All @@ -229,18 +235,21 @@ async def async_step_confirm_discovery(
) -> FlowResult:
"""Handle discovery confirm."""
errors: dict[str, str] = {}
if user_input is not None:
return self.async_create_entry(
title=self.device_info["title"],
data={
"host": self.host,
CONF_SLEEP_PERIOD: self.device_info[CONF_SLEEP_PERIOD],
"model": self.device_info["model"],
"gen": self.device_info["gen"],
},
)

self._set_confirm_only()
try:
if user_input is not None:
return self.async_create_entry(
title=self.device_info["title"],
data={
"host": self.host,
CONF_SLEEP_PERIOD: self.device_info[CONF_SLEEP_PERIOD],
"model": self.device_info["model"],
"gen": self.device_info["gen"],
},
)
except KeyError:
errors["base"] = "firmware_not_fully_provisioned"
else:
self._set_confirm_only()

return self.async_show_form(
step_id="confirm_discovery",
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/shelly/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
"unknown": "[%key:common::config_flow::error::unknown%]",
"firmware_not_fully_provisioned": "Device not fully provisioned. Please contact Shelly support"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/shelly/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"error": {
"cannot_connect": "Failed to connect",
"firmware_not_fully_provisioned": "Device not fully provisioned. Please contact Shelly support",
"invalid_auth": "Invalid authentication",
"unknown": "Unexpected error"
},
Expand Down
23 changes: 23 additions & 0 deletions tests/components/shelly/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,29 @@ async def test_form_errors_get_info(hass, error):
assert result2["errors"] == {"base": base_error}


@pytest.mark.parametrize("error", [(KeyError, "firmware_not_fully_provisioned")])
async def test_form_missing_key_get_info(hass, error):
"""Test we handle missing key."""
exc, base_error = error
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch(
"aioshelly.common.get_info",
return_value={"mac": "test-mac", "type": "SHSW-1", "auth": False, "gen": "2"},
), patch(
"homeassistant.components.shelly.config_flow.validate_input",
side_effect=KeyError,
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{"host": "1.1.1.1"},
)

assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result2["errors"] == {"base": base_error}


@pytest.mark.parametrize(
"error", [(asyncio.TimeoutError, "cannot_connect"), (ValueError, "unknown")]
)
Expand Down
0