mirror of
https://github.com/mjg59/python-broadlink.git
synced 2024-11-13 03:00:11 +01:00
Add support for SmartOne Alarm Kit
This commit is contained in:
parent
c85f6ac213
commit
b8cf8d073e
@ -11,6 +11,7 @@ import random
|
||||
import socket
|
||||
import sys
|
||||
import threading
|
||||
import codecs
|
||||
|
||||
def gendevice(devtype, host, mac):
|
||||
if devtype == 0: # SP1
|
||||
@ -55,6 +56,8 @@ def gendevice(devtype, host, mac):
|
||||
return a1(host=host, mac=mac)
|
||||
elif devtype == 0x4EB5 or devtype == 0x4EF7: # MP1: 0x4eb5, honyar oem mp1: 0x4ef7
|
||||
return mp1(host=host, mac=mac)
|
||||
elif devtype == 0x2722: # S1 (SmartOne Alarm Kit)
|
||||
return S1C(host=host, mac=mac)
|
||||
else:
|
||||
return device(host=host, mac=mac)
|
||||
|
||||
@ -278,7 +281,7 @@ class device:
|
||||
try:
|
||||
self.cs.sendto(packet, self.host)
|
||||
self.cs.settimeout(1)
|
||||
response = self.cs.recvfrom(1024)
|
||||
response = self.cs.recvfrom(2048)
|
||||
break
|
||||
except socket.timeout:
|
||||
if (time.time() - starttime) > self.timeout:
|
||||
@ -521,6 +524,63 @@ class rm2(rm):
|
||||
self.host = dev.host
|
||||
self.mac = dev.mac
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
class S1C(device):
|
||||
"""
|
||||
Its VERY VERY VERY DIRTY IMPLEMENTATION of S1C
|
||||
"""
|
||||
def __init__(self, *a, **kw):
|
||||
device.__init__(self, *a, **kw)
|
||||
self.type = 'S1C'
|
||||
|
||||
def get_sensors_status(self):
|
||||
packet = bytearray(16)
|
||||
packet[0] = 0x06 # 0x06 - get sensors info, 0x07 - probably add sensors
|
||||
response = self.send_packet(0x6a, packet)
|
||||
err = response[0x22] | (response[0x23] << 8)
|
||||
if err == 0:
|
||||
aes = AES.new(bytes(self.key), AES.MODE_CBC, bytes(self.iv))
|
||||
|
||||
payload = aes.decrypt(bytes(response[0x38:]))
|
||||
if payload:
|
||||
head = payload[:4]
|
||||
count = payload[0x4] #need to fix for python 2.x
|
||||
sensors = payload[0x6:]
|
||||
sensors_a = [bytearray(sensors[i * 83:(i + 1) * 83]) for i in range(len(sensors) // 83)]
|
||||
|
||||
sens_res = []
|
||||
for sens in sensors_a:
|
||||
status = ord(chr(sens[0]))
|
||||
_name = str(bytes(sens[4:26]).decode())
|
||||
_order = ord(chr(sens[1]))
|
||||
_type = ord(chr(sens[3]))
|
||||
_serial = bytes(codecs.encode(sens[26:30],"hex")).decode()
|
||||
|
||||
type_str = S1C_SENSORS_TYPES.get(_type, 'Unknown')
|
||||
|
||||
r = {
|
||||
'status': status,
|
||||
'name': _name.strip('\x00'),
|
||||
'type': type_str,
|
||||
'order': _order,
|
||||
'serial': _serial,
|
||||
}
|
||||
if r['serial'] != '00000000':
|
||||
sens_res.append(r)
|
||||
result = {
|
||||
'count': count,
|
||||
'sensors': sens_res
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
# Setup a new Broadlink device via AP Mode. Review the README to see how to enter AP Mode.
|
||||
# Only tested with Broadlink RM3 Mini (Blackbean)
|
||||
def setup(ssid, password, security_mode):
|
||||
|
Loading…
Reference in New Issue
Block a user