@@ -147,6 +147,7 @@ def __init__(
147147 self .battery_info = None
148148 self .link_encrypted = None
149149 self ._active = None # lags self.online - is used to help determine when to setup devices
150+ self .present = True # used for devices that are integral with their receiver but that separately be disconnected
150151
151152 self ._feature_settings_checked = False
152153 self ._gestures_lock = threading .Lock ()
@@ -432,6 +433,8 @@ def read_battery(self):
432433 def changed (self , active = None , alert = Alert .NONE , reason = None , push = False ):
433434 """The status of the device had changed, so invoke the status callback.
434435 Also push notifications and settings to the device when necessary."""
436+ if logger .isEnabledFor (logging .DEBUG ):
437+ logger .debug ("device %d changing: active=%s %s present=%s" , self .number , active , self ._active , self .present )
435438 if active is not None :
436439 self .online = active
437440 was_active , self ._active = self ._active , active
@@ -533,7 +536,8 @@ def feature_request(self, feature, function=0x00, *params, no_reply=False):
533536 return hidpp20 .feature_request (self , feature , function , * params , no_reply = no_reply )
534537
535538 def ping (self ):
536- """Checks if the device is online, returns True of False"""
539+ """Checks if the device is online and present, returns True of False.
540+ Some devices are integral with their receiver but may not be present even if the receiver responds to ping."""
537541 long = self .hidpp_long is True or (
538542 self .hidpp_long is None and (self .bluetooth or self ._protocol is not None and self ._protocol >= 2.0 )
539543 )
@@ -542,9 +546,11 @@ def ping(self):
542546 protocol = self .low_level .ping (handle , self .number , long_message = long )
543547 except exceptions .NoReceiver : # if ping fails, device is offline
544548 protocol = None
545- self .online = protocol is not None
549+ self .online = protocol is not None and self . present
546550 if protocol :
547551 self ._protocol = protocol
552+ if logger .isEnabledFor (logging .DEBUG ):
553+ logger .debug ("pinged %s: online %s protocol %s present %s" , self .online , protocol , self .present )
548554 return self .online
549555
550556 def notify_devices (self ): # no need to notify, as there are none
0 commit comments