feat(fun/idual): Support multiple simultaneous Broadlink devices

There are now two devices in this room, and they're being used
simultaneously.
This commit is contained in:
Vincent Ambo 2020-04-26 15:24:11 +01:00
parent 64894062a9
commit a34f7ef119

View file

@ -39,17 +39,22 @@ commands = {
'desaturate' : 'JgBIAAABLI8VERQ2FBEUERQSFBEUERURFBEUNhQ1FTUUNhQ2FDYUNRQ2FDYUNhQ1FREUERQSFBEUERQSFBEUERQ2FDYUNhQ1FQANBQ==', 'desaturate' : 'JgBIAAABLI8VERQ2FBEUERQSFBEUERURFBEUNhQ1FTUUNhQ2FDYUNRQ2FDYUNhQ1FREUERQSFBEUERQSFBEUERQ2FDYUNhQ1FQANBQ==',
} }
def cmd(name):
return base64.b64decode(commands[name])
class LightController: class LightController:
def __init__(self): def __init__(self):
devices = broadlink.discover(timeout=2, discover_ip_address='192.168.1.11') self.devices = broadlink.discover(timeout=10, max_devices=2)
if devices == []: if self.devices == []:
raise Exception('no devices found') raise Exception('no devices found')
devices[0].auth() for device in self.devices:
self.device = devices[0] device.auth()
def send_cmd(self, name): def send_cmd(self, name, iterations=5):
packet = base64.b64decode(commands[name]) packet = cmd(name)
self.device.send_data(packet) for i in range(iterations):
for device in self.devices:
device.send_data(packet)
def lights_on(self): def lights_on(self):
self.send_cmd('on') self.send_cmd('on')