Skip to content

Commit

Permalink
Add support for Broadlink MP1 with power meter (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipediel authored Oct 18, 2021
1 parent 9873af9 commit f2a582b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions broadlink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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, sp1, sp2, sp2s, sp3, sp3s, sp4, sp4b
from .switch import bg1, mp1, mp1s, sp1, sp2, sp2s, sp3, sp3s, sp4, sp4b

SUPPORTED_TYPES = {
sp1: {
Expand Down Expand Up @@ -133,10 +133,12 @@
},
mp1: {
0x4EB5: ("MP1-1K4S", "Broadlink"),
0x4EF7: ("MP1-1K4S", "Broadlink (OEM)"),
0x4F1B: ("MP1-1K3S2U", "Broadlink (OEM)"),
0x4F65: ("MP1-1K3S2U", "Broadlink"),
},
mp1s: {
0x4EF7: ("MP1-1K4S", "Broadlink (OEM)"),
},
lb1: {
0x5043: ("SB800TD", "Broadlink (OEM)"),
0x504E: ("LB1", "Broadlink"),
Expand Down
15 changes: 15 additions & 0 deletions broadlink/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,18 @@ def check_power(self) -> dict:
"s3": bool(data & 4),
"s4": bool(data & 8),
}


class mp1s(mp1):
"""Controls a Broadlink MP1S."""

TYPE = "MP1S"

def get_energy(self) -> float:
"""Return the power consumption in W."""
packet = bytearray([8, 0, 254, 1, 5, 1, 0, 0, 0, 45])
response = self.send_packet(0x6A, packet)
e.check_error(response[0x22:0x24])
payload = self.decrypt(response[0x38:])
energy = payload[0x7:0x4:-1].hex()
return int(energy) / 100

0 comments on commit f2a582b

Please sign in to comment.