mirror of
https://github.com/mjg59/python-broadlink.git
synced 2024-11-21 22:51:41 +01:00
Adding support for LB1 (RGB Light Bulb - 0x60e8) (#332)
This commit is contained in:
parent
26a4565e58
commit
2bc7b06c69
@ -61,7 +61,8 @@ def gendevice(devtype, host, mac, name=None, cloud=None):
|
||||
hysen: [0x4EAD], # Hysen controller
|
||||
S1C: [0x2722], # S1 (SmartOne Alarm Kit)
|
||||
dooya: [0x4E4D], # Dooya DT360E (DOOYA_CURTAIN_V2)
|
||||
bg1: [0x51E3] # BG Electrical Smart Power Socket
|
||||
bg1: [0x51E3], # BG Electrical Smart Power Socket
|
||||
lb1 : [0x60c8] # RGB Smart Bulb
|
||||
}
|
||||
|
||||
# Look for the class associated to devtype in devices
|
||||
@ -972,6 +973,65 @@ class dooya(device):
|
||||
current = self.get_percentage()
|
||||
self.stop()
|
||||
|
||||
class lb1(device):
|
||||
state_dict = []
|
||||
effect_map_dict = { 'lovely color' : 0,
|
||||
'flashlight' : 1,
|
||||
'lightning' : 2,
|
||||
'color fading' : 3,
|
||||
'color breathing' : 4,
|
||||
'multicolor breathing' : 5,
|
||||
'color jumping' : 6,
|
||||
'multicolor jumping' : 7 }
|
||||
|
||||
def __init__(self, host, mac, devtype):
|
||||
device.__init__(self, host, mac, devtype)
|
||||
self.type = "SmartBulb"
|
||||
|
||||
def send_command(self,command, type = 'set'):
|
||||
packet = bytearray(16+(int(len(command)/16) + 1)*16)
|
||||
packet[0x02] = 0xa5
|
||||
packet[0x03] = 0xa5
|
||||
packet[0x04] = 0x5a
|
||||
packet[0x05] = 0x5a
|
||||
packet[0x08] = 0x02 if type == "set" else 0x01 # 0x01 => query, # 0x02 => set
|
||||
packet[0x09] = 0x0b
|
||||
packet[0x0a] = len(command)
|
||||
packet[0x0e:] = map(ord, command)
|
||||
|
||||
checksum = adler32(packet, 0xbeaf) & 0xffff
|
||||
|
||||
packet[0x00] = (0x0c + len(command)) & 0xff
|
||||
packet[0x06] = checksum & 0xff # Checksum 1 position
|
||||
packet[0x07] = checksum >> 8 # Checksum 2 position
|
||||
|
||||
response = self.send_packet(0x6a, packet)
|
||||
|
||||
err = response[0x36] | (response[0x37] << 8)
|
||||
if err != 0:
|
||||
return None
|
||||
payload = self.decrypt(bytes(response[0x38:]))
|
||||
|
||||
responseLength = int(payload[0x0a]) | (int(payload[0x0b]) << 8)
|
||||
if responseLength > 0:
|
||||
self.state_dict = json.loads(payload[0x0e:0x0e+responseLength])
|
||||
|
||||
def set_json(self, jsonstr):
|
||||
reconvert = json.loads(jsonstr)
|
||||
if 'bulb_sceneidx' in reconvert.keys():
|
||||
reconvert['bulb_sceneidx'] = self.effect_map_dict.get(reconvert['bulb_sceneidx'], 255)
|
||||
|
||||
self.send_command(json.dumps(reconvert))
|
||||
return json.dumps(self.state_dict)
|
||||
|
||||
def set_state(self, state):
|
||||
cmd = '{"pwr":%d}' % (1 if state == "ON" or state == 1 else 0)
|
||||
self.send_command(cmd)
|
||||
|
||||
def get_state(self):
|
||||
cmd = "{}"
|
||||
self.send_command(cmd)
|
||||
return self.state_dict
|
||||
|
||||
# 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)
|
||||
|
Loading…
Reference in New Issue
Block a user