From d6c5aaa0cb8904903b956c0cce3eea7164a356f6 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 19 Nov 2021 15:12:31 +0100 Subject: [PATCH] Use ServiceInfo in hunterdouglas_powerview (#59981) Co-authored-by: epenet --- .../hunterdouglas_powerview/config_flow.py | 25 +++++++++++-------- .../test_config_flow.py | 23 +++++++++-------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/hunterdouglas_powerview/config_flow.py b/homeassistant/components/hunterdouglas_powerview/config_flow.py index 8dbe21eb10e..d2c78227fef 100644 --- a/homeassistant/components/hunterdouglas_powerview/config_flow.py +++ b/homeassistant/components/hunterdouglas_powerview/config_flow.py @@ -8,8 +8,9 @@ import async_timeout import voluptuous as vol from homeassistant import config_entries, core, exceptions -from homeassistant.components.dhcp import HOSTNAME, IP_ADDRESS +from homeassistant.components import dhcp, zeroconf from homeassistant.const import CONF_HOST, CONF_NAME +from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers.aiohttp_client import async_get_clientsession from . import async_get_device_info @@ -85,25 +86,29 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): return info, None - async def async_step_dhcp(self, discovery_info): + async def async_step_dhcp(self, discovery_info: dhcp.DhcpServiceInfo) -> FlowResult: """Handle DHCP discovery.""" - self.discovered_ip = discovery_info[IP_ADDRESS] - self.discovered_name = discovery_info[HOSTNAME] + self.discovered_ip = discovery_info[dhcp.IP_ADDRESS] + self.discovered_name = discovery_info[dhcp.HOSTNAME] return await self.async_step_discovery_confirm() - async def async_step_zeroconf(self, discovery_info): + async def async_step_zeroconf( + self, discovery_info: zeroconf.ZeroconfServiceInfo + ) -> FlowResult: """Handle zeroconf discovery.""" - self.discovered_ip = discovery_info[CONF_HOST] - name = discovery_info[CONF_NAME] + self.discovered_ip = discovery_info[zeroconf.ATTR_HOST] + name = discovery_info[zeroconf.ATTR_NAME] if name.endswith(POWERVIEW_SUFFIX): name = name[: -len(POWERVIEW_SUFFIX)] self.discovered_name = name return await self.async_step_discovery_confirm() - async def async_step_homekit(self, discovery_info): + async def async_step_homekit( + self, discovery_info: zeroconf.ZeroconfServiceInfo + ) -> FlowResult: """Handle HomeKit discovery.""" - self.discovered_ip = discovery_info[CONF_HOST] - name = discovery_info[CONF_NAME] + self.discovered_ip = discovery_info[zeroconf.ATTR_HOST] + name = discovery_info[zeroconf.ATTR_NAME] if name.endswith(HAP_SUFFIX): name = name[: -len(HAP_SUFFIX)] self.discovered_name = name diff --git a/tests/components/hunterdouglas_powerview/test_config_flow.py b/tests/components/hunterdouglas_powerview/test_config_flow.py index e3cb9aa4c8b..1631cd2cb60 100644 --- a/tests/components/hunterdouglas_powerview/test_config_flow.py +++ b/tests/components/hunterdouglas_powerview/test_config_flow.py @@ -6,22 +6,25 @@ from unittest.mock import AsyncMock, MagicMock, patch import pytest from homeassistant import config_entries +from homeassistant.components import dhcp, zeroconf from homeassistant.components.hunterdouglas_powerview.const import DOMAIN from tests.common import MockConfigEntry, load_fixture -HOMEKIT_DISCOVERY_INFO = { - "name": "Hunter Douglas Powerview Hub._hap._tcp.local.", - "host": "1.2.3.4", - "properties": {"id": "AA::BB::CC::DD::EE::FF"}, -} +HOMEKIT_DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo( + name="Hunter Douglas Powerview Hub._hap._tcp.local.", + host="1.2.3.4", + properties={"id": "AA::BB::CC::DD::EE::FF"}, +) -ZEROCONF_DISCOVERY_INFO = { - "name": "Hunter Douglas Powerview Hub._powerview._tcp.local.", - "host": "1.2.3.4", -} +ZEROCONF_DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo( + name="Hunter Douglas Powerview Hub._powerview._tcp.local.", + host="1.2.3.4", +) -DHCP_DISCOVERY_INFO = {"hostname": "Hunter Douglas Powerview Hub", "ip": "1.2.3.4"} +DHCP_DISCOVERY_INFO = dhcp.DhcpServiceInfo( + hostname="Hunter Douglas Powerview Hub", ip="1.2.3.4" +) DISCOVERY_DATA = [ (