소스 검색

Automatic configuration improved

master
Dirk Alders 6 달 전
부모
커밋
8455facb1c
3개의 변경된 파일17개의 추가작업 그리고 12개의 파일을 삭제
  1. 15
    10
      devices/base.py
  2. 1
    1
      mqtt
  3. 1
    1
      report

+ 15
- 10
devices/base.py 파일 보기

@@ -33,21 +33,26 @@ class base(mqtt_base):
33 33
     def __init__(self, mqtt_client, topic):
34 34
         super().__init__(mqtt_client, topic, default_values=dict.fromkeys(self.RX_KEYS))
35 35
         # data storage
36
+        self.__cfg_by_mid__ = None
36 37
         # initialisations
37 38
         mqtt_client.add_callback(topic=self.topic, callback=self.receive_callback)
38 39
         mqtt_client.add_callback(topic=self.topic+"/#", callback=self.receive_callback)
39 40
         #
40 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 54
         if key in self.CFG_DATA:
50
-            self.__cfg_callback__(key, data)
55
+            self.__cfg_callback__(key, data, mid)
51 56
         if key in self.RX_IGNORE_KEYS:
52 57
             pass    # ignore these keys
53 58
         elif key in self.RX_KEYS:
@@ -64,12 +69,12 @@ class base(mqtt_base):
64 69
                     data = json.loads(message.payload)
65 70
                     if type(data) is dict:
66 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 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 75
                 # String
71 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 78
             else:
74 79
                 self.logger.debug("Ignoring topic %s", content_key)
75 80
 

+ 1
- 1
mqtt

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

+ 1
- 1
report

@@ -1 +1 @@
1
-Subproject commit b53dd30eae1d679b7eec4999bec50aed55bc105b
1
+Subproject commit 7003c13ef8c7e7c3a55a545cbbad4039cc024a9f

Loading…
취소
저장