feat(fun/idual): Implement some utilities for controlling lights
This program, if build in its executable form, will try to turn the lights on and put them into "morning mode".
This commit is contained in:
parent
e7aaa0bc2f
commit
dff91042fd
2 changed files with 36 additions and 5 deletions
|
@ -1,7 +1,11 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
colours = {
|
import base64
|
||||||
|
import broadlink
|
||||||
|
import time
|
||||||
|
|
||||||
|
commands = {
|
||||||
# system commands
|
# system commands
|
||||||
'on' : 'JgBIAAABK5AVERQ2FBEUERQSFBEUERQSFBEUNhQ2FDUUNhQ2FDYUNRU1FBIUERQRFBIUERQRFBIUERQ2FDYUNRQ2FDYUNhQ1FQANBQ==',
|
'on' : 'JgBIAAABK5AVERQ2FBEUERQSFBEUERQSFBEUNhQ2FDUUNhQ2FDYUNRU1FBIUERQRFBIUERQRFBIUERQ2FDYUNRQ2FDYUNhQ1FQANBQ==',
|
||||||
'off' : 'JgBIAAABLJAUERQ2FBEUEhQRFBEUEhQRFBEUNhQ2FDUVNRQ2FDYUNhQRFDYUERQSFBEUERQSFBEUNhQRFDYUNhQ2FDUUNhQ2FAANBQ==',
|
'off' : 'JgBIAAABLJAUERQ2FBEUEhQRFBEUEhQRFBEUNhQ2FDUVNRQ2FDYUNhQRFDYUERQSFBEUERQSFBEUNhQRFDYUNhQ2FDUUNhQ2FAANBQ==',
|
||||||
|
@ -35,6 +39,33 @@ colours = {
|
||||||
'desaturate' : 'JgBIAAABLI8VERQ2FBEUERQSFBEUERURFBEUNhQ1FTUUNhQ2FDYUNRQ2FDYUNhQ1FREUERQSFBEUERQSFBEUERQ2FDYUNhQ1FQANBQ==',
|
'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__":
|
if __name__ == "__main__":
|
||||||
# execute only if run as a script
|
# Attempt to turn the lights on, in morning mode, 10 times.
|
||||||
print(colours)
|
#
|
||||||
|
# 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)
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='idualctl',
|
name='idualctl',
|
||||||
|
@ -10,7 +10,7 @@ setup(
|
||||||
url='https://git.tazj.in/about/fun/idual',
|
url='https://git.tazj.in/about/fun/idual',
|
||||||
packages=['idual'],
|
packages=['idual'],
|
||||||
package_dir = {'idual': ''},
|
package_dir = {'idual': ''},
|
||||||
scripts = ['idual.py'],
|
scripts = ['__init__.py'],
|
||||||
install_requires=['broadlink>=0.13.2'],
|
install_requires=['broadlink>=0.13.2'],
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue