diff --git a/homeassistant/components/modern_forms/config_flow.py b/homeassistant/components/modern_forms/config_flow.py index 147976ee2b0..bd52ae6f5a2 100644 --- a/homeassistant/components/modern_forms/config_flow.py +++ b/homeassistant/components/modern_forms/config_flow.py @@ -30,14 +30,14 @@ class ModernFormsFlowHandler(ConfigFlow, domain=DOMAIN): self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle zeroconf discovery.""" - host = discovery_info["hostname"].rstrip(".") + host = discovery_info[zeroconf.ATTR_HOSTNAME].rstrip(".") name, _ = host.rsplit(".") self.context.update( { - CONF_HOST: discovery_info["host"], + CONF_HOST: discovery_info[zeroconf.ATTR_HOST], CONF_NAME: name, - CONF_MAC: discovery_info["properties"].get(CONF_MAC), + CONF_MAC: discovery_info[zeroconf.ATTR_PROPERTIES].get(CONF_MAC), "title_placeholders": {"name": name}, } ) diff --git a/tests/components/modern_forms/test_config_flow.py b/tests/components/modern_forms/test_config_flow.py index 967e9d354d5..39db815064b 100644 --- a/tests/components/modern_forms/test_config_flow.py +++ b/tests/components/modern_forms/test_config_flow.py @@ -4,6 +4,7 @@ from unittest.mock import MagicMock, patch import aiohttp from aiomodernforms import ModernFormsConnectionError +from homeassistant.components import zeroconf from homeassistant.components.modern_forms.const import DOMAIN from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, CONTENT_TYPE_JSON @@ -68,7 +69,9 @@ async def test_full_zeroconf_flow_implementation( result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_ZEROCONF}, - data={"host": "192.168.1.123", "hostname": "example.local.", "properties": {}}, + data=zeroconf.ZeroconfServiceInfo( + host="192.168.1.123", hostname="example.local.", properties={} + ), ) flows = hass.config_entries.flow.async_progress() @@ -130,7 +133,9 @@ async def test_zeroconf_connection_error( result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_ZEROCONF}, - data={"host": "192.168.1.123", "hostname": "example.local.", "properties": {}}, + data=zeroconf.ZeroconfServiceInfo( + host="192.168.1.123", hostname="example.local.", properties={} + ), ) assert result.get("type") == RESULT_TYPE_ABORT @@ -154,7 +159,9 @@ async def test_zeroconf_confirm_connection_error( CONF_HOST: "example.com", CONF_NAME: "test", }, - data={"host": "192.168.1.123", "hostname": "example.com.", "properties": {}}, + data=zeroconf.ZeroconfServiceInfo( + host="192.168.1.123", hostname="example.com.", properties={} + ), ) assert result.get("type") == RESULT_TYPE_ABORT @@ -216,11 +223,11 @@ async def test_zeroconf_with_mac_device_exists_abort( result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_ZEROCONF}, - data={ - "host": "192.168.1.123", - "hostname": "example.local.", - "properties": {CONF_MAC: "AA:BB:CC:DD:EE:FF"}, - }, + data=zeroconf.ZeroconfServiceInfo( + host="192.168.1.123", + hostname="example.local.", + properties={CONF_MAC: "AA:BB:CC:DD:EE:FF"}, + ), ) assert result.get("type") == RESULT_TYPE_ABORT