Add run_immediately to usb start/stop listeners (#113658)

pull/113702/head
J. Nick Koston 2024-03-17 08:15:14 -10:00 committed by GitHub
parent 324c922c0d
commit 412fd3dc05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 3 deletions

View File

@ -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: