Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions homeassistant/components/gogogate2/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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 (
Expand Down Expand Up @@ -35,10 +36,12 @@ def __init__(self):
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"])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a constant for id since its a defined field for homekit?

Copy link
Copy Markdown
Contributor Author

@epenet epenet Nov 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id is harder to pinpoint with grep, but I had a quick scan of the components and there does seem to be a few components using it. Should I add ATTR_PROPERTIES_ID constant to zeroconf?
It's a bit long, and I could add ATTR_ID but I am worried about adding confusion with the base attributes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe you want me to add the constant to homekit?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HomeKit discovery is a subset of zeroconf discovery. I think you have it in the right place.

I hate to ask for a one line change, but It really should be a separate PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you wanted it in this PR... I have reverted it now.

return await self._async_discovery_handler(discovery_info[zeroconf.ATTR_HOST])

async def async_step_dhcp(self, discovery_info):
"""Handle dhcp discovery."""
Expand Down
21 changes: 16 additions & 5 deletions tests/components/gogogate2/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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,
Expand Down Expand Up @@ -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"] == {}
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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"] == {}
Expand Down Expand Up @@ -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"] == {}
Expand Down