diff --git a/src/control_any.py b/src/control_any.py deleted file mode 100644 index 19cd1e8..0000000 --- a/src/control_any.py +++ /dev/null @@ -1,49 +0,0 @@ -# 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_any_noreg.py b/src/control_any_noreg.py new file mode 100644 index 0000000..ea19bf9 --- /dev/null +++ b/src/control_any_noreg.py @@ -0,0 +1,51 @@ +# control_any_noreg.py 17/03/2016 D.J.Whale +# +# Control up to 4 legacy green-button sockets (or MiHome control-only sockets) + +import time +import energenie + +APP_DELAY = 1 + +# Devices that use the standard Energenie house code +all_sockets = energenie.Devices.ENER002(0) +socket1 = energenie.Devices.ENER002(1) +socket2 = energenie.Devices.ENER002(2) +socket3 = energenie.Devices.ENER002(3) +socket4 = energenie.Devices.ENER002(4) + +# A device that uses a custom house code (e.g. learnt from a hand controller) +socket5 = energenie.Devices.ENER002((0x1234, 1)) + +sockets = [all_sockets, socket1, socket2, socket3, socket4, socket5] + + +def legacy_socket_loop(): + """Turn all sockets on or off every few seconds""" + + while True: + for socket_no in range(len(sockets)): + # socket_no 0 is ALL, then 1=1, 2=2, 3=3, 4=4 + # ON + print("socket %d ON" % socket_no) + sockets[socket_no].turn_on() + time.sleep(APP_DELAY) + + # OFF + print("socket %d OFF" % socket_no) + sockets[socket_no].turn_off() + time.sleep(APP_DELAY) + + +if __name__ == "__main__": + print("starting legacy socket tester") + + energenie.init() + + try: + legacy_socket_loop() + finally: + energenie.finished() + +# END + diff --git a/src/control_any_reg.py b/src/control_any_reg.py new file mode 100644 index 0000000..19cd1e8 --- /dev/null +++ b/src/control_any_reg.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_legacy.py b/src/control_legacy.py deleted file mode 100644 index 298063a..0000000 --- a/src/control_legacy.py +++ /dev/null @@ -1,51 +0,0 @@ -# legacy.py 17/03/2016 D.J.Whale -# -# Control up to 4 legacy green-button sockets (or MiHome control-only sockets) - -import time -import energenie - -APP_DELAY = 1 - -# Devices that use the standard Energenie house code -all_sockets = energenie.Devices.ENER002(0) -socket1 = energenie.Devices.ENER002(1) -socket2 = energenie.Devices.ENER002(2) -socket3 = energenie.Devices.ENER002(3) -socket4 = energenie.Devices.ENER002(4) - -# A device that uses a custom house code (e.g. learnt from a hand controller) -socket5 = energenie.Devices.ENER002((0x1234, 1)) - -sockets = [all_sockets, socket1, socket2, socket3, socket4, socket5] - - -def legacy_socket_loop(): - """Turn all sockets on or off every few seconds""" - - while True: - for socket_no in range(len(sockets)): - # socket_no 0 is ALL, then 1=1, 2=2, 3=3, 4=4 - # ON - print("socket %d ON" % socket_no) - sockets[socket_no].turn_on() - time.sleep(APP_DELAY) - - # OFF - print("socket %d OFF" % socket_no) - sockets[socket_no].turn_off() - time.sleep(APP_DELAY) - - -if __name__ == "__main__": - print("starting legacy socket tester") - - energenie.init() - - try: - legacy_socket_loop() - finally: - energenie.finished() - -# END -