From 3f93419ececc8b86bbd0b4858ebfb782fd3d4223 Mon Sep 17 00:00:00 2001 From: Kevin Robert Keegan Date: Sat, 12 Dec 2020 11:47:40 -0800 Subject: [PATCH 1/2] Increment Database Delta on Writing This should dramatically decrease the number of full refreshes of a device and should speed things up. --- insteon_mqtt/db/Device.py | 1 + insteon_mqtt/db/DeviceModifyManagerI1.py | 18 +++++++++++++++++- insteon_mqtt/handler/DeviceDbModify.py | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/insteon_mqtt/db/Device.py b/insteon_mqtt/db/Device.py index 445a5c0f..927e85a8 100644 --- a/insteon_mqtt/db/Device.py +++ b/insteon_mqtt/db/Device.py @@ -184,6 +184,7 @@ def set_delta(self, delta): """ self.delta = delta if delta is not None: + self.delta = self.delta % 256 # Roll over db if it goes past 256 self.save() #----------------------------------------------------------------------- diff --git a/insteon_mqtt/db/DeviceModifyManagerI1.py b/insteon_mqtt/db/DeviceModifyManagerI1.py index e1948b2f..7cdaa101 100644 --- a/insteon_mqtt/db/DeviceModifyManagerI1.py +++ b/insteon_mqtt/db/DeviceModifyManagerI1.py @@ -151,6 +151,22 @@ def handle_lsb_response(self, msg, on_done): else: self.advance_lsb(on_done) + #------------------------------------------------------------------- + def handle_lsb_write_response(self, msg, on_done): + """Handle Write of LSB + + This is only used to increment the delta for this device. + + Args: + msg: (message.InpStandard) The lsb message reply. The lsb data + is in the msg.cmd2 field. + on_done: (callback) a callback that is passed around and run on the + completion of the modification + """ + # Increment the delta 1 + self.db.set_delta(self.db.delta + 1) + self.handle_lsb_response(self, msg, on_done) + #------------------------------------------------------------------- def write_lsb_byte(self, on_done): """Writes the next byte in the record to the device. @@ -165,7 +181,7 @@ def write_lsb_byte(self, on_done): db_msg = Msg.OutStandard.direct(self.db.addr, 0x29, self.record[self.record_index]) msg_handler = handler.StandardCmd(db_msg, - self.handle_lsb_response, + self.handle_lsb_write_response, on_done=on_done, num_retry=self._num_retry) self.device.send(db_msg, msg_handler) diff --git a/insteon_mqtt/handler/DeviceDbModify.py b/insteon_mqtt/handler/DeviceDbModify.py index 73c632a1..d59b6bd2 100644 --- a/insteon_mqtt/handler/DeviceDbModify.py +++ b/insteon_mqtt/handler/DeviceDbModify.py @@ -72,6 +72,8 @@ def msg_received(self, protocol, msg): # entry, or an marked unused (deletion). LOG.info("Updating entry: %s", self.entry) self.db.add_entry(self.entry) + # Increment the delta 1 + self.db.set_delta(self.db.delta + 1) self.on_done(True, "Device database update complete", self.entry) From 7f17ac746cc750f3b923d35bb653c9014d453ac3 Mon Sep 17 00:00:00 2001 From: KRKeegan Date: Sat, 12 Dec 2020 13:39:36 -0800 Subject: [PATCH 2/2] Update History --- HISTORY.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 94e80f99..73d98af9 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -16,7 +16,7 @@ - [MQTT Doc](https://github.com/TD22057/insteon-mqtt/blob/master/docs/mqtt.md) - note the new set_flags options for IOLinc and the IOLinc section - - A new queueing system for battery devices ([PR240][P240]): +- A new queueing system for battery devices ([PR240][P240]): - Messages sent to the device will be queued until the device is awake - When the device sends a message, the modem will attempt to immediately send the oldest outgoing message. This only works for some devices. @@ -26,6 +26,10 @@ ### Fixes +- Database delta is updated on database writes. This eliminates a number of + unnecessary refresh requirements, particularly around pairing. + ([PR 248][P248]) + ## [0.7.3] Fixing a number of small bugs in preparation for upcoming releases which @@ -429,3 +433,4 @@ will add new features. [P237]: https://github.com/TD22057/insteon-mqtt/pull/227 [P197]: https://github.com/TD22057/insteon-mqtt/pull/197 [P240]: https://github.com/TD22057/insteon-mqtt/pull/240 +[P248]: https://github.com/TD22057/insteon-mqtt/pull/248