Commit f0ff045 1 parent 1d30743 commit f0ff045 Copy full SHA for f0ff045
File tree 3 files changed +14
-7
lines changed
3 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ cdef class BaseHaScanner:
30
30
31
31
cpdef tuple get_discovered_device_advertisement_data(self , str address)
32
32
33
+ cpdef float time_since_last_detection(self )
34
+
33
35
34
36
cdef class BaseHaRemoteScanner(BaseHaScanner):
35
37
Original file line number Diff line number Diff line change @@ -88,6 +88,10 @@ def __init__(
88
88
adapter = self .adapter ,
89
89
)
90
90
91
+ def time_since_last_detection (self ) -> float :
92
+ """Return the time since the last detection."""
93
+ return monotonic_time_coarse () - self ._last_detection
94
+
91
95
def async_setup (self ) -> CALLBACK_TYPE :
92
96
"""Set up the scanner."""
93
97
self ._loop = asyncio .get_running_loop ()
@@ -123,7 +127,7 @@ def _async_call_scanner_watchdog(self) -> None:
123
127
124
128
def _async_watchdog_triggered (self ) -> bool :
125
129
"""Check if the watchdog has been triggered."""
126
- time_since_last_detection = monotonic_time_coarse () - self ._last_detection
130
+ time_since_last_detection = self .time_since_last_detection ()
127
131
_LOGGER .debug (
128
132
"%s: Scanner watchdog time_since_last_detection: %s" ,
129
133
self .name ,
@@ -139,13 +143,14 @@ def _async_scanner_watchdog(self) -> None:
139
143
is triggered.
140
144
"""
141
145
if self ._async_watchdog_triggered ():
142
- _LOGGER .info (
146
+ _LOGGER .log (
147
+ logging .WARNING if self .scanning else logging .DEBUG ,
143
148
(
144
149
"%s: Bluetooth scanner has gone quiet for %ss, check logs on the"
145
150
" scanner device for more information"
146
151
),
147
152
self .name ,
148
- SCANNER_WATCHDOG_TIMEOUT ,
153
+ self . time_since_last_detection () ,
149
154
)
150
155
self .scanning = False
151
156
return
Original file line number Diff line number Diff line change @@ -508,10 +508,11 @@ def _async_scanner_watchdog(self) -> None:
508
508
self .name ,
509
509
)
510
510
return
511
- _LOGGER .info (
511
+ _LOGGER .log (
512
+ logging .WARNING if self .scanning else logging .DEBUG ,
512
513
"%s: Bluetooth scanner has gone quiet for %ss, restarting" ,
513
514
self .name ,
514
- SCANNER_WATCHDOG_TIMEOUT ,
515
+ self . time_since_last_detection () ,
515
516
)
516
517
# Immediately mark the scanner as not scanning
517
518
# since the restart task will have to wait for the lock
@@ -521,7 +522,6 @@ def _async_scanner_watchdog(self) -> None:
521
522
async def _async_restart_scanner (self ) -> None :
522
523
"""Restart the scanner."""
523
524
async with self ._start_stop_lock :
524
- time_since_last_detection = monotonic_time_coarse () - self ._last_detection
525
525
# Stop the scanner but not the watchdog
526
526
# since we want to try again later if it's still quiet
527
527
await self ._async_stop_scanner ()
@@ -530,7 +530,7 @@ async def _async_restart_scanner(self) -> None:
530
530
# do the reset.
531
531
if (
532
532
self ._start_time == self ._last_detection
533
- or time_since_last_detection > SCANNER_WATCHDOG_MULTIPLE
533
+ or self . time_since_last_detection () > SCANNER_WATCHDOG_MULTIPLE
534
534
):
535
535
await self ._async_reset_adapter ()
536
536
try :
You can’t perform that action at this time.
0 commit comments