Skip to content

Commit

Permalink
Linting, typing and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
agittins committed Nov 7, 2024
1 parent dd09064 commit c8d72b1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions custom_components/bermuda/bermuda_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def __init__(self, address, options) -> None:

def set_ref_power(self, value: float):
"""
Set a new reference power for this device and apply an interim
distance calculation.
Set a new reference power for this device and immediately apply
an interim distance calculation.
"""
self.ref_power = value
nearest_distance = 9999 # running tally to find closest scanner
Expand Down
14 changes: 6 additions & 8 deletions custom_components/bermuda/bermuda_device_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def __init__(
self.adapter: str = scandata.scanner.adapter
self.address = scanner_device.address
self.source: str = scandata.scanner.source
self.area_id: str = scanner_device.area_id
self.area_name: str = scanner_device.area_name
self.area_id: str | None = scanner_device.area_id
self.area_name: str | None = scanner_device.area_name
self.parent_device = parent_device
self.parent_device_address = parent_device.address
self.scanner_device = scanner_device # links to the source device
Expand Down Expand Up @@ -105,10 +105,10 @@ def update_advertisement(self, scandata: BluetoothScannerDevice):
claims to have data.
"""
# In case the scanner has changed it's details since startup:
self.name: str = scandata.scanner.name
self.area_id: str = self.scanner_device.area_id
self.name = scandata.scanner.name
self.area_id = self.scanner_device.area_id
self.area_name = self.scanner_device.area_name
new_stamp: float | None = None
new_stamp = None

# Only remote scanners log timestamps here (local usb adaptors do not),
if hasattr(scandata.scanner, "_discovered_device_timestamps"):
Expand Down Expand Up @@ -361,9 +361,7 @@ def calculate_data(self):
# (not so for == 0 since it might still be an invalid retreat)
break

if velocity > peak_velocity:
# but on subsequent comparisons we only care if they're faster retreats
peak_velocity = velocity
peak_velocity = max(velocity, peak_velocity)
# we've been through the history and have peak velo retreat, or the most recent
# approach velo.
velocity = peak_velocity
Expand Down
5 changes: 5 additions & 0 deletions custom_components/bermuda/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ async def async_set_native_value(self, value: float) -> None:
"""Set value."""
self.coordinator.devices[self.address].set_ref_power(value)
self.async_write_ha_state()
# Beware that STATE_DUMP_INTERVAL for restore_state's dump_state
# is 15 minutes, so if HA is killed instead of exiting cleanly,
# updated values may not be restored. Tempting to schedule a dump
# here, since updates to calib will be infrequent, but users are
# moderately likely to restart HA after playing with them.

@property
def unique_id(self):
Expand Down

0 comments on commit c8d72b1

Please sign in to comment.