1
0
mirror of https://github.com/mjg59/python-broadlink.git synced 2024-11-22 07:00:12 +01:00
python-broadlink/broadlink/alarm.py
Felipe Martins Diel 1a8ee21a34 Make better use of namespaces (#564)
Use namespaces for typing and exceptions.
2021-04-26 17:57:02 -03:00

46 lines
1.4 KiB
Python

"""Support for alarm kits."""
from . import exceptions as e
from .device import device
class S1C(device):
"""Controls a Broadlink S1C."""
TYPE = "S1C"
_SENSORS_TYPES = {
0x31: "Door Sensor", # 49 as hex
0x91: "Key Fob", # 145 as hex, as serial on fob corpse
0x21: "Motion Sensor", # 33 as hex
}
def get_sensors_status(self) -> dict:
"""Return the state of the sensors."""
packet = bytearray(16)
packet[0] = 0x06 # 0x06 - get sensors info, 0x07 - probably add sensors
response = self.send_packet(0x6A, packet)
e.check_error(response[0x22:0x24])
payload = self.decrypt(response[0x38:])
if not payload:
return None
count = payload[0x4]
sensor_data = payload[0x6:]
sensors = [
bytearray(sensor_data[i * 83 : (i + 1) * 83])
for i in range(len(sensor_data) // 83)
]
return {
"count": count,
"sensors": [
{
"status": sensor[0],
"name": sensor[4:26].decode().strip("\x00"),
"type": self._SENSORS_TYPES.get(sensor[3], "Unknown"),
"order": sensor[1],
"serial": sensor[26:30].hex(),
}
for sensor in sensors
if any(sensor[26:30])
],
}