Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the FastCon technology #669

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions broadlink/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@ class sp4(Device):
"""Controls a Broadlink SP4."""

TYPE = "SP4"
MAX_SUBDEVICES = 8

def get_subdevices(self) -> list:
"""Return the lit of sub devices."""
sub_devices = []
step = 5

for index in range(0, self.MAX_SUBDEVICES, step):
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"]:
break

return sub_devices

def set_power(self, pwr: bool) -> None:
"""Set the power state of the device."""
Expand All @@ -127,6 +146,7 @@ def set_nightlight(self, ntlight: bool) -> None:

def set_state(
self,
did: str = None,
pwr: bool = None,
ntlight: bool = None,
indicator: bool = None,
Expand All @@ -136,6 +156,8 @@ def set_state(
) -> dict:
"""Set state of device."""
state = {}
if did is not None:
state["did"] = did
if pwr is not None:
state["pwr"] = int(bool(pwr))
if ntlight is not None:
Expand Down Expand Up @@ -163,9 +185,13 @@ def check_nightlight(self) -> bool:
state = self.get_state()
return bool(state["ntlight"])

def get_state(self) -> dict:
"""Get full state of device."""
packet = self._encode(1, {})
def get_state(self, did: str = None) -> dict:
"""Return the state of the device."""
state = {}
if did is not None:
state["did"] = did

packet = self._encode(1, state)
response = self.send_packet(0x6A, packet)
return self._decode(response)

Expand Down