2020-09-24 07:36:12 +02:00
|
|
|
"""Support for alarm kits."""
|
2021-03-31 19:27:05 +02:00
|
|
|
from . import exceptions as e
|
2020-09-17 05:41:32 +02:00
|
|
|
from .device import device
|
|
|
|
|
|
|
|
|
|
|
|
class S1C(device):
|
|
|
|
"""Controls a Broadlink S1C."""
|
|
|
|
|
2021-01-28 23:16:25 +01:00
|
|
|
TYPE = "S1C"
|
|
|
|
|
2020-09-24 07:36:12 +02:00
|
|
|
_SENSORS_TYPES = {
|
2020-11-05 20:00:42 +01:00
|
|
|
0x31: "Door Sensor", # 49 as hex
|
|
|
|
0x91: "Key Fob", # 145 as hex, as serial on fob corpse
|
|
|
|
0x21: "Motion Sensor", # 33 as hex
|
2020-09-24 07:36:12 +02:00
|
|
|
}
|
|
|
|
|
2020-09-17 05:41:32 +02:00
|
|
|
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
|
2020-11-05 20:00:42 +01:00
|
|
|
response = self.send_packet(0x6A, packet)
|
2021-03-31 19:27:05 +02:00
|
|
|
e.check_error(response[0x22:0x24])
|
2020-09-20 11:16:49 +02:00
|
|
|
payload = self.decrypt(response[0x38:])
|
2020-09-17 05:41:32 +02:00
|
|
|
if not payload:
|
|
|
|
return None
|
|
|
|
count = payload[0x4]
|
2020-09-24 07:36:12 +02:00
|
|
|
sensor_data = payload[0x6:]
|
|
|
|
sensors = [
|
2020-11-05 20:00:42 +01:00
|
|
|
bytearray(sensor_data[i * 83 : (i + 1) * 83])
|
2020-09-24 07:36:12 +02:00
|
|
|
for i in range(len(sensor_data) // 83)
|
|
|
|
]
|
|
|
|
return {
|
2020-11-05 20:00:42 +01:00
|
|
|
"count": count,
|
|
|
|
"sensors": [
|
2020-09-24 07:36:12 +02:00
|
|
|
{
|
2020-11-05 20:00:42 +01:00
|
|
|
"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(),
|
2020-09-24 07:36:12 +02:00
|
|
|
}
|
|
|
|
for sensor in sensors
|
|
|
|
if any(sensor[26:30])
|
2020-11-05 20:00:42 +01:00
|
|
|
],
|
2020-09-17 05:41:32 +02:00
|
|
|
}
|