From 8f7f32d844e62c551d78563096a35b728e959809 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 21 Nov 2021 23:33:26 +0100 Subject: [PATCH] Use DhcpServiceInfo in screenlogic (#60103) --- homeassistant/components/screenlogic/config_flow.py | 13 +++++++------ tests/components/screenlogic/test_config_flow.py | 10 +++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/screenlogic/config_flow.py b/homeassistant/components/screenlogic/config_flow.py index 1fc01a2e854..e8f2fca1be5 100644 --- a/homeassistant/components/screenlogic/config_flow.py +++ b/homeassistant/components/screenlogic/config_flow.py @@ -7,9 +7,10 @@ from screenlogicpy.requests import login import voluptuous as vol from homeassistant import config_entries -from homeassistant.components.dhcp import HOSTNAME, IP_ADDRESS +from homeassistant.components import dhcp from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT, CONF_SCAN_INTERVAL from homeassistant.core import callback +from homeassistant.data_entry_flow import FlowResult import homeassistant.helpers.config_validation as cv from homeassistant.helpers.device_registry import format_mac @@ -88,15 +89,15 @@ class ScreenlogicConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): self.discovered_gateways = await async_discover_gateways_by_unique_id(self.hass) return await self.async_step_gateway_select() - async def async_step_dhcp(self, discovery_info): + async def async_step_dhcp(self, discovery_info: dhcp.DhcpServiceInfo) -> FlowResult: """Handle dhcp discovery.""" - mac = _extract_mac_from_name(discovery_info[HOSTNAME]) + mac = _extract_mac_from_name(discovery_info[dhcp.HOSTNAME]) await self.async_set_unique_id(mac) self._abort_if_unique_id_configured( - updates={CONF_IP_ADDRESS: discovery_info[IP_ADDRESS]} + updates={CONF_IP_ADDRESS: discovery_info[dhcp.IP_ADDRESS]} ) - self.discovered_ip = discovery_info[IP_ADDRESS] - self.context["title_placeholders"] = {"name": discovery_info[HOSTNAME]} + self.discovered_ip = discovery_info[dhcp.IP_ADDRESS] + self.context["title_placeholders"] = {"name": discovery_info[dhcp.HOSTNAME]} return await self.async_step_gateway_entry() async def async_step_gateway_select(self, user_input=None): diff --git a/tests/components/screenlogic/test_config_flow.py b/tests/components/screenlogic/test_config_flow.py index d1333cb7514..9a6715bc401 100644 --- a/tests/components/screenlogic/test_config_flow.py +++ b/tests/components/screenlogic/test_config_flow.py @@ -11,7 +11,7 @@ from screenlogicpy.const import ( ) from homeassistant import config_entries -from homeassistant.components.dhcp import HOSTNAME, IP_ADDRESS +from homeassistant.components import dhcp from homeassistant.components.screenlogic.config_flow import ( GATEWAY_MANUAL_ENTRY, GATEWAY_SELECT_KEY, @@ -138,10 +138,10 @@ async def test_dhcp(hass): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_DHCP}, - data={ - HOSTNAME: "Pentair: 01-01-01", - IP_ADDRESS: "1.1.1.1", - }, + data=dhcp.DhcpServiceInfo( + hostname="Pentair: 01-01-01", + ip="1.1.1.1", + ), ) assert result["type"] == "form"