Browse Source

videv sends the initial state on startup

tags/v1.2.6
Dirk Alders 1 year ago
parent
commit
04f269c750
4 changed files with 5 additions and 59 deletions
  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 View File

58
         super().__init__(mqtt_client, topic, default_values=default_values)
58
         super().__init__(mqtt_client, topic, default_values=default_values)
59
         self.__display_dict__ = {}
59
         self.__display_dict__ = {}
60
         self.__control_dict__ = {}
60
         self.__control_dict__ = {}
61
-        self.__capabilities__ = None
62
 
61
 
63
     def add_display(self, my_key, ext_device, ext_key, on_change_only=True):
62
     def add_display(self, my_key, ext_device, ext_key, on_change_only=True):
64
         """
63
         """
76
             self.__display_dict__[(id(ext_device), ext_key)] = my_key
75
             self.__display_dict__[(id(ext_device), ext_key)] = my_key
77
             # register a callback to listen for data from external device
76
             # register a callback to listen for data from external device
78
             ext_device.add_callback(ext_key, None, self.__rx_ext_device_data__, on_change_only)
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
     def __rx_ext_device_data__(self, ext_device, ext_key, data):
81
     def __rx_ext_device_data__(self, ext_device, ext_key, data):
82
         my_key = self.__display_dict__[(id(ext_device), ext_key)]
82
         my_key = self.__display_dict__[(id(ext_device), ext_key)]
87
         if type(data) not in (str, ):
87
         if type(data) not in (str, ):
88
             data = json.dumps(data)
88
             data = json.dumps(data)
89
         self.mqtt_client.send('/'.join([self.topic, key]), data)
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
     def add_control(self, my_key, ext_device, ext_key, on_change_only=True):
91
     def add_control(self, my_key, ext_device, ext_key, on_change_only=True):
96
         """
92
         """
125
         # add display
121
         # add display
126
         self.add_display(my_key, ext_device, ext_key, on_change_only_disp)
122
         self.add_display(my_key, ext_device, ext_key, on_change_only_disp)
127
         self.add_control(my_key, ext_device, ext_key, on_change_only_videv)
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 View File

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

+ 0
- 37
function/videv.py View File

26
     def __init__(self, mqtt_client, topic, sw_device, sw_key):
26
     def __init__(self, mqtt_client, topic, sw_device, sw_key):
27
         super().__init__(mqtt_client, topic)
27
         super().__init__(mqtt_client, topic)
28
         self.add_routing(self.KEY_STATE, sw_device, sw_key)
28
         self.add_routing(self.KEY_STATE, sw_device, sw_key)
29
-        #
30
-        self.__tx_capabilities__()
31
 
29
 
32
 
30
 
33
 class videv_switching_timer(videv_base):
31
 class videv_switching_timer(videv_base):
38
         super().__init__(mqtt_client, topic)
36
         super().__init__(mqtt_client, topic)
39
         self.add_routing(self.KEY_STATE, sw_device, sw_key)
37
         self.add_routing(self.KEY_STATE, sw_device, sw_key)
40
         self.add_display(self.KEY_TIMER, tm_device, tm_key)
38
         self.add_display(self.KEY_TIMER, tm_device, tm_key)
41
-        #
42
-        self.__tx_capabilities__()
43
 
39
 
44
 
40
 
45
 class videv_switching_motion(videv_base):
41
 class videv_switching_motion(videv_base):
57
         # motion sensor state
53
         # motion sensor state
58
         for index, motion_sensor in enumerate(self.motion_sensors):
54
         for index, motion_sensor in enumerate(self.motion_sensors):
59
             self.add_display(self.KEY_MOTION_SENSOR % index, motion_sensor, motion_sensor.KEY_OCCUPANCY)
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
 class videv_switch_brightness(videv_base):
58
 class videv_switch_brightness(videv_base):
69
         super().__init__(mqtt_client, topic)
63
         super().__init__(mqtt_client, topic)
70
         self.add_routing(self.KEY_STATE, sw_device, sw_key)
64
         self.add_routing(self.KEY_STATE, sw_device, sw_key)
71
         self.add_routing(self.KEY_BRIGHTNESS, br_device, br_key)
65
         self.add_routing(self.KEY_BRIGHTNESS, br_device, br_key)
72
-        #
73
-        self.__tx_capabilities__()
74
 
66
 
75
 
67
 
76
 class videv_switch_brightness_color_temp(videv_base):
68
 class videv_switch_brightness_color_temp(videv_base):
83
         self.add_routing(self.KEY_STATE, sw_device, sw_key)
75
         self.add_routing(self.KEY_STATE, sw_device, sw_key)
84
         self.add_routing(self.KEY_BRIGHTNESS, br_device, br_key)
76
         self.add_routing(self.KEY_BRIGHTNESS, br_device, br_key)
85
         self.add_routing(self.KEY_COLOR_TEMP, ct_device, ct_key)
77
         self.add_routing(self.KEY_COLOR_TEMP, ct_device, ct_key)
86
-        #
87
-        self.__tx_capabilities__()
88
 
78
 
89
 
79
 
90
 class videv_heating(videv_base):
80
 class videv_heating(videv_base):
111
         self.add_display(self.KEY_VALVE_TEMPERATURE_SETPOINT, heating_function, heating_function.KEY_TEMPERATURE_SETPOINT)
101
         self.add_display(self.KEY_VALVE_TEMPERATURE_SETPOINT, heating_function, heating_function.KEY_TEMPERATURE_SETPOINT)
112
         self.add_display(self.KEY_BOOST_TIMER, heating_function, heating_function.KEY_BOOST_TIMER)
102
         self.add_display(self.KEY_BOOST_TIMER, heating_function, heating_function.KEY_BOOST_TIMER)
113
         self.add_display(self.KEY_TEMPERATURE, heating_function, heating_function.KEY_TEMPERATURE_CURRENT, False)
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
 class videv_multistate(videv_base):
106
 class videv_multistate(videv_base):
126
             self.__tx__(self.KEY_STATE % i, False)
114
             self.__tx__(self.KEY_STATE % i, False)
127
         #
115
         #
128
         device.add_callback(key_for_device, None, self.__index_rx__, True)
116
         device.add_callback(key_for_device, None, self.__index_rx__, True)
129
-        #
130
-        self.__tx_capabilities__()
131
 
117
 
132
     def __index_rx__(self, device, key, data):
118
     def __index_rx__(self, device, key, data):
133
         for i in range(0, self.num_states):
119
         for i in range(0, self.num_states):
134
             self.__tx__(self.KEY_STATE % i, i == data)
120
             self.__tx__(self.KEY_STATE % i, i == data)
135
-        #
136
-        self.__tx_capabilities__()
137
 
121
 
138
 
122
 
139
 class videv_audio_player(videv_base):
123
 class videv_audio_player(videv_base):
148
         #
132
         #
149
         for audio_device in args:
133
         for audio_device in args:
150
             audio_device.add_callback(audio_device.KEY_TITLE, None, self.__title_rx__, True)
134
             audio_device.add_callback(audio_device.KEY_TITLE, None, self.__title_rx__, True)
151
-        #
152
-        self.__tx_capabilities__()
153
 
135
 
154
     def __title_rx__(self, device, key, data):
136
     def __title_rx__(self, device, key, data):
155
         self.__tx__(self.KEY_TITLE, data or self.NO_TITLE)
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
 class videv_warnings(videv_base):
140
 class videv_warnings(videv_base):
165
     MAX_WARNINGS = 10
141
     MAX_WARNINGS = 10
188
         # register mqtt callbacks for all my keys
164
         # register mqtt callbacks for all my keys
189
         for key in self.__inst_dict__:
165
         for key in self.__inst_dict__:
190
             mqtt_client.add_callback(topic + "/" + key, self.all_off)
166
             mqtt_client.add_callback(topic + "/" + key, self.all_off)
191
-        #
192
-        self.__tx_capabilities__()
193
 
167
 
194
     def __check_inst_capabilities__(self, name, inst):
168
     def __check_inst_capabilities__(self, name, inst):
195
         # fits to specified classes
169
         # fits to specified classes
220
     def all_off(self, client, userdata, message):
194
     def all_off(self, client, userdata, message):
221
         key = message.topic[len(self.topic) + 1:]
195
         key = message.topic[len(self.topic) + 1:]
222
         self.__inst_dict__[key].all_off()
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 View File

13
 
13
 
14
 VERS_MAJOR = 1
14
 VERS_MAJOR = 1
15
 VERS_MINOR = 2
15
 VERS_MINOR = 2
16
-VERS_PATCH = 4
16
+VERS_PATCH = 5
17
 
17
 
18
 INFO_TOPIC = "__info__"
18
 INFO_TOPIC = "__info__"
19
 INFO_DATA = {
19
 INFO_DATA = {

Loading…
Cancel
Save