Skip to content

Fix sensor data retrieval for Broadlink A2 devices #826

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

Open
wants to merge 2 commits into
base: master
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
29 changes: 3 additions & 26 deletions broadlink/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,16 @@ class a2(Device):

TYPE = "A2"

def _send(self, operation: int, data: Sequence = b""):
def _send(self, data: bytes) -> bytes:
"""Send a command to the device."""
packet = bytearray(12)
packet[0x02] = 0xA5
packet[0x03] = 0xA5
packet[0x04] = 0x5A
packet[0x05] = 0x5A
packet[0x08] = operation
packet[0x09] = 0x0B

if data:
data_len = len(data)
packet[0x0A] = data_len & 0xFF
packet[0x0B] = data_len >> 8
packet += bytes(2)
packet.extend(data)

checksum = sum(packet, 0xBEAF) & 0xFFFF
packet[0x06] = checksum & 0xFF
packet[0x07] = checksum >> 8

packet_len = len(packet) - 2
packet[0x00] = packet_len & 0xFF
packet[0x01] = packet_len >> 8

resp = self.send_packet(0x6A, packet)
resp = self.send_packet(0x6A, data)
e.check_error(resp[0x22:0x24])
payload = self.decrypt(resp[0x38:])
return payload

def check_sensors_raw(self) -> dict:
"""Return the state of the sensors in raw format."""
data = self._send(1)
data = self._send(bytes.fromhex("0c00a5a55a5ab9c0010b000000000000"))

return {
"temperature": data[0x13] * 256 + data[0x14],
Expand Down