Procházet zdrojové kódy

videv sends the initial state on startup

tags/v1.2.6
Dirk Alders před 1 rokem
rodič
revize
04f269c750
4 změnil soubory, kde provedl 5 přidání a 59 odebrání
  1. 2
    21
      base.py
  2. 2
    0
      devices/__init__.py
  3. 0
    37
      function/videv.py
  4. 1
    1
      smart_brain.py

+ 2
- 21
base.py Zobrazit soubor

@@ -58,7 +58,6 @@ class videv_base(mqtt_base):
58 58
         super().__init__(mqtt_client, topic, default_values=default_values)
59 59
         self.__display_dict__ = {}
60 60
         self.__control_dict__ = {}
61
-        self.__capabilities__ = None
62 61
 
63 62
     def add_display(self, my_key, ext_device, ext_key, on_change_only=True):
64 63
         """
@@ -76,7 +75,8 @@ class videv_base(mqtt_base):
76 75
             self.__display_dict__[(id(ext_device), ext_key)] = my_key
77 76
             # register a callback to listen for data from external device
78 77
             ext_device.add_callback(ext_key, None, self.__rx_ext_device_data__, on_change_only)
79
-        # send default data to videv interface
78
+        # send initial display data to videv interface
79
+        self.__tx__(my_key, ext_device.get(ext_key))
80 80
 
81 81
     def __rx_ext_device_data__(self, ext_device, ext_key, data):
82 82
         my_key = self.__display_dict__[(id(ext_device), ext_key)]
@@ -87,10 +87,6 @@ class videv_base(mqtt_base):
87 87
         if type(data) not in (str, ):
88 88
             data = json.dumps(data)
89 89
         self.mqtt_client.send('/'.join([self.topic, key]), data)
90
-        self.__tx_capabilities__()
91
-
92
-    def __tx_capabilities__(self):
93
-        self.mqtt_client.send(self.topic + '/' + self.KEY_INFO, json.dumps(self.capabilities))
94 90
 
95 91
     def add_control(self, my_key, ext_device, ext_key, on_change_only=True):
96 92
         """
@@ -125,18 +121,3 @@ class videv_base(mqtt_base):
125 121
         # add display
126 122
         self.add_display(my_key, ext_device, ext_key, on_change_only_disp)
127 123
         self.add_control(my_key, ext_device, ext_key, on_change_only_videv)
128
-
129
-    @property
130
-    def capabilities(self):
131
-        if self.__capabilities__ is None:
132
-            self.__capabilities__ = {}
133
-            self.__capabilities__['__type__'] = self.__class__.__name__
134
-            for key in self.__control_dict__:
135
-                if not key in self.__capabilities__:
136
-                    self.__capabilities__[key] = {}
137
-                self.__capabilities__[key]['control'] = True
138
-            for key in self.__display_dict__.values():
139
-                if not key in self.__capabilities__:
140
-                    self.__capabilities__[key] = {}
141
-                self.__capabilities__[key]['display'] = True
142
-        return self.__capabilities__

+ 2
- 0
devices/__init__.py Zobrazit soubor

@@ -449,6 +449,8 @@ class silvercrest_motion_sensor(base):
449 449
     KEY_UNMOUNTED = "tamper"
450 450
     KEY_VOLTAGE = "voltage"
451 451
     #
452
+    TX_TYPE = base.TX_DICT
453
+    #
452 454
     RX_KEYS = [KEY_BATTERY, KEY_BATTERY_LOW, KEY_LINKQUALITY, KEY_OCCUPANCY, KEY_UNMOUNTED, KEY_VOLTAGE]
453 455
 
454 456
     def __init__(self, mqtt_client, topic):

+ 0
- 37
function/videv.py Zobrazit soubor

@@ -26,8 +26,6 @@ class videv_switching(videv_base):
26 26
     def __init__(self, mqtt_client, topic, sw_device, sw_key):
27 27
         super().__init__(mqtt_client, topic)
28 28
         self.add_routing(self.KEY_STATE, sw_device, sw_key)
29
-        #
30
-        self.__tx_capabilities__()
31 29
 
32 30
 
33 31
 class videv_switching_timer(videv_base):
@@ -38,8 +36,6 @@ class videv_switching_timer(videv_base):
38 36
         super().__init__(mqtt_client, topic)
39 37
         self.add_routing(self.KEY_STATE, sw_device, sw_key)
40 38
         self.add_display(self.KEY_TIMER, tm_device, tm_key)
41
-        #
42
-        self.__tx_capabilities__()
43 39
 
44 40
 
45 41
 class videv_switching_motion(videv_base):
@@ -57,8 +53,6 @@ class videv_switching_motion(videv_base):
57 53
         # motion sensor state
58 54
         for index, motion_sensor in enumerate(self.motion_sensors):
59 55
             self.add_display(self.KEY_MOTION_SENSOR % index, motion_sensor, motion_sensor.KEY_OCCUPANCY)
60
-        #
61
-        self.__tx_capabilities__()
62 56
 
63 57
 
64 58
 class videv_switch_brightness(videv_base):
@@ -69,8 +63,6 @@ class videv_switch_brightness(videv_base):
69 63
         super().__init__(mqtt_client, topic)
70 64
         self.add_routing(self.KEY_STATE, sw_device, sw_key)
71 65
         self.add_routing(self.KEY_BRIGHTNESS, br_device, br_key)
72
-        #
73
-        self.__tx_capabilities__()
74 66
 
75 67
 
76 68
 class videv_switch_brightness_color_temp(videv_base):
@@ -83,8 +75,6 @@ class videv_switch_brightness_color_temp(videv_base):
83 75
         self.add_routing(self.KEY_STATE, sw_device, sw_key)
84 76
         self.add_routing(self.KEY_BRIGHTNESS, br_device, br_key)
85 77
         self.add_routing(self.KEY_COLOR_TEMP, ct_device, ct_key)
86
-        #
87
-        self.__tx_capabilities__()
88 78
 
89 79
 
90 80
 class videv_heating(videv_base):
@@ -111,8 +101,6 @@ class videv_heating(videv_base):
111 101
         self.add_display(self.KEY_VALVE_TEMPERATURE_SETPOINT, heating_function, heating_function.KEY_TEMPERATURE_SETPOINT)
112 102
         self.add_display(self.KEY_BOOST_TIMER, heating_function, heating_function.KEY_BOOST_TIMER)
113 103
         self.add_display(self.KEY_TEMPERATURE, heating_function, heating_function.KEY_TEMPERATURE_CURRENT, False)
114
-        #
115
-        self.__tx_capabilities__()
116 104
 
117 105
 
118 106
 class videv_multistate(videv_base):
@@ -126,14 +114,10 @@ class videv_multistate(videv_base):
126 114
             self.__tx__(self.KEY_STATE % i, False)
127 115
         #
128 116
         device.add_callback(key_for_device, None, self.__index_rx__, True)
129
-        #
130
-        self.__tx_capabilities__()
131 117
 
132 118
     def __index_rx__(self, device, key, data):
133 119
         for i in range(0, self.num_states):
134 120
             self.__tx__(self.KEY_STATE % i, i == data)
135
-        #
136
-        self.__tx_capabilities__()
137 121
 
138 122
 
139 123
 class videv_audio_player(videv_base):
@@ -148,18 +132,10 @@ class videv_audio_player(videv_base):
148 132
         #
149 133
         for audio_device in args:
150 134
             audio_device.add_callback(audio_device.KEY_TITLE, None, self.__title_rx__, True)
151
-        #
152
-        self.__tx_capabilities__()
153 135
 
154 136
     def __title_rx__(self, device, key, data):
155 137
         self.__tx__(self.KEY_TITLE, data or self.NO_TITLE)
156 138
 
157
-    @property
158
-    def capabilities(self):
159
-        super().capabilities
160
-        self.__capabilities__[self.KEY_TITLE] = {'display': True}
161
-        return self.__capabilities__
162
-
163 139
 
164 140
 class videv_warnings(videv_base):
165 141
     MAX_WARNINGS = 10
@@ -188,8 +164,6 @@ class all_off(videv_base):
188 164
         # register mqtt callbacks for all my keys
189 165
         for key in self.__inst_dict__:
190 166
             mqtt_client.add_callback(topic + "/" + key, self.all_off)
191
-        #
192
-        self.__tx_capabilities__()
193 167
 
194 168
     def __check_inst_capabilities__(self, name, inst):
195 169
         # fits to specified classes
@@ -220,14 +194,3 @@ class all_off(videv_base):
220 194
     def all_off(self, client, userdata, message):
221 195
         key = message.topic[len(self.topic) + 1:]
222 196
         self.__inst_dict__[key].all_off()
223
-        self.__tx_capabilities__()
224
-
225
-    @property
226
-    def capabilities(self):
227
-        if self.__capabilities__ is None:
228
-            self.__capabilities__ = {}
229
-            self.__capabilities__['__type__'] = self.__class__.__name__
230
-            for key in self.__inst_dict__:
231
-                self.__capabilities__[key] = {}
232
-                self.__capabilities__[key]['control'] = True
233
-        return self.__capabilities__

+ 1
- 1
smart_brain.py Zobrazit soubor

@@ -13,7 +13,7 @@ logger = logging.getLogger(config.APP_NAME)
13 13
 
14 14
 VERS_MAJOR = 1
15 15
 VERS_MINOR = 2
16
-VERS_PATCH = 4
16
+VERS_PATCH = 5
17 17
 
18 18
 INFO_TOPIC = "__info__"
19 19
 INFO_DATA = {

Načítá se…
Zrušit
Uložit