mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Avoid creating a task in the bluetooth watchdog when everything is OK (#84669)
This commit is contained in:
parent
4296f227cf
commit
94d1375be3
@ -103,7 +103,8 @@ class BaseHaScanner(ABC):
|
|||||||
)
|
)
|
||||||
return time_since_last_detection > SCANNER_WATCHDOG_TIMEOUT
|
return time_since_last_detection > SCANNER_WATCHDOG_TIMEOUT
|
||||||
|
|
||||||
async def _async_scanner_watchdog(self, now: datetime.datetime) -> None:
|
@hass_callback
|
||||||
|
def _async_scanner_watchdog(self, now: datetime.datetime) -> None:
|
||||||
"""Check if the scanner is running.
|
"""Check if the scanner is running.
|
||||||
|
|
||||||
Override this method if you need to do something else when the watchdog is triggered.
|
Override this method if you need to do something else when the watchdog is triggered.
|
||||||
|
@ -309,7 +309,8 @@ class HaScanner(BaseHaScanner):
|
|||||||
self._async_setup_scanner_watchdog()
|
self._async_setup_scanner_watchdog()
|
||||||
await restore_discoveries(self.scanner, self.adapter)
|
await restore_discoveries(self.scanner, self.adapter)
|
||||||
|
|
||||||
async def _async_scanner_watchdog(self, now: datetime) -> None:
|
@hass_callback
|
||||||
|
def _async_scanner_watchdog(self, now: datetime) -> None:
|
||||||
"""Check if the scanner is running."""
|
"""Check if the scanner is running."""
|
||||||
if not self._async_watchdog_triggered():
|
if not self._async_watchdog_triggered():
|
||||||
return
|
return
|
||||||
@ -324,6 +325,10 @@ class HaScanner(BaseHaScanner):
|
|||||||
self.name,
|
self.name,
|
||||||
SCANNER_WATCHDOG_TIMEOUT,
|
SCANNER_WATCHDOG_TIMEOUT,
|
||||||
)
|
)
|
||||||
|
self.hass.async_create_task(self._async_restart_scanner())
|
||||||
|
|
||||||
|
async def _async_restart_scanner(self) -> None:
|
||||||
|
"""Restart the scanner."""
|
||||||
async with self._start_stop_lock:
|
async with self._start_stop_lock:
|
||||||
time_since_last_detection = MONOTONIC_TIME() - self._last_detection
|
time_since_last_detection = MONOTONIC_TIME() - self._last_detection
|
||||||
# Stop the scanner but not the watchdog
|
# Stop the scanner but not the watchdog
|
||||||
|
Loading…
x
Reference in New Issue
Block a user