mirror of
https://github.com/mjg59/python-broadlink.git
synced 2024-11-21 22:51:41 +01:00
Fix s3.get_subdevices() (#790)
* Fix s3.get_subdevices() * Fix docstring
This commit is contained in:
parent
eb0f98a410
commit
24b9d308b6
@ -12,22 +12,34 @@ class s3(Device):
|
|||||||
TYPE = "S3"
|
TYPE = "S3"
|
||||||
MAX_SUBDEVICES = 8
|
MAX_SUBDEVICES = 8
|
||||||
|
|
||||||
def get_subdevices(self) -> list:
|
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 = []
|
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}
|
state = {"count": step, "index": index}
|
||||||
packet = self._encode(14, state)
|
packet = self._encode(14, state)
|
||||||
resp = self.send_packet(0x6A, packet)
|
resp = self.send_packet(0x6A, packet)
|
||||||
e.check_error(resp[0x22:0x24])
|
e.check_error(resp[0x22:0x24])
|
||||||
resp = self._decode(resp)
|
resp = self._decode(resp)
|
||||||
|
|
||||||
sub_devices.extend(resp["list"])
|
for device in resp["list"]:
|
||||||
if len(sub_devices) == resp["total"]:
|
did = device["did"]
|
||||||
|
if did in seen:
|
||||||
|
continue
|
||||||
|
|
||||||
|
seen.add(did)
|
||||||
|
sub_devices.append(device)
|
||||||
|
|
||||||
|
total = resp["total"]
|
||||||
|
if len(seen) >= total:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
index += step
|
||||||
|
|
||||||
return sub_devices
|
return sub_devices
|
||||||
|
|
||||||
def get_state(self, did: str = None) -> dict:
|
def get_state(self, did: str = None) -> dict:
|
||||||
|
Loading…
Reference in New Issue
Block a user