diff options
-rw-r--r-- | fun/idual/__init__.py (renamed from fun/idual/idual.py) | 37 | ||||
-rw-r--r-- | fun/idual/setup.py | 4 |
2 files changed, 36 insertions, 5 deletions
diff --git a/fun/idual/idual.py b/fun/idual/__init__.py index da0a73c309f2..4a1344e303a3 100644 --- a/fun/idual/idual.py +++ b/fun/idual/__init__.py @@ -1,7 +1,11 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -colours = { +import base64 +import broadlink +import time + +commands = { # system commands 'on' : 'JgBIAAABK5AVERQ2FBEUERQSFBEUERQSFBEUNhQ2FDUUNhQ2FDYUNRU1FBIUERQRFBIUERQRFBIUERQ2FDYUNRQ2FDYUNhQ1FQANBQ==', 'off' : 'JgBIAAABLJAUERQ2FBEUEhQRFBEUEhQRFBEUNhQ2FDUVNRQ2FDYUNhQRFDYUERQSFBEUERQSFBEUNhQRFDYUNhQ2FDUUNhQ2FAANBQ==', @@ -35,6 +39,33 @@ colours = { 'desaturate' : 'JgBIAAABLI8VERQ2FBEUERQSFBEUERURFBEUNhQ1FTUUNhQ2FDYUNRQ2FDYUNhQ1FREUERQSFBEUERQSFBEUERQ2FDYUNhQ1FQANBQ==', } +class LightController: + def __init__(self): + devices = broadlink.discover(timeout=2) + if devices == []: + raise Exception('no devices found') + devices[0].auth() + self.device = devices[0] + + def send_cmd(self, name): + packet = base64.b64decode(commands[name]) + self.device.send_data(packet) + + def lights_on(self): + self.send_cmd('on') + + def lights_off(self): + self.send_cmd('off') + if __name__ == "__main__": - # execute only if run as a script - print(colours) + # Attempt to turn the lights on, in morning mode, 10 times. + # + # The command sending doesn't always work, hence this brute-force + # approach. + ctrl = LightController() + + for i in range(9): + ctrl.send_cmd('morning') + time.sleep(0.2) + ctrl.lights_on() + time.sleep(0.8) diff --git a/fun/idual/setup.py b/fun/idual/setup.py index b218b07f7875..74156bcb0436 100644 --- a/fun/idual/setup.py +++ b/fun/idual/setup.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from setuptools import setup, find_packages +from setuptools import setup setup( name='idualctl', @@ -10,7 +10,7 @@ setup( url='https://git.tazj.in/about/fun/idual', packages=['idual'], package_dir = {'idual': ''}, - scripts = ['idual.py'], + scripts = ['__init__.py'], install_requires=['broadlink>=0.13.2'], include_package_data=True, ) |