Fix guardian being rediscovered via dhcp (#65332)
parent
649b4ce329
commit
eea9e26ef5
|
@ -68,6 +68,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
self._abort_if_unique_id_configured(
|
||||
updates={CONF_IP_ADDRESS: self.discovery_info[CONF_IP_ADDRESS]}
|
||||
)
|
||||
self._async_abort_entries_match(
|
||||
{CONF_IP_ADDRESS: self.discovery_info[CONF_IP_ADDRESS]}
|
||||
)
|
||||
else:
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
|
@ -103,6 +106,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
CONF_IP_ADDRESS: discovery_info.ip,
|
||||
CONF_PORT: DEFAULT_PORT,
|
||||
}
|
||||
await self._async_set_unique_id(
|
||||
async_get_pin_from_uid(discovery_info.macaddress.replace(":", "").upper())
|
||||
)
|
||||
return await self._async_handle_discovery()
|
||||
|
||||
async def async_step_zeroconf(
|
||||
|
|
|
@ -13,6 +13,8 @@ from homeassistant.components.guardian.config_flow import (
|
|||
from homeassistant.config_entries import SOURCE_DHCP, SOURCE_USER, SOURCE_ZEROCONF
|
||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_duplicate_error(hass, config, config_entry, setup_guardian):
|
||||
"""Test that errors are shown when duplicate entries are added."""
|
||||
|
@ -166,3 +168,45 @@ async def test_step_dhcp_already_in_progress(hass):
|
|||
)
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_in_progress"
|
||||
|
||||
|
||||
async def test_step_dhcp_already_setup_match_mac(hass):
|
||||
"""Test we abort if the device is already setup with matching unique id and discovered via DHCP."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN, data={CONF_IP_ADDRESS: "1.2.3.4"}, unique_id="guardian_ABCD"
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_DHCP},
|
||||
data=dhcp.DhcpServiceInfo(
|
||||
ip="192.168.1.100",
|
||||
hostname="GVC1-ABCD.local.",
|
||||
macaddress="aa:bb:cc:dd:ab:cd",
|
||||
),
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_step_dhcp_already_setup_match_ip(hass):
|
||||
"""Test we abort if the device is already setup with matching ip and discovered via DHCP."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={CONF_IP_ADDRESS: "192.168.1.100"},
|
||||
unique_id="guardian_0000",
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_DHCP},
|
||||
data=dhcp.DhcpServiceInfo(
|
||||
ip="192.168.1.100",
|
||||
hostname="GVC1-ABCD.local.",
|
||||
macaddress="aa:bb:cc:dd:ab:cd",
|
||||
),
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
|
Loading…
Reference in New Issue