From 412fd3dc057a2a74a60e6f38e445556f56531635 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 17 Mar 2024 08:15:14 -1000 Subject: [PATCH] Add run_immediately to usb start/stop listeners (#113658) --- homeassistant/components/usb/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/usb/__init__.py b/homeassistant/components/usb/__init__.py index 959a8f5894c..48697c98ae7 100644 --- a/homeassistant/components/usb/__init__.py +++ b/homeassistant/components/usb/__init__.py @@ -207,8 +207,12 @@ class USBDiscovery: async def async_setup(self) -> None: """Set up USB Discovery.""" await self._async_start_monitor() - self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, self.async_start) - self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.async_stop) + self.hass.bus.async_listen_once( + EVENT_HOMEASSISTANT_STARTED, self.async_start, run_immediately=True + ) + self.hass.bus.async_listen_once( + EVENT_HOMEASSISTANT_STOP, self.async_stop, run_immediately=True + ) async def async_start(self, event: Event) -> None: """Start USB Discovery and run a manual scan.""" @@ -238,7 +242,9 @@ class USBDiscovery: def _stop_observer(event: Event) -> None: observer.stop() - self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _stop_observer) + self.hass.bus.async_listen_once( + EVENT_HOMEASSISTANT_STOP, _stop_observer, run_immediately=True + ) self.observer_active = True def _get_monitor_observer(self) -> MonitorObserver | None: