Skip to content

Commit

Permalink
receiver: Refactor unpair code
Browse files Browse the repository at this point in the history
  • Loading branch information
MattHag committed Mar 3, 2024
1 parent c8204fe commit 8148373
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/logitech_receiver/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,7 @@ def _unpair_device(self, key, force=False):
del self._devices[key]
logger.warning("%s removed device %s", self, dev)
else:
if self.receiver_kind == "bolt":
reply = self.write_register(_R.bolt_pairing, 0x03, key)
else:
reply = self.write_register(_R.receiver_pairing, 0x03, key)
reply = self._unpair_device_per_receiver(key)
if reply:
# invalidate the device
dev.online = False
Expand All @@ -358,6 +355,10 @@ def _unpair_device(self, key, force=False):
logger.error("%s failed to unpair device %s", self, dev)
raise Exception("failed to unpair device %s: %s" % (dev.name, key))

def _unpair_device_per_receiver(self, key):
"""Receiver specific unpairing."""
return self.write_register(_R.receiver_pairing, 0x03, key)

def __len__(self):
return len([d for d in self._devices.values() if d is not None])

Expand Down Expand Up @@ -428,6 +429,10 @@ def pair_device(self, pair=True, slot=0, address=b"\0\0\0\0\0\0", authentication
return True
logger.warning("%s: failed to %s device %s", self, "pair" if pair else "unpair", address)

def _unpair_device_per_receiver(self, key):
"""Receiver specific unpairing."""
return self.write_register(_R.bolt_pairing, 0x03, key)


class UnifyingReceiver(Receiver):
def __init__(self, product_info, handle, path, product_id, setting_callback=None):
Expand Down

0 comments on commit 8148373

Please sign in to comment.