Abort flux_led discovery if another device gets the ip (#61074)
- If the dhcp reservation expired for the device that was at the ip and a new flux_led device appears we would discover it because the unique_id did not match
This commit is contained in:
parent
40b99135e5
commit
52d6b83da8
2 changed files with 33 additions and 2 deletions
|
@ -115,8 +115,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
await self.async_set_unique_id(mac)
|
await self.async_set_unique_id(mac)
|
||||||
self._abort_if_unique_id_configured(updates={CONF_HOST: host})
|
self._abort_if_unique_id_configured(updates={CONF_HOST: host})
|
||||||
for entry in self._async_current_entries(include_ignore=False):
|
for entry in self._async_current_entries(include_ignore=False):
|
||||||
if entry.data[CONF_HOST] == host and not entry.unique_id:
|
if entry.data[CONF_HOST] == host:
|
||||||
async_update_entry_from_discovery(self.hass, entry, device)
|
if not entry.unique_id:
|
||||||
|
async_update_entry_from_discovery(self.hass, entry, device)
|
||||||
return self.async_abort(reason="already_configured")
|
return self.async_abort(reason="already_configured")
|
||||||
self.context[CONF_HOST] = host
|
self.context[CONF_HOST] = host
|
||||||
for progress in self._async_in_progress():
|
for progress in self._async_in_progress():
|
||||||
|
|
|
@ -40,6 +40,8 @@ from . import (
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
MAC_ADDRESS_DIFFERENT = "ff:bb:ff:dd:ee:ff"
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery(hass: HomeAssistant):
|
async def test_discovery(hass: HomeAssistant):
|
||||||
"""Test setting up discovery."""
|
"""Test setting up discovery."""
|
||||||
|
@ -472,6 +474,34 @@ async def test_discovered_by_dhcp_or_discovery_adds_missing_unique_id(
|
||||||
assert config_entry.unique_id == MAC_ADDRESS
|
assert config_entry.unique_id == MAC_ADDRESS
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"source, data",
|
||||||
|
[
|
||||||
|
(config_entries.SOURCE_DHCP, DHCP_DISCOVERY),
|
||||||
|
(config_entries.SOURCE_DISCOVERY, FLUX_DISCOVERY),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_discovered_by_dhcp_or_discovery_mac_address_mismatch_host_already_configured(
|
||||||
|
hass, source, data
|
||||||
|
):
|
||||||
|
"""Test we abort if the host is already configured but the mac does not match."""
|
||||||
|
config_entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN, data={CONF_HOST: IP_ADDRESS}, unique_id=MAC_ADDRESS_DIFFERENT
|
||||||
|
)
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
with _patch_discovery(), _patch_wifibulb():
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": source}, data=data
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert result["type"] == RESULT_TYPE_ABORT
|
||||||
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
assert config_entry.unique_id == MAC_ADDRESS_DIFFERENT
|
||||||
|
|
||||||
|
|
||||||
async def test_options(hass: HomeAssistant):
|
async def test_options(hass: HomeAssistant):
|
||||||
"""Test options flow."""
|
"""Test options flow."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue