|
@@ -0,0 +1,810 @@
|
|
1
|
+from base import mqtt_base
|
|
2
|
+import colored
|
|
3
|
+import copy
|
|
4
|
+import json
|
|
5
|
+import task
|
|
6
|
+import time
|
|
7
|
+
|
|
8
|
+COLOR_GUI_ACTIVE = colored.fg("light_blue")
|
|
9
|
+COLOR_GUI_PASSIVE = COLOR_GUI_ACTIVE + colored.attr("dim")
|
|
10
|
+COLOR_SHELLY = colored.fg("light_magenta")
|
|
11
|
+COLOR_POWERPLUG = colored.fg("light_cyan")
|
|
12
|
+COLOR_LIGHT_ACTIVE = colored.fg("yellow")
|
|
13
|
+COLOR_LIGHT_PASSIVE = COLOR_LIGHT_ACTIVE + colored.attr("dim")
|
|
14
|
+COLOR_MOTION_SENSOR = colored.fg("dark_orange_3b")
|
|
15
|
+COLOR_HEATING_VALVE = colored.fg("red")
|
|
16
|
+COLOR_REMOTE = colored.fg("green")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+class base(mqtt_base):
|
|
20
|
+ AUTOSEND = True
|
|
21
|
+ COMMANDS = []
|
|
22
|
+ BOOL_KEYS = []
|
|
23
|
+
|
|
24
|
+ def __init__(self, mqtt_client, topic, default_values=None):
|
|
25
|
+ super().__init__(mqtt_client, topic, default_values)
|
|
26
|
+
|
|
27
|
+ self.names = {}
|
|
28
|
+ self.commands = self.COMMANDS[:]
|
|
29
|
+ #
|
|
30
|
+ self.mqtt_client.add_callback(self.topic, self.__rx__)
|
|
31
|
+ self.mqtt_client.add_callback(self.topic + '/#', self.__rx__)
|
|
32
|
+
|
|
33
|
+ def add_channel_name(self, key, name):
|
|
34
|
+ self.names[key] = name
|
|
35
|
+
|
|
36
|
+ def capabilities(self):
|
|
37
|
+ return self.commands
|
|
38
|
+
|
|
39
|
+ def __payload_filter__(self, payload):
|
|
40
|
+ try:
|
|
41
|
+ return json.loads(payload)
|
|
42
|
+ except json.decoder.JSONDecodeError:
|
|
43
|
+ return payload.decode("utf-8")
|
|
44
|
+
|
|
45
|
+ def __rx__(self, client, userdata, message):
|
|
46
|
+ print("%s: __rx__ not handled!" % self.__class__.__name__)
|
|
47
|
+
|
|
48
|
+ def __tx__(self, keys_changed):
|
|
49
|
+ print("%s: __tx__ not handled!" % self.__class__.__name__)
|
|
50
|
+
|
|
51
|
+ def __send__(self, client, key, data):
|
|
52
|
+ self.__tx__([key])
|
|
53
|
+
|
|
54
|
+ def __ext_to_int__(self, key, data):
|
|
55
|
+ if key in self.BOOL_KEYS:
|
|
56
|
+ if data == 'toggle':
|
|
57
|
+ return not self.get(key)
|
|
58
|
+ return data == "on"
|
|
59
|
+ return data
|
|
60
|
+
|
|
61
|
+ def __int_to_ext__(self, key, value):
|
|
62
|
+ if key in self.BOOL_KEYS:
|
|
63
|
+ return "on" if value is True else "off"
|
|
64
|
+ return value
|
|
65
|
+
|
|
66
|
+ def __devicename__(self):
|
|
67
|
+ return " - ".join(self.topic.split('/')[1:])
|
|
68
|
+
|
|
69
|
+ def __percent_bar__(self, percent_value):
|
|
70
|
+ rv = ""
|
|
71
|
+ for i in range(0, 10):
|
|
72
|
+ rv += u"\u25ac" if (percent_value - 5) > 10*i else u"\u25ad"
|
|
73
|
+ return rv
|
|
74
|
+
|
|
75
|
+ def __command_int_value__(self, value):
|
|
76
|
+ try:
|
|
77
|
+ return int(value)
|
|
78
|
+ except TypeError:
|
|
79
|
+ print("You need to give a integer parameter not '%s'" % str(value))
|
|
80
|
+
|
|
81
|
+ def __command_float_value__(self, value):
|
|
82
|
+ try:
|
|
83
|
+ return float(value)
|
|
84
|
+ except TypeError:
|
|
85
|
+ print("You need to give a numeric parameter not '%s'" % str(value))
|
|
86
|
+
|
|
87
|
+ def print_formatted_light(self, color, state, description, led=False):
|
|
88
|
+ if led is True:
|
|
89
|
+ if state is True:
|
|
90
|
+ icon = colored.fg('green') + "\u2b24" + color
|
|
91
|
+ else:
|
|
92
|
+ icon = colored.fg('light_gray') + "\u2b24" + color
|
|
93
|
+ else:
|
|
94
|
+ icon = u'\u2b24' if state is True else u'\u25ef'
|
|
95
|
+ print(color + 10 * ' ' + icon + 9 * ' ' + self.__devicename__(), description + colored.attr("reset"))
|
|
96
|
+
|
|
97
|
+ def print_formatted_videv(self, color, state, description):
|
|
98
|
+ icon = u'\u25a0' if state is True else u'\u25a1'
|
|
99
|
+ print(color + 10 * ' ' + icon + 9 * ' ' + self.__devicename__(), description + colored.attr("reset"))
|
|
100
|
+
|
|
101
|
+ def print_formatted_percent(self, color, prefix, perc_value, value_str, description):
|
|
102
|
+ if len(prefix) > 1 or len(value_str) > 7:
|
|
103
|
+ raise ValueError("Length of prefix (%d) > 1 or length of value_str (%d) > 7" % (len(prefix), len(value_str)))
|
|
104
|
+ print(color + prefix + self.__percent_bar__(perc_value), value_str + (8 - len(value_str))
|
|
105
|
+ * ' ' + self.__devicename__(), description + colored.attr("reset"))
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+class base_videv(base):
|
|
109
|
+ def set(self, key, data, block_callback=[]):
|
|
110
|
+ if key in self.keys():
|
|
111
|
+ return super().set(key, data, block_callback)
|
|
112
|
+ else:
|
|
113
|
+ self.__send__(self, key, data)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+class shelly(base):
|
|
117
|
+ KEY_OUTPUT_0 = "relay/0"
|
|
118
|
+ KEY_OUTPUT_1 = "relay/1"
|
|
119
|
+ KEY_INPUT_0 = "input/0"
|
|
120
|
+ KEY_INPUT_1 = "input/1"
|
|
121
|
+ KEY_LONGPUSH_0 = "longpush/0"
|
|
122
|
+ KEY_LONGPUSH_1 = "longpush/1"
|
|
123
|
+ #
|
|
124
|
+ BOOL_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_INPUT_0, KEY_INPUT_1, KEY_LONGPUSH_0, KEY_LONGPUSH_1, ]
|
|
125
|
+ #
|
|
126
|
+ INPUT_FUNC_OUT1_FOLLOW = "out1_follow"
|
|
127
|
+ INPUT_FUNC_OUT1_TRIGGER = "out1_trigger"
|
|
128
|
+ INPUT_FUNC_OUT2_FOLLOW = "out2_follow"
|
|
129
|
+ INPUT_FUNC_OUT2_TRIGGER = "out2_trigger"
|
|
130
|
+ #
|
|
131
|
+ COMMANDS = [
|
|
132
|
+ "get_output_0", "toggle_output_0",
|
|
133
|
+ "get_output_1", "toggle_output_1",
|
|
134
|
+ "get_input_0", "toggle_input_0",
|
|
135
|
+ "get_input_1", "toggle_input_1",
|
|
136
|
+ "trigger_input_0_longpress", "trigger_input_1_longpress",
|
|
137
|
+ ]
|
|
138
|
+
|
|
139
|
+ def __init__(self, mqtt_client, topic, input_0_func=None, input_1_func=None, output_0_auto_off=None):
|
|
140
|
+ super().__init__(mqtt_client, topic, default_values={self.KEY_OUTPUT_0: False, self.KEY_OUTPUT_1: False,
|
|
141
|
+ self.KEY_INPUT_0: False, self.KEY_INPUT_1: False})
|
|
142
|
+ #
|
|
143
|
+ self.__input_0_func = input_0_func
|
|
144
|
+ self.__input_1_func = input_1_func
|
|
145
|
+ self.__output_0_auto_off__ = output_0_auto_off
|
|
146
|
+ # print ouput changes
|
|
147
|
+ self.add_callback(self.KEY_OUTPUT_0, None, self.print_formatted, True)
|
|
148
|
+ self.add_callback(self.KEY_OUTPUT_1, None, self.print_formatted, True)
|
|
149
|
+ # publish state changes
|
|
150
|
+ self.add_callback(self.KEY_OUTPUT_0, None, self.__send__, True)
|
|
151
|
+ self.add_callback(self.KEY_OUTPUT_1, None, self.__send__, True)
|
|
152
|
+ #
|
|
153
|
+ if self.__output_0_auto_off__ is not None:
|
|
154
|
+ self.__delayed_off__ = task.delayed(float(self.__output_0_auto_off__), self.__auto_off__, self.KEY_OUTPUT_0)
|
|
155
|
+ self.add_callback(self.KEY_OUTPUT_0, True, self.__start_auto_off__)
|
|
156
|
+ #
|
|
157
|
+ self.add_callback(self.KEY_INPUT_0, self.__input_function__, None)
|
|
158
|
+ self.add_callback(self.KEY_INPUT_1, self.__input_function__, None)
|
|
159
|
+ #
|
|
160
|
+ self.__tx__((self.KEY_OUTPUT_0, self.KEY_OUTPUT_1))
|
|
161
|
+
|
|
162
|
+ def __rx__(self, client, userdata, message):
|
|
163
|
+ value = self.__payload_filter__(message.payload)
|
|
164
|
+ if message.topic.startswith(self.topic) and message.topic.endswith("/command"):
|
|
165
|
+ key = '/'.join(message.topic.split('/')[-3:-1])
|
|
166
|
+ self.set(key, self.__ext_to_int__(key, value))
|
|
167
|
+
|
|
168
|
+ def __tx__(self, keys_changed):
|
|
169
|
+ for key in keys_changed:
|
|
170
|
+ self.mqtt_client.send(self.topic + '/' + key, self.__int_to_ext__(key, self[key]))
|
|
171
|
+
|
|
172
|
+ def __input_function__(self, device, key, data):
|
|
173
|
+ if key == self.KEY_INPUT_0:
|
|
174
|
+ func = self.__input_0_func
|
|
175
|
+ elif key == self.KEY_INPUT_1:
|
|
176
|
+ func = self.__input_1_func
|
|
177
|
+ else:
|
|
178
|
+ func = None
|
|
179
|
+ if func == self.INPUT_FUNC_OUT1_FOLLOW:
|
|
180
|
+ self.set(self.KEY_OUTPUT_0, data)
|
|
181
|
+ elif func == self.INPUT_FUNC_OUT1_TRIGGER:
|
|
182
|
+ self.set__toggle_data__(self.KEY_OUTPUT_0)
|
|
183
|
+ elif func == self.INPUT_FUNC_OUT2_FOLLOW:
|
|
184
|
+ self.__set_data__(self.KEY_OUTPUT_1, data)
|
|
185
|
+ elif func == self.INPUT_FUNC_OUT2_TRIGGER:
|
|
186
|
+ self.__toggle_data__(self.KEY_OUTPUT_1)
|
|
187
|
+
|
|
188
|
+ def __start_auto_off__(self, device, key, data):
|
|
189
|
+ # stop delayed task if needed
|
|
190
|
+ if self.__output_0_auto_off__ is not None:
|
|
191
|
+ if not self.__delayed_off__._stopped:
|
|
192
|
+ self.__delayed_off__.stop()
|
|
193
|
+ # start delayed task
|
|
194
|
+ if self.__output_0_auto_off__ is not None:
|
|
195
|
+ self.__delayed_off__.run()
|
|
196
|
+
|
|
197
|
+ def __auto_off__(self, key):
|
|
198
|
+ if key == self.KEY_OUTPUT_0:
|
|
199
|
+ self.set(key, False)
|
|
200
|
+
|
|
201
|
+ def command(self, command):
|
|
202
|
+ if command in self.COMMANDS:
|
|
203
|
+ if command == self.COMMANDS[0]:
|
|
204
|
+ self.print_formatted(self, self.KEY_OUTPUT_0, self.get(self.KEY_OUTPUT_0))
|
|
205
|
+ elif command == self.COMMANDS[1]:
|
|
206
|
+ self.set(self.KEY_OUTPUT_0, not self[self.KEY_OUTPUT_0])
|
|
207
|
+ elif command == self.COMMANDS[2]:
|
|
208
|
+ self.print_formatted(self, self.KEY_OUTPUT_1, self.get(self.KEY_OUTPUT_1))
|
|
209
|
+ elif command == self.COMMANDS[3]:
|
|
210
|
+ self.set(self.KEY_OUTPUT_1, not self[self.KEY_OUTPUT_1])
|
|
211
|
+ elif command == self.COMMANDS[4]:
|
|
212
|
+ self.print_formatted(self, self.KEY_INPUT_0, self.get(self.KEY_INPUT_0))
|
|
213
|
+ elif command == self.COMMANDS[5]:
|
|
214
|
+ self.set(self.KEY_INPUT_0, not self[self.KEY_INPUT_0])
|
|
215
|
+ elif command == self.COMMANDS[6]:
|
|
216
|
+ self.print_formatted(self, self.KEY_INPUT_1, self.get(self.KEY_INPUT_1))
|
|
217
|
+ elif command == self.COMMANDS[7]:
|
|
218
|
+ self.set(self.KEY_INPUT_1, not self[self.KEY_INPUT_1])
|
|
219
|
+ elif command == self.COMMANDS[8]:
|
|
220
|
+ self.set(self.KEY_INPUT_0, not self[self.KEY_INPUT_0])
|
|
221
|
+ time.sleep(0.4)
|
|
222
|
+ self.set(self.KEY_LONGPUSH_0, True)
|
|
223
|
+ time.sleep(0.1)
|
|
224
|
+ self.set(self.KEY_INPUT_0, not self[self.KEY_INPUT_0])
|
|
225
|
+ self.set(self.KEY_LONGPUSH_0, False)
|
|
226
|
+ elif command == self.COMMANDS[9]:
|
|
227
|
+ self.set(self.KEY_INPUT_1, not self[self.KEY_INPUT_1])
|
|
228
|
+ time.sleep(0.4)
|
|
229
|
+ self.set(self.KEY_LONGPUSH_1, True)
|
|
230
|
+ time.sleep(0.1)
|
|
231
|
+ self.set(self.KEY_INPUT_1, not self[self.KEY_INPUT_1])
|
|
232
|
+ self.set(self.KEY_LONGPUSH_1, False)
|
|
233
|
+ else:
|
|
234
|
+ print("%s: not yet implemented!" % command)
|
|
235
|
+ else:
|
|
236
|
+ print("Unknown command!")
|
|
237
|
+
|
|
238
|
+ def print_formatted(self, device, key, value):
|
|
239
|
+ if value is not None:
|
|
240
|
+ info = (" - %ds" % self.__output_0_auto_off__) if self.__output_0_auto_off__ is not None and value else ""
|
|
241
|
+ channel = "(%s%s)" % (self.names.get(key, key), info)
|
|
242
|
+ self.print_formatted_light(COLOR_SHELLY, value, channel)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+class my_powerplug(base):
|
|
246
|
+ KEY_OUTPUT_0 = "state"
|
|
247
|
+ #
|
|
248
|
+ COMMANDS = [
|
|
249
|
+ "get_output", "toggle_output",
|
|
250
|
+ ]
|
|
251
|
+
|
|
252
|
+ def __init__(self, mqtt_client, topic, channel):
|
|
253
|
+ super().__init__(mqtt_client, topic + '/' + "output/%d" % (channel + 1), default_values={self.KEY_OUTPUT_0: False})
|
|
254
|
+ #
|
|
255
|
+ self.add_callback(self.KEY_OUTPUT_0, None, self.print_formatted, True)
|
|
256
|
+ self.add_callback(self.KEY_OUTPUT_0, None, self.__send__, True)
|
|
257
|
+ #
|
|
258
|
+ self.__tx__((self.KEY_OUTPUT_0, ))
|
|
259
|
+
|
|
260
|
+ def __rx__(self, client, userdata, message):
|
|
261
|
+ if message.topic == self.topic + '/set':
|
|
262
|
+ payload = self.__payload_filter__(message.payload)
|
|
263
|
+ if payload == "toggle":
|
|
264
|
+ payload = not self.get(self.KEY_OUTPUT_0)
|
|
265
|
+ self.set(self.KEY_OUTPUT_0, payload)
|
|
266
|
+
|
|
267
|
+ def __tx__(self, keys_changed):
|
|
268
|
+ for key in keys_changed:
|
|
269
|
+ self.mqtt_client.send(self.topic, json.dumps(self.get(key)))
|
|
270
|
+
|
|
271
|
+ def command(self, command):
|
|
272
|
+ if command in self.COMMANDS:
|
|
273
|
+ if command == self.COMMANDS[0]:
|
|
274
|
+ self.print_formatted(self, self.KEY_OUTPUT_0, self.get(self.KEY_OUTPUT_0))
|
|
275
|
+ elif command == self.COMMANDS[1]:
|
|
276
|
+ self.set(self.KEY_OUTPUT_0, not self.get(self.KEY_OUTPUT_0))
|
|
277
|
+ else:
|
|
278
|
+ print("%s: not yet implemented!" % command)
|
|
279
|
+ else:
|
|
280
|
+ print("Unknown command!")
|
|
281
|
+
|
|
282
|
+ def print_formatted(self, device, key, value):
|
|
283
|
+ if value is not None:
|
|
284
|
+ self.print_formatted_light(COLOR_POWERPLUG, value, "(%s)" % self.names.get(key, "State"))
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+class silvercrest_powerplug(base):
|
|
288
|
+ KEY_OUTPUT_0 = "state"
|
|
289
|
+ #
|
|
290
|
+ BOOL_KEYS = [KEY_OUTPUT_0, ]
|
|
291
|
+ #
|
|
292
|
+ COMMANDS = [
|
|
293
|
+ "get_output", "toggle_output",
|
|
294
|
+ ]
|
|
295
|
+
|
|
296
|
+ def __init__(self, mqtt_client, topic):
|
|
297
|
+ super().__init__(mqtt_client, topic, default_values={self.KEY_OUTPUT_0: False})
|
|
298
|
+ #
|
|
299
|
+ self.add_callback(self.KEY_OUTPUT_0, None, self.print_formatted, True)
|
|
300
|
+ self.add_callback(self.KEY_OUTPUT_0, None, self.__send__, True)
|
|
301
|
+ #
|
|
302
|
+ self.__tx__((self.KEY_OUTPUT_0, ))
|
|
303
|
+
|
|
304
|
+ def __rx__(self, client, userdata, message):
|
|
305
|
+ if message.topic == self.topic + '/set':
|
|
306
|
+ state = json.loads(message.payload).get('state')
|
|
307
|
+ self.set(self.KEY_OUTPUT_0, self.__ext_to_int__(self.KEY_OUTPUT_0, state))
|
|
308
|
+
|
|
309
|
+ def __tx__(self, keys_changed):
|
|
310
|
+ for key in keys_changed:
|
|
311
|
+ self.mqtt_client.send(self.topic + '/' + key, self.__int_to_ext__(self.KEY_OUTPUT_0, self.get(self.KEY_OUTPUT_0)))
|
|
312
|
+
|
|
313
|
+ def command(self, command):
|
|
314
|
+ if command in self.COMMANDS:
|
|
315
|
+ if command == self.COMMANDS[0]:
|
|
316
|
+ self.print_formatted(self, self.KEY_OUTPUT_0, self.get(self.KEY_OUTPUT_0))
|
|
317
|
+ elif command == self.COMMANDS[1]:
|
|
318
|
+ self.set(self.KEY_OUTPUT_0, not self.get(self.KEY_OUTPUT_0))
|
|
319
|
+ else:
|
|
320
|
+ print("%s: not yet implemented!" % command)
|
|
321
|
+ else:
|
|
322
|
+ print("Unknown command!")
|
|
323
|
+
|
|
324
|
+ def print_formatted(self, device, key, value):
|
|
325
|
+ if value is not None:
|
|
326
|
+ self.print_formatted_light(COLOR_POWERPLUG, value, "(%s)" % self.names.get(key, key))
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+class tradfri_light(base):
|
|
330
|
+ KEY_OUTPUT_0 = "state"
|
|
331
|
+ KEY_BRIGHTNESS = "brightness"
|
|
332
|
+ KEY_COLOR_TEMP = "color_temp"
|
|
333
|
+ #
|
|
334
|
+ BOOL_KEYS = [KEY_OUTPUT_0, ]
|
|
335
|
+ #
|
|
336
|
+ STATE_COMMANDS = ("get_state", "toggle_state", )
|
|
337
|
+ BRIGHTNESS_COMMANDS = ("get_brightness", "set_brightness",)
|
|
338
|
+ COLOR_TEMP_COMMANDS = ("get_color_temp", "set_color_temp",)
|
|
339
|
+
|
|
340
|
+ def __init__(self, mqtt_client, topic, enable_state=True, enable_brightness=False, enable_color_temp=False, send_on_power_on=True):
|
|
341
|
+ default_values = {}
|
|
342
|
+ if enable_state:
|
|
343
|
+ default_values[self.KEY_OUTPUT_0] = False
|
|
344
|
+ if enable_brightness:
|
|
345
|
+ default_values[self.KEY_BRIGHTNESS] = 50
|
|
346
|
+ if enable_color_temp:
|
|
347
|
+ default_values[self.KEY_COLOR_TEMP] = 5
|
|
348
|
+ super().__init__(mqtt_client, topic, default_values=default_values)
|
|
349
|
+ #
|
|
350
|
+ self.send_on_power_on = send_on_power_on
|
|
351
|
+ #
|
|
352
|
+ if enable_state:
|
|
353
|
+ self.commands.extend(self.STATE_COMMANDS)
|
|
354
|
+ if enable_brightness:
|
|
355
|
+ self.commands.extend(self.BRIGHTNESS_COMMANDS)
|
|
356
|
+ if enable_color_temp:
|
|
357
|
+ self.commands.extend(self.COLOR_TEMP_COMMANDS)
|
|
358
|
+ #
|
|
359
|
+ self.add_callback(self.KEY_OUTPUT_0, None, self.print_formatted, True)
|
|
360
|
+ self.add_callback(self.KEY_BRIGHTNESS, None, self.print_formatted, True)
|
|
361
|
+ self.add_callback(self.KEY_COLOR_TEMP, None, self.print_formatted, True)
|
|
362
|
+ self.add_callback(self.KEY_OUTPUT_0, None, self.__send__, True)
|
|
363
|
+ self.add_callback(self.KEY_BRIGHTNESS, None, self.__send__, True)
|
|
364
|
+ self.add_callback(self.KEY_COLOR_TEMP, None, self.__send__, True)
|
|
365
|
+
|
|
366
|
+ def __ext_to_int__(self, key, data):
|
|
367
|
+ if key == self.KEY_BRIGHTNESS:
|
|
368
|
+ return round((data - 1) / 2.53, 0)
|
|
369
|
+ elif key == self.KEY_COLOR_TEMP:
|
|
370
|
+ return round((data - 250) / 20.4, 0)
|
|
371
|
+ else:
|
|
372
|
+ return super().__ext_to_int__(key, data)
|
|
373
|
+
|
|
374
|
+ def __int_to_ext__(self, key, data):
|
|
375
|
+ if key == self.KEY_BRIGHTNESS:
|
|
376
|
+ return 1 + round(2.53 * data, 0)
|
|
377
|
+ elif key == self.KEY_COLOR_TEMP:
|
|
378
|
+ return 250 + round(20.4 * data, 0)
|
|
379
|
+ else:
|
|
380
|
+ return super().__int_to_ext__(key, data)
|
|
381
|
+
|
|
382
|
+ def __rx__(self, client, userdata, message):
|
|
383
|
+ data = json.loads(message.payload)
|
|
384
|
+ if self.get(self.KEY_OUTPUT_0) or data.get(self.KEY_OUTPUT_0) in ['on', 'toggle']: # prevent non power changes, if not powered on
|
|
385
|
+ if message.topic.startswith(self.topic) and message.topic.endswith('/set'):
|
|
386
|
+ for targetkey in data.keys():
|
|
387
|
+ value = data[targetkey]
|
|
388
|
+ if targetkey in self.keys():
|
|
389
|
+ self.set(targetkey, self.__ext_to_int__(targetkey, value))
|
|
390
|
+ elif message.topic == self.topic + '/get':
|
|
391
|
+ self.__tx__(None)
|
|
392
|
+
|
|
393
|
+ def __tx__(self, keys_changed):
|
|
394
|
+ tx_data = dict(self)
|
|
395
|
+ for key in tx_data:
|
|
396
|
+ tx_data[key] = self.__int_to_ext__(key, self[key])
|
|
397
|
+ self.mqtt_client.send(self.topic, json.dumps(tx_data))
|
|
398
|
+
|
|
399
|
+ def command(self, command):
|
|
400
|
+ try:
|
|
401
|
+ command, value = command.split(' ')
|
|
402
|
+ except ValueError:
|
|
403
|
+ value = None
|
|
404
|
+ if command in self.capabilities():
|
|
405
|
+ if command == self.STATE_COMMANDS[0]:
|
|
406
|
+ self.print_formatted(self, self.KEY_OUTPUT_0, self.get(self.KEY_OUTPUT_0))
|
|
407
|
+ elif command == self.STATE_COMMANDS[1]:
|
|
408
|
+ self.set(self.KEY_OUTPUT_0, not self.get(self.KEY_OUTPUT_0))
|
|
409
|
+ elif command == self.BRIGHTNESS_COMMANDS[0]:
|
|
410
|
+ self.print_formatted(self, self.KEY_BRIGHTNESS, self.get(self.KEY_BRIGHTNESS))
|
|
411
|
+ elif command == self.BRIGHTNESS_COMMANDS[1]:
|
|
412
|
+ self.set(self.KEY_BRIGHTNESS, self.__command_int_value__(value))
|
|
413
|
+ elif command == self.COLOR_TEMP_COMMANDS[0]:
|
|
414
|
+ self.print_formatted(self, self.KEY_COLOR_TEMP, self.get(self.KEY_COLOR_TEMP))
|
|
415
|
+ elif command == self.COLOR_TEMP_COMMANDS[1]:
|
|
416
|
+ self.set(self.KEY_COLOR_TEMP, self.__command_int_value__(value))
|
|
417
|
+ else:
|
|
418
|
+ print("%s: not yet implemented!" % command)
|
|
419
|
+ else:
|
|
420
|
+ print("Unknown command!")
|
|
421
|
+
|
|
422
|
+ def power_off(self, device, key, value):
|
|
423
|
+ self.set(self.KEY_OUTPUT_0, False, block_callback=(self.__send__, ))
|
|
424
|
+
|
|
425
|
+ def power_on(self, device, key, value):
|
|
426
|
+ block_callback = [] if self.send_on_power_on else (self.__send__, )
|
|
427
|
+ self.set(self.KEY_OUTPUT_0, True, block_callback=block_callback)
|
|
428
|
+
|
|
429
|
+ def print_formatted(self, device, key, value):
|
|
430
|
+ if value is not None:
|
|
431
|
+ color = COLOR_LIGHT_ACTIVE
|
|
432
|
+ if key == self.KEY_OUTPUT_0:
|
|
433
|
+ self.print_formatted_light(COLOR_LIGHT_ACTIVE, value, "")
|
|
434
|
+ self.print_formatted(device, self.KEY_BRIGHTNESS, self.get(self.KEY_BRIGHTNESS))
|
|
435
|
+ self.print_formatted(device, self.KEY_COLOR_TEMP, self.get(self.KEY_COLOR_TEMP))
|
|
436
|
+ elif key in [self.KEY_BRIGHTNESS, self.KEY_COLOR_TEMP]:
|
|
437
|
+ perc_value = round(value, 0) if key == self.KEY_BRIGHTNESS else round(10 * value, 0)
|
|
438
|
+ self.print_formatted_percent(
|
|
439
|
+ COLOR_LIGHT_PASSIVE if not self.get(self.KEY_OUTPUT_0) else COLOR_LIGHT_ACTIVE,
|
|
440
|
+ 'B' if key == self.KEY_BRIGHTNESS else 'C',
|
|
441
|
+ perc_value,
|
|
442
|
+ "%3d%%" % perc_value,
|
|
443
|
+ ""
|
|
444
|
+ )
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+class brennenstuhl_heating_valve(base):
|
|
448
|
+ TEMP_RANGE = [10, 30]
|
|
449
|
+ #
|
|
450
|
+ KEY_TEMPERATURE_SETPOINT = "current_heating_setpoint"
|
|
451
|
+ KEY_TEMPERATURE = "local_temperature"
|
|
452
|
+ #
|
|
453
|
+ COMMANDS = [
|
|
454
|
+ "get_temperature_setpoint", "set_temperature_setpoint", "set_local_temperature",
|
|
455
|
+ ]
|
|
456
|
+
|
|
457
|
+ def __init__(self, mqtt_client, topic):
|
|
458
|
+ super().__init__(mqtt_client, topic, default_values={
|
|
459
|
+ self.KEY_TEMPERATURE_SETPOINT: 20,
|
|
460
|
+ self.KEY_TEMPERATURE: 20.7,
|
|
461
|
+ })
|
|
462
|
+ #
|
|
463
|
+ self.add_callback(self.KEY_TEMPERATURE_SETPOINT, None, self.print_formatted, True)
|
|
464
|
+ self.add_callback(self.KEY_TEMPERATURE_SETPOINT, None, self.__send__, True)
|
|
465
|
+ self.add_callback(self.KEY_TEMPERATURE, None, self.__send__, True)
|
|
466
|
+ #
|
|
467
|
+ self.__tx__((self.KEY_TEMPERATURE_SETPOINT, ))
|
|
468
|
+
|
|
469
|
+ def __rx__(self, client, userdata, message):
|
|
470
|
+ if message.topic.startswith(self.topic) and message.topic.endswith("/set"):
|
|
471
|
+ payload = self.__payload_filter__(message.payload)
|
|
472
|
+ for key in payload:
|
|
473
|
+ self.set(key, self.__ext_to_int__(key, payload[key]))
|
|
474
|
+
|
|
475
|
+ def __tx__(self, keys_changed):
|
|
476
|
+ tx_data = dict(self)
|
|
477
|
+ for key in tx_data:
|
|
478
|
+ tx_data[key] = self.__int_to_ext__(key, self[key])
|
|
479
|
+ self.mqtt_client.send(self.topic, json.dumps(tx_data))
|
|
480
|
+
|
|
481
|
+ def command(self, command):
|
|
482
|
+ try:
|
|
483
|
+ command, value = command.split(' ')
|
|
484
|
+ except ValueError:
|
|
485
|
+ value = None
|
|
486
|
+ if command in self.COMMANDS:
|
|
487
|
+ if command == self.COMMANDS[0]:
|
|
488
|
+ self.print_formatted(self, self.KEY_TEMPERATURE_SETPOINT, self.get(self.KEY_TEMPERATURE_SETPOINT))
|
|
489
|
+ elif command == self.COMMANDS[1]:
|
|
490
|
+ self.set(self.KEY_TEMPERATURE_SETPOINT, self.__command_float_value__(value))
|
|
491
|
+ elif command == self.COMMANDS[2]:
|
|
492
|
+ self.set(self.KEY_TEMPERATURE, self.__command_float_value__(value))
|
|
493
|
+
|
|
494
|
+ def print_formatted(self, device, key, value):
|
|
495
|
+ if key == self.KEY_TEMPERATURE_SETPOINT:
|
|
496
|
+ perc = 100 * (value - self.TEMP_RANGE[0]) / (self.TEMP_RANGE[1] - self.TEMP_RANGE[0])
|
|
497
|
+ perc = 100 if perc > 100 else perc
|
|
498
|
+ perc = 0 if perc < 0 else perc
|
|
499
|
+ self.print_formatted_percent(COLOR_HEATING_VALVE, '\u03d1', perc, "%4.1f°C" % value, "")
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+class videv_light(base_videv):
|
|
503
|
+ KEY_OUTPUT_0 = "state"
|
|
504
|
+ KEY_BRIGHTNESS = "brightness"
|
|
505
|
+ KEY_COLOR_TEMP = "color_temp"
|
|
506
|
+ KEY_TIMER = "timer"
|
|
507
|
+ #
|
|
508
|
+ STATE_COMMANDS = ("get_state", "toggle_state", )
|
|
509
|
+ BRIGHTNESS_COMMANDS = ("get_brightness", "set_brightness", )
|
|
510
|
+ COLOR_TEMP_COMMANDS = ("get_color_temp", "set_color_temp", )
|
|
511
|
+ TIMER_COMMANDS = ("get_timer", )
|
|
512
|
+
|
|
513
|
+ def __init__(self, mqtt_client, topic, enable_state=True, enable_brightness=False, enable_color_temp=False, enable_timer=False):
|
|
514
|
+ default_values = {}
|
|
515
|
+ if enable_state:
|
|
516
|
+ default_values[self.KEY_OUTPUT_0] = False
|
|
517
|
+ if enable_brightness:
|
|
518
|
+ default_values[self.KEY_BRIGHTNESS] = 50
|
|
519
|
+ if enable_color_temp:
|
|
520
|
+ default_values[self.KEY_COLOR_TEMP] = 5
|
|
521
|
+ if enable_timer:
|
|
522
|
+ default_values[self.KEY_TIMER] = 0
|
|
523
|
+ super().__init__(mqtt_client, topic, default_values=default_values)
|
|
524
|
+ #
|
|
525
|
+ self.enable_state = enable_state
|
|
526
|
+ self.enable_brightness = enable_brightness
|
|
527
|
+ self.enable_color_temp = enable_color_temp
|
|
528
|
+ self.enable_timer = enable_timer
|
|
529
|
+ #
|
|
530
|
+ if enable_state:
|
|
531
|
+ self.commands.extend(self.STATE_COMMANDS)
|
|
532
|
+ if enable_brightness:
|
|
533
|
+ self.commands.extend(self.BRIGHTNESS_COMMANDS)
|
|
534
|
+ if enable_color_temp:
|
|
535
|
+ self.commands.extend(self.COLOR_TEMP_COMMANDS)
|
|
536
|
+ if enable_timer:
|
|
537
|
+ self.commands.extend(self.TIMER_COMMANDS)
|
|
538
|
+ #
|
|
539
|
+ self.timer_maxvalue = None
|
|
540
|
+ # add commands to be available
|
|
541
|
+ self.add_callback(self.KEY_OUTPUT_0, None, self.print_formatted, True)
|
|
542
|
+ self.add_callback(self.KEY_BRIGHTNESS, None, self.print_formatted, True)
|
|
543
|
+ self.add_callback(self.KEY_COLOR_TEMP, None, self.print_formatted, True)
|
|
544
|
+ self.add_callback(self.KEY_TIMER, None, self.print_formatted, True)
|
|
545
|
+ self.add_callback(self.KEY_OUTPUT_0, None, self.__send__, True)
|
|
546
|
+ self.add_callback(self.KEY_BRIGHTNESS, None, self.__send__, True)
|
|
547
|
+ self.add_callback(self.KEY_COLOR_TEMP, None, self.__send__, True)
|
|
548
|
+ self.add_callback(self.KEY_TIMER, None, self.__send__, True)
|
|
549
|
+
|
|
550
|
+ def __rx__(self, client, userdata, message):
|
|
551
|
+ value = self.__payload_filter__(message.payload)
|
|
552
|
+ if message.topic.startswith(self.topic):
|
|
553
|
+ targetkey = message.topic.split('/')[-1]
|
|
554
|
+ if targetkey in self.keys():
|
|
555
|
+ self.set(targetkey, value, block_callback=(self.__send__, ))
|
|
556
|
+ elif targetkey != "__info__":
|
|
557
|
+ print("Unknown key %s in %s::%s" % (targetkey, message.topic, self.__class__.__name__))
|
|
558
|
+
|
|
559
|
+ def __tx__(self, keys_changed):
|
|
560
|
+ for key in keys_changed:
|
|
561
|
+ topic = self.topic + '/' + key
|
|
562
|
+ self.mqtt_client.send(topic, json.dumps(self[key]))
|
|
563
|
+
|
|
564
|
+ def command(self, command):
|
|
565
|
+ try:
|
|
566
|
+ command, value = command.split(' ')
|
|
567
|
+ except ValueError:
|
|
568
|
+ value = None
|
|
569
|
+ if command in self.capabilities():
|
|
570
|
+ if command == self.STATE_COMMANDS[0]:
|
|
571
|
+ self.print_formatted(self, self.KEY_OUTPUT_0, self.get(self.KEY_OUTPUT_0))
|
|
572
|
+ elif command == self.STATE_COMMANDS[1]:
|
|
573
|
+ self.set(self.KEY_OUTPUT_0, not self.get(self.KEY_OUTPUT_0))
|
|
574
|
+ elif command == self.BRIGHTNESS_COMMANDS[0]:
|
|
575
|
+ self.print_formatted(self, self.KEY_BRIGHTNESS, self.get(self.KEY_BRIGHTNESS))
|
|
576
|
+ elif command == self.BRIGHTNESS_COMMANDS[1]:
|
|
577
|
+ self.set(self.KEY_BRIGHTNESS, self.__command_int_value__(value))
|
|
578
|
+ elif command == self.COLOR_TEMP_COMMANDS[0]:
|
|
579
|
+ self.print_formatted(self, self.KEY_COLOR_TEMP, self.get(self.KEY_COLOR_TEMP))
|
|
580
|
+ elif command == self.COLOR_TEMP_COMMANDS[1]:
|
|
581
|
+ self.set(self.KEY_COLOR_TEMP, self.__command_int_value__(value))
|
|
582
|
+ elif command == self.TIMER_COMMANDS[0]:
|
|
583
|
+ self.print_formatted(self, self.KEY_TIMER, self.get(self.KEY_TIMER))
|
|
584
|
+ else:
|
|
585
|
+ print("%s: not yet implemented!" % command)
|
|
586
|
+ else:
|
|
587
|
+ print("Unknown command!")
|
|
588
|
+
|
|
589
|
+ def print_formatted(self, device, key, value):
|
|
590
|
+ if value is not None:
|
|
591
|
+ if key == self.KEY_OUTPUT_0:
|
|
592
|
+ self.print_formatted_videv(COLOR_GUI_ACTIVE, value, "")
|
|
593
|
+ elif key in [self.KEY_BRIGHTNESS, self.KEY_COLOR_TEMP]:
|
|
594
|
+ perc_value = round(value * 10 if key == self.KEY_COLOR_TEMP else value, 0)
|
|
595
|
+ self.print_formatted_percent(
|
|
596
|
+ COLOR_GUI_ACTIVE,
|
|
597
|
+ 'B' if key == self.KEY_BRIGHTNESS else 'C',
|
|
598
|
+ perc_value,
|
|
599
|
+ "%3d%%" % perc_value,
|
|
600
|
+ ""
|
|
601
|
+ )
|
|
602
|
+ elif key == self.KEY_TIMER:
|
|
603
|
+ if value > 0:
|
|
604
|
+ if self.timer_maxvalue is None and value != 0:
|
|
605
|
+ self.timer_maxvalue = value
|
|
606
|
+ disp_value = value
|
|
607
|
+ try:
|
|
608
|
+ perc = disp_value / self.timer_maxvalue * 100
|
|
609
|
+ except ZeroDivisionError:
|
|
610
|
+ perc = 0
|
|
611
|
+ else:
|
|
612
|
+ disp_value = 0
|
|
613
|
+ perc = 0
|
|
614
|
+ self.timer_maxvalue = None
|
|
615
|
+ self.print_formatted_percent(COLOR_GUI_ACTIVE, 't', perc, '%3d%%' % perc, '(%.1f)' % disp_value)
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+class videv_heating(base_videv):
|
|
619
|
+ TEMP_RANGE = [10, 30]
|
|
620
|
+ #
|
|
621
|
+ KEY_USER_TEMPERATURE_SETPOINT = 'user_temperature_setpoint'
|
|
622
|
+ KEY_VALVE_TEMPERATURE_SETPOINT = 'valve_temperature_setpoint'
|
|
623
|
+ KEY_AWAY_MODE = 'away_mode'
|
|
624
|
+ KEY_SUMMER_MODE = 'summer_mode'
|
|
625
|
+ KEY_SET_DEFAULT_TEMPERATURE = 'set_default_temperature'
|
|
626
|
+ KEY_START_BOOST = 'start_boost'
|
|
627
|
+ KEY_BOOST_TIMER = 'boost_timer'
|
|
628
|
+ #
|
|
629
|
+ KEY_TEMPERATURE = 'temperature'
|
|
630
|
+ #
|
|
631
|
+ COMMANDS = ["get_temperature_setpoint", "set_temperature_setpoint", "toggle_away_mode",
|
|
632
|
+ "toggle_summer_mode", "trigger_default_temperature", "trigger_boost"]
|
|
633
|
+
|
|
634
|
+ def __init__(self, mqtt_client, topic):
|
|
635
|
+ super().__init__(mqtt_client, topic, default_values={
|
|
636
|
+ self.KEY_USER_TEMPERATURE_SETPOINT: 20,
|
|
637
|
+ self.KEY_VALVE_TEMPERATURE_SETPOINT: 20,
|
|
638
|
+ self.KEY_TEMPERATURE: 20.7,
|
|
639
|
+ self.KEY_AWAY_MODE: False,
|
|
640
|
+ self.KEY_SUMMER_MODE: False,
|
|
641
|
+ self.KEY_BOOST_TIMER: 0
|
|
642
|
+ })
|
|
643
|
+ self.add_callback(self.KEY_USER_TEMPERATURE_SETPOINT, None, self.print_formatted, True)
|
|
644
|
+ self.add_callback(self.KEY_VALVE_TEMPERATURE_SETPOINT, None, self.print_formatted, True)
|
|
645
|
+ self.add_callback(self.KEY_TEMPERATURE, None, self.print_formatted, True)
|
|
646
|
+ self.add_callback(self.KEY_AWAY_MODE, None, self.print_formatted, True)
|
|
647
|
+ self.add_callback(self.KEY_SUMMER_MODE, None, self.print_formatted, True)
|
|
648
|
+ self.add_callback(self.KEY_BOOST_TIMER, None, self.print_formatted, True)
|
|
649
|
+ self.add_callback(self.KEY_USER_TEMPERATURE_SETPOINT, None, self.__send__, True)
|
|
650
|
+ self.add_callback(self.KEY_TEMPERATURE, None, self.__send__, True)
|
|
651
|
+ self.add_callback(self.KEY_AWAY_MODE, None, self.__send__, True)
|
|
652
|
+ self.add_callback(self.KEY_SUMMER_MODE, None, self.__send__, True)
|
|
653
|
+ #
|
|
654
|
+ self.timer_maxvalue = None
|
|
655
|
+
|
|
656
|
+ def __rx__(self, client, userdata, message):
|
|
657
|
+ value = self.__payload_filter__(message.payload)
|
|
658
|
+ if message.topic.startswith(self.topic):
|
|
659
|
+ targetkey = message.topic.split('/')[-1]
|
|
660
|
+ if targetkey in self.keys():
|
|
661
|
+ self.set(targetkey, value, block_callback=(self.__send__, ))
|
|
662
|
+ elif targetkey not in ["__info__", self.KEY_SET_DEFAULT_TEMPERATURE, self.KEY_START_BOOST]:
|
|
663
|
+ print("Unknown key %s in %s::%s" % (targetkey, message.topic, self.__class__.__name__))
|
|
664
|
+
|
|
665
|
+ def __tx__(self, keys_changed):
|
|
666
|
+ for key in keys_changed:
|
|
667
|
+ topic = self.topic + '/' + key
|
|
668
|
+ try:
|
|
669
|
+ self.mqtt_client.send(topic, json.dumps(self[key]))
|
|
670
|
+ except KeyError:
|
|
671
|
+ self.mqtt_client.send(topic, json.dumps(True))
|
|
672
|
+
|
|
673
|
+ def command(self, command):
|
|
674
|
+ try:
|
|
675
|
+ command, value = command.split(' ')
|
|
676
|
+ except ValueError:
|
|
677
|
+ value = None
|
|
678
|
+ if command in self.capabilities():
|
|
679
|
+ if command == self.commands[0]:
|
|
680
|
+ self.print_formatted(self, self.KEY_USER_TEMPERATURE_SETPOINT, self.get(self.KEY_USER_TEMPERATURE_SETPOINT))
|
|
681
|
+ elif command == self.commands[1]:
|
|
682
|
+ self.set(self.KEY_USER_TEMPERATURE_SETPOINT, self.__command_float_value__(value))
|
|
683
|
+ elif command == self.commands[2]:
|
|
684
|
+ self.set(self.KEY_AWAY_MODE, not self.get(self.KEY_AWAY_MODE))
|
|
685
|
+ elif command == self.commands[3]:
|
|
686
|
+ self.set(self.KEY_SUMMER_MODE, not self.get(self.KEY_SUMMER_MODE))
|
|
687
|
+ elif command == self.commands[4]:
|
|
688
|
+ self.set(self, self.KEY_SET_DEFAULT_TEMPERATURE, True)
|
|
689
|
+ elif command == self.commands[5]:
|
|
690
|
+ self.set(self, self.KEY_START_BOOST, True)
|
|
691
|
+ else:
|
|
692
|
+ print("%s: not yet implemented!" % command)
|
|
693
|
+ else:
|
|
694
|
+ print("Unknown command!")
|
|
695
|
+
|
|
696
|
+ def print_formatted(self, device, key, value):
|
|
697
|
+ desc_temp_dict = {
|
|
698
|
+ self.KEY_TEMPERATURE: "Current Temperature",
|
|
699
|
+ self.KEY_USER_TEMPERATURE_SETPOINT: "User Setpoint",
|
|
700
|
+ self.KEY_VALVE_TEMPERATURE_SETPOINT: "Valve Setpoint"
|
|
701
|
+ }
|
|
702
|
+ if value is not None:
|
|
703
|
+ if key in [self.KEY_TEMPERATURE, self.KEY_USER_TEMPERATURE_SETPOINT, self.KEY_VALVE_TEMPERATURE_SETPOINT]:
|
|
704
|
+ perc = 100 * (value - self.TEMP_RANGE[0]) / (self.TEMP_RANGE[1] - self.TEMP_RANGE[0])
|
|
705
|
+ perc = 100 if perc > 100 else perc
|
|
706
|
+ perc = 0 if perc < 0 else perc
|
|
707
|
+ self.print_formatted_percent(COLOR_GUI_ACTIVE, '\u03d1', perc, "%4.1f°C" % value, "(%s)" % desc_temp_dict[key])
|
|
708
|
+ elif key in [self.KEY_AWAY_MODE, self.KEY_SUMMER_MODE]:
|
|
709
|
+ self.print_formatted_videv(COLOR_GUI_ACTIVE, value, "(%s)" % "Away-Mode" if key == self.KEY_AWAY_MODE else "Summer-Mode")
|
|
710
|
+ elif key == self.KEY_BOOST_TIMER:
|
|
711
|
+ if value > 0:
|
|
712
|
+ if self.timer_maxvalue is None and value != 0:
|
|
713
|
+ self.timer_maxvalue = value
|
|
714
|
+ disp_value = value
|
|
715
|
+ try:
|
|
716
|
+ perc = disp_value / self.timer_maxvalue * 100
|
|
717
|
+ except ZeroDivisionError:
|
|
718
|
+ perc = 0
|
|
719
|
+ else:
|
|
720
|
+ disp_value = 0
|
|
721
|
+ perc = 0
|
|
722
|
+ self.timer_maxvalue = None
|
|
723
|
+ self.print_formatted_percent(COLOR_GUI_ACTIVE, 't', perc, '%3d%%' % perc, '(%.1f)' % disp_value)
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+# class silvercrest_motion_sensor(base):
|
|
727
|
+# KEY_OCCUPANCY = "occupancy"
|
|
728
|
+# COMMANDS = ['motion']
|
|
729
|
+
|
|
730
|
+# def __init__(self, mqtt_client, topic):
|
|
731
|
+# super().__init__(mqtt_client, topic)
|
|
732
|
+# self.data[self.KEY_OCCUPANCY] = False
|
|
733
|
+# self.add_callback(self.KEY_OCCUPANCY, self.print_formatted, None)
|
|
734
|
+
|
|
735
|
+# def __rx__(self, client, userdata, message):
|
|
736
|
+# pass
|
|
737
|
+
|
|
738
|
+# def command(self, command):
|
|
739
|
+# try:
|
|
740
|
+# command, value = command.split(' ')
|
|
741
|
+# except ValueError:
|
|
742
|
+# value = None
|
|
743
|
+# else:
|
|
744
|
+# value = json.loads(value)
|
|
745
|
+# if command == self.COMMANDS[0]:
|
|
746
|
+# self.store_data(**{self.KEY_OCCUPANCY: True})
|
|
747
|
+# time.sleep(value or 10)
|
|
748
|
+# self.store_data(**{self.KEY_OCCUPANCY: False})
|
|
749
|
+
|
|
750
|
+# def print_formatted(self, device, key, value):
|
|
751
|
+# if value is not None:
|
|
752
|
+# print_light(COLOR_MOTION_SENSOR, value, self.topic, "")
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+# class tradfri_button(base):
|
|
756
|
+# KEY_ACTION = "action"
|
|
757
|
+# #
|
|
758
|
+# ACTION_TOGGLE = "toggle"
|
|
759
|
+# ACTION_BRIGHTNESS_UP = "brightness_up_click"
|
|
760
|
+# ACTION_BRIGHTNESS_DOWN = "brightness_down_click"
|
|
761
|
+# ACTION_RIGHT = "arrow_right_click"
|
|
762
|
+# ACTION_LEFT = "arrow_left_click"
|
|
763
|
+# ACTION_BRIGHTNESS_UP_LONG = "brightness_up_hold"
|
|
764
|
+# ACTION_BRIGHTNESS_DOWN_LONG = "brightness_down_hold"
|
|
765
|
+# ACTION_RIGHT_LONG = "arrow_right_hold"
|
|
766
|
+# ACTION_LEFT_LONG = "arrow_left_hold"
|
|
767
|
+# #
|
|
768
|
+# COMMANDS = [ACTION_TOGGLE, ACTION_LEFT, ACTION_RIGHT, ACTION_BRIGHTNESS_UP, ACTION_BRIGHTNESS_DOWN,
|
|
769
|
+# ACTION_LEFT_LONG, ACTION_RIGHT_LONG, ACTION_BRIGHTNESS_UP_LONG, ACTION_BRIGHTNESS_DOWN_LONG]
|
|
770
|
+
|
|
771
|
+# def __init__(self, mqtt_client, topic):
|
|
772
|
+# super().__init__(mqtt_client, topic)
|
|
773
|
+
|
|
774
|
+# def __rx__(self, client, userdata, message):
|
|
775
|
+# pass
|
|
776
|
+
|
|
777
|
+# def command(self, command):
|
|
778
|
+# try:
|
|
779
|
+# command, value = command.split(' ')
|
|
780
|
+# except ValueError:
|
|
781
|
+# value = None
|
|
782
|
+# else:
|
|
783
|
+# value = json.loads(value)
|
|
784
|
+# if command in self.capabilities():
|
|
785
|
+# action = self.COMMANDS[self.COMMANDS.index(command)]
|
|
786
|
+# if self.COMMANDS.index(command) <= 4:
|
|
787
|
+# self.mqtt_client.send(self.topic, json.dumps({self.KEY_ACTION: action}))
|
|
788
|
+# elif self.COMMANDS.index(command) <= 8:
|
|
789
|
+# self.mqtt_client.send(self.topic, json.dumps({self.KEY_ACTION: action}))
|
|
790
|
+# time.sleep(value or 0.5)
|
|
791
|
+# action = '_'.join(action.split('_')[:-1] + ['release'])
|
|
792
|
+# self.mqtt_client.send(self.topic, json.dumps({self.KEY_ACTION: action}))
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+# class remote(base):
|
|
796
|
+# def __rx__(self, client, userdata, message):
|
|
797
|
+# if message.topic == self.topic + "/VOLUP":
|
|
798
|
+# if self.__payload_filter__(message.payload):
|
|
799
|
+# icon = u'\u1403'
|
|
800
|
+# else:
|
|
801
|
+# icon = u'\u25a1'
|
|
802
|
+# elif message.topic == self.topic + "/VOLDOWN":
|
|
803
|
+# if self.__payload_filter__(message.payload):
|
|
804
|
+# icon = u'\u1401'
|
|
805
|
+# else:
|
|
806
|
+# icon = u'\u25a1'
|
|
807
|
+# else:
|
|
808
|
+# return
|
|
809
|
+# devicename = ' - '.join(self.topic.split('/')[1:-1])
|
|
810
|
+# print(COLOR_REMOTE + 10 * ' ' + icon + 6 * ' ' + devicename + colored.attr("reset"))
|