Skip to content

Commit

Permalink
Add support for BG Electrical EHC31 (0x6480)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipediel committed Apr 9, 2024
1 parent cacebe7 commit 1f3aca6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
5 changes: 4 additions & 1 deletion broadlink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .light import lb1, lb2
from .remote import rm, rm4, rm4mini, rm4pro, rmmini, rmminib, rmpro
from .sensor import a1
from .switch import bg1, mp1, mp1s, sp1, sp2, sp2s, sp3, sp3s, sp4, sp4b
from .switch import bg1, ehc31, mp1, mp1s, sp1, sp2, sp2s, sp3, sp3s, sp4, sp4b

SUPPORTED_TYPES = {
sp1: {
Expand Down Expand Up @@ -183,6 +183,9 @@
bg1: {
0x51E3: ("BG800/BG900", "BG Electrical"),
},
ehc31: {
0x6480: ("EHC31", "BG Electrical"),
},
}


Expand Down
56 changes: 56 additions & 0 deletions broadlink/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,62 @@ def _decode(self, response: bytes) -> dict:
return state


class ehc31(bg1):
"""Controls a BG Electrical smart extension lead."""

TYPE = "EHC31"

def set_state(
self,
pwr: bool = None,
pwr1: bool = None,
pwr2: bool = None,
pwr3: bool = None,
maxworktime1: int = None,
maxworktime2: int = None,
maxworktime3: int = None,
idcbrightness: int = None,
childlock: bool = None,
childlock1: bool = None,
childlock2: bool = None,
childlock3: bool = None,
childlock4: bool = None,
) -> dict:
"""Set the power state of the device."""
state = {}
if pwr is not None:
state["pwr"] = int(bool(pwr))
if pwr1 is not None:
state["pwr1"] = int(bool(pwr1))
if pwr2 is not None:
state["pwr2"] = int(bool(pwr2))
if pwr3 is not None:
state["pwr3"] = int(bool(pwr3))
if maxworktime1 is not None:
state["maxworktime1"] = maxworktime1
if maxworktime2 is not None:
state["maxworktime2"] = maxworktime2
if maxworktime3 is not None:
state["maxworktime3"] = maxworktime3
if idcbrightness is not None:
state["idcbrightness"] = idcbrightness
if childlock is not None:
state["childlock"] = int(bool(childlock))
if childlock1 is not None:
state["childlock1"] = int(bool(childlock1))
if childlock2 is not None:
state["childlock2"] = int(bool(childlock2))
if childlock3 is not None:
state["childlock3"] = int(bool(childlock3))
if childlock4 is not None:
state["childlock4"] = int(bool(childlock4))

packet = self._encode(2, state)
response = self.send_packet(0x6A, packet)
e.check_error(response[0x22:0x24])
return self._decode(response)


class mp1(Device):
"""Controls a Broadlink MP1."""

Expand Down

0 comments on commit 1f3aca6

Please sign in to comment.