diff --git a/doc/devices_classes_branch.txt b/doc/devices_classes_branch.txt index f6b8da3..b60d3de 100644 --- a/doc/devices_classes_branch.txt +++ b/doc/devices_classes_branch.txt @@ -410,6 +410,12 @@ TODO NEXT Add auto join semantics to monitor_mihome +(might just work with the defaults - set default to discovery_joinauto + +Change monitor_mihome so that it sends a switch on/off message on a flag +to all devices currently in the registry that have a switch + + ---- PERSISTENT REGISTRY diff --git a/src/energenie/Devices.py b/src/energenie/Devices.py index f7a2762..165aef1 100644 --- a/src/energenie/Devices.py +++ b/src/energenie/Devices.py @@ -128,6 +128,22 @@ ] } +JOIN_REQ = { + "header": { + "mfrid": 0, # FILL IN + "productid": 0, # FILL IN + "encryptPIP": CRYPT_PIP, + "sensorid": 0 # FILL IN + }, + "recs": [ + { + "wr": False, + "paramid": OpenThings.PARAM_JOIN, + "typeid": OpenThings.Value.UINT, + "length": 0 + } + ] +} JOIN_ACK = { "header": { @@ -381,6 +397,15 @@ def get_product_id(self): # -> id:int return self.product_id + @staticmethod + def get_join_req(mfrid, productid, deviceid): + """Used for testing, synthesises a JOIN_REQ message from this device""" + msg = OpenThings.Message(JOIN_REQ) + msg["header_mfrid"] = mfrid + msg["header_productid"] = productid + msg["header_sensorid"] = deviceid + return msg + def join_ack(self): """Send a join-ack to the real device""" msg = OpenThings.Message(header_mfrid=MFRID_ENERGENIE, header_productid=self.product_id, header_sensorid=self.device_id) diff --git a/src/energenie/Registry.py b/src/energenie/Registry.py index 81ac25b..df5ff87 100644 --- a/src/energenie/Registry.py +++ b/src/energenie/Registry.py @@ -441,9 +441,9 @@ # Default discovery mode, unless changed by app ##discovery_none() -discovery_auto() +##discovery_auto() ##discovery_ask(ask) -##discovery_autojoin() +discovery_autojoin() ##discovery_askjoin(ask) # END diff --git a/src/energenie/Registry_test.py b/src/energenie/Registry_test.py index b6e2a70..431cdf2 100644 --- a/src/energenie/Registry_test.py +++ b/src/energenie/Registry_test.py @@ -87,10 +87,12 @@ print("switch %s" % switch) -import OpenThings UNKNOWN_SENSOR_ID = 0x111 +#TODO: Due to use of the fsk_router and registry instances, +#these tests will not run back to back yet. Have to run them one at a time. + class TestDiscovery(unittest.TestCase): def setUp(self): # build a synthetic message @@ -151,13 +153,10 @@ discovery_autojoin() # Poke synthetic unknown JOIN into the router and let it route to unknown handler - self.msg = OpenThings.Message(header_mfrid=Devices.MFRID_ENERGENIE, - header_productid=Devices.PRODUCTID_MIHO005, - header_sensorid=UNKNOWN_SENSOR_ID) - self.msg[OpenThings.PARAM_JOIN] = {} + msg = Devices.MIHO005.get_join_req(Devices.MFRID_ENERGENIE, Devices.PRODUCTID_MIHO005, UNKNOWN_SENSOR_ID) fsk_router.incoming_message( - (Devices.MFRID_ENERGENIE, Devices.PRODUCTID_MIHO005, UNKNOWN_SENSOR_ID), self.msg) + (Devices.MFRID_ENERGENIE, Devices.PRODUCTID_MIHO005, UNKNOWN_SENSOR_ID), msg) # expect auto accept and join_ack logic to fire registry.list() @@ -171,13 +170,9 @@ discovery_askjoin(no) # Poke synthetic unknown JOIN into the router and let it route to unknown handler - self.msg = OpenThings.Message(header_mfrid=Devices.MFRID_ENERGENIE, - header_productid=Devices.PRODUCTID_MIHO005, - header_sensorid=UNKNOWN_SENSOR_ID) - self.msg[OpenThings.PARAM_JOIN] = {} - + msg = Devices.MIHO005.get_join_req(Devices.MFRID_ENERGENIE, Devices.PRODUCTID_MIHO005, UNKNOWN_SENSOR_ID) fsk_router.incoming_message( - (Devices.MFRID_ENERGENIE, Devices.PRODUCTID_MIHO005, UNKNOWN_SENSOR_ID), self.msg) + (Devices.MFRID_ENERGENIE, Devices.PRODUCTID_MIHO005, UNKNOWN_SENSOR_ID), msg) # expect reject registry.list() @@ -186,7 +181,7 @@ discovery_askjoin(yes) fsk_router.incoming_message( - (Devices.MFRID_ENERGENIE, Devices.PRODUCTID_MIHO005, UNKNOWN_SENSOR_ID), self.msg) + (Devices.MFRID_ENERGENIE, Devices.PRODUCTID_MIHO005, UNKNOWN_SENSOR_ID), msg) # expect auto accept and join_ack logic to fire registry.list()