Skip to content

Commit

Permalink
gui: defend against lightspeed receivers that contact devices for bas…
Browse files Browse the repository at this point in the history
…ic information
  • Loading branch information
pfps committed Dec 24, 2023
1 parent 7fbd59a commit 0b271eb
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions lib/solaar/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,20 @@ def has_stopped(self):
def _status_changed(self, device, alert=_status.ALERT.NONE, reason=None):
assert device is not None
if _log.isEnabledFor(_INFO):
if device.kind is None:
_log.info(
'status_changed %r: %s, %s (%X) %s', device, 'present' if bool(device) else 'removed', device.status,
alert, reason or ''
)
else:
_log.info(
'status_changed %r: %s %s, %s (%X) %s', device, 'paired' if bool(device) else 'unpaired',
'online' if device.online else 'offline', device.status, alert, reason or ''
)
try:
device.ping()
if device.kind is None:
_log.info(
'status_changed %r: %s, %s (%X) %s', device, 'present' if bool(device) else 'removed', device.status,
alert, reason or ''
)
else:
_log.info(
'status_changed %r: %s %s, %s (%X) %s', device, 'paired' if bool(device) else 'unpaired',
'online' if device.online else 'offline', device.status, alert, reason or ''
)
except Exception:
_log.info('status_changed for unknown device')

if device.kind is None:
assert device == self.receiver
Expand Down Expand Up @@ -253,7 +257,11 @@ def _notifications_handler(self, n):
# Apply settings every time the device connects
if n.sub_id == 0x41:
if _log.isEnabledFor(_INFO):
_log.info('connection %s for %r', n, dev)
try:
dev.ping()
_log.info('connection %s for %r', n, dev)
except Exception:
_log.info('connection %s for unknown device, number %s', n, n.devnumber)
# If there are saved configs, bring the device's settings up-to-date.
# They will be applied when the device is marked as online.
configuration.attach_to(dev)
Expand Down

0 comments on commit 0b271eb

Please sign in to comment.