|
@@ -10,9 +10,8 @@ Targets:
|
10
|
10
|
* No functionality should be implemented here
|
11
|
11
|
"""
|
12
|
12
|
|
13
|
|
-from base import mqtt_base
|
|
13
|
+from base import videv_base
|
14
|
14
|
from function.rooms import room, room_collection
|
15
|
|
-import json
|
16
|
15
|
import time
|
17
|
16
|
|
18
|
17
|
try:
|
|
@@ -21,100 +20,7 @@ except ImportError:
|
21
|
20
|
ROOT_LOGGER_NAME = 'root'
|
22
|
21
|
|
23
|
22
|
|
24
|
|
-class base(mqtt_base):
|
25
|
|
- KEY_INFO = '__info__'
|
26
|
|
- #
|
27
|
|
- SET_TOPIC = "set"
|
28
|
|
-
|
29
|
|
- def __init__(self, mqtt_client, topic, default_values=None):
|
30
|
|
- super().__init__(mqtt_client, topic, default_values=default_values)
|
31
|
|
- self.__display_dict__ = {}
|
32
|
|
- self.__control_dict__ = {}
|
33
|
|
- self.__capabilities__ = None
|
34
|
|
-
|
35
|
|
- def add_display(self, my_key, ext_device, ext_key, on_change_only=True):
|
36
|
|
- """
|
37
|
|
- listen to data changes of ext_device and update videv information
|
38
|
|
- """
|
39
|
|
- if my_key not in self.keys():
|
40
|
|
- self[my_key] = None
|
41
|
|
- if ext_device.__class__.__name__ == "group":
|
42
|
|
- # store information to identify callback from ext_device
|
43
|
|
- self.__display_dict__[(id(ext_device[0]), ext_key)] = my_key
|
44
|
|
- # register a callback to listen for data from external device
|
45
|
|
- ext_device[0].add_callback(ext_key, None, self.__rx_ext_device_data__, on_change_only)
|
46
|
|
- else:
|
47
|
|
- # store information to identify callback from ext_device
|
48
|
|
- self.__display_dict__[(id(ext_device), ext_key)] = my_key
|
49
|
|
- # register a callback to listen for data from external device
|
50
|
|
- ext_device.add_callback(ext_key, None, self.__rx_ext_device_data__, on_change_only)
|
51
|
|
- # send default data to videv interface
|
52
|
|
-
|
53
|
|
- def __rx_ext_device_data__(self, ext_device, ext_key, data):
|
54
|
|
- my_key = self.__display_dict__[(id(ext_device), ext_key)]
|
55
|
|
- self.set(my_key, data)
|
56
|
|
- self.__tx__(my_key, data)
|
57
|
|
-
|
58
|
|
- def __tx__(self, key, data):
|
59
|
|
- if type(data) not in (str, ):
|
60
|
|
- data = json.dumps(data)
|
61
|
|
- self.mqtt_client.send('/'.join([self.topic, key]), data)
|
62
|
|
- self.__tx_capabilities__()
|
63
|
|
-
|
64
|
|
- def __tx_capabilities__(self):
|
65
|
|
- self.mqtt_client.send(self.topic + '/' + self.KEY_INFO, json.dumps(self.capabilities))
|
66
|
|
-
|
67
|
|
- def add_control(self, my_key, ext_device, ext_key, on_change_only=True):
|
68
|
|
- """
|
69
|
|
- listen to videv information and pass data to ext_device
|
70
|
|
- """
|
71
|
|
- if my_key not in self.keys():
|
72
|
|
- self[my_key] = None
|
73
|
|
- # store information to identify callback from videv
|
74
|
|
- self.__control_dict__[my_key] = (ext_device, ext_key, on_change_only)
|
75
|
|
- # add callback for videv changes
|
76
|
|
- self.mqtt_client.add_callback('/'.join([self.topic, my_key, self.SET_TOPIC]), self.__rx_videv_data__)
|
77
|
|
-
|
78
|
|
- def __rx_videv_data__(self, client, userdata, message):
|
79
|
|
- my_key = message.topic.split('/')[-2]
|
80
|
|
- try:
|
81
|
|
- data = json.loads(message.payload)
|
82
|
|
- except json.decoder.JSONDecodeError:
|
83
|
|
- data = message.payload
|
84
|
|
- ext_device, ext_key, on_change_only = self.__control_dict__[my_key]
|
85
|
|
- if my_key in self.keys():
|
86
|
|
- if data != self[my_key] or not on_change_only:
|
87
|
|
- ext_device.send_command(ext_key, data)
|
88
|
|
- else:
|
89
|
|
- self.logger.info("Ignoring rx message with topic %s", message.topic)
|
90
|
|
-
|
91
|
|
- def add_routing(self, my_key, ext_device, ext_key, on_change_only_disp=True, on_change_only_videv=True):
|
92
|
|
- """
|
93
|
|
- listen to data changes of ext_device and update videv information
|
94
|
|
- and
|
95
|
|
- listen to videv information and pass data to ext_device
|
96
|
|
- """
|
97
|
|
- # add display
|
98
|
|
- self.add_display(my_key, ext_device, ext_key, on_change_only_disp)
|
99
|
|
- self.add_control(my_key, ext_device, ext_key, on_change_only_videv)
|
100
|
|
-
|
101
|
|
- @property
|
102
|
|
- def capabilities(self):
|
103
|
|
- if self.__capabilities__ is None:
|
104
|
|
- self.__capabilities__ = {}
|
105
|
|
- self.__capabilities__['__type__'] = self.__class__.__name__
|
106
|
|
- for key in self.__control_dict__:
|
107
|
|
- if not key in self.__capabilities__:
|
108
|
|
- self.__capabilities__[key] = {}
|
109
|
|
- self.__capabilities__[key]['control'] = True
|
110
|
|
- for key in self.__display_dict__.values():
|
111
|
|
- if not key in self.__capabilities__:
|
112
|
|
- self.__capabilities__[key] = {}
|
113
|
|
- self.__capabilities__[key]['display'] = True
|
114
|
|
- return self.__capabilities__
|
115
|
|
-
|
116
|
|
-
|
117
|
|
-class videv_switching(base):
|
|
23
|
+class videv_switching(videv_base):
|
118
|
24
|
KEY_STATE = 'state'
|
119
|
25
|
|
120
|
26
|
def __init__(self, mqtt_client, topic, sw_device, sw_key):
|
|
@@ -124,7 +30,7 @@ class videv_switching(base):
|
124
|
30
|
self.__tx_capabilities__()
|
125
|
31
|
|
126
|
32
|
|
127
|
|
-class videv_switching_timer(base):
|
|
33
|
+class videv_switching_timer(videv_base):
|
128
|
34
|
KEY_STATE = 'state'
|
129
|
35
|
KEY_TIMER = 'timer'
|
130
|
36
|
|
|
@@ -136,7 +42,7 @@ class videv_switching_timer(base):
|
136
|
42
|
self.__tx_capabilities__()
|
137
|
43
|
|
138
|
44
|
|
139
|
|
-class videv_switching_motion(base):
|
|
45
|
+class videv_switching_motion(videv_base):
|
140
|
46
|
KEY_STATE = 'state'
|
141
|
47
|
#
|
142
|
48
|
KEY_TIMER = 'timer'
|
|
@@ -155,7 +61,7 @@ class videv_switching_motion(base):
|
155
|
61
|
self.__tx_capabilities__()
|
156
|
62
|
|
157
|
63
|
|
158
|
|
-class videv_switch_brightness(base):
|
|
64
|
+class videv_switch_brightness(videv_base):
|
159
|
65
|
KEY_STATE = 'state'
|
160
|
66
|
KEY_BRIGHTNESS = 'brightness'
|
161
|
67
|
|
|
@@ -167,7 +73,7 @@ class videv_switch_brightness(base):
|
167
|
73
|
self.__tx_capabilities__()
|
168
|
74
|
|
169
|
75
|
|
170
|
|
-class videv_switch_brightness_color_temp(base):
|
|
76
|
+class videv_switch_brightness_color_temp(videv_base):
|
171
|
77
|
KEY_STATE = 'state'
|
172
|
78
|
KEY_BRIGHTNESS = 'brightness'
|
173
|
79
|
KEY_COLOR_TEMP = 'color_temp'
|
|
@@ -181,7 +87,7 @@ class videv_switch_brightness_color_temp(base):
|
181
|
87
|
self.__tx_capabilities__()
|
182
|
88
|
|
183
|
89
|
|
184
|
|
-class videv_heating(base):
|
|
90
|
+class videv_heating(videv_base):
|
185
|
91
|
KEY_USER_TEMPERATURE_SETPOINT = 'user_temperature_setpoint'
|
186
|
92
|
KEY_VALVE_TEMPERATURE_SETPOINT = 'valve_temperature_setpoint'
|
187
|
93
|
KEY_AWAY_MODE = 'away_mode'
|
|
@@ -209,7 +115,7 @@ class videv_heating(base):
|
209
|
115
|
self.__tx_capabilities__()
|
210
|
116
|
|
211
|
117
|
|
212
|
|
-class videv_multistate(base):
|
|
118
|
+class videv_multistate(videv_base):
|
213
|
119
|
KEY_STATE = 'state_%d'
|
214
|
120
|
|
215
|
121
|
def __init__(self, mqtt_client, topic, key_for_device, device, num_states, default_values=None):
|
|
@@ -230,7 +136,7 @@ class videv_multistate(base):
|
230
|
136
|
self.__tx_capabilities__()
|
231
|
137
|
|
232
|
138
|
|
233
|
|
-class videv_audio_player(base):
|
|
139
|
+class videv_audio_player(videv_base):
|
234
|
140
|
KEY_ACTIVE_PLAYER = 'player_%d'
|
235
|
141
|
KEY_TITLE = 'title'
|
236
|
142
|
NO_TITLE = '---'
|
|
@@ -255,7 +161,7 @@ class videv_audio_player(base):
|
255
|
161
|
return self.__capabilities__
|
256
|
162
|
|
257
|
163
|
|
258
|
|
-class videv_warnings(base):
|
|
164
|
+class videv_warnings(videv_base):
|
259
|
165
|
MAX_WARNINGS = 10
|
260
|
166
|
KEY_WARNING = 'html_short'
|
261
|
167
|
|
|
@@ -270,7 +176,7 @@ class videv_warnings(base):
|
270
|
176
|
self.__tx__(self.KEY_WARNING, txt)
|
271
|
177
|
|
272
|
178
|
|
273
|
|
-class all_off(base):
|
|
179
|
+class all_off(videv_base):
|
274
|
180
|
ALLOWED_CLASSES = (room, room_collection, )
|
275
|
181
|
|
276
|
182
|
def __init__(self, mqtt_client, topic, room_collection):
|