gui: defend against lightspeed receivers that contact devices for basic information

This commit is contained in:
Peter F. Patel-Schneider 2023-12-24 07:57:34 -05:00
parent 94e9cfce8e
commit 195e28ad76
1 changed files with 19 additions and 11 deletions

View File

@ -154,16 +154,20 @@ class ReceiverListener(_listener.EventsListener):
def _status_changed(self, device, alert=_status.ALERT.NONE, reason=None): def _status_changed(self, device, alert=_status.ALERT.NONE, reason=None):
assert device is not None assert device is not None
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
if device.kind is None: try:
_log.info( device.ping()
'status_changed %r: %s, %s (%X) %s', device, 'present' if bool(device) else 'removed', device.status, if device.kind is None:
alert, reason or '' _log.info(
) 'status_changed %r: %s, %s (%X) %s', device, 'present' if bool(device) else 'removed', device.status,
else: alert, reason or ''
_log.info( )
'status_changed %r: %s %s, %s (%X) %s', device, 'paired' if bool(device) else 'unpaired', else:
'online' if device.online else 'offline', device.status, alert, reason or '' _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: if device.kind is None:
assert device == self.receiver assert device == self.receiver
@ -253,7 +257,11 @@ class ReceiverListener(_listener.EventsListener):
# Apply settings every time the device connects # Apply settings every time the device connects
if n.sub_id == 0x41: if n.sub_id == 0x41:
if _log.isEnabledFor(_INFO): 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. # If there are saved configs, bring the device's settings up-to-date.
# They will be applied when the device is marked as online. # They will be applied when the device is marked as online.
configuration.attach_to(dev) configuration.attach_to(dev)