From 0b43cff37724eaa329bc140b566f1ddfdce371c3 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 15 Nov 2021 23:13:17 +0100 Subject: [PATCH] Use ZeroconfServiceInfo in guardian (#59741) Co-authored-by: epenet --- .../components/guardian/config_flow.py | 8 +++-- tests/components/guardian/test_config_flow.py | 33 ++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/guardian/config_flow.py b/homeassistant/components/guardian/config_flow.py index 452574d4eed..2aa00f56d99 100644 --- a/homeassistant/components/guardian/config_flow.py +++ b/homeassistant/components/guardian/config_flow.py @@ -112,10 +112,12 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): ) -> FlowResult: """Handle the configuration via zeroconf.""" self.discovery_info = { - CONF_IP_ADDRESS: discovery_info["host"], - CONF_PORT: discovery_info["port"], + CONF_IP_ADDRESS: discovery_info[zeroconf.ATTR_HOST], + CONF_PORT: discovery_info[zeroconf.ATTR_PORT], } - pin = async_get_pin_from_discovery_hostname(discovery_info["hostname"]) + pin = async_get_pin_from_discovery_hostname( + discovery_info[zeroconf.ATTR_HOSTNAME] + ) await self._async_set_unique_id(pin) return await self._async_handle_discovery() diff --git a/tests/components/guardian/test_config_flow.py b/tests/components/guardian/test_config_flow.py index 4fbff7d7e48..b8d23508c77 100644 --- a/tests/components/guardian/test_config_flow.py +++ b/tests/components/guardian/test_config_flow.py @@ -4,6 +4,7 @@ from unittest.mock import patch from aioguardian.errors import GuardianError from homeassistant import data_entry_flow +from homeassistant.components import zeroconf from homeassistant.components.dhcp import HOSTNAME, IP_ADDRESS, MAC_ADDRESS from homeassistant.components.guardian import CONF_UID, DOMAIN from homeassistant.components.guardian.config_flow import ( @@ -83,14 +84,14 @@ async def test_step_user(hass, ping_client): async def test_step_zeroconf(hass, ping_client): """Test the zeroconf step.""" - zeroconf_data = { - "host": "192.168.1.100", - "port": 7777, - "hostname": "GVC1-ABCD.local.", - "type": "_api._udp.local.", - "name": "Guardian Valve Controller API._api._udp.local.", - "properties": {"_raw": {}}, - } + zeroconf_data = zeroconf.ZeroconfServiceInfo( + host="192.168.1.100", + port=7777, + hostname="GVC1-ABCD.local.", + type="_api._udp.local.", + name="Guardian Valve Controller API._api._udp.local.", + properties={"_raw": {}}, + ) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_ZEROCONF}, data=zeroconf_data @@ -112,14 +113,14 @@ async def test_step_zeroconf(hass, ping_client): async def test_step_zeroconf_already_in_progress(hass): """Test the zeroconf step aborting because it's already in progress.""" - zeroconf_data = { - "host": "192.168.1.100", - "port": 7777, - "hostname": "GVC1-ABCD.local.", - "type": "_api._udp.local.", - "name": "Guardian Valve Controller API._api._udp.local.", - "properties": {"_raw": {}}, - } + zeroconf_data = zeroconf.ZeroconfServiceInfo( + host="192.168.1.100", + port=7777, + hostname="GVC1-ABCD.local.", + type="_api._udp.local.", + name="Guardian Valve Controller API._api._udp.local.", + properties={"_raw": {}}, + ) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_ZEROCONF}, data=zeroconf_data