diff --git a/src/control_legacy.py b/src/control_legacy.py index c51ea99..298063a 100644 --- a/src/control_legacy.py +++ b/src/control_legacy.py @@ -6,68 +6,25 @@ import energenie APP_DELAY = 1 -##energenie.radio.DEBUG = True +# 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) -sockets = [all_sockets, socket1, socket2, socket3, socket4] +# A device that uses a custom house code (e.g. learnt from a hand controller) +socket5 = energenie.Devices.ENER002((0x1234, 1)) -try: - readin = raw_input # Python 2 -except NameError: - readin = input # Python 3 - - -def get_yes_no(): - """Get a simple yes or no answer""" - answer = readin() - if answer.upper() in ['Y', 'YES']: - return True - return False - - -def legacy_learn_mode(): - """Give the user a chance to learn any sockets""" - print("Do you want to program any sockets?") - y = get_yes_no() - if not y: - return - - for socket_no in range(1,5): - print("Learn socket %d?" % socket_no) - y = get_yes_no() - if y: - print("Press the LEARN button on any socket %d for 5 secs until LED flashes" % socket_no) - readin("press ENTER when LED is flashing") - - print("ON") - sockets[1].turn_on() - time.sleep(APP_DELAY) - - print("Device should now be programmed") - - print("Testing....") - for i in range(4): - time.sleep(APP_DELAY) - print("OFF") - sockets[socket_no].turn_off() - - time.sleep(APP_DELAY) - print("ON") - sockets[socket_no].turn_on() - - print("Test completed") +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(5): + 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) @@ -80,25 +37,13 @@ time.sleep(APP_DELAY) -def socket1_loop(): - """Repeatedly turn socket 1 ON then OFF""" - while True: - print("Plug 1 ON") - sockets[1].turn_on() - time.sleep(APP_DELAY) - - print("Plug 1 OFF") - sockets[1].turn_off() - time.sleep(APP_DELAY) - if __name__ == "__main__": print("starting legacy socket tester") + energenie.init() try: - legacy_learn_mode() legacy_socket_loop() - ##socket1_loop() finally: energenie.finished() diff --git a/src/energenie/registry.kvs b/src/energenie/registry.kvs new file mode 100644 index 0000000..5173a2f --- /dev/null +++ b/src/energenie/registry.kvs @@ -0,0 +1,8 @@ +ADD tv +type=MIHO005 +device_id=1675 + +ADD fan +type=ENER002 +device_id=[822412, 1] +