diff --git a/src/control_any.py b/src/control_any.py new file mode 100644 index 0000000..19cd1e8 --- /dev/null +++ b/src/control_any.py @@ -0,0 +1,49 @@ +# control_any.py 17/03/2016 D.J.Whale +# +# Control Energenie MiHome Adaptor or AdaptorPlus sockets +# and also ENER002 legacy green button sockets. + +# Shows how to use the registry to create devices. +# You should first run setup_tool.py and join some sockets + +import time +import energenie + +APP_DELAY = 2 # number of seconds to toggle the socket switches + + +#----- TEST APPLICATION ------------------------------------------------------- + +def socket_toggle_loop(): + """Toggle the switch on all devices in the directory""" + + global socket_state + + print("Setting socket switches to %s" % str(socket_state)) + + for device in energenie.registry.devices(): #TODO: Make energenie.registry iterable + # Only try to toggle the switch for devices that actually have a switch + + if device.has_switch(): + print(" socket id %s" % device) + device.set_switch(socket_state) + + socket_state = not socket_state + time.sleep(APP_DELAY) + + +if __name__ == "__main__": + + print("starting socket tester") + energenie.init() + + socket_state = False + + try: + while True: + socket_toggle_loop() + + finally: + energenie.finished() + +# END diff --git a/src/control_both.py b/src/control_both.py deleted file mode 100644 index d6a1511..0000000 --- a/src/control_both.py +++ /dev/null @@ -1,44 +0,0 @@ -# control_both.py 15/05/2016 D.J.Whale -# -# A simple demo of combining both FSK (MiHome) and OOK (green button legacy) - -import time -import energenie - -GREEN_ID = 1 # using default house code of 0x6C6C6 -PURPLE_ID = 0x68b - -green = energenie.Devices.ENER002(GREEN_ID) -purple = energenie.Devices.MIHO005(PURPLE_ID) - -def switch_loop(): - print("Turning green ON") - green.turn_on() - time.sleep(0.5) - - print("Turning purple ON") - purple.turn_on() - time.sleep(2) - - print("Turning green OFF") - green.turn_off() - time.sleep(0.5) - - print("Turning purple OFF") - purple.turn_off() - time.sleep(2) - - -if __name__ == "__main__": - - print("starting combined socket tester") - energenie.init() - - try: - while True: - switch_loop() - - finally: - energenie.finished() - -# END diff --git a/src/control_mihome.py b/src/control_mihome.py deleted file mode 100644 index 1b9eed3..0000000 --- a/src/control_mihome.py +++ /dev/null @@ -1,48 +0,0 @@ -# control_mihome.py 17/03/2016 D.J.Whale -# -# Control Energenie MiHome Adaptor or AdaptorPlus sockets - -# Shows how to use the registry to create devices. -# You should first run setup_tool.py and join some sockets - -import time -import energenie - -APP_DELAY = 2 # number of seconds to toggle the socket switches - - -#----- TEST APPLICATION ------------------------------------------------------- - -def socket_toggle_loop(): - """Toggle the switch on all devices in the directory""" - - global socket_state - - print("Setting socket switches to %s" % str(socket_state)) - - for device in energenie.registry.devices(): #TODO: Make energenie.registry iterable - # Only try to toggle the switch for devices that actually have a switch - - if device.has_switch(): - print(" socket id %s" % device) - device.set_switch(socket_state) - - socket_state = not socket_state - time.sleep(APP_DELAY) - - -if __name__ == "__main__": - - print("starting socket tester") - energenie.init() - - socket_state = False - - try: - while True: - socket_toggle_loop() - - finally: - energenie.finished() - -# END