diff --git a/src/control_mihome.py b/src/control_mihome.py index 96a9f82..1b9eed3 100644 --- a/src/control_mihome.py +++ b/src/control_mihome.py @@ -2,14 +2,14 @@ # # 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 -from Timer import Timer -# Define this if you want to seed the registry with know device_id's for testing -# Alternatively, remove this line, and use discover_mihome.py to fill your registry -MY_SOCKET_IDS = [0x68b] +APP_DELAY = 2 # number of seconds to toggle the socket switches -TX_RATE = 2 # number of seconds to toggle the socket switches #----- TEST APPLICATION ------------------------------------------------------- @@ -18,17 +18,17 @@ global socket_state - if energenie.registry.size() > 0 and send_timer.check(): - print("Setting socket switches to %s" % str(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 + 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) + if device.has_switch(): + print(" socket id %s" % device) + device.set_switch(socket_state) - socket_state = not socket_state + socket_state = not socket_state + time.sleep(APP_DELAY) if __name__ == "__main__": @@ -36,15 +36,6 @@ print("starting socket tester") energenie.init() - # Seed the registry with known devices to simplify tx-only testing - try: - for id in MY_SOCKET_IDS: - socket = energenie.Devices.MIHO005(id) - energenie.registry.add(socket, "socket_%s" % str(hex(id))) - except: - pass - - send_timer = Timer(TX_RATE, 1) # every n seconds offset by initial 1 socket_state = False try: diff --git a/src/energenie/Devices.py b/src/energenie/Devices.py index ca457a7..569a78a 100644 --- a/src/energenie/Devices.py +++ b/src/energenie/Devices.py @@ -580,6 +580,11 @@ } self.send_message(payload) + def set_switch(self, state): + if state: + self.turn_on() + else: + self.turn_off() class MIHO004(MiHomeDevice):