diff --git a/homeassistant/components/shelly/config_flow.py b/homeassistant/components/shelly/config_flow.py index b7b9ab729767af53081edce99c9eeb6c08e272c6..0f744fad4c7f5edc940375c96bad8f06b94d365f 100644 --- a/homeassistant/components/shelly/config_flow.py +++ b/homeassistant/components/shelly/config_flow.py @@ -189,16 +189,17 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle zeroconf discovery.""" + host = discovery_info[zeroconf.ATTR_HOST] try: - self.info = await self._async_get_info(discovery_info["host"]) + self.info = await self._async_get_info(host) except HTTP_CONNECT_ERRORS: return self.async_abort(reason="cannot_connect") except aioshelly.exceptions.FirmwareUnsupported: return self.async_abort(reason="unsupported_firmware") await self.async_set_unique_id(self.info["mac"]) - self._abort_if_unique_id_configured({CONF_HOST: discovery_info["host"]}) - self.host = discovery_info["host"] + self._abort_if_unique_id_configured({CONF_HOST: host}) + self.host = host self.context["title_placeholders"] = { "name": discovery_info.get("name", "").split(".")[0] diff --git a/tests/components/shelly/test_config_flow.py b/tests/components/shelly/test_config_flow.py index dc6921b973500812971718ad769285b9545e66cb..ec88856603aaa8f5257550d1c568559f6a6cd205 100644 --- a/tests/components/shelly/test_config_flow.py +++ b/tests/components/shelly/test_config_flow.py @@ -8,6 +8,7 @@ import aioshelly import pytest from homeassistant import config_entries, data_entry_flow +from homeassistant.components import zeroconf from homeassistant.components.shelly.const import DOMAIN from tests.common import MockConfigEntry @@ -16,11 +17,11 @@ MOCK_SETTINGS = { "name": "Test name", "device": {"mac": "test-mac", "hostname": "test-host", "type": "SHSW-1"}, } -DISCOVERY_INFO = { - "host": "1.1.1.1", - "name": "shelly1pm-12345", - "properties": {"id": "shelly1pm-12345"}, -} +DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo( + host="1.1.1.1", + name="shelly1pm-12345", + properties={"id": "shelly1pm-12345"}, +) MOCK_CONFIG = { "wifi": {"ap": {"ssid": "Test name"}}, }