Fix lifx homekit discoveries not being ignorable or updating the IP (#76825)
parent
ff3fd4c29d
commit
b43242ef0d
|
@ -119,18 +119,20 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Confirm discovery."""
|
"""Confirm discovery."""
|
||||||
assert self._discovered_device is not None
|
assert self._discovered_device is not None
|
||||||
|
discovered = self._discovered_device
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Confirming discovery: %s with serial %s",
|
"Confirming discovery: %s with serial %s",
|
||||||
self._discovered_device.label,
|
discovered.label,
|
||||||
self.unique_id,
|
self.unique_id,
|
||||||
)
|
)
|
||||||
if user_input is not None or self._async_discovered_pending_migration():
|
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()
|
self._set_confirm_only()
|
||||||
placeholders = {
|
placeholders = {
|
||||||
"label": self._discovered_device.label,
|
"label": discovered.label,
|
||||||
"host": self._discovered_device.ip_addr,
|
"host": discovered.ip_addr,
|
||||||
"serial": self.unique_id,
|
"serial": self.unique_id,
|
||||||
}
|
}
|
||||||
self.context["title_placeholders"] = placeholders
|
self.context["title_placeholders"] = placeholders
|
||||||
|
|
|
@ -466,21 +466,38 @@ async def test_discovered_by_dhcp_or_discovery_failed_to_get_device(hass, source
|
||||||
assert result["reason"] == "cannot_connect"
|
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."""
|
"""Update host from dhcp."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=DOMAIN, data={CONF_HOST: "127.0.0.2"}, unique_id=SERIAL
|
domain=DOMAIN, data={CONF_HOST: "127.0.0.2"}, unique_id=SERIAL
|
||||||
)
|
)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
with _patch_discovery(no_device=True), _patch_config_flow_try_connect(
|
with _patch_discovery(), _patch_config_flow_try_connect():
|
||||||
no_device=True
|
|
||||||
):
|
|
||||||
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": source},
|
||||||
data=dhcp.DhcpServiceInfo(
|
data=data,
|
||||||
ip=IP_ADDRESS, macaddress=MAC_ADDRESS, hostname=LABEL
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert result["type"] == FlowResultType.ABORT
|
assert result["type"] == FlowResultType.ABORT
|
||||||
|
|
Loading…
Reference in New Issue