diff --git a/src/energenie/Devices.py b/src/energenie/Devices.py index 22b311e..f0c76b5 100644 --- a/src/energenie/Devices.py +++ b/src/energenie/Devices.py @@ -212,7 +212,7 @@ def incoming_message(self, payload): # incoming_message (OOK or OpenThings as appropriate, stripped of header? decrypted, decoded to pydict) # default action of base class is to just print the payload - print("incoming:%s" % payload) + print("incoming(unhandled):%s" % payload) def send_message(self, payload): print("send_message %s" % payload) @@ -299,8 +299,9 @@ # so payload at this point must be a pydict? #we know at this point that it's a FSK message - #TODO: do we OpenThings.decrypt() here? Done by OpenThings.decode() by default - #TODO: do we OpenThings.decode() here into a pydict header/recs?? + #OpenThingsAirInterface has already decrypted and decoded + #so we get a pydict payload here with header and recs in it + #the header has the address which is used for routing #TODO join request might be handled generically here #TODO: subclass can override and call back to this if it wants to diff --git a/src/energenie/Registry.py b/src/energenie/Registry.py index f656873..001c6ed 100644 --- a/src/energenie/Registry.py +++ b/src/energenie/Registry.py @@ -276,7 +276,9 @@ #----- SIMPLE TEST HARNESS ---------------------------------------------------- -def test_with_registry(): +def test_with_registry_tx(): + """Test sending a message to a green button and a MiHome Adaptor Plus switch""" + #TODO need a way to separate device creation from device restoration #and the app needs to know what mode it is in. #creation is probably just a test feature, as a user would either @@ -299,7 +301,7 @@ tv.turn_off() fan.turn_on() fan.turn_off() - + #print("tv switch:%s" % tv.has_switch()) #print("tv send:%s" % tv.can_send()) #print("tv receive:%s" % tv.can_receive()) @@ -309,12 +311,50 @@ #print("fan receive:%s" % fan.can_receive()) +def test_with_registry_rx(): + """Test receiving a dummy message on a MiHome adaptor plus""" + + # seed the registry + registry.add(Devices.ENER002(device_id=(0xC8C8C, 1)), "fan") + + # test the auto create mechanism + import sys + registry.auto_create(sys.modules[__name__]) + + fan.turn_on() + + #TODO: synthesise receiving a report message + #push it down the receive pipeline + #radio.receive() + # ->OpenThingsAirInterface.incoming + # ->OpenThings.decrypt + # ->OpenThings.decode + # ->OpenThingsAirInterface->route + # ->ENER005.incoming_message() + # + #it should update voltage, power etc + + + #TODO: get readings from device + ##voltage = fan.get_voltage() + ##frequency = fan.get_frequency() + ##power = fan.get_real_power() + ##switch = fan.is_on() + + ##print("voltage %f" % voltage) + ##print("frequency %f" % frequency) + ##print("power %f" % power) + ##print("switch %s" % switch) + + if __name__ == "__main__": import OpenThings OpenThings.init(Devices.CRYPT_PID) - test_with_registry() + test_with_registry_tx() + + ##test_with_registry_rx() # END