Browse Source

Automatic configuration improved

master
Dirk Alders 6 months ago
parent
commit
8455facb1c
3 changed files with 17 additions and 12 deletions
  1. 15
    10
      devices/base.py
  2. 1
    1
      mqtt
  3. 1
    1
      report

+ 15
- 10
devices/base.py View File

33
     def __init__(self, mqtt_client, topic):
33
     def __init__(self, mqtt_client, topic):
34
         super().__init__(mqtt_client, topic, default_values=dict.fromkeys(self.RX_KEYS))
34
         super().__init__(mqtt_client, topic, default_values=dict.fromkeys(self.RX_KEYS))
35
         # data storage
35
         # data storage
36
+        self.__cfg_by_mid__ = None
36
         # initialisations
37
         # initialisations
37
         mqtt_client.add_callback(topic=self.topic, callback=self.receive_callback)
38
         mqtt_client.add_callback(topic=self.topic, callback=self.receive_callback)
38
         mqtt_client.add_callback(topic=self.topic+"/#", callback=self.receive_callback)
39
         mqtt_client.add_callback(topic=self.topic+"/#", callback=self.receive_callback)
39
         #
40
         #
40
         self.add_callback(None, None, self.__state_logging__, on_change_only=True)
41
         self.add_callback(None, None, self.__state_logging__, on_change_only=True)
41
 
42
 
42
-    def __cfg_callback__(self, key, value):
43
-        if self.CFG_DATA.get(key) != value:
44
-            self.logger.warning("Differing configuration identified: %s=%s --> %s=%s",
45
-                                repr(key), repr(value), repr(key), repr(self.CFG_DATA.get(key)))
46
-            self.send_command(key, self.CFG_DATA.get(key))
43
+    def __cfg_callback__(self, key, value, mid):
44
+        if self.CFG_DATA.get(key) != value and self.__cfg_by_mid__ != mid and mid is not None:
45
+            self.__cfg_by_mid__ = mid
46
+            self.logger.warning("Differing configuration identified: Sending default configuration to defice: %s", repr(self.CFG_DATA))
47
+            if self.TX_TYPE == self.TX_DICT:
48
+                self.mqtt_client.send(self.topic + '/' + self.TX_TOPIC, json.dumps(self.CFG_DATA))
49
+            else:
50
+                for key in self.CFG_DATA:
51
+                    self.send_command(key, self.CFG_DATA.get(key))
47
 
52
 
48
-    def set(self, key, data, block_callback=[]):
53
+    def set(self, key, data, mid=None, block_callback=[]):
49
         if key in self.CFG_DATA:
54
         if key in self.CFG_DATA:
50
-            self.__cfg_callback__(key, data)
55
+            self.__cfg_callback__(key, data, mid)
51
         if key in self.RX_IGNORE_KEYS:
56
         if key in self.RX_IGNORE_KEYS:
52
             pass    # ignore these keys
57
             pass    # ignore these keys
53
         elif key in self.RX_KEYS:
58
         elif key in self.RX_KEYS:
64
                     data = json.loads(message.payload)
69
                     data = json.loads(message.payload)
65
                     if type(data) is dict:
70
                     if type(data) is dict:
66
                         for key in data:
71
                         for key in data:
67
-                            self.set(key, self.__device_to_instance_filter__(key, data[key]))
72
+                            self.set(key, self.__device_to_instance_filter__(key, data[key]), message.mid)
68
                     else:
73
                     else:
69
-                        self.set(content_key, self.__device_to_instance_filter__(content_key, data))
74
+                        self.set(content_key, self.__device_to_instance_filter__(content_key, data), message.mid)
70
                 # String
75
                 # String
71
                 else:
76
                 else:
72
-                    self.set(content_key, self.__device_to_instance_filter__(content_key, message.payload.decode('utf-8')))
77
+                    self.set(content_key, self.__device_to_instance_filter__(content_key, message.payload.decode('utf-8')), message.mid)
73
             else:
78
             else:
74
                 self.logger.debug("Ignoring topic %s", content_key)
79
                 self.logger.debug("Ignoring topic %s", content_key)
75
 
80
 

+ 1
- 1
mqtt

1
-Subproject commit 328d3471a748472695a61193becdda76c7eefe69
1
+Subproject commit 14e56ccdbf6594f699b4afcfb4acafe9b899e914

+ 1
- 1
report

1
-Subproject commit b53dd30eae1d679b7eec4999bec50aed55bc105b
1
+Subproject commit 7003c13ef8c7e7c3a55a545cbbad4039cc024a9f

Loading…
Cancel
Save