diff --git a/doc/devices_classes_branch.txt b/doc/devices_classes_branch.txt index 5e1461d..a5ce070 100644 --- a/doc/devices_classes_branch.txt +++ b/doc/devices_classes_branch.txt @@ -408,20 +408,16 @@ -------------------------------------------------------------------------------- TODO NEXT -* implement discovery code +DONE auto discovery, accept and reject + * write test cases in Registry_test.py to test the 4 different discovery types (might need some mocking to soft-test the join/ack mechanism, probably just route in a synthetic join_req, and capture the tx log to see the join_ack going out) -* put a discovery agent configuration in monitor_mihome.py and re test, - specifically to see if the default flow is simple for a new user to set up - (with lots of sensible defaults, perhaps JoinAuto as the default). - - ----- +---- PERSISTENT REGISTRY * Need the registry to be persistent with save and load choose a file format that is human readable, like a config file? @@ -435,7 +431,8 @@ later iterate through all devices and decide what to do with them, such as displaying them all in a GUI selection list. ----- + +---- NOTIFY, UPDATE, or DATA SEQUENCE? Consider whether there is a need for a general update notify mechanism - perhaps could have a message sequence counter that @@ -444,13 +441,14 @@ when_updated callback) ----- +---- HARDWARE TESTING Test with real radio * add back in the loop() call in the monitor_mihome.py program ------ + +----- RELEASE TESTING AND RELEASE * update the test instructions and re-test everything before merge diff --git a/src/energenie/Devices.py b/src/energenie/Devices.py index 33186a2..5c3f07a 100644 --- a/src/energenie/Devices.py +++ b/src/energenie/Devices.py @@ -470,6 +470,7 @@ return "MIHO005(%s)" % str(hex(self.device_id)) def handle_message(self, payload): + ##print("MIHO005 new data %s" % self.device_id) for rec in payload["recs"]: paramid = rec["paramid"] #TODO: consider making this table driven and allowing our base class to fill our readings in for us diff --git a/src/energenie/Registry.py b/src/energenie/Registry.py index 4abcf8f..29a1b83 100644 --- a/src/energenie/Registry.py +++ b/src/energenie/Registry.py @@ -12,6 +12,7 @@ except ImportError: from . import Devices # python 3 +import Devices directory = {} @@ -146,15 +147,14 @@ def list(self): """List the registry in a vaguely printable format, mostly for debug""" + print("REGISTERED DEVICES:") for k in self.store.keys(): - print("DEVICE %s" % k) - print(" %s" % self.store[k]) + print(" %s -> %s" % (k, self.store[k])) def size(self): """How many entries are there in the registry?""" return self.store.size() - def devices(self): """Get a list of all device classes in the registry""" #TODO: Temporary method until we read up about iterable, so we can say @@ -241,6 +241,11 @@ # address might be a string, a number, a tuple, but probably always the same for any one router self.routes[address] = instance + def list(self): + print("ROUTES:") + for address in self.routes: + print(" %s->%s" % (str(address), str(self.routes[address]))) + def incoming_message(self, address, message): if self.incoming_cb != None: self.incoming_cb(address, message) @@ -290,13 +295,21 @@ # override this method if you want special processing def accept_device(self, address, message): - print("TODO: accept_device:%s" % str(address)) - pass #TODO - # create device class instance from id information - # add to registry - # add to router - # forward message to new class instance for processing - #TODO: return the new device class instance to caller + print("accept_device:%s" % str(address)) + # At moment, intentionally assume everything is mfrid=Energenie + product_id = address[1] + device_id = address[2] + print("**** wiring up registry and router for %s" % str(address)) + ci = Devices.DeviceFactory.get_device_from_id(product_id, device_id) + self.registry.add(ci, "auto_%s_%s" % (str(hex(product_id)), str(hex(device_id)))) + self.router.add(address, ci) + + # Finally, forward the first message to the new device class instance + print("**** routing first message to class instance") + ci.incoming_message(message) + + ##self.registry.list() + ##self.router.list() class AutoDiscovery(Discovery): @@ -375,6 +388,9 @@ # (temporary) helpful methods to switch between different discovery methods # Note that the __init__ automaticall registers itself with router +def discovery_none(): + fsk_router.when_unknown(None) + def discovery_auto(): d = AutoDiscovery(registry, fsk_router) print("Using auto discovery") @@ -405,6 +421,7 @@ # Default discovery mode, unless changed by app +##discovery_none() discovery_auto() ##discovery_ask(ask) ##discovery_autojoin()