From 2832f4e8ae7219fa495a11b0d2597d2e072c2748 Mon Sep 17 00:00:00 2001 From: Felipe Martins Diel Date: Wed, 10 Apr 2024 23:44:12 -0300 Subject: [PATCH 1/2] Fix s3.get_subdevices() --- broadlink/hub.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/broadlink/hub.py b/broadlink/hub.py index 07b02e82..24357a24 100644 --- a/broadlink/hub.py +++ b/broadlink/hub.py @@ -12,22 +12,34 @@ class s3(Device): TYPE = "S3" MAX_SUBDEVICES = 8 - def get_subdevices(self) -> list: + def get_subdevices(self, step: int = 5) -> list: """Return the lit of sub devices.""" + total = self.MAX_SUBDEVICES sub_devices = [] - step = 5 + seen = set() + index = 0 - for index in range(0, self.MAX_SUBDEVICES, step): + while index < total: state = {"count": step, "index": index} packet = self._encode(14, state) resp = self.send_packet(0x6A, packet) e.check_error(resp[0x22:0x24]) resp = self._decode(resp) - sub_devices.extend(resp["list"]) - if len(sub_devices) == resp["total"]: + for device in resp["list"]: + did = device["did"] + if did in seen: + continue + + seen.add(did) + sub_devices.append(device) + + total = resp["total"] + if len(seen) >= total: break + index += step + return sub_devices def get_state(self, did: str = None) -> dict: From b8bf87232fb356e4383e826cbcbe171e8cdc2497 Mon Sep 17 00:00:00 2001 From: Felipe Martins Diel Date: Wed, 10 Apr 2024 23:48:20 -0300 Subject: [PATCH 2/2] Fix docstring --- broadlink/hub.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/broadlink/hub.py b/broadlink/hub.py index 24357a24..cb24dc8d 100644 --- a/broadlink/hub.py +++ b/broadlink/hub.py @@ -13,7 +13,7 @@ class s3(Device): MAX_SUBDEVICES = 8 def get_subdevices(self, step: int = 5) -> list: - """Return the lit of sub devices.""" + """Return a list of sub devices.""" total = self.MAX_SUBDEVICES sub_devices = [] seen = set()