diff --git a/homeassistant/components/dhcp/__init__.py b/homeassistant/components/dhcp/__init__.py index 45d3ff77c3a..5325283eb0a 100644 --- a/homeassistant/components/dhcp/__init__.py +++ b/homeassistant/components/dhcp/__init__.py @@ -2,7 +2,6 @@ from __future__ import annotations -from abc import ABC, abstractmethod import asyncio from collections.abc import Callable from dataclasses import dataclass @@ -132,18 +131,26 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # For the passive classes we need to start listening # for state changes and connect the dispatchers before # everything else starts up or we will miss events - for passive_cls in (DeviceTrackerRegisteredWatcher, DeviceTrackerWatcher): - passive_watcher = passive_cls(hass, address_data, integration_matchers) - passive_watcher.async_start() - watchers.append(passive_watcher) + device_watcher = DeviceTrackerWatcher(hass, address_data, integration_matchers) + device_watcher.async_start() + watchers.append(device_watcher) + + device_tracker_registered_watcher = DeviceTrackerRegisteredWatcher( + hass, address_data, integration_matchers + ) + device_tracker_registered_watcher.async_start() + watchers.append(device_tracker_registered_watcher) async def _async_initialize(event: Event) -> None: await aiodhcpwatcher.async_init() - for active_cls in (DHCPWatcher, NetworkWatcher): - active_watcher = active_cls(hass, address_data, integration_matchers) - active_watcher.async_start() - watchers.append(active_watcher) + network_watcher = NetworkWatcher(hass, address_data, integration_matchers) + network_watcher.async_start() + watchers.append(network_watcher) + + dhcp_watcher = DHCPWatcher(hass, address_data, integration_matchers) + await dhcp_watcher.async_start() + watchers.append(dhcp_watcher) @callback def _async_stop(event: Event) -> None: @@ -156,7 +163,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: return True -class WatcherBase(ABC): +class WatcherBase: """Base class for dhcp and device tracker watching.""" def __init__( @@ -180,11 +187,6 @@ class WatcherBase(ABC): self._unsub() self._unsub = None - @abstractmethod - @callback - def async_start(self) -> None: - """Start the watcher.""" - @callback def async_process_client( self, ip_address: str, hostname: str, unformatted_mac_address: str @@ -403,10 +405,9 @@ class DHCPWatcher(WatcherBase): response.ip_address, response.hostname, response.mac_address ) - @callback - def async_start(self) -> None: + async def async_start(self) -> None: """Start watching for dhcp packets.""" - self._unsub = aiodhcpwatcher.start(self._async_process_dhcp_request) + self._unsub = await aiodhcpwatcher.async_start(self._async_process_dhcp_request) @lru_cache(maxsize=4096, typed=True) diff --git a/homeassistant/components/dhcp/manifest.json b/homeassistant/components/dhcp/manifest.json index dfe44d0022f..0d77b997e82 100644 --- a/homeassistant/components/dhcp/manifest.json +++ b/homeassistant/components/dhcp/manifest.json @@ -14,7 +14,7 @@ ], "quality_scale": "internal", "requirements": [ - "aiodhcpwatcher==0.8.2", + "aiodhcpwatcher==1.0.0", "aiodiscover==2.0.0", "cached_ipaddress==0.3.0" ] diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 11acc893b79..49b7b032dcb 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -1,6 +1,6 @@ # Automatically generated by gen_requirements_all.py, do not edit -aiodhcpwatcher==0.8.2 +aiodhcpwatcher==1.0.0 aiodiscover==2.0.0 aiohttp-fast-url-dispatcher==0.3.0 aiohttp-zlib-ng==0.3.1 diff --git a/requirements_all.txt b/requirements_all.txt index 1555c4e1601..1c15c49d8cb 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -218,7 +218,7 @@ aiobotocore==2.9.1 aiocomelit==0.9.0 # homeassistant.components.dhcp -aiodhcpwatcher==0.8.2 +aiodhcpwatcher==1.0.0 # homeassistant.components.dhcp aiodiscover==2.0.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index c3f9f98a7b0..33614520ee1 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -197,7 +197,7 @@ aiobotocore==2.9.1 aiocomelit==0.9.0 # homeassistant.components.dhcp -aiodhcpwatcher==0.8.2 +aiodhcpwatcher==1.0.0 # homeassistant.components.dhcp aiodiscover==2.0.0 diff --git a/tests/components/dhcp/test_init.py b/tests/components/dhcp/test_init.py index ea0b64e4219..2ba651307ed 100644 --- a/tests/components/dhcp/test_init.py +++ b/tests/components/dhcp/test_init.py @@ -145,8 +145,8 @@ async def _async_get_handle_dhcp_packet( {}, integration_matchers, ) - with patch("aiodhcpwatcher.start"): - dhcp_watcher.async_start() + with patch("aiodhcpwatcher.async_start"): + await dhcp_watcher.async_start() def _async_handle_dhcp_request(request: aiodhcpwatcher.DHCPRequest) -> None: dhcp_watcher._async_process_dhcp_request(request)