Fix lifx homekit discoveries not being ignorable or updating the IP (#76825)

pull/75425/head^2
J. Nick Koston 2022-08-15 15:09:13 -10:00 committed by GitHub
parent ff3fd4c29d
commit b43242ef0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 12 deletions

View File

@ -119,18 +119,20 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
) -> FlowResult:
"""Confirm discovery."""
assert self._discovered_device is not None
discovered = self._discovered_device
_LOGGER.debug(
"Confirming discovery: %s with serial %s",
self._discovered_device.label,
discovered.label,
self.unique_id,
)
if user_input is not None or self._async_discovered_pending_migration():
return self._async_create_entry_from_device(self._discovered_device)
return self._async_create_entry_from_device(discovered)
self._abort_if_unique_id_configured(updates={CONF_HOST: discovered.ip_addr})
self._set_confirm_only()
placeholders = {
"label": self._discovered_device.label,
"host": self._discovered_device.ip_addr,
"label": discovered.label,
"host": discovered.ip_addr,
"serial": self.unique_id,
}
self.context["title_placeholders"] = placeholders

View File

@ -466,21 +466,38 @@ async def test_discovered_by_dhcp_or_discovery_failed_to_get_device(hass, source
assert result["reason"] == "cannot_connect"
async def test_discovered_by_dhcp_updates_ip(hass):
@pytest.mark.parametrize(
"source, data",
[
(
config_entries.SOURCE_DHCP,
dhcp.DhcpServiceInfo(ip=IP_ADDRESS, macaddress=MAC_ADDRESS, hostname=LABEL),
),
(
config_entries.SOURCE_HOMEKIT,
zeroconf.ZeroconfServiceInfo(
host=IP_ADDRESS,
addresses=[IP_ADDRESS],
hostname=LABEL,
name=LABEL,
port=None,
properties={zeroconf.ATTR_PROPERTIES_ID: "any"},
type="mock_type",
),
),
],
)
async def test_discovered_by_dhcp_or_homekit_updates_ip(hass, source, data):
"""Update host from dhcp."""
config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_HOST: "127.0.0.2"}, unique_id=SERIAL
)
config_entry.add_to_hass(hass)
with _patch_discovery(no_device=True), _patch_config_flow_try_connect(
no_device=True
):
with _patch_discovery(), _patch_config_flow_try_connect():
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_DHCP},
data=dhcp.DhcpServiceInfo(
ip=IP_ADDRESS, macaddress=MAC_ADDRESS, hostname=LABEL
),
context={"source": source},
data=data,
)
await hass.async_block_till_done()
assert result["type"] == FlowResultType.ABORT