소스 검색

structere change for videv (set)

tags/v1.2.0^0
Dirk Alders 1 년 전
부모
커밋
f3ed72974e
2개의 변경된 파일13개의 추가작업 그리고 22개의 파일을 삭제
  1. 11
    19
      function/videv.py
  2. 2
    3
      smart_brain.py

+ 11
- 19
function/videv.py 파일 보기

23
 
23
 
24
 class base(mqtt_base):
24
 class base(mqtt_base):
25
     KEY_INFO = '__info__'
25
     KEY_INFO = '__info__'
26
+    #
27
+    SET_TOPIC = "set"
26
 
28
 
27
     def __init__(self, mqtt_client, topic, default_values=None):
29
     def __init__(self, mqtt_client, topic, default_values=None):
28
         super().__init__(mqtt_client, topic, default_values=default_values)
30
         super().__init__(mqtt_client, topic, default_values=default_values)
29
         self.__display_dict__ = {}
31
         self.__display_dict__ = {}
30
         self.__control_dict__ = {}
32
         self.__control_dict__ = {}
31
         self.__capabilities__ = None
33
         self.__capabilities__ = None
32
-        self.__active_tx__ = {}
33
 
34
 
34
     def add_display(self, my_key, ext_device, ext_key, on_change_only=True):
35
     def add_display(self, my_key, ext_device, ext_key, on_change_only=True):
35
         """
36
         """
49
 
50
 
50
     def __rx_ext_device_data__(self, ext_device, ext_key, data):
51
     def __rx_ext_device_data__(self, ext_device, ext_key, data):
51
         my_key = self.__display_dict__[(id(ext_device), ext_key)]
52
         my_key = self.__display_dict__[(id(ext_device), ext_key)]
52
-        self[my_key] = data
53
+        self.set(my_key, data)
53
         self.__tx__(my_key, data)
54
         self.__tx__(my_key, data)
54
 
55
 
55
     def __tx__(self, key, data):
56
     def __tx__(self, key, data):
56
-        if key in self.__control_dict__:
57
-            self.__active_tx__[key] = (time.time(), data)
58
         if type(data) not in (str, ):
57
         if type(data) not in (str, ):
59
             data = json.dumps(data)
58
             data = json.dumps(data)
60
-        self.mqtt_client.send(self.topic + '/' + key, data)
59
+        self.mqtt_client.send('/'.join([self.topic, key]), data)
61
         self.__tx_capabilities__()
60
         self.__tx_capabilities__()
62
 
61
 
63
     def __tx_capabilities__(self):
62
     def __tx_capabilities__(self):
71
         # store information to identify callback from videv
70
         # store information to identify callback from videv
72
         self.__control_dict__[my_key] = (ext_device, ext_key, on_change_only)
71
         self.__control_dict__[my_key] = (ext_device, ext_key, on_change_only)
73
         # add callback for videv changes
72
         # add callback for videv changes
74
-        self.mqtt_client.add_callback(self.topic + '/' + my_key, self.__rx_videv_data__)
73
+        self.mqtt_client.add_callback('/'.join([self.topic, my_key, self.SET_TOPIC]), self.__rx_videv_data__)
75
 
74
 
76
     def __rx_videv_data__(self, client, userdata, message):
75
     def __rx_videv_data__(self, client, userdata, message):
77
-        my_key = message.topic.split('/')[-1]
76
+        my_key = message.topic.split('/')[-2]
78
         try:
77
         try:
79
             data = json.loads(message.payload)
78
             data = json.loads(message.payload)
80
         except json.decoder.JSONDecodeError:
79
         except json.decoder.JSONDecodeError:
81
             data = message.payload
80
             data = message.payload
82
-        if my_key in self.__active_tx__:
83
-            tm, tx_data = self.__active_tx__.pop(my_key)
84
-            do_ex = data != tx_data and time.time() - tm < 2
81
+        ext_device, ext_key, on_change_only = self.__control_dict__[my_key]
82
+        if my_key in self.keys():
83
+            if data != self[my_key] or not on_change_only:
84
+                ext_device.send_command(ext_key, data)
85
         else:
85
         else:
86
-            do_ex = True
87
-        if do_ex:
88
-            ext_device, ext_key, on_change_only = self.__control_dict__[my_key]
89
-            if my_key in self.keys():
90
-                if data != self[my_key] or not on_change_only:
91
-                    ext_device.send_command(ext_key, data)
92
-                self.set(my_key, data)
93
-            else:
94
-                self.logger.info("Ignoring rx message with topic %s", message.topic)
86
+            self.logger.info("Ignoring rx message with topic %s", message.topic)
95
 
87
 
96
     def add_routing(self, my_key, ext_device, ext_key, on_change_only_disp=True, on_change_only_videv=True):
88
     def add_routing(self, my_key, ext_device, ext_key, on_change_only_disp=True, on_change_only_videv=True):
97
         """
89
         """

+ 2
- 3
smart_brain.py 파일 보기

10
 
10
 
11
 logger = logging.getLogger(config.APP_NAME)
11
 logger = logging.getLogger(config.APP_NAME)
12
 
12
 
13
-# TODO: Implement handling of warnings (videv element to show in webapp?)
14
 # TODO: implement garland (incl. day events like sunset, sunrise, ...)
13
 # TODO: implement garland (incl. day events like sunset, sunrise, ...)
15
 
14
 
16
 VERS_MAJOR = 1
15
 VERS_MAJOR = 1
17
-VERS_MINOR = 1
18
-VERS_PATCH = 2
16
+VERS_MINOR = 2
17
+VERS_PATCH = 0
19
 
18
 
20
 INFO_TOPIC = "__info__"
19
 INFO_TOPIC = "__info__"
21
 INFO_DATA = {
20
 INFO_DATA = {

Loading…
취소
저장