|
@@ -504,10 +504,19 @@ class gui_light(tradfri_light):
|
504
|
504
|
AUTOSEND = False
|
505
|
505
|
#
|
506
|
506
|
KEY_ENABLE = "enable"
|
|
507
|
+ KEY_TIMER = "timer"
|
|
508
|
+ KEY_LED_X = "led%d"
|
507
|
509
|
|
508
|
510
|
def __init__(self, mqtt_client, topic, enable_state=True, enable_brightness=False, enable_color_temp=False):
|
509
|
511
|
super().__init__(mqtt_client, topic, enable_state, enable_brightness, enable_color_temp)
|
510
|
512
|
self.add_callback(self.KEY_ENABLE, self.print_formatted, None)
|
|
513
|
+ self.add_callback(self.KEY_TIMER, self.print_formatted, None)
|
|
514
|
+ for i in range(0, 10):
|
|
515
|
+ self.add_callback(self.KEY_LED_X % i, self.print_formatted, None)
|
|
516
|
+ self.led_names = {}
|
|
517
|
+ #
|
|
518
|
+ self.maxvalue = None
|
|
519
|
+ self.last_printed = None
|
511
|
520
|
|
512
|
521
|
def __init_data__(self, enable_state, enable_brightness, enable_color_temp):
|
513
|
522
|
data = {}
|
|
@@ -518,6 +527,9 @@ class gui_light(tradfri_light):
|
518
|
527
|
data[self.KEY_BRIGHTNESS] = 50
|
519
|
528
|
if enable_color_temp:
|
520
|
529
|
data[self.KEY_COLOR_TEMP] = 5
|
|
530
|
+ data[self.KEY_TIMER] = '-'
|
|
531
|
+ for i in range(0, 10):
|
|
532
|
+ data[self.KEY_LED_X % i] = False
|
521
|
533
|
self.store_data(**data)
|
522
|
534
|
|
523
|
535
|
def __rx__(self, client, userdata, message):
|
|
@@ -559,14 +571,18 @@ class gui_light(tradfri_light):
|
559
|
571
|
else:
|
560
|
572
|
print("Unknown command!")
|
561
|
573
|
|
|
574
|
+ def add_led_name(self, key, name):
|
|
575
|
+ self.led_names[key] = name
|
|
576
|
+
|
562
|
577
|
def print_formatted(self, device, key, value):
|
563
|
578
|
if value is not None:
|
564
|
579
|
color = COLOR_GUI_ACTIVE
|
|
580
|
+ device = " - ".join(self.topic.split('/')[1:])
|
565
|
581
|
if key == self.KEY_STATE:
|
566
|
582
|
if value == True:
|
567
|
|
- print(color + 10 * ' ' + u'\u25a0' + 9 * ' ' + " - ".join(self.topic.split('/')[1:]) + colored.attr("reset"))
|
|
583
|
+ print(color + 10 * ' ' + u'\u25a0' + 9 * ' ' + device + colored.attr("reset"))
|
568
|
584
|
else:
|
569
|
|
- print(color + 10 * ' ' + u'\u25a1' + 9*' ' + " - ".join(self.topic.split('/')[1:]) + colored.attr("reset"))
|
|
585
|
+ print(color + 10 * ' ' + u'\u25a1' + 9 * ' ' + device + colored.attr("reset"))
|
570
|
586
|
elif key == self.KEY_ENABLE:
|
571
|
587
|
self.print_formatted(device, self.KEY_BRIGHTNESS, self.data.get(self.KEY_BRIGHTNESS))
|
572
|
588
|
self.print_formatted(device, self.KEY_COLOR_TEMP, self.data.get(self.KEY_COLOR_TEMP))
|
|
@@ -577,8 +593,26 @@ class gui_light(tradfri_light):
|
577
|
593
|
sys.stdout.write(color)
|
578
|
594
|
sys.stdout.write('B' if key == self.KEY_BRIGHTNESS else 'C')
|
579
|
595
|
sys.stdout.write(percent_bar(value))
|
580
|
|
- sys.stdout.write("%3d%%" % value + 5 * " ")
|
581
|
|
- print(" - ".join(self.topic.split('/')[1:]) + colored.attr("reset"))
|
|
596
|
+ print("%3d%%" % value + 5 * " " + device + colored.attr("reset"))
|
|
597
|
+ elif key == self.KEY_TIMER:
|
|
598
|
+ if isinstance(value, (int, float, complex)) and not isinstance(value, bool):
|
|
599
|
+ if self.maxvalue is None:
|
|
600
|
+ self.maxvalue = value
|
|
601
|
+ disp_value = value
|
|
602
|
+ perc = disp_value / self.maxvalue * 100
|
|
603
|
+ else:
|
|
604
|
+ disp_value = 0
|
|
605
|
+ perc = 0
|
|
606
|
+ self.maxvalue = None
|
|
607
|
+ self.last_printed = None
|
|
608
|
+ if self.last_printed is None or abs(self.last_printed - perc) >= 4.95:
|
|
609
|
+ print(color + 't' + percent_bar(perc) + '%3d%%' % perc + 5 * ' ' + device + ' (%.1f)' % disp_value + colored.attr('reset'))
|
|
610
|
+ self.last_printed = perc
|
|
611
|
+ elif key.startswith(self.KEY_LED_X[:-2]):
|
|
612
|
+ led = green_led() if value else grey_led()
|
|
613
|
+ ledname = '(%s)' % self.led_names.get(key, key)
|
|
614
|
+ devicename = ' - '.join(self.topic.split('/')[1:])
|
|
615
|
+ print(10 * ' ' + led + 9 * ' ' + COLOR_GUI_ACTIVE + devicename + ' ' + ledname + colored.attr("reset"))
|
582
|
616
|
|
583
|
617
|
|
584
|
618
|
class tradfri_button(base):
|
|
@@ -676,34 +710,6 @@ class remote(base):
|
676
|
710
|
print(COLOR_REMOTE + 10 * ' ' + icon + 6 * ' ' + devicename + colored.attr("reset"))
|
677
|
711
|
|
678
|
712
|
|
679
|
|
-class gui_timer(base):
|
680
|
|
- AUTOSEND = False
|
681
|
|
-
|
682
|
|
- def __init__(self, mqtt_client, topic):
|
683
|
|
- super().__init__(mqtt_client, topic)
|
684
|
|
- self.maxvalue = None
|
685
|
|
- self.last_printed = None
|
686
|
|
-
|
687
|
|
- def __rx__(self, client, userdata, message):
|
688
|
|
- payload = payload_filter(message.payload)
|
689
|
|
- if message.topic.startswith(self.topic) and message.topic.endswith('/feedback/set'):
|
690
|
|
- if isinstance(payload, (int, float, complex)) and not isinstance(payload, bool):
|
691
|
|
- if self.maxvalue is None:
|
692
|
|
- self.maxvalue = payload
|
693
|
|
- perc = payload / self.maxvalue * 100
|
694
|
|
- if self.last_printed is None or abs(self.last_printed - perc) >= 4.8:
|
695
|
|
- sys.stdout.write(COLOR_GUI_ACTIVE + 't' + percent_bar(perc))
|
696
|
|
- print('%3d%%' % perc + 2 * ' ' + ' - '.join(self.topic.split('/')[1:]) + ' (%.1f)' % payload + colored.attr('reset'))
|
697
|
|
- self.last_printed = perc
|
698
|
|
- else:
|
699
|
|
- self.maxvalue = None
|
700
|
|
- self.last_printed = None
|
701
|
|
- sys.stdout.write(COLOR_GUI_ACTIVE + 't' + percent_bar(0))
|
702
|
|
- print('%3d%%' % 0 + 2 * ' ' + ' - '.join(self.topic.split('/')[1:]) + colored.attr('reset'))
|
703
|
|
- else:
|
704
|
|
- print("Unknown Message")
|
705
|
|
-
|
706
|
|
-
|
707
|
713
|
class brennenstuhl_radiator_valve(base):
|
708
|
714
|
TEMP_RANGE = [10, 30]
|
709
|
715
|
#
|