From 7e1b00c491d99b1a6fa9c4ae10848ece2422b91e Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 22 Nov 2021 15:19:54 +0100 Subject: [PATCH] Use ZeroconfServiceInfo in wled (#60130) Co-authored-by: epenet --- homeassistant/components/wled/config_flow.py | 6 ++--- tests/components/wled/test_config_flow.py | 27 +++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/wled/config_flow.py b/homeassistant/components/wled/config_flow.py index 828dfc3368a..fa02c14ed27 100644 --- a/homeassistant/components/wled/config_flow.py +++ b/homeassistant/components/wled/config_flow.py @@ -44,14 +44,14 @@ class WLEDFlowHandler(ConfigFlow, domain=DOMAIN): """Handle zeroconf discovery.""" # Hostname is format: wled-livingroom.local. - 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/wled/test_config_flow.py b/tests/components/wled/test_config_flow.py index 842e7e332e0..5fc735b4742 100644 --- a/tests/components/wled/test_config_flow.py +++ b/tests/components/wled/test_config_flow.py @@ -3,6 +3,7 @@ from unittest.mock import MagicMock from wled import WLEDConnectionError +from homeassistant.components import zeroconf from homeassistant.components.wled.const import CONF_KEEP_MASTER_LIGHT, DOMAIN from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME @@ -47,7 +48,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() @@ -100,7 +103,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 @@ -120,7 +125,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 @@ -152,7 +159,9 @@ async def test_zeroconf_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": {}}, + data=zeroconf.ZeroconfServiceInfo( + host="192.168.1.123", hostname="example.local.", properties={} + ), ) assert result.get("type") == RESULT_TYPE_ABORT @@ -168,11 +177,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: "aabbccddeeff"}, - }, + data=zeroconf.ZeroconfServiceInfo( + host="192.168.1.123", + hostname="example.local.", + properties={CONF_MAC: "aabbccddeeff"}, + ), ) assert result.get("type") == RESULT_TYPE_ABORT