|
@@ -40,10 +40,6 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
40
|
40
|
BATTERY_WARN_LEVEL = 5
|
41
|
41
|
|
42
|
42
|
|
43
|
|
-def DEVICE_TYPE_LIST():
|
44
|
|
- return [shelly, silvercrest_powerplug, my_powerplug, tradfri_light, tradfri_button]
|
45
|
|
-
|
46
|
|
-
|
47
|
43
|
def is_json(data):
|
48
|
44
|
try:
|
49
|
45
|
json.loads(data)
|
|
@@ -54,7 +50,7 @@ def is_json(data):
|
54
|
50
|
|
55
|
51
|
|
56
|
52
|
class base(dict):
|
57
|
|
- TX_TOPIC = None
|
|
53
|
+ TX_TOPIC = "set"
|
58
|
54
|
TX_VALUE = 0
|
59
|
55
|
TX_DICT = 1
|
60
|
56
|
TX_TYPE = -1
|
|
@@ -98,11 +94,8 @@ class base(dict):
|
98
|
94
|
self.__previous__[key] = prev_value
|
99
|
95
|
# Filter, if needed
|
100
|
96
|
self.unpack_filter(key)
|
101
|
|
- if prev_value != self.get(key):
|
102
|
|
- logger.info("Received new data for (%s) %s - %s", self.topic, key, str(self.get(key)))
|
103
|
|
- else:
|
104
|
|
- logger.debug("Received data for (%s) %s - %s", self.topic, key, str(self.get(key)))
|
105
|
|
- self.callback_caller(key, self[key])
|
|
97
|
+ logger.debug("Received data for (%s) %s - %s", self.topic, key, str(self.get(key)))
|
|
98
|
+ self.callback_caller(key, self[key], self.get(key) != self.__previous__.get(key))
|
106
|
99
|
elif key not in self.RX_IGNORE_KEYS:
|
107
|
100
|
logger.warning('Got a message from \"%s\" with unparsed content "%s"', self.topic, key)
|
108
|
101
|
else:
|
|
@@ -147,24 +140,23 @@ class base(dict):
|
147
|
140
|
logger.error(
|
148
|
141
|
"Unknown tx type. Set TX_TYPE of class to a known value")
|
149
|
142
|
else:
|
150
|
|
- logger.info("Sending data for (%s) %s - %s", self.topic, key, str(data))
|
|
143
|
+ logger.debug("Sending data for (%s) %s - %s", self.topic, key, str(data))
|
151
|
144
|
if self.TX_TYPE == self.TX_DICT:
|
152
|
145
|
self.mqtt_client.send('/'.join([self.topic, self.TX_TOPIC]), json.dumps({key: data}))
|
153
|
146
|
else:
|
154
|
147
|
if type(data) not in [str, bytes]:
|
155
|
148
|
data = json.dumps(data)
|
156
|
|
- self.mqtt_client.send('/'.join([self.topic, key, self.TX_TOPIC]
|
157
|
|
- if len(self.TX_TOPIC) > 0 else [self.topic, key]), data)
|
|
149
|
+ self.mqtt_client.send('/'.join([self.topic, key, self.TX_TOPIC] if len(self.TX_TOPIC) > 0 else [self.topic, key]), data)
|
158
|
150
|
else:
|
159
|
151
|
logger.error(
|
160
|
152
|
"Unknown tx toptic. Set TX_TOPIC of class to a known value")
|
161
|
153
|
|
162
|
|
- def add_callback(self, key, data, callback):
|
|
154
|
+ def add_callback(self, key, data, callback, on_change_only=False):
|
163
|
155
|
"""
|
164
|
156
|
key: key or None for all keys
|
165
|
157
|
data: data or None for all data
|
166
|
158
|
"""
|
167
|
|
- cb_tup = (key, data, callback)
|
|
159
|
+ cb_tup = (key, data, callback, on_change_only)
|
168
|
160
|
if cb_tup not in self.callback_list:
|
169
|
161
|
self.callback_list.append(cb_tup)
|
170
|
162
|
|
|
@@ -174,10 +166,11 @@ class base(dict):
|
174
|
166
|
def warning_call_condition(self):
|
175
|
167
|
return False
|
176
|
168
|
|
177
|
|
- def callback_caller(self, key, data):
|
178
|
|
- for cb_key, cb_data, callback in self.callback_list:
|
|
169
|
+ def callback_caller(self, key, data, value_changed):
|
|
170
|
+ for cb_key, cb_data, callback, on_change_only in self.callback_list:
|
179
|
171
|
if (cb_key == key or cb_key is None) and (cb_data == data or cb_data is None) and callback is not None:
|
180
|
|
- callback(self, key, data)
|
|
172
|
+ if not on_change_only or value_changed:
|
|
173
|
+ callback(self, key, data)
|
181
|
174
|
|
182
|
175
|
def warning_caller(self):
|
183
|
176
|
if self.warning_call_condition():
|
|
@@ -202,19 +195,22 @@ class shelly(base):
|
202
|
195
|
KEY_LONGPUSH_1 = "longpush/1"
|
203
|
196
|
KEY_TEMPERATURE = "temperature"
|
204
|
197
|
KEY_OVERTEMPERATURE = "overtemperature"
|
205
|
|
- #
|
206
|
|
- TX_TOPIC = 'command'
|
|
198
|
+ KEY_ID = "id"
|
|
199
|
+ KEY_MODEL = "model"
|
|
200
|
+ KEY_MAC = "mac"
|
|
201
|
+ KEY_IP = "ip"
|
|
202
|
+ KEY_NEW_FIRMWARE = "new_fw"
|
|
203
|
+ KEY_FIRMWARE_VERSION = "fw_ver"
|
|
204
|
+ #
|
|
205
|
+ TX_TOPIC = "command"
|
207
|
206
|
TX_TYPE = base.TX_VALUE
|
208
|
207
|
TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1]
|
209
|
208
|
#
|
210
|
|
- RX_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1,
|
211
|
|
- KEY_INPUT_0, KEY_INPUT_1, KEY_LONGPUSH_0, KEY_LONGPUSH_1,
|
212
|
|
- KEY_OVERTEMPERATURE, KEY_TEMPERATURE]
|
213
|
|
- RX_IGNORE_TOPICS = [KEY_OUTPUT_0 + '/' + "energy", KEY_OUTPUT_1 + '/' + "energy",
|
214
|
|
- 'input_event/0', 'input_event/1']
|
|
209
|
+ RX_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_INPUT_0, KEY_INPUT_1, KEY_LONGPUSH_0, KEY_LONGPUSH_1, KEY_OVERTEMPERATURE, KEY_TEMPERATURE,
|
|
210
|
+ KEY_ID, KEY_MODEL, KEY_MAC, KEY_IP, KEY_NEW_FIRMWARE, KEY_FIRMWARE_VERSION]
|
|
211
|
+ RX_IGNORE_TOPICS = [KEY_OUTPUT_0 + '/' + "energy", KEY_OUTPUT_1 + '/' + "energy", 'input_event/0', 'input_event/1']
|
215
|
212
|
RX_IGNORE_KEYS = ['temperature_f']
|
216
|
|
- RX_FILTER_DATA_KEYS = [KEY_INPUT_0, KEY_INPUT_1, KEY_LONGPUSH_0, KEY_LONGPUSH_1,
|
217
|
|
- KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OVERTEMPERATURE]
|
|
213
|
+ RX_FILTER_DATA_KEYS = [KEY_INPUT_0, KEY_INPUT_1, KEY_LONGPUSH_0, KEY_LONGPUSH_1, KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OVERTEMPERATURE]
|
218
|
214
|
|
219
|
215
|
def __init__(self, mqtt_client, topic):
|
220
|
216
|
super().__init__(mqtt_client, topic)
|
|
@@ -277,16 +273,31 @@ class shelly(base):
|
277
|
273
|
"""state: [True, False, 'toggle']"""
|
278
|
274
|
self.pack(self.KEY_OUTPUT_0, state)
|
279
|
275
|
|
|
276
|
+ def set_output_0_mcb(self, device, key, data):
|
|
277
|
+ logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "%s: Changing output 0 to %s", self.topic, str(data))
|
|
278
|
+ self.set_output_0(data)
|
|
279
|
+
|
|
280
|
+ def toggle_output_0_mcb(self, device, key, data):
|
|
281
|
+ logger.info("%s: Toggeling output 0", self.topic)
|
|
282
|
+ self.set_output_0('toggle')
|
|
283
|
+
|
280
|
284
|
def set_output_1(self, state):
|
281
|
285
|
"""state: [True, False, 'toggle']"""
|
282
|
286
|
self.pack(self.KEY_OUTPUT_1, state)
|
283
|
287
|
|
|
288
|
+ def set_output_1_mcb(self, device, key, data):
|
|
289
|
+ logger.log(logging.INFO if data != self.output_1 else logging.DEBUG, "%s: Changing output 1 to %s", self.topic, str(data))
|
|
290
|
+ self.set_output_1(data)
|
|
291
|
+
|
|
292
|
+ def toggle_output_1_mcb(self, device, key, data):
|
|
293
|
+ logger.info("%s: Toggeling output 1", self.topic)
|
|
294
|
+ self.set_output_1('toggle')
|
|
295
|
+
|
284
|
296
|
|
285
|
297
|
class silvercrest_powerplug(base):
|
286
|
298
|
KEY_LINKQUALITY = "linkquality"
|
287
|
299
|
KEY_OUTPUT_0 = "state"
|
288
|
300
|
#
|
289
|
|
- TX_TOPIC = 'set'
|
290
|
301
|
TX_TYPE = base.TX_DICT
|
291
|
302
|
TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0]
|
292
|
303
|
#
|
|
@@ -316,6 +327,14 @@ class silvercrest_powerplug(base):
|
316
|
327
|
"""state: [True, False, 'toggle']"""
|
317
|
328
|
self.pack(self.KEY_OUTPUT_0, state)
|
318
|
329
|
|
|
330
|
+ def set_output_0_mcb(self, device, key, data):
|
|
331
|
+ logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "%s: Changing output 0 to %s", self.topic, str(data))
|
|
332
|
+ self.set_output_0(data)
|
|
333
|
+
|
|
334
|
+ def toggle_output_0_mcb(self, device, key, data):
|
|
335
|
+ logger.info("%s: Toggeling output 0", self.topic)
|
|
336
|
+ self.set_output_0('toggle')
|
|
337
|
+
|
319
|
338
|
|
320
|
339
|
class my_powerplug(base):
|
321
|
340
|
KEY_OUTPUT_0 = "output/1"
|
|
@@ -325,7 +344,6 @@ class my_powerplug(base):
|
325
|
344
|
KEY_OUTPUT_ALL = "output/all"
|
326
|
345
|
KEY_OUTPUT_LIST = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OUTPUT_2, KEY_OUTPUT_3]
|
327
|
346
|
#
|
328
|
|
- TX_TOPIC = 'set'
|
329
|
347
|
TX_TYPE = base.TX_VALUE
|
330
|
348
|
#
|
331
|
349
|
RX_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OUTPUT_2, KEY_OUTPUT_3]
|
|
@@ -369,22 +387,62 @@ class my_powerplug(base):
|
369
|
387
|
"""state: [True, False, 'toggle']"""
|
370
|
388
|
self.pack(self.KEY_OUTPUT_0, state)
|
371
|
389
|
|
|
390
|
+ def set_output_0_mcb(self, device, key, data):
|
|
391
|
+ logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "%s: Changing output 0 to %s", self.topic, str(data))
|
|
392
|
+ self.set_output_0(data)
|
|
393
|
+
|
|
394
|
+ def toggle_output_0_mcb(self, device, key, data):
|
|
395
|
+ logger.info("%s: Toggeling output 0", self.topic)
|
|
396
|
+ self.set_output_0('toggle')
|
|
397
|
+
|
372
|
398
|
def set_output_1(self, state):
|
373
|
399
|
"""state: [True, False, 'toggle']"""
|
374
|
400
|
self.pack(self.KEY_OUTPUT_1, state)
|
375
|
401
|
|
|
402
|
+ def set_output_1_mcb(self, device, key, data):
|
|
403
|
+ logger.log(logging.INFO if data != self.output_1 else logging.DEBUG, "%s: Changing output 1 to %s", self.topic, str(data))
|
|
404
|
+ self.set_output_1(data)
|
|
405
|
+
|
|
406
|
+ def toggle_output_1_mcb(self, device, key, data):
|
|
407
|
+ logger.info("%s: Toggeling output 1", self.topic)
|
|
408
|
+ self.set_output_1('toggle')
|
|
409
|
+
|
376
|
410
|
def set_output_2(self, state):
|
377
|
411
|
"""state: [True, False, 'toggle']"""
|
378
|
412
|
self.pack(self.KEY_OUTPUT_2, state)
|
379
|
413
|
|
|
414
|
+ def set_output_2_mcb(self, device, key, data):
|
|
415
|
+ logger.log(logging.INFO if data != self.output_2 else logging.DEBUG, "%s: Changing output 2 to %s", self.topic, str(data))
|
|
416
|
+ self.set_output_2(data)
|
|
417
|
+
|
|
418
|
+ def toggle_output_2_mcb(self, device, key, data):
|
|
419
|
+ logger.info("%s: Toggeling output 2", self.topic)
|
|
420
|
+ self.set_output_2('toggle')
|
|
421
|
+
|
380
|
422
|
def set_output_3(self, state):
|
381
|
423
|
"""state: [True, False, 'toggle']"""
|
382
|
424
|
self.pack(self.KEY_OUTPUT_3, state)
|
383
|
425
|
|
|
426
|
+ def set_output_3_mcb(self, device, key, data):
|
|
427
|
+ logger.log(logging.INFO if data != self.output_3 else logging.DEBUG, "%s: Changing output 3 to %s", self.topic, str(data))
|
|
428
|
+ self.set_output_3(data)
|
|
429
|
+
|
|
430
|
+ def toggle_output_3_mcb(self, device, key, data):
|
|
431
|
+ logger.info("%s: Toggeling output 3", self.topic)
|
|
432
|
+ self.set_output_3('toggle')
|
|
433
|
+
|
384
|
434
|
def set_output_all(self, state):
|
385
|
435
|
"""state: [True, False, 'toggle']"""
|
386
|
436
|
self.pack(self.KEY_OUTPUT_ALL, state)
|
387
|
437
|
|
|
438
|
+ def set_output_all_mcb(self, device, key, data):
|
|
439
|
+ logger.info("%s: Changing all outputs to %s", self.topic, str(data))
|
|
440
|
+ self.set_output_all(data)
|
|
441
|
+
|
|
442
|
+ def toggle_output_all_mcb(self, device, key, data):
|
|
443
|
+ logger.info("%s: Toggeling all outputs", self.topic)
|
|
444
|
+ self.set_output_0('toggle')
|
|
445
|
+
|
388
|
446
|
|
389
|
447
|
class tradfri_light(base):
|
390
|
448
|
KEY_LINKQUALITY = "linkquality"
|
|
@@ -393,7 +451,6 @@ class tradfri_light(base):
|
393
|
451
|
KEY_COLOR_TEMP = "color_temp"
|
394
|
452
|
KEY_BRIGHTNESS_FADE = "brightness_move"
|
395
|
453
|
#
|
396
|
|
- TX_TOPIC = 'set'
|
397
|
454
|
TX_TYPE = base.TX_DICT
|
398
|
455
|
TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP, KEY_BRIGHTNESS_FADE]
|
399
|
456
|
#
|
|
@@ -408,7 +465,7 @@ class tradfri_light(base):
|
408
|
465
|
if key == self.KEY_BRIGHTNESS:
|
409
|
466
|
self[key] = (self[key] - 1) * 100 / 254
|
410
|
467
|
elif key == self.KEY_COLOR_TEMP:
|
411
|
|
- self[key] = (self[key] - 250) * 100 / 204
|
|
468
|
+ self[key] = (self[key] - 250) * 10 / 204
|
412
|
469
|
else:
|
413
|
470
|
super().unpack_filter(key)
|
414
|
471
|
|
|
@@ -416,7 +473,7 @@ class tradfri_light(base):
|
416
|
473
|
if key == self.KEY_BRIGHTNESS:
|
417
|
474
|
return data * 254 / 100 + 1
|
418
|
475
|
elif key == self.KEY_COLOR_TEMP:
|
419
|
|
- return data * 204 / 100 + 250
|
|
476
|
+ return data * 204 / 10 + 250
|
420
|
477
|
else:
|
421
|
478
|
return super().pack_filter(key, data)
|
422
|
479
|
|
|
@@ -435,12 +492,12 @@ class tradfri_light(base):
|
435
|
492
|
|
436
|
493
|
@property
|
437
|
494
|
def brightness(self):
|
438
|
|
- """rv: numeric value [0%, ..., 100%"""
|
|
495
|
+ """rv: numeric value [0%, ..., 100%]"""
|
439
|
496
|
return self.get(self.KEY_BRIGHTNESS, 0)
|
440
|
497
|
|
441
|
498
|
@property
|
442
|
499
|
def color_temp(self):
|
443
|
|
- """rv: numeric value [0%, ..., 100%"""
|
|
500
|
+ """rv: numeric value [0, ..., 10]"""
|
444
|
501
|
return self.get(self.KEY_COLOR_TEMP, 0)
|
445
|
502
|
|
446
|
503
|
#
|
|
@@ -450,10 +507,22 @@ class tradfri_light(base):
|
450
|
507
|
"""state: [True, False, 'toggle']"""
|
451
|
508
|
self.pack(self.KEY_OUTPUT_0, state)
|
452
|
509
|
|
|
510
|
+ def set_output_0_mcb(self, device, key, data):
|
|
511
|
+ logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "%s: Changing output 0 to %s", self.topic, str(data))
|
|
512
|
+ self.set_output_0(data)
|
|
513
|
+
|
|
514
|
+ def toggle_output_0_mcb(self, device, key, data):
|
|
515
|
+ logger.info("%s: Toggeling output 0", self.topic)
|
|
516
|
+ self.set_output_0('toggle')
|
|
517
|
+
|
453
|
518
|
def set_brightness(self, brightness):
|
454
|
519
|
"""brightness: [0, ..., 100]"""
|
455
|
520
|
self.pack(self.KEY_BRIGHTNESS, brightness)
|
456
|
521
|
|
|
522
|
+ def set_brightness_mcb(self, device, key, data):
|
|
523
|
+ logger.log(logging.INFO if data != self.brightness else logging.DEBUG, "%s: Changing brightness to %s", self.topic, str(data))
|
|
524
|
+ self.set_brightness(data)
|
|
525
|
+
|
457
|
526
|
def default_inc(self, speed=40):
|
458
|
527
|
self.pack(self.KEY_BRIGHTNESS_FADE, speed)
|
459
|
528
|
|
|
@@ -464,9 +533,13 @@ class tradfri_light(base):
|
464
|
533
|
self.default_inc(0)
|
465
|
534
|
|
466
|
535
|
def set_color_temp(self, color_temp):
|
467
|
|
- """color_temp: [0, ..., 100]"""
|
|
536
|
+ """color_temp: [0, ..., 10]"""
|
468
|
537
|
self.pack(self.KEY_COLOR_TEMP, color_temp)
|
469
|
538
|
|
|
539
|
+ def set_color_temp_mcb(self, device, key, data):
|
|
540
|
+ logger.log(logging.INFO if data != self.color_temp else logging.DEBUG, "%s: Changing color temperature to %s", self.topic, str(data))
|
|
541
|
+ self.set_color_temp(data)
|
|
542
|
+
|
470
|
543
|
|
471
|
544
|
class tradfri_button(base):
|
472
|
545
|
ACTION_TOGGLE = "toggle"
|
|
@@ -488,8 +561,6 @@ class tradfri_button(base):
|
488
|
561
|
KEY_ACTION = "action"
|
489
|
562
|
KEY_ACTION_DURATION = "action_duration"
|
490
|
563
|
#
|
491
|
|
- TX_TOPIC = ''
|
492
|
|
- #
|
493
|
564
|
RX_KEYS = [KEY_LINKQUALITY, KEY_BATTERY, KEY_ACTION]
|
494
|
565
|
RX_IGNORE_KEYS = ['update', KEY_ACTION_DURATION]
|
495
|
566
|
|
|
@@ -514,7 +585,7 @@ class tradfri_button(base):
|
514
|
585
|
return "Low battery level detected for %s. Battery level was %.0f%%." % (self.topic, self.get(self.KEY_BATTERY))
|
515
|
586
|
|
516
|
587
|
|
517
|
|
-class nodered_gui(base):
|
|
588
|
+class nodered_gui_heatvalve(base):
|
518
|
589
|
KEY_FEEDBACK = "feedback"
|
519
|
590
|
KEY_ENABLE = "enable"
|
520
|
591
|
KEY_STATE = "state"
|
|
@@ -524,7 +595,6 @@ class nodered_gui(base):
|
524
|
595
|
KEY_HEATING_SETPOINT = "heating_setpoint"
|
525
|
596
|
KEY_OFF_BUTTON = "off_button"
|
526
|
597
|
#
|
527
|
|
- TX_TOPIC = 'set'
|
528
|
598
|
TX_TYPE = base.TX_VALUE
|
529
|
599
|
#
|
530
|
600
|
RX_KEYS = [KEY_STATE, KEY_BRIGHTNESS, KEY_COLOR_TEMP, KEY_HEATING_BOOST, KEY_HEATING_SETPOINT, KEY_OFF_BUTTON]
|
|
@@ -571,10 +641,114 @@ class nodered_gui(base):
|
571
|
641
|
def set_feedback(self, data):
|
572
|
642
|
self.pack(self.KEY_FEEDBACK, data)
|
573
|
643
|
|
574
|
|
- def enable(self, data):
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+class nodered_gui_button(base):
|
|
647
|
+ KEY_STATE = "state"
|
|
648
|
+ #
|
|
649
|
+ RX_KEYS = [KEY_STATE]
|
|
650
|
+
|
|
651
|
+ #
|
|
652
|
+ # RX
|
|
653
|
+ #
|
|
654
|
+ @property
|
|
655
|
+ def state(self):
|
|
656
|
+ """rv: [True, False]"""
|
|
657
|
+ return self.get(self.KEY_STATE)
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+class nodered_gui_switch(nodered_gui_button):
|
|
661
|
+ TX_TYPE = base.TX_VALUE
|
|
662
|
+
|
|
663
|
+ #
|
|
664
|
+ # TX
|
|
665
|
+ #
|
|
666
|
+ def set_state(self, data):
|
|
667
|
+ """data: [True, False]"""
|
|
668
|
+ self.pack(self.KEY_STATE, data)
|
|
669
|
+
|
|
670
|
+ def set_state_mcb(self, device, key, data):
|
|
671
|
+ logger.log(logging.INFO if data != self.get(self.KEY_STATE) else logging.DEBUG, "%s: Changing data to %s", self.topic, str(data))
|
|
672
|
+ self.set_state(data)
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+class nodered_gui_brightness_color_temp(base):
|
|
676
|
+ KEY_ENABLE = "enable"
|
|
677
|
+ KEY_BRIGHTNESS = "brightness"
|
|
678
|
+ KEY_COLOR_TEMP = "color_temp"
|
|
679
|
+ #
|
|
680
|
+ TX_TYPE = base.TX_VALUE
|
|
681
|
+ #
|
|
682
|
+ RX_KEYS = [KEY_ENABLE, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
|
|
683
|
+
|
|
684
|
+ #
|
|
685
|
+ # RX
|
|
686
|
+ #
|
|
687
|
+ @property
|
|
688
|
+ def enable(self):
|
|
689
|
+ """rv: [True, False]"""
|
|
690
|
+ return self.get(self.KEY_ENABLE)
|
|
691
|
+
|
|
692
|
+ @property
|
|
693
|
+ def brightness(self):
|
|
694
|
+ """rv: [True, False]"""
|
|
695
|
+ return self.get(self.KEY_BRIGHTNESS)
|
|
696
|
+
|
|
697
|
+ @property
|
|
698
|
+ def color_temp(self):
|
|
699
|
+ """rv: [True, False]"""
|
|
700
|
+ return self.get(self.KEY_COLOR_TEMP)
|
|
701
|
+
|
|
702
|
+ #
|
|
703
|
+ # TX
|
|
704
|
+ #
|
|
705
|
+ def set_enable(self, data):
|
575
|
706
|
"""data: [True, False]"""
|
576
|
707
|
self.pack(self.KEY_ENABLE, data)
|
577
|
708
|
|
|
709
|
+ def set_enable_mcb(self, device, key, data):
|
|
710
|
+ logger.log(logging.INFO if data != self.get(self.KEY_ENABLE) else logging.DEBUG, "%s: Changing enable to %s", self.topic, str(data))
|
|
711
|
+ self.set_enable(data)
|
|
712
|
+
|
|
713
|
+ def set_brightness(self, data):
|
|
714
|
+ """data: [0%, ..., 100%]"""
|
|
715
|
+ self.pack(self.KEY_BRIGHTNESS, data)
|
|
716
|
+
|
|
717
|
+ def set_brightness_mcb(self, device, key, data):
|
|
718
|
+ logger.log(logging.INFO if data != self.get(self.KEY_BRIGHTNESS) else logging.DEBUG, "%s: Changing brightness to %s", self.topic, str(data))
|
|
719
|
+ self.set_brightness(data)
|
|
720
|
+
|
|
721
|
+ def set_color_temp(self, data):
|
|
722
|
+ """data: [0, ..., 10]"""
|
|
723
|
+ self.pack(self.KEY_COLOR_TEMP, data)
|
|
724
|
+
|
|
725
|
+ def set_color_temp_mcb(self, device, key, data):
|
|
726
|
+ logger.log(logging.INFO if data != self.get(self.KEY_COLOR_TEMP) else logging.DEBUG,
|
|
727
|
+ "%s: Changing color temperature to %s", self.topic, str(data))
|
|
728
|
+ self.set_color_temp(data)
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+class nodered_gui_leds(base):
|
|
732
|
+ KEY_LED_0 = "led0"
|
|
733
|
+ KEY_LED_1 = "led1"
|
|
734
|
+ KEY_LED_2 = "led2"
|
|
735
|
+ KEY_LED_3 = "led3"
|
|
736
|
+ KEY_LED_4 = "led4"
|
|
737
|
+ KEY_LED_5 = "led5"
|
|
738
|
+ KEY_LED_6 = "led6"
|
|
739
|
+ KEY_LED_7 = "led7"
|
|
740
|
+ KEY_LED_8 = "led8"
|
|
741
|
+ KEY_LED_9 = "led9"
|
|
742
|
+ #
|
|
743
|
+ TX_TYPE = base.TX_VALUE
|
|
744
|
+ #
|
|
745
|
+ RX_KEYS = [KEY_LED_0, KEY_LED_1, KEY_LED_2, KEY_LED_3, KEY_LED_4, KEY_LED_5, KEY_LED_6, KEY_LED_7, KEY_LED_8, KEY_LED_9]
|
|
746
|
+
|
|
747
|
+ def set_led(self, key, data):
|
|
748
|
+ """data: [True, False]"""
|
|
749
|
+ logger.log(logging.INFO if data != self.get(key) else logging.DEBUG, "%s: Changing led state for %s to %s", self.topic, key, str(data))
|
|
750
|
+ self.pack(key, data)
|
|
751
|
+
|
578
|
752
|
|
579
|
753
|
class brennenstuhl_heatingvalve(base):
|
580
|
754
|
KEY_LINKQUALITY = "linkquality"
|
|
@@ -589,17 +763,15 @@ class brennenstuhl_heatingvalve(base):
|
589
|
763
|
KEY_VALVE_DETECTION = "valve_detection"
|
590
|
764
|
KEY_WINDOW_DETECTION = "window_detection"
|
591
|
765
|
#
|
592
|
|
- TX_TOPIC = 'set'
|
593
|
766
|
TX_TYPE = base.TX_DICT
|
594
|
767
|
#
|
595
|
768
|
RX_KEYS = [KEY_LINKQUALITY, KEY_BATTERY, KEY_HEATING_SETPOINT, KEY_TEMPERATURE]
|
596
|
|
- RX_IGNORE_KEYS = [KEY_AWAY_MODE, KEY_CHILD_LOCK, KEY_PRESET,
|
597
|
|
- KEY_SYSTEM_MODE, KEY_VALVE_DETECTION, KEY_WINDOW_DETECTION]
|
|
769
|
+ RX_IGNORE_KEYS = [KEY_AWAY_MODE, KEY_CHILD_LOCK, KEY_PRESET, KEY_SYSTEM_MODE, KEY_VALVE_DETECTION, KEY_WINDOW_DETECTION]
|
598
|
770
|
|
599
|
771
|
def __init__(self, mqtt_client, topic):
|
600
|
772
|
super().__init__(mqtt_client, topic)
|
601
|
|
- self.mqtt_client.send(self.topic + '/' + self.TX_TOPIC, json.dumps(
|
602
|
|
- {self.KEY_WINDOW_DETECTION: "ON", self.KEY_CHILD_LOCK: "UNLOCK", self.KEY_VALVE_DETECTION: "ON", self.KEY_SYSTEM_MODE: "heat"}))
|
|
773
|
+ self.mqtt_client.send(self.topic + '/' + self.TX_TOPIC, json.dumps({self.KEY_WINDOW_DETECTION: "ON",
|
|
774
|
+ self.KEY_CHILD_LOCK: "UNLOCK", self.KEY_VALVE_DETECTION: "ON", self.KEY_SYSTEM_MODE: "heat"}))
|
603
|
775
|
|
604
|
776
|
def warning_call_condition(self):
|
605
|
777
|
return self.get(self.KEY_BATTERY) <= BATTERY_WARN_LEVEL
|
|
@@ -628,6 +800,10 @@ class brennenstuhl_heatingvalve(base):
|
628
|
800
|
def set_heating_setpoint(self, setpoint):
|
629
|
801
|
self.pack(self.KEY_HEATING_SETPOINT, setpoint)
|
630
|
802
|
|
|
803
|
+ def set_heating_setpoint_mcb(self, device, key, data):
|
|
804
|
+ logger.info("%s: Changing heating setpoint to %s", self.topic, str(data))
|
|
805
|
+ self.set_heating_setpoint(data)
|
|
806
|
+
|
631
|
807
|
|
632
|
808
|
class remote(base):
|
633
|
809
|
KEY_CD = "CD"
|
|
@@ -643,19 +819,19 @@ class remote(base):
|
643
|
819
|
#
|
644
|
820
|
RX_IGNORE_TOPICS = [KEY_CD, KEY_LINE1, KEY_LINE3, KEY_MUTE, KEY_POWER, KEY_VOLUP, KEY_VOLDOWN]
|
645
|
821
|
|
646
|
|
- def set_cd(self):
|
|
822
|
+ def set_cd(self, device=None, key=None, data=None):
|
647
|
823
|
self.pack(self.KEY_CD, None)
|
648
|
824
|
|
649
|
|
- def set_line1(self):
|
|
825
|
+ def set_line1(self, device=None, key=None, data=None):
|
650
|
826
|
self.pack(self.KEY_LINE1, None)
|
651
|
827
|
|
652
|
|
- def set_line3(self):
|
|
828
|
+ def set_line3(self, device=None, key=None, data=None):
|
653
|
829
|
self.pack(self.KEY_LINE3, None)
|
654
|
830
|
|
655
|
|
- def set_mute(self):
|
|
831
|
+ def set_mute(self, device=None, key=None, data=None):
|
656
|
832
|
self.pack(self.KEY_MUTE, None)
|
657
|
833
|
|
658
|
|
- def set_power(self):
|
|
834
|
+ def set_power(self, device=None, key=None, data=None):
|
659
|
835
|
self.pack(self.KEY_POWER, None)
|
660
|
836
|
|
661
|
837
|
def set_volume_up(self, data=False):
|
|
@@ -666,20 +842,19 @@ class remote(base):
|
666
|
842
|
"""data: [True, False]"""
|
667
|
843
|
self.pack(self.KEY_VOLDOWN, data)
|
668
|
844
|
|
669
|
|
- def default_inc(self):
|
|
845
|
+ def default_inc(self, device=None, key=None, data=None):
|
670
|
846
|
self.set_volume_up(True)
|
671
|
847
|
|
672
|
|
- def default_dec(self):
|
|
848
|
+ def default_dec(self, device=None, key=None, data=None):
|
673
|
849
|
self.set_volume_down(True)
|
674
|
850
|
|
675
|
|
- def default_stop(self):
|
|
851
|
+ def default_stop(self, device=None, key=None, data=None):
|
676
|
852
|
self.set_volume_up(False)
|
677
|
853
|
|
678
|
854
|
|
679
|
855
|
class status(base):
|
680
|
856
|
KEY_STATE = "state"
|
681
|
857
|
#
|
682
|
|
- TX_TOPIC = 'set'
|
683
|
858
|
TX_TYPE = base.TX_VALUE
|
684
|
859
|
#
|
685
|
860
|
RX_KEYS = [KEY_STATE]
|
|
@@ -688,6 +863,10 @@ class status(base):
|
688
|
863
|
"""data: [True, False]"""
|
689
|
864
|
self.pack(self.KEY_STATE + "/" + str(num), data)
|
690
|
865
|
|
|
866
|
+ def set_state_mcb(self, device, key, data):
|
|
867
|
+ logger.info("%s: Changing state to %s", self.topic, str(data))
|
|
868
|
+ self.set_state(data)
|
|
869
|
+
|
691
|
870
|
|
692
|
871
|
class audio_status(status):
|
693
|
872
|
KEY_TITLE = "title"
|