mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Warn user if "model" key is missing from Shelly firmware (#71612)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
c74b241949
commit
4a95539d9d
@ -119,6 +119,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
except HTTP_CONNECT_ERRORS:
|
except HTTP_CONNECT_ERRORS:
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
|
except KeyError:
|
||||||
|
errors["base"] = "firmware_not_fully_provisioned"
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
LOGGER.exception("Unexpected exception")
|
LOGGER.exception("Unexpected exception")
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
@ -160,6 +162,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
except aioshelly.exceptions.JSONRPCError:
|
except aioshelly.exceptions.JSONRPCError:
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
|
except KeyError:
|
||||||
|
errors["base"] = "firmware_not_fully_provisioned"
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
LOGGER.exception("Unexpected exception")
|
LOGGER.exception("Unexpected exception")
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
@ -219,6 +223,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self.device_info = await validate_input(self.hass, self.host, self.info, {})
|
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:
|
except HTTP_CONNECT_ERRORS:
|
||||||
return self.async_abort(reason="cannot_connect")
|
return self.async_abort(reason="cannot_connect")
|
||||||
|
|
||||||
@ -229,18 +235,21 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle discovery confirm."""
|
"""Handle discovery confirm."""
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
if user_input is not None:
|
try:
|
||||||
return self.async_create_entry(
|
if user_input is not None:
|
||||||
title=self.device_info["title"],
|
return self.async_create_entry(
|
||||||
data={
|
title=self.device_info["title"],
|
||||||
"host": self.host,
|
data={
|
||||||
CONF_SLEEP_PERIOD: self.device_info[CONF_SLEEP_PERIOD],
|
"host": self.host,
|
||||||
"model": self.device_info["model"],
|
CONF_SLEEP_PERIOD: self.device_info[CONF_SLEEP_PERIOD],
|
||||||
"gen": self.device_info["gen"],
|
"model": self.device_info["model"],
|
||||||
},
|
"gen": self.device_info["gen"],
|
||||||
)
|
},
|
||||||
|
)
|
||||||
self._set_confirm_only()
|
except KeyError:
|
||||||
|
errors["base"] = "firmware_not_fully_provisioned"
|
||||||
|
else:
|
||||||
|
self._set_confirm_only()
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="confirm_discovery",
|
step_id="confirm_discovery",
|
||||||
|
@ -21,7 +21,8 @@
|
|||||||
"error": {
|
"error": {
|
||||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
"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": {
|
"abort": {
|
||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"cannot_connect": "Failed to connect",
|
"cannot_connect": "Failed to connect",
|
||||||
|
"firmware_not_fully_provisioned": "Device not fully provisioned. Please contact Shelly support",
|
||||||
"invalid_auth": "Invalid authentication",
|
"invalid_auth": "Invalid authentication",
|
||||||
"unknown": "Unexpected error"
|
"unknown": "Unexpected error"
|
||||||
},
|
},
|
||||||
|
@ -225,6 +225,29 @@ async def test_form_errors_get_info(hass, error):
|
|||||||
assert result2["errors"] == {"base": base_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(
|
@pytest.mark.parametrize(
|
||||||
"error", [(asyncio.TimeoutError, "cannot_connect"), (ValueError, "unknown")]
|
"error", [(asyncio.TimeoutError, "cannot_connect"), (ValueError, "unknown")]
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user