Use DhcpServiceInfo in gogogate2 (#59968)

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

View File

@ -7,8 +7,7 @@ from ismartgate.const import GogoGate2ApiErrorCode, ISmartGateApiErrorCode
import voluptuous as vol
from homeassistant import data_entry_flow
from homeassistant.components import zeroconf
from homeassistant.components.dhcp import IP_ADDRESS, MAC_ADDRESS
from homeassistant.components import dhcp, zeroconf
from homeassistant.config_entries import ConfigFlow
from homeassistant.const import (
CONF_DEVICE,
@ -43,10 +42,12 @@ class Gogogate2FlowHandler(ConfigFlow, domain=DOMAIN):
await self.async_set_unique_id(discovery_info[zeroconf.ATTR_PROPERTIES]["id"])
return await self._async_discovery_handler(discovery_info[zeroconf.ATTR_HOST])
async def async_step_dhcp(self, discovery_info):
async def async_step_dhcp(
self, discovery_info: dhcp.DhcpServiceInfo
) -> data_entry_flow.FlowResult:
"""Handle dhcp discovery."""
await self.async_set_unique_id(discovery_info[MAC_ADDRESS])
return await self._async_discovery_handler(discovery_info[IP_ADDRESS])
await self.async_set_unique_id(discovery_info[dhcp.MAC_ADDRESS])
return await self._async_discovery_handler(discovery_info[dhcp.IP_ADDRESS])
async def _async_discovery_handler(self, ip_address):
"""Start the user flow from any discovery."""

View File

@ -6,7 +6,7 @@ from ismartgate.common import ApiError
from ismartgate.const import GogoGate2ApiErrorCode
from homeassistant import config_entries
from homeassistant.components import zeroconf
from homeassistant.components import dhcp, zeroconf
from homeassistant.components.gogogate2.const import (
DEVICE_TYPE_GOGOGATE2,
DEVICE_TYPE_ISMARTGATE,
@ -191,7 +191,7 @@ async def test_discovered_dhcp(
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_DHCP},
data={"ip": "1.2.3.4", "macaddress": MOCK_MAC_ADDR},
data=dhcp.DhcpServiceInfo(ip="1.2.3.4", macaddress=MOCK_MAC_ADDR),
)
assert result["type"] == RESULT_TYPE_FORM
assert result["errors"] == {}
@ -246,7 +246,7 @@ async def test_discovered_by_homekit_and_dhcp(hass):
result2 = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_DHCP},
data={"ip": "1.2.3.4", "macaddress": MOCK_MAC_ADDR},
data=dhcp.DhcpServiceInfo(ip="1.2.3.4", macaddress=MOCK_MAC_ADDR),
)
assert result2["type"] == RESULT_TYPE_ABORT
assert result2["reason"] == "already_in_progress"
@ -254,7 +254,7 @@ async def test_discovered_by_homekit_and_dhcp(hass):
result3 = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_DHCP},
data={"ip": "1.2.3.4", "macaddress": "00:00:00:00:00:00"},
data=dhcp.DhcpServiceInfo(ip="1.2.3.4", macaddress="00:00:00:00:00:00"),
)
assert result3["type"] == RESULT_TYPE_ABORT
assert result3["reason"] == "already_in_progress"