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

CREAT broadlink A2 #714

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion broadlink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .hub import s3
from .light import lb1, lb2
from .remote import rm, rm4, rm4mini, rm4pro, rmmini, rmminib, rmpro
from .sensor import a1
from .sensor import a1,a2
from .switch import bg1, mp1, sp1, sp2, sp2s, sp3, sp3s, sp4, sp4b

SUPPORTED_TYPES = {
Expand Down Expand Up @@ -67,6 +67,7 @@
0xA56C: ("SP4L-EU", "Broadlink"),
0xA589: ("SP4L-UK", "Broadlink"),
0xA5D3: ("SP4L-EU", "Broadlink"),
0xA4F9: ("WS4", "Broadlink (OEM)"),
},
sp4b: {
0x5115: ("SCB1E", "Broadlink"),
Expand Down Expand Up @@ -140,6 +141,9 @@
a1: {
0x2714: ("e-Sensor", "Broadlink"),
},
a2: {
0x4F60: ("e-Sensor", "Broadlink"),
},
mp1: {
0x4EB5: ("MP1-1K4S", "Broadlink"),
0x4EF7: ("MP1-1K4S", "Broadlink (OEM)"),
Expand Down
23 changes: 23 additions & 0 deletions broadlink/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,26 @@ def check_sensors_raw(self) -> dict:
"air_quality": data[0x6],
"noise": data[0x8],
}

class a2(Device):
"""Controls a Broadlink A2."""

TYPE = "A2"


def check_sensors_raw(self) -> dict:
"""Return the state of the sensors in raw format."""
#packet = bytearray([0x1])
packet=bytes.fromhex("0c00a5a55a5ab9c0010b")
response = self.send_packet(0x6A, packet)
e.check_error(response[0x22:0x24])
payload = self.decrypt(response[0x38:])
data = payload[0x6:]

return {
"temperature": data[0xd]*255+ data[0xe],
"humidity": data[0xf]*255+ data[0x10],
"PM10": data[0x7]*255+ data[0x8],
"PM2.5": data[0x9]*255+ data[0xa],
"PM1.0": data[0xb]*255+ data[0xc],
}
Comment on lines +64 to +70
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe * 256 instead?

        return {
            "temperature": data[0xd] * 256 + data[0xe],
            "humidity": data[0xf] * 256 + data[0x10],
            "PM10": data[0x7] * 256 + data[0x8],
            "PM2.5": data[0x9] * 256 + data[0xa],
            "PM1.0": data[0xb] * 256 + data[0xc],
        }