From 07c3981de73c1f7e79fa3a370545524d8a2386f3 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Tue, 19 Jan 2021 09:15:41 +0100 Subject: [PATCH] Use methods available to verify link local address (#45309) --- homeassistant/components/dhcp/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/dhcp/__init__.py b/homeassistant/components/dhcp/__init__.py index 7f872979ed7..d926e6f7925 100644 --- a/homeassistant/components/dhcp/__init__.py +++ b/homeassistant/components/dhcp/__init__.py @@ -2,6 +2,7 @@ from abc import abstractmethod import fnmatch +from ipaddress import ip_address as make_ip_address import logging import os import threading @@ -28,6 +29,7 @@ from homeassistant.core import Event, HomeAssistant, State, callback from homeassistant.helpers.device_registry import format_mac from homeassistant.helpers.event import async_track_state_added_domain from homeassistant.loader import async_get_dhcp +from homeassistant.util.network import is_link_local from .const import DOMAIN @@ -37,7 +39,6 @@ MESSAGE_TYPE = "message-type" HOSTNAME = "hostname" MAC_ADDRESS = "macaddress" IP_ADDRESS = "ip" -SELF_ASSIGNED_BLOCK = "169.254." DHCP_REQUEST = 3 _LOGGER = logging.getLogger(__name__) @@ -82,7 +83,7 @@ class WatcherBase: def process_client(self, ip_address, hostname, mac_address): """Process a client.""" - if ip_address.startswith(SELF_ASSIGNED_BLOCK): + if is_link_local(make_ip_address(ip_address)): # Ignore self assigned addresses return