From 95075448bd17d65800231dc84f39cd49672016df Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 21 Nov 2021 17:35:51 +0100 Subject: [PATCH] Use DhcpServiceInfo in nuki (#60046) --- homeassistant/components/nuki/config_flow.py | 9 +++++---- tests/components/nuki/test_config_flow.py | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/nuki/config_flow.py b/homeassistant/components/nuki/config_flow.py index 330f38c96bd..c3e0ed93372 100644 --- a/homeassistant/components/nuki/config_flow.py +++ b/homeassistant/components/nuki/config_flow.py @@ -7,8 +7,9 @@ from requests.exceptions import RequestException import voluptuous as vol from homeassistant import config_entries, exceptions -from homeassistant.components.dhcp import HOSTNAME, IP_ADDRESS +from homeassistant.components import dhcp from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TOKEN +from homeassistant.data_entry_flow import FlowResult from .const import DEFAULT_PORT, DEFAULT_TIMEOUT, DOMAIN @@ -66,15 +67,15 @@ class NukiConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Handle a flow initiated by the user.""" return await self.async_step_validate(user_input) - async def async_step_dhcp(self, discovery_info: dict): + async def async_step_dhcp(self, discovery_info: dhcp.DhcpServiceInfo) -> FlowResult: """Prepare configuration for a DHCP discovered Nuki bridge.""" - await self.async_set_unique_id(int(discovery_info.get(HOSTNAME)[12:], 16)) + await self.async_set_unique_id(int(discovery_info[dhcp.HOSTNAME][12:], 16)) self._abort_if_unique_id_configured() self.discovery_schema = vol.Schema( { - vol.Required(CONF_HOST, default=discovery_info[IP_ADDRESS]): str, + vol.Required(CONF_HOST, default=discovery_info[dhcp.IP_ADDRESS]): str, vol.Required(CONF_PORT, default=DEFAULT_PORT): int, vol.Required(CONF_TOKEN): str, } diff --git a/tests/components/nuki/test_config_flow.py b/tests/components/nuki/test_config_flow.py index 8e3636dbdef..fd7bfa2137b 100644 --- a/tests/components/nuki/test_config_flow.py +++ b/tests/components/nuki/test_config_flow.py @@ -5,7 +5,7 @@ from pynuki.bridge import InvalidCredentialsException from requests.exceptions import RequestException from homeassistant import config_entries, data_entry_flow -from homeassistant.components.dhcp import HOSTNAME, IP_ADDRESS, MAC_ADDRESS +from homeassistant.components import dhcp from homeassistant.components.nuki.const import DOMAIN from homeassistant.const import CONF_TOKEN @@ -178,7 +178,7 @@ async def test_dhcp_flow(hass): """Test that DHCP discovery for new bridge works.""" result = await hass.config_entries.flow.async_init( DOMAIN, - data={HOSTNAME: NAME, IP_ADDRESS: HOST, MAC_ADDRESS: MAC}, + data=dhcp.DhcpServiceInfo(hostname=NAME, ip=HOST, macaddress=MAC), context={"source": config_entries.SOURCE_DHCP}, ) @@ -221,7 +221,7 @@ async def test_dhcp_flow_already_configured(hass): await setup_nuki_integration(hass) result = await hass.config_entries.flow.async_init( DOMAIN, - data={HOSTNAME: NAME, IP_ADDRESS: HOST, MAC_ADDRESS: MAC}, + data=dhcp.DhcpServiceInfo(hostname=NAME, ip=HOST, macaddress=MAC), context={"source": config_entries.SOURCE_DHCP}, ) -- GitLab