Skip to content

Commit

Permalink
fix: prevent non-scanner devices being saved to config (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
agittins committed Feb 27, 2024
1 parent de71f9e commit 07b0aab
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions custom_components/bermuda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,15 +750,22 @@ def _refresh_scanners(
for scanner in scanners:
addresses.add(scanner.scanner.source.upper())

if do_full_scan or len(addresses) > 0:
# If we are doing a full scan, add all the known
# scanner addresses to the list, since that will cover
# the scanners that have been restored from config.data
if do_full_scan:
for address in self.scanner_list:
addresses.add(address)

if len(addresses) > 0:
# FIXME: Really? This can't possibly be a sensible nesting of loops.
# should probably look at the API. Anyway, we are checking any devices
# that have a "mac" or "bluetooth" connection,
for dev_entry in self.hass.data["device_registry"].devices.data.values():
for dev_connection in dev_entry.connections:
if dev_connection[0] in ["mac", "bluetooth"]:
found_address = dev_connection[1].upper()
if do_full_scan or found_address in addresses:
if found_address in addresses:
scandev = self._get_device(found_address)
if scandev is None:
# It's a new scanner, we will need to update our saved config.
Expand Down

0 comments on commit 07b0aab

Please sign in to comment.