Use ZeroconfServiceInfo in gogogate2 (#59746)

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

View File

@ -7,6 +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.config_entries import ConfigFlow
from homeassistant.const import (
@ -35,10 +36,12 @@ class Gogogate2FlowHandler(ConfigFlow, domain=DOMAIN):
self._ip_address = None
self._device_type = None
async def async_step_homekit(self, discovery_info):
async def async_step_homekit(
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> data_entry_flow.FlowResult:
"""Handle homekit discovery."""
await self.async_set_unique_id(discovery_info["properties"]["id"])
return await self._async_discovery_handler(discovery_info["host"])
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):
"""Handle dhcp discovery."""

View File

@ -6,6 +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.gogogate2.const import (
DEVICE_TYPE_GOGOGATE2,
DEVICE_TYPE_ISMARTGATE,
@ -106,7 +107,9 @@ async def test_form_homekit_unique_id_already_setup(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_HOMEKIT},
data={"host": "1.2.3.4", "properties": {"id": MOCK_MAC_ADDR}},
data=zeroconf.ZeroconfServiceInfo(
host="1.2.3.4", properties={"id": MOCK_MAC_ADDR}
),
)
assert result["type"] == RESULT_TYPE_FORM
assert result["errors"] == {}
@ -126,7 +129,9 @@ async def test_form_homekit_unique_id_already_setup(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_HOMEKIT},
data={"host": "1.2.3.4", "properties": {"id": MOCK_MAC_ADDR}},
data=zeroconf.ZeroconfServiceInfo(
host="1.2.3.4", properties={"id": MOCK_MAC_ADDR}
),
)
assert result["type"] == RESULT_TYPE_ABORT
@ -143,7 +148,9 @@ async def test_form_homekit_ip_address_already_setup(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_HOMEKIT},
data={"host": "1.2.3.4", "properties": {"id": MOCK_MAC_ADDR}},
data=zeroconf.ZeroconfServiceInfo(
host="1.2.3.4", properties={"id": MOCK_MAC_ADDR}
),
)
assert result["type"] == RESULT_TYPE_ABORT
@ -154,7 +161,9 @@ async def test_form_homekit_ip_address(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_HOMEKIT},
data={"host": "1.2.3.4", "properties": {"id": MOCK_MAC_ADDR}},
data=zeroconf.ZeroconfServiceInfo(
host="1.2.3.4", properties={"id": MOCK_MAC_ADDR}
),
)
assert result["type"] == RESULT_TYPE_FORM
assert result["errors"] == {}
@ -227,7 +236,9 @@ async def test_discovered_by_homekit_and_dhcp(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_HOMEKIT},
data={"host": "1.2.3.4", "properties": {"id": MOCK_MAC_ADDR}},
data=zeroconf.ZeroconfServiceInfo(
host="1.2.3.4", properties={"id": MOCK_MAC_ADDR}
),
)
assert result["type"] == RESULT_TYPE_FORM
assert result["errors"] == {}