mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Make DHCP discovery ignore self assigned ip addresses (#45256)
This commit is contained in:
parent
a42d43d054
commit
fbc98b1291
@ -37,6 +37,7 @@ MESSAGE_TYPE = "message-type"
|
|||||||
HOSTNAME = "hostname"
|
HOSTNAME = "hostname"
|
||||||
MAC_ADDRESS = "macaddress"
|
MAC_ADDRESS = "macaddress"
|
||||||
IP_ADDRESS = "ip"
|
IP_ADDRESS = "ip"
|
||||||
|
SELF_ASSIGNED_BLOCK = "169.254."
|
||||||
DHCP_REQUEST = 3
|
DHCP_REQUEST = 3
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -81,6 +82,10 @@ class WatcherBase:
|
|||||||
|
|
||||||
def process_client(self, ip_address, hostname, mac_address):
|
def process_client(self, ip_address, hostname, mac_address):
|
||||||
"""Process a client."""
|
"""Process a client."""
|
||||||
|
if ip_address.startswith(SELF_ASSIGNED_BLOCK):
|
||||||
|
# Ignore self assigned addresses
|
||||||
|
return
|
||||||
|
|
||||||
data = self._address_data.get(ip_address)
|
data = self._address_data.get(ip_address)
|
||||||
|
|
||||||
if data and data[MAC_ADDRESS] == mac_address and data[HOSTNAME] == hostname:
|
if data and data[MAC_ADDRESS] == mac_address and data[HOSTNAME] == hostname:
|
||||||
|
@ -504,3 +504,32 @@ async def test_device_tracker_hostname_and_macaddress_after_start_hostname_missi
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(mock_init.mock_calls) == 0
|
assert len(mock_init.mock_calls) == 0
|
||||||
|
|
||||||
|
|
||||||
|
async def test_device_tracker_ignore_self_assigned_ips_before_start(hass):
|
||||||
|
"""Test matching ignores self assigned ip address."""
|
||||||
|
hass.states.async_set(
|
||||||
|
"device_tracker.august_connect",
|
||||||
|
STATE_HOME,
|
||||||
|
{
|
||||||
|
ATTR_HOST_NAME: "connect",
|
||||||
|
ATTR_IP: "169.254.210.56",
|
||||||
|
ATTR_SOURCE_TYPE: SOURCE_TYPE_ROUTER,
|
||||||
|
ATTR_MAC: "B8:B7:F1:6D:B5:33",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
with patch.object(
|
||||||
|
hass.config_entries.flow, "async_init", return_value=mock_coro()
|
||||||
|
) as mock_init:
|
||||||
|
device_tracker_watcher = dhcp.DeviceTrackerWatcher(
|
||||||
|
hass,
|
||||||
|
{},
|
||||||
|
[{"domain": "mock-domain", "hostname": "connect", "macaddress": "B8B7F1*"}],
|
||||||
|
)
|
||||||
|
device_tracker_watcher.async_start()
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
device_tracker_watcher.async_stop()
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(mock_init.mock_calls) == 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user