Use ServiceInfo in hunterdouglas_powerview (#59981)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-11-19 15:12:31 +01:00 committed by GitHub
parent c557da028a
commit d6c5aaa0cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 20 deletions

View File

@ -8,8 +8,9 @@ import async_timeout
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries, core, exceptions 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.const import CONF_HOST, CONF_NAME
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from . import async_get_device_info from . import async_get_device_info
@ -85,25 +86,29 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
return info, None 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.""" """Handle DHCP discovery."""
self.discovered_ip = discovery_info[IP_ADDRESS] self.discovered_ip = discovery_info[dhcp.IP_ADDRESS]
self.discovered_name = discovery_info[HOSTNAME] self.discovered_name = discovery_info[dhcp.HOSTNAME]
return await self.async_step_discovery_confirm() 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.""" """Handle zeroconf discovery."""
self.discovered_ip = discovery_info[CONF_HOST] self.discovered_ip = discovery_info[zeroconf.ATTR_HOST]
name = discovery_info[CONF_NAME] name = discovery_info[zeroconf.ATTR_NAME]
if name.endswith(POWERVIEW_SUFFIX): if name.endswith(POWERVIEW_SUFFIX):
name = name[: -len(POWERVIEW_SUFFIX)] name = name[: -len(POWERVIEW_SUFFIX)]
self.discovered_name = name self.discovered_name = name
return await self.async_step_discovery_confirm() 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.""" """Handle HomeKit discovery."""
self.discovered_ip = discovery_info[CONF_HOST] self.discovered_ip = discovery_info[zeroconf.ATTR_HOST]
name = discovery_info[CONF_NAME] name = discovery_info[zeroconf.ATTR_NAME]
if name.endswith(HAP_SUFFIX): if name.endswith(HAP_SUFFIX):
name = name[: -len(HAP_SUFFIX)] name = name[: -len(HAP_SUFFIX)]
self.discovered_name = name self.discovered_name = name

View File

@ -6,22 +6,25 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest import pytest
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components import dhcp, zeroconf
from homeassistant.components.hunterdouglas_powerview.const import DOMAIN from homeassistant.components.hunterdouglas_powerview.const import DOMAIN
from tests.common import MockConfigEntry, load_fixture from tests.common import MockConfigEntry, load_fixture
HOMEKIT_DISCOVERY_INFO = { HOMEKIT_DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(
"name": "Hunter Douglas Powerview Hub._hap._tcp.local.", name="Hunter Douglas Powerview Hub._hap._tcp.local.",
"host": "1.2.3.4", host="1.2.3.4",
"properties": {"id": "AA::BB::CC::DD::EE::FF"}, properties={"id": "AA::BB::CC::DD::EE::FF"},
} )
ZEROCONF_DISCOVERY_INFO = { ZEROCONF_DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(
"name": "Hunter Douglas Powerview Hub._powerview._tcp.local.", name="Hunter Douglas Powerview Hub._powerview._tcp.local.",
"host": "1.2.3.4", 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 = [ DISCOVERY_DATA = [
( (