about summary refs log tree commit diff
path: root/fun
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-04-26T14·24+0100
committerVincent Ambo <tazjin@google.com>2020-04-26T14·24+0100
commita34f7ef11999636deffd47f8efdc6847d4c676d7 (patch)
treed57f0b5c4c9dfaa9e4298816683898e144fa29eb /fun
parent64894062a9ddac94a1c65ed7b6803303ecf3b3ba (diff)
feat(fun/idual): Support multiple simultaneous Broadlink devices r/691
There are now two devices in this room, and they're being used
simultaneously.
Diffstat (limited to 'fun')
-rw-r--r--fun/idual/__init__.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/fun/idual/__init__.py b/fun/idual/__init__.py
index ad103ef049..d8a21dcc5b 100644
--- a/fun/idual/__init__.py
+++ b/fun/idual/__init__.py
@@ -39,17 +39,22 @@ commands = {
     'desaturate' : 'JgBIAAABLI8VERQ2FBEUERQSFBEUERURFBEUNhQ1FTUUNhQ2FDYUNRQ2FDYUNhQ1FREUERQSFBEUERQSFBEUERQ2FDYUNhQ1FQANBQ==',
 }
 
+def cmd(name):
+    return base64.b64decode(commands[name])
+
 class LightController:
     def __init__(self):
-        devices = broadlink.discover(timeout=2, discover_ip_address='192.168.1.11')
-        if devices == []:
+        self.devices = broadlink.discover(timeout=10, max_devices=2)
+        if self.devices == []:
             raise Exception('no devices found')
-        devices[0].auth()
-        self.device = devices[0]
+        for device in self.devices:
+            device.auth()
 
-    def send_cmd(self, name):
-        packet = base64.b64decode(commands[name])
-        self.device.send_data(packet)
+    def send_cmd(self, name, iterations=5):
+        packet = cmd(name)
+        for i in range(iterations):
+            for device in self.devices:
+                device.send_data(packet)
 
     def lights_on(self):
         self.send_cmd('on')