diff --git a/homeassistant/components/forked_daapd/config_flow.py b/homeassistant/components/forked_daapd/config_flow.py index 86bc39c05ed..28177bef97d 100644 --- a/homeassistant/components/forked_daapd/config_flow.py +++ b/homeassistant/components/forked_daapd/config_flow.py @@ -160,20 +160,15 @@ class ForkedDaapdFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): ) -> FlowResult: """Prepare configuration for a discovered forked-daapd device.""" version_num = 0 - if discovery_info.get(zeroconf.ATTR_PROPERTIES) and discovery_info[ - zeroconf.ATTR_PROPERTIES - ].get("Machine Name"): + zeroconf_properties = discovery_info[zeroconf.ATTR_PROPERTIES] + if zeroconf_properties.get("Machine Name"): with suppress(ValueError): version_num = int( - discovery_info[zeroconf.ATTR_PROPERTIES] - .get("mtd-version", "0") - .split(".")[0] + zeroconf_properties.get("mtd-version", "0").split(".")[0] ) if version_num < 27: return self.async_abort(reason="not_forked_daapd") - await self.async_set_unique_id( - discovery_info[zeroconf.ATTR_PROPERTIES]["Machine Name"] - ) + await self.async_set_unique_id(zeroconf_properties["Machine Name"]) self._abort_if_unique_id_configured() # Update title and abort if we already have an entry for this host @@ -182,14 +177,14 @@ class ForkedDaapdFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): continue self.hass.config_entries.async_update_entry( entry, - title=discovery_info[zeroconf.ATTR_PROPERTIES]["Machine Name"], + title=zeroconf_properties["Machine Name"], ) return self.async_abort(reason="already_configured") zeroconf_data = { CONF_HOST: discovery_info[zeroconf.ATTR_HOST], CONF_PORT: discovery_info[zeroconf.ATTR_PORT], - CONF_NAME: discovery_info[zeroconf.ATTR_PROPERTIES]["Machine Name"], + CONF_NAME: zeroconf_properties["Machine Name"], } self.discovery_schema = vol.Schema(fill_in_schema_dict(zeroconf_data)) self.context.update({"title_placeholders": zeroconf_data}) diff --git a/homeassistant/components/freebox/config_flow.py b/homeassistant/components/freebox/config_flow.py index 77041d803ee..76b99dc31d2 100644 --- a/homeassistant/components/freebox/config_flow.py +++ b/homeassistant/components/freebox/config_flow.py @@ -111,6 +111,7 @@ class FreeboxFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Initialize flow from zeroconf.""" - host = discovery_info[zeroconf.ATTR_PROPERTIES]["api_domain"] - port = discovery_info[zeroconf.ATTR_PROPERTIES]["https_port"] + zeroconf_properties = discovery_info[zeroconf.ATTR_PROPERTIES] + host = zeroconf_properties["api_domain"] + port = zeroconf_properties["https_port"] return await self.async_step_user({CONF_HOST: host, CONF_PORT: port}) diff --git a/tests/components/forked_daapd/test_config_flow.py b/tests/components/forked_daapd/test_config_flow.py index c8b82c7a2e9..5c7bf8db97f 100644 --- a/tests/components/forked_daapd/test_config_flow.py +++ b/tests/components/forked_daapd/test_config_flow.py @@ -130,7 +130,9 @@ async def test_config_flow_no_websocket(hass, config_entry): async def test_config_flow_zeroconf_invalid(hass): """Test that an invalid zeroconf entry doesn't work.""" # test with no discovery properties - discovery_info = zeroconf.ZeroconfServiceInfo(host="127.0.0.1", port=23) + discovery_info = zeroconf.ZeroconfServiceInfo( + host="127.0.0.1", port=23, properties={} + ) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_ZEROCONF}, data=discovery_info ) # doesn't create the entry, tries to show form but gets abort