Skip to content

Commit

Permalink
(bugfix): Fix init failure with usb bluetooth
Browse files Browse the repository at this point in the history
Bluetooth adaptors don't store a log of device
timestamps, so we now check for those before
trying to access them.
  • Loading branch information
agittins committed Aug 24, 2023
1 parent de38f6a commit d58624d
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions custom_components/bermuda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,26 @@ async def _async_update_data(self):
if discovered.scanner.source not in self.devices:
self._refresh_scanners()

# FIXME: Find a method or request one be added for this
# pylint: disable-next=protected-access
stamps = discovered.scanner._discovered_device_timestamps
scanner_stamp = stamps[service_info.address]
if device.last_seen < scanner_stamp:
device.last_seen = scanner_stamp
# Only remote scanners log timestamps (so not local usb adaptors),
# so check if the dict is there at all first...
if "_discovered_device_timestamps" in vars(discovered.scanner):
# FIXME: Find a method or request one be added for this
# pylint: disable-next=protected-access
stamps = discovered.scanner._discovered_device_timestamps
scanner_stamp = stamps[service_info.address]
if device.last_seen < scanner_stamp:
device.last_seen = scanner_stamp
else:
# FIXME: Work out how to handle a bluetooth adaptors reports.
# Options are: (a) find a timestamp somehwere (b) if we are
# doing updates as ads come in, use now()-some_safety_offset.
# For now, pretend it's as young as the previous update...
if device.last_seen < (
MONOTONIC_TIME() - SCAN_INTERVAL.total_seconds()
):
device.last_seen = (
MONOTONIC_TIME() - SCAN_INTERVAL.total_seconds()
)

# Just replace the scanner entries outright...
device.scanners[discovered.scanner.source] = BermudaDeviceScanner(
Expand Down

0 comments on commit d58624d

Please sign in to comment.