Use DhcpServiceInfo in screenlogic (#60103)

This commit is contained in:
epenet 2021-11-21 23:33:26 +01:00 committed by GitHub
parent 4555820987
commit 8f7f32d844
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 11 deletions

View File

@ -7,9 +7,10 @@ from screenlogicpy.requests import login
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries 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.const import CONF_IP_ADDRESS, CONF_PORT, CONF_SCAN_INTERVAL
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import format_mac 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) self.discovered_gateways = await async_discover_gateways_by_unique_id(self.hass)
return await self.async_step_gateway_select() 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.""" """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) await self.async_set_unique_id(mac)
self._abort_if_unique_id_configured( 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.discovered_ip = discovery_info[dhcp.IP_ADDRESS]
self.context["title_placeholders"] = {"name": discovery_info[HOSTNAME]} self.context["title_placeholders"] = {"name": discovery_info[dhcp.HOSTNAME]}
return await self.async_step_gateway_entry() return await self.async_step_gateway_entry()
async def async_step_gateway_select(self, user_input=None): async def async_step_gateway_select(self, user_input=None):

View File

@ -11,7 +11,7 @@ from screenlogicpy.const import (
) )
from homeassistant import config_entries 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 ( from homeassistant.components.screenlogic.config_flow import (
GATEWAY_MANUAL_ENTRY, GATEWAY_MANUAL_ENTRY,
GATEWAY_SELECT_KEY, GATEWAY_SELECT_KEY,
@ -138,10 +138,10 @@ async def test_dhcp(hass):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_DHCP}, context={"source": config_entries.SOURCE_DHCP},
data={ data=dhcp.DhcpServiceInfo(
HOSTNAME: "Pentair: 01-01-01", hostname="Pentair: 01-01-01",
IP_ADDRESS: "1.1.1.1", ip="1.1.1.1",
}, ),
) )
assert result["type"] == "form" assert result["type"] == "form"