diff options
author | csabavirag <mr.csaba.virag@gmail.com> | 2020-04-05T17·14+0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-05T17·14+0200 |
commit | 2bc7b06c69487b7750792e1f913905aecd46da3c (patch) | |
tree | e3a51fe9d98fce9a6d1172eba37ad3b172aaa06d | |
parent | 26a4565e58057d9b34b99bf7ac7ffa69e530ab9a (diff) |
Adding support for LB1 (RGB Light Bulb - 0x60e8) (#332)
-rw-r--r-- | broadlink/__init__.py | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/broadlink/__init__.py b/broadlink/__init__.py index 9fdee5f3546d..c9e581fd6c78 100644 --- a/broadlink/__init__.py +++ b/broadlink/__init__.py @@ -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) |