Skip to content

Commit

Permalink
receiver: Refactor device_codename
Browse files Browse the repository at this point in the history
Provide default implementation and Bolt overrides it. This removes the
need for if else of receiver_kind.

Related pwr-Solaar#2350
  • Loading branch information
MattHag committed Mar 3, 2024
1 parent ea984cf commit 2549fc6
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/logitech_receiver/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,10 @@ def enable_connection_notifications(self, enable=True):
return flag_bits

def device_codename(self, n):
if self.receiver_kind == "bolt":
codename = self.read_register(_R.receiver_info, _IR.bolt_device_name + n, 0x01)
if codename:
codename = codename[3 : 3 + min(14, ord(codename[2:3]))]
return codename.decode("ascii")
else:
codename = self.read_register(_R.receiver_info, _IR.device_name + n - 1)
if codename:
codename = codename[2 : 2 + ord(codename[1:2])]
return codename.decode("ascii")
codename = self.read_register(_R.receiver_info, _IR.device_name + n - 1)
if codename:
codename = codename[2 : 2 + ord(codename[1:2])]
return codename.decode("ascii")

def device_pairing_information(self, n: int) -> dict:
"""Return information from pairing registers (and elsewhere when necessary)"""
Expand Down Expand Up @@ -408,6 +402,12 @@ def initialize(self, product_info: dict):
self.max_devices = product_info.get("max_devices", 1)
self.may_unpair = product_info.get("may_unpair", False)

def device_codename(self, n):
codename = self.read_register(_R.receiver_info, _IR.bolt_device_name + n, 0x01)
if codename:
codename = codename[3 : 3 + min(14, ord(codename[2:3]))]
return codename.decode("ascii")

def discover(self, cancel=False, timeout=30):
"""Discover Logitech Bolt devices."""
if self.handle:
Expand Down

0 comments on commit 2549fc6

Please sign in to comment.