瀏覽代碼

GUI elements switch and brightness+color_temp joined; simulation extended by 1st automated test

tags/v1.0.0
Dirk Alders 1 年之前
父節點
當前提交
9907924e54

+ 7
- 7
__simulation__/devices.py 查看文件

527
             if targetkey in self.data.keys():
527
             if targetkey in self.data.keys():
528
                 self.store_data(**{targetkey: value})
528
                 self.store_data(**{targetkey: value})
529
             else:
529
             else:
530
-                print("Unknown key %s in %s" % (targetkey, self.__class__.__name__))
530
+                print("Unknown key %s in %s::%s" % (targetkey, message.topic, self.__class__.__name__))
531
         elif message.topic == self.topic + '/get':
531
         elif message.topic == self.topic + '/get':
532
             self.__tx__(None)
532
             self.__tx__(None)
533
 
533
 
564
             color = COLOR_GUI_ACTIVE
564
             color = COLOR_GUI_ACTIVE
565
             if key == self.KEY_STATE:
565
             if key == self.KEY_STATE:
566
                 if value == True:
566
                 if value == True:
567
-                    print(color + 10 * ' ' + u'\u25a0' + 9 * ' ' + " - ".join(self.topic.split('/')[1:-1]) + colored.attr("reset"))
567
+                    print(color + 10 * ' ' + u'\u25a0' + 9 * ' ' + " - ".join(self.topic.split('/')[1:]) + colored.attr("reset"))
568
                 else:
568
                 else:
569
-                    print(color + 10 * ' ' + u'\u25a1' + 9*' ' + " - ".join(self.topic.split('/')[1:-1]) + colored.attr("reset"))
569
+                    print(color + 10 * ' ' + u'\u25a1' + 9*' ' + " - ".join(self.topic.split('/')[1:]) + colored.attr("reset"))
570
             elif key == self.KEY_ENABLE:
570
             elif key == self.KEY_ENABLE:
571
                 self.print_formatted(device, self.KEY_BRIGHTNESS, self.data.get(self.KEY_BRIGHTNESS))
571
                 self.print_formatted(device, self.KEY_BRIGHTNESS, self.data.get(self.KEY_BRIGHTNESS))
572
                 self.print_formatted(device, self.KEY_COLOR_TEMP, self.data.get(self.KEY_COLOR_TEMP))
572
                 self.print_formatted(device, self.KEY_COLOR_TEMP, self.data.get(self.KEY_COLOR_TEMP))
578
                 sys.stdout.write('B' if key == self.KEY_BRIGHTNESS else 'C')
578
                 sys.stdout.write('B' if key == self.KEY_BRIGHTNESS else 'C')
579
                 sys.stdout.write(percent_bar(value))
579
                 sys.stdout.write(percent_bar(value))
580
                 sys.stdout.write("%3d%%" % value + 5 * " ")
580
                 sys.stdout.write("%3d%%" % value + 5 * " ")
581
-                print(" - ".join(self.topic.split('/')[1:-1]) + colored.attr("reset"))
581
+                print(" - ".join(self.topic.split('/')[1:]) + colored.attr("reset"))
582
 
582
 
583
 
583
 
584
 class tradfri_button(base):
584
 class tradfri_button(base):
654
     def print_formatted(self, device, key, value):
654
     def print_formatted(self, device, key, value):
655
         led = green_led() if value else grey_led()
655
         led = green_led() if value else grey_led()
656
         channel = '(%s)' % self.names.get(key, key)
656
         channel = '(%s)' % self.names.get(key, key)
657
-        devicename = ' - '.join(self.topic.split('/')[1:-1])
657
+        devicename = ' - '.join(self.topic.split('/')[1:])
658
         print(10 * ' ' + led + 9 * ' ' + COLOR_GUI_ACTIVE + devicename + ' ' + channel + colored.attr("reset"))
658
         print(10 * ' ' + led + 9 * ' ' + COLOR_GUI_ACTIVE + devicename + ' ' + channel + colored.attr("reset"))
659
 
659
 
660
 
660
 
693
                 perc = payload / self.maxvalue * 100
693
                 perc = payload / self.maxvalue * 100
694
                 if self.last_printed is None or abs(self.last_printed - perc) >= 4.8:
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))
695
                     sys.stdout.write(COLOR_GUI_ACTIVE + 't' + percent_bar(perc))
696
-                    print('%3d%%' % perc + 2 * ' ' + ' - '.join(self.topic.split('/')[1:-1]) + ' (%.1f)' % payload + colored.attr('reset'))
696
+                    print('%3d%%' % perc + 2 * ' ' + ' - '.join(self.topic.split('/')[1:]) + ' (%.1f)' % payload + colored.attr('reset'))
697
                     self.last_printed = perc
697
                     self.last_printed = perc
698
             else:
698
             else:
699
                 self.maxvalue = None
699
                 self.maxvalue = None
700
                 self.last_printed = None
700
                 self.last_printed = None
701
                 sys.stdout.write(COLOR_GUI_ACTIVE + 't' + percent_bar(0))
701
                 sys.stdout.write(COLOR_GUI_ACTIVE + 't' + percent_bar(0))
702
-                print('%3d%%' % 0 + 2 * ' ' + ' - '.join(self.topic.split('/')[1:-1]) + colored.attr('reset'))
702
+                print('%3d%%' % 0 + 2 * ' ' + ' - '.join(self.topic.split('/')[1:]) + colored.attr('reset'))
703
         else:
703
         else:
704
             print("Unknown Message")
704
             print("Unknown Message")
705
 
705
 

+ 35
- 33
__simulation__/rooms.py 查看文件

40
 
40
 
41
 class gfw_floor(base):
41
 class gfw_floor(base):
42
     def __init__(self, mqtt_client):
42
     def __init__(self, mqtt_client):
43
-        self.gui_switch_main_light = gui_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_GUI_SWITCH, True, False, False)
43
+        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_GUI, True, True, True)
44
         self.main_light = shelly(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
44
         self.main_light = shelly(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
45
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
45
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
46
         self.main_light_zigbee_1 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_1_ZIGBEE, True, True, True, False)
46
         self.main_light_zigbee_1 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_1_ZIGBEE, True, True, True, False)
49
         self.main_light_zigbee_2 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_2_ZIGBEE, True, True, True, False)
49
         self.main_light_zigbee_2 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_2_ZIGBEE, True, True, True, False)
50
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_2.power_on, "on")
50
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_2.power_on, "on")
51
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_1.power_off, "off")
51
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_1.power_off, "off")
52
-        self.gui_br_ct_main_light = gui_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_GUI_BR_CT, False, True, True)
53
 
52
 
54
 
53
 
55
 class gfw_marion(base):
54
 class gfw_marion(base):
56
     def __init__(self, mqtt_client):
55
     def __init__(self, mqtt_client):
57
-        self.gui_switch_main_light = gui_light(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_GUI_SWITCH, True, False, False)
56
+        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_GUI, True, False, False)
58
         self.main_light = shelly(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
57
         self.main_light = shelly(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
59
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
58
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
60
 
59
 
61
 
60
 
62
 class gfw_dirk(base):
61
 class gfw_dirk(base):
63
     def __init__(self, mqtt_client):
62
     def __init__(self, mqtt_client):
64
-        self.gui_switch_main_light = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_GUI_SWITCH, True, False, False)
63
+        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_GUI, True, True, True)
65
         self.main_light = shelly(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
64
         self.main_light = shelly(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
66
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
65
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
67
         self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE, True, True, True)
66
         self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE, True, True, True)
68
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
67
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
69
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
68
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
70
-        self.gui_br_ct_main_light = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_GUI_BR_CT, False, True, True)
71
         #
69
         #
72
         self.powerplug = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG)
70
         self.powerplug = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG)
73
         self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_0, "Amplifier")
71
         self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_0, "Amplifier")
74
-        self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_1, "Desk Light")
75
-        self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_2, "CD-Player")
76
-        self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_3, "PC-Dock")
77
-        self.gui_switch_amplifier = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_GUI_SWITCH, True, False, False)
78
-        self.gui_switch_desk_light = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_GUI_SWITCH, True, False, False)
79
-        self.gui_br_ct_desk_light = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_GUI_BR_CT, False, True, True)
80
-        self.gui_switch_cd_player = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_GUI_SWITCH, True, False, False)
81
-        self.gui_switch_pc_dock = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_GUI_SWITCH, True, False, False)
72
+        self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_1, "Desk_Light")
73
+        self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_2, "CD_Player")
74
+        self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_3, "PC_Dock")
75
+        self.gui_amplifier = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_GUI, True, False, False)
76
+        self.gui_desk_light = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_GUI, True, True, True)
77
+        self.desk_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE, True, True, True)
78
+        self.powerplug.add_callback(my_powerplug.KEY_OUTPUT_1, self.desk_light_zigbee.power_on, True)
79
+        self.powerplug.add_callback(my_powerplug.KEY_OUTPUT_1, self.desk_light_zigbee.power_off, False)
80
+        self.gui_cd_player = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_GUI, True, False, False)
81
+        self.gui_pc_dock = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_GUI, True, False, False)
82
         #
82
         #
83
         self.remote = remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
83
         self.remote = remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
84
         #
84
         #
98
 
98
 
99
 class ffw_julian(base):
99
 class ffw_julian(base):
100
     def __init__(self, mqtt_client):
100
     def __init__(self, mqtt_client):
101
-        self.gui_switch_main_light = gui_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_GUI_SWITCH, True, False, False)
101
+        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_GUI, True, True, True)
102
         self.main_light = shelly(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
102
         self.main_light = shelly(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
103
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
103
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
104
         self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE, True, True, True)
104
         self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE, True, True, True)
105
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
105
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
106
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
106
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
107
-        self.gui_br_ct_main_light = gui_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_GUI_BR_CT, False, True, True)
108
 
107
 
109
 
108
 
110
 class ffw_livingroom(base):
109
 class ffw_livingroom(base):
111
     def __init__(self, mqtt_client):
110
     def __init__(self, mqtt_client):
112
-        self.gui_switch_main_light = gui_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_GUI_SWITCH, True, False, False)
111
+        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_GUI, True, False, False)
113
         self.main_light = shelly(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
112
         self.main_light = shelly(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
114
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
113
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
115
 
114
 
122
 
121
 
123
 class ffe_floor(base):
122
 class ffe_floor(base):
124
     def __init__(self, mqtt_client):
123
     def __init__(self, mqtt_client):
125
-        self.gui_switch_main_light = gui_light(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_GUI_SWITCH, True, False, False)
124
+        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_GUI, True, False, False)
126
         self.main_light = shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
125
         self.main_light = shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
127
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
126
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
128
 
127
 
129
 
128
 
130
 class ffe_kitchen(base):
129
 class ffe_kitchen(base):
131
     def __init__(self, mqtt_client):
130
     def __init__(self, mqtt_client):
132
-        self.gui_switch_main_light = gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI_SWITCH, True, False, False)
131
+        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI, True, False, False)
133
         self.main_light = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
132
         self.main_light = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
134
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
133
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
135
         #
134
         #
136
-        self.gui_switch_circulation_pump = gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_GUI_SWITCH, True, False, False)
135
+        self.gui_circulation_pump = gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_GUI, True, False, False)
137
         self.circulation_pump = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY,
136
         self.circulation_pump = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY,
138
                                        input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER, output_0_auto_off=10*60)
137
                                        input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER, output_0_auto_off=10*60)
139
         self.circulation_pump.add_channel_name(shelly.KEY_OUTPUT_0, "Circulation Pump")
138
         self.circulation_pump.add_channel_name(shelly.KEY_OUTPUT_0, "Circulation Pump")
142
 
141
 
143
 class ffe_diningroom(base):
142
 class ffe_diningroom(base):
144
     def __init__(self, mqtt_client):
143
     def __init__(self, mqtt_client):
145
-        self.gui_switch_main_light = gui_light(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_GUI_SWITCH, True, False, False)
144
+        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_GUI, True, False, False)
146
         self.main_light = shelly(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
145
         self.main_light = shelly(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
147
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
146
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
148
-        self.gui_switch_floor_lamp = gui_light(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_GUI_SWITCH, True, False, False)
147
+        self.gui_floor_lamp = gui_light(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_GUI, True, False, False)
149
         self.floor_lamp = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
148
         self.floor_lamp = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
150
         self.floor_lamp.add_channel_name(silvercrest_powerplug.KEY_OUTPUT_0, "Floor Lamp")
149
         self.floor_lamp.add_channel_name(silvercrest_powerplug.KEY_OUTPUT_0, "Floor Lamp")
151
-        self.garland = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
152
-        self.garland.add_channel_name(silvercrest_powerplug, "Garland")
150
+        if config.CHRISTMAS:
151
+            self.garland = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
152
+            self.garland.add_channel_name(silvercrest_powerplug, "Garland")
153
 
153
 
154
 
154
 
155
 class ffe_sleep(base):
155
 class ffe_sleep(base):
156
     def __init__(self, mqtt_client):
156
     def __init__(self, mqtt_client):
157
-        self.gui_switch_main_light = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_GUI_SWITCH, True, False, False)
157
+        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_GUI, True, True, True)
158
         self.main_light = shelly(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
158
         self.main_light = shelly(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
159
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
159
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
160
         self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE, True, True, True)
160
         self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE, True, True, True)
161
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
161
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
162
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
162
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
163
-        self.gui_br_ct_main_light = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_GUI_BR_CT, False, True, True)
164
         #
163
         #
165
-        self.gui_switch_bed_light_di = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_GUI_SWITCH, True, False, False)
164
+        self.gui_bed_light_di = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_GUI, True, True, False)
166
         self.bed_light_di_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE, True, True, False)
165
         self.bed_light_di_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE, True, True, False)
167
-        self.gui_br_ct_bed_light_di = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_GUI_BR_CT, False, True, False)
168
         #
166
         #
169
         self.input_device = tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
167
         self.input_device = tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
170
         self.led_array = gui_led_array(mqtt_client, config.TOPIC_FFE_SLEEP_DEVICE_CHOOSER_LED)
168
         self.led_array = gui_led_array(mqtt_client, config.TOPIC_FFE_SLEEP_DEVICE_CHOOSER_LED)
179
 
177
 
180
 class ffe_livingroom(base):
178
 class ffe_livingroom(base):
181
     def __init__(self, mqtt_client):
179
     def __init__(self, mqtt_client):
182
-        self.gui_switch_main_light = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_GUI_SWITCH, True, False, False)
180
+        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_GUI, True, True, True)
183
         self.main_light = shelly(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
181
         self.main_light = shelly(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
184
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
182
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
185
         self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE, True, True, True)
183
         self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE, True, True, True)
186
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
184
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
187
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
185
         self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
188
-        self.gui_br_ct_main_light = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_GUI_BR_CT, False, True, True)
189
         for i in range(1, 7):
186
         for i in range(1, 7):
190
-            setattr(self, "floor_lamp_%d" % i, tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i, True, True, True))
191
-        self.gui_switch_floor_lamp = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_GUI_SWITCH, True, False, False)
192
-        self.gui_br_ct_floor_lamp = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_GUI_BR_CT, False, True, True)
187
+            setattr(self, "floor_lamp_zigbee_%d" % i, tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i, True, True, True))
188
+        self.gui_floor_lamp = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_GUI, True, True, True)
189
+        if config.CHRISTMAS:
190
+            self.xmas_tree = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)
191
+            self.xmas_tree.add_channel_name(silvercrest_powerplug, "Xmas-Tree")
192
+            self.gui_xmas_tree = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_GUI)
193
+            self.xmas_star = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)
194
+            self.xmas_star.add_channel_name(silvercrest_powerplug, "Xmas-Star")
193
 
195
 
194
 
196
 
195
 class ffe(base):
197
 class ffe(base):
203
 
205
 
204
 class stairway(base):
206
 class stairway(base):
205
     def __init__(self, mqtt_client):
207
     def __init__(self, mqtt_client):
206
-        self.gui_switch_main_light = gui_light(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_GUI_SWITCH, True, False, False)
208
+        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_GUI, True, False, False)
207
         self.main_light = shelly(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
209
         self.main_light = shelly(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
208
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
210
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
209
         self.motion_sensor_gf = silvercrest_motion_sensor(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF)
211
         self.motion_sensor_gf = silvercrest_motion_sensor(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF)

+ 232
- 0
__simulation__/test.py 查看文件

1
+import colored
2
+import time
3
+
4
+
5
+DT_TOGGLE = 0.1
6
+
7
+
8
+class test_smarthome(object):
9
+    def __init__(self, house):
10
+        self.house = house
11
+
12
+    def __smoke__(self):
13
+        result = ""
14
+        result += "Smoke-Test\n"
15
+        result += "  GUI Element exists for every shelly instance\n"
16
+        result += self.__gui_element_exists__("shelly")
17
+        result += "  On-Off test for every shelly instance\n"
18
+        result += self.__on_off_test__("shelly")
19
+        result += "  GUI Element exists for every silvercrest_powerplug instance\n"
20
+        result += self.__gui_element_exists__("silvercrest_powerplug")
21
+        result += "  On-Off test for every silvercrest_powerplug instance\n"
22
+        result += self.__on_off_test__("silvercrest_powerplug")
23
+        result += "  GUI Element exists for every my_powerplug instance and port\n"
24
+        result += self.__gui_element_exists_my_powerplug__()
25
+        result += "  On-Off test for every my_powerplug instance\n"
26
+        result += self.__on_off_test_my_powerplug__()
27
+        result += "  GUI Element exists for every tradfri_light instance\n"
28
+        result += self.__gui_element_exists__("tradfri_light")
29
+        result += "  Enable and disable test for gui elements corresponding with tradfri_light\n"
30
+        result += self.__br_ct_enable_test__()
31
+        result += "  Chnage brightness and color_temp by gui test\n"
32
+        result += self.__br_ct_change_test__()
33
+        return result
34
+
35
+    def __full__(self):
36
+        result = "Full-Test"
37
+        return result
38
+
39
+    def smoke(self):
40
+        print(self.__smoke__())
41
+
42
+    def full(self):
43
+        out = self.__smoke__()
44
+        out += self.__full__()
45
+        print(out)
46
+
47
+    def print_error(self, text, lvl=2):
48
+        return lvl*"  " + colored.fg("light_red") + '* ' + text + "\n" + colored.attr("reset")
49
+
50
+    def print_success(self, text, lvl=2):
51
+        return lvl*"  " + colored.fg("light_green") + '* ' + text + "\n" + colored.attr("reset")
52
+
53
+    def __gui_element_exists__(self, obj_name):
54
+        result = ""
55
+        for member in self.house.getmembers():
56
+            obj = self.house.getobjbyname(member)
57
+            if obj.__class__.__name__ == obj_name:
58
+                if obj_name == "tradfri_light":
59
+                    basename = member[:member.index('_zigbee')]
60
+                else:
61
+                    basename = member
62
+                try:
63
+                    gui = self.house.getobjbyname('.'.join(basename.split('.')[:-1]) + '.gui_' + basename.split('.')[-1])
64
+                except AttributeError:
65
+                    result += self.print_error("No GUI element available, while testing %s (%s)." % (member, obj_name))
66
+                else:
67
+                    result += self.print_success("GUI element available, while testing %s (%s)." % (member, obj_name))
68
+        return result
69
+
70
+    def __gui_element_exists_my_powerplug__(self):
71
+        result = ""
72
+        for member in self.house.getmembers():
73
+            obj = self.house.getobjbyname(member)
74
+            if obj.__class__.__name__ == "my_powerplug":
75
+                for channel in [obj.KEY_OUTPUT_0, obj.KEY_OUTPUT_1, obj.KEY_OUTPUT_2, obj.KEY_OUTPUT_3]:
76
+                    try:
77
+                        gui = self.house.getobjbyname('.'.join(member.split(
78
+                            '.')[:-1]) + '.gui_' + obj.names.get(channel.lower(), "__dummy__").lower())
79
+                    except AttributeError:
80
+                        result += self.print_error("No GUI element available, while testing %s (%s)." % (member, obj.names.get(channel)))
81
+                    else:
82
+                        result += self.print_success("GUI element available, while testing %s (%s)." % (member, obj.names.get(channel)))
83
+        return result
84
+
85
+    def __on_off_test_my_powerplug__(self):
86
+        result = ""
87
+        for member in self.house.getmembers():
88
+            obj = self.house.getobjbyname(member)
89
+            if obj.__class__.__name__ == "my_powerplug":
90
+                for channel in [obj.KEY_OUTPUT_0, obj.KEY_OUTPUT_1, obj.KEY_OUTPUT_2, obj.KEY_OUTPUT_3]:
91
+                    try:
92
+                        gui = self.house.getobjbyname('.'.join(member.split(
93
+                            '.')[:-1]) + '.gui_' + obj.names.get(channel.lower(), "__dummy__").lower())
94
+                    except AttributeError:
95
+                        raise AttributeError
96
+                        pass  # exists test already covers non existing gui-elements
97
+                    else:
98
+                        success = True
99
+                        # Initial state equal between obj and gui
100
+                        obj_state = obj.data.get(channel)
101
+                        gui_state = gui.data.get(gui.KEY_STATE)
102
+                        if obj_state != gui_state:
103
+                            result += self.print_error("Initial state of %s (%s) is not equal to GUI state (%s), while testing %s (%s)" %
104
+                                                       ("my_powerplug", obj_state, gui_state, member, obj.names.get(channel)))
105
+                            success = False
106
+                        # state obj change results in state change of obj and gui
107
+                        for i in range(1, 3):
108
+                            gui.command("toggle_state")
109
+                            time.sleep(2 * DT_TOGGLE)
110
+                            last_obj_state = obj_state
111
+                            obj_state = obj.data.get(channel)
112
+                            gui_state = gui.data.get(gui.KEY_STATE)
113
+                            if last_obj_state == obj_state:
114
+                                result += self.print_error("State after %d. toggle of gui state: State unchanged (%s), while testing %s (%s)" %
115
+                                                           (i, obj_state, member, obj.names.get(channel)))
116
+                                success = False
117
+                            if obj_state != gui_state:
118
+                                result += self.print_error("State after %d. toggle of gui state:: State of device (%s) is not equal to GUI state (%s), while testing %s (%s)" %
119
+                                                           (i, obj_state, gui_state, member, obj.names.get(channel)))
120
+                                success = False
121
+                        #
122
+                        if success:
123
+                            result += self.print_success("On-Off test successfull, while testing %s (%s)." % (member, obj.names.get(channel)))
124
+        return result
125
+
126
+    def __on_off_test__(self, obj_name):
127
+        result = ""
128
+        for member in self.house.getmembers():
129
+            obj = self.house.getobjbyname(member)
130
+            if obj.__class__.__name__ == obj_name:
131
+                try:
132
+                    gui = self.house.getobjbyname('.'.join(member.split('.')[:-1]) + '.gui_' + member.split('.')[-1])
133
+                except AttributeError:
134
+                    pass  # exists test already covers non existing gui-elements
135
+                else:
136
+                    success = True
137
+                    # Initial state equal between obj and gui
138
+                    obj_state = obj.data.get(obj.KEY_OUTPUT_0).lower() == "on"
139
+                    gui_state = gui.data.get(gui.KEY_STATE)
140
+                    if obj_state != gui_state:
141
+                        result += self.print_error("Initial state of %s (%s) is not equal to GUI state (%s), while testing %s (%s)" %
142
+                                                   (obj_name, obj_state, gui_state, member, obj_name))
143
+                        success = False
144
+                    # state obj change results in state change of obj and gui
145
+                    for i in range(1, 3):
146
+                        gui.command("toggle_state")
147
+                        time.sleep(2 * DT_TOGGLE)
148
+                        last_obj_state = obj_state
149
+                        obj_state = obj.data.get(obj.KEY_OUTPUT_0).lower() == "on"
150
+                        gui_state = gui.data.get(gui.KEY_STATE)
151
+                        if last_obj_state == obj_state:
152
+                            result += self.print_error("State after %d. toggle of gui state: State unchanged (%s), while testing %s (%s)" %
153
+                                                       (i, obj_state, member, obj_name))
154
+                            success = False
155
+                        if obj_state != gui_state:
156
+                            result += self.print_error("State after %d. toggle of gui state:: State of device (%s) is not equal to GUI state (%s), while testing %s (%s)" %
157
+                                                       (i, obj_state, gui_state, member, obj_name))
158
+                            success = False
159
+                    #
160
+                    if success:
161
+                        result += self.print_success("On-Off test successfull, while testing %s." % (member))
162
+        return result
163
+
164
+    def __br_ct_enable_test__(self):
165
+        result = ""
166
+        for member in self.house.getmembers():
167
+            obj = self.house.getobjbyname(member)
168
+            if obj.__class__.__name__ == "tradfri_light":
169
+                basename = member[:member.index('_zigbee')]
170
+                gui = self.house.getobjbyname('.'.join(basename.split('.')[:-1]) + '.gui_' + basename.split('.')[-1])
171
+                success = True
172
+                #
173
+                if gui.data.get(gui.KEY_ENABLE) != False:
174
+                    result += self.print_error("Inital enable state is not False, while testing %s." % (member))
175
+                    success = False
176
+                #
177
+                gui.command("toggle_state")
178
+                time.sleep(2 * DT_TOGGLE)
179
+                if gui.data.get(gui.KEY_ENABLE) != True:
180
+                    result += self.print_error("Enable state is not True after switching on, while testing %s." % (member))
181
+                    success = False
182
+                #
183
+                gui.command("toggle_state")
184
+                time.sleep(2 * DT_TOGGLE)
185
+                if gui.data.get(gui.KEY_ENABLE) != False:
186
+                    result += self.print_error("Enable state is not False after switching off, while testing %s." % (member))
187
+                    success = False
188
+                #
189
+                if success:
190
+                    result += self.print_success("Enable-Disable test successfull, while testing %s." % (member))
191
+        return result
192
+
193
+    def __br_ct_change_test__(self):
194
+        result = ""
195
+        for member in self.house.getmembers():
196
+            obj = self.house.getobjbyname(member)
197
+            if obj.__class__.__name__ == "tradfri_light":
198
+                basename = member[:member.index('_zigbee')]
199
+                gui = self.house.getobjbyname('.'.join(basename.split('.')[:-1]) + '.gui_' + basename.split('.')[-1])
200
+                success = True
201
+                #
202
+                if gui.data.get(gui.KEY_STATE) != True:
203
+                    gui.command("toggle_state")
204
+                    time.sleep(2 * DT_TOGGLE)
205
+                if gui.data.get(gui.KEY_STATE) != True:
206
+                    result += self.print_error("Unable to switch on light, while testing %s." % (member))
207
+                    success = False
208
+                    continue
209
+                #
210
+                if "set_brightness" in obj.capabilities():
211
+                    brightness = gui.data.get(obj.KEY_BRIGHTNESS)
212
+                    targetvalue = brightness + (25 if brightness <= 50 else -25)
213
+                    gui.command("set_brightness %d" % targetvalue)
214
+                    time.sleep(2 * DT_TOGGLE)
215
+                    if gui.data.get(obj.KEY_BRIGHTNESS) != targetvalue:
216
+                        result += self.print_error("Brightness change by gui was not successfull, while testing %s." % (member))
217
+                        success = False
218
+                if "set_color_temp" in obj.capabilities():
219
+                    color_temp = gui.data.get(obj.KEY_COLOR_TEMP)
220
+                    targetvalue = color_temp + (3 if color_temp <= 5 else -3)
221
+                    gui.command("set_color_temp %d" % targetvalue)
222
+                    time.sleep(2 * DT_TOGGLE)
223
+                    if gui.data.get(obj.KEY_COLOR_TEMP) != targetvalue:
224
+                        result += self.print_error("Color temperature change by gui was not successfull, while testing %s." % (member))
225
+                        success = False
226
+                #
227
+                gui.command("toggle_state")
228
+                time.sleep(2 * DT_TOGGLE)
229
+                #
230
+                if success:
231
+                    result += self.print_success("Brightness-ColorTemp test successfull, while testing %s." % (member))
232
+        return result

+ 2
- 2
devices/__init__.py 查看文件

700
         self.set_state(data)
700
         self.set_state(data)
701
 
701
 
702
 
702
 
703
-class nodered_gui_brightness_color_temp(base):
703
+class nodered_gui_light(nodered_gui_switch):
704
     KEY_ENABLE = "enable"
704
     KEY_ENABLE = "enable"
705
     KEY_BRIGHTNESS = "brightness"
705
     KEY_BRIGHTNESS = "brightness"
706
     KEY_COLOR_TEMP = "color_temp"
706
     KEY_COLOR_TEMP = "color_temp"
707
     #
707
     #
708
     TX_TYPE = base.TX_VALUE
708
     TX_TYPE = base.TX_VALUE
709
     #
709
     #
710
-    RX_KEYS = [KEY_ENABLE, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
710
+    RX_KEYS = nodered_gui_switch.RX_KEYS + [KEY_ENABLE, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
711
 
711
 
712
     #
712
     #
713
     # RX
713
     # RX

+ 2
- 5
function/__init__.py 查看文件

16
     ROOT_LOGGER_NAME = 'root'
16
     ROOT_LOGGER_NAME = 'root'
17
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
17
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
18
 
18
 
19
-# TODO: implement TOPIC-changes in config.py (gfw.floor.main_light)
20
-# TODO: implement gui element for tradfri light as one class
19
+# TODO: implement devices.nodered_gui_timer (for circulation pump)
21
 # TODO: implement devices.nodered_gui_heatvalve incl. setpoint, boost, ... + replace led with timer
20
 # TODO: implement devices.nodered_gui_heatvalve incl. setpoint, boost, ... + replace led with timer
22
 # TODO: improve heating function
21
 # TODO: improve heating function
23
 # TODO: implement timer and motion leds for stairwasy
22
 # TODO: implement timer and motion leds for stairwasy
24
-# TODO: implement devices.nodered_gui_timer (for circulation pump)
25
-#       improve devices.brennenstuhl_heatvalve
26
-#       improve the implementation in common if highly reduced, just move it to function.__init__.py
23
+# TODO: improve devices.brennenstuhl_heatvalve
27
 # TODO: implement garland (incl. day events like sunset, sunrise, ...)
24
 # TODO: implement garland (incl. day events like sunset, sunrise, ...)
28
 # TODO: implement warning message
25
 # TODO: implement warning message
29
 
26
 

+ 1
- 1
function/common.py 查看文件

19
 class common_circulation_pump(room_shelly):
19
 class common_circulation_pump(room_shelly):
20
     def __init__(self, mqtt_client):
20
     def __init__(self, mqtt_client):
21
         # http://shelly1-E89F6D85A466
21
         # http://shelly1-E89F6D85A466
22
-        super().__init__(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_GUI_SWITCH)
22
+        super().__init__(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_GUI)
23
         #
23
         #
24
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.circ_pump_actions, True)
24
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.circ_pump_actions, True)
25
         #
25
         #

+ 27
- 31
function/first_floor_east.py 查看文件

17
 class first_floor_east_floor(room_shelly):
17
 class first_floor_east_floor(room_shelly):
18
     def __init__(self, mqtt_client):
18
     def __init__(self, mqtt_client):
19
         # http://shelly1l-3C6105E4E629
19
         # http://shelly1l-3C6105E4E629
20
-        super().__init__(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_GUI_SWITCH)
20
+        super().__init__(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_GUI)
21
 
21
 
22
 
22
 
23
 class first_floor_east_kitchen(room_shelly):
23
 class first_floor_east_kitchen(room_shelly):
24
     def __init__(self, mqtt_client):
24
     def __init__(self, mqtt_client):
25
         # http://shelly1l-8CAAB5616C01
25
         # http://shelly1l-8CAAB5616C01
26
-        super().__init__(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI_SWITCH)
26
+        super().__init__(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI)
27
 
27
 
28
 
28
 
29
 class first_floor_east_dining(room_shelly):
29
 class first_floor_east_dining(room_shelly):
30
     def __init__(self, mqtt_client):
30
     def __init__(self, mqtt_client):
31
         # http://shelly1l-84CCA8ADD055
31
         # http://shelly1l-84CCA8ADD055
32
-        super().__init__(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_GUI_SWITCH)
32
+        super().__init__(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_GUI)
33
         self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
33
         self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
34
         if config.CHRISTMAS:
34
         if config.CHRISTMAS:
35
             self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
35
             self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
36
         #
36
         #
37
-        self.gui_switch_floorlamp = devices.nodered_gui_switch(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_GUI_SWITCH)
37
+        self.gui_floorlamp = devices.nodered_gui_switch(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_GUI)
38
         #
38
         #
39
         # Callback initialisation
39
         # Callback initialisation
40
         #
40
         #
41
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_powerplug.set_output_0_mcb, True)
41
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_powerplug.set_output_0_mcb, True)
42
-        self.gui_switch_floorlamp.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.floorlamp_powerplug.set_output_0_mcb)
43
-        self.floorlamp_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.gui_switch_floorlamp.set_state_mcb)
42
+        self.gui_floorlamp.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.floorlamp_powerplug.set_output_0_mcb)
43
+        self.floorlamp_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.gui_floorlamp.set_state_mcb)
44
 
44
 
45
     def all_off(self, device=None, key=None, data=None):
45
     def all_off(self, device=None, key=None, data=None):
46
         super().all_off(device, key, data)
46
         super().all_off(device, key, data)
52
 class first_floor_east_sleep(room_shelly_tradfri_light):
52
 class first_floor_east_sleep(room_shelly_tradfri_light):
53
     def __init__(self, mqtt_client):
53
     def __init__(self, mqtt_client):
54
         # http://shelly1l-E8DB84A254C7
54
         # http://shelly1l-E8DB84A254C7
55
-        super().__init__(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_GUI_SWITCH,
56
-                         config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_GUI_BR_CT)
55
+        super().__init__(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_GUI, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE)
57
         #
56
         #
58
         self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE)
57
         self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE)
59
         #
58
         #
60
-        self.gui_switch_bed_light_di = devices.nodered_gui_switch(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_GUI_SWITCH)
61
-        self.gui_br_ct_bed_light_di = devices.nodered_gui_brightness_color_temp(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_GUI_BR_CT)
59
+        self.gui_bed_light_di = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_GUI)
62
         #
60
         #
63
         self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
61
         self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
64
         #
62
         #
76
 
74
 
77
         # bed light
75
         # bed light
78
         # switch
76
         # switch
79
-        self.gui_switch_bed_light_di.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.bed_light_di_tradfri.set_output_0_mcb)
80
-        self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_switch_bed_light_di.set_state_mcb)
77
+        self.gui_bed_light_di.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.bed_light_di_tradfri.set_output_0_mcb)
78
+        self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_bed_light_di.set_state_mcb)
81
         # brightness and color temperature
79
         # brightness and color temperature
82
-        self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_br_ct_bed_light_di.set_enable_mcb)
83
-        self.gui_br_ct_bed_light_di.add_callback(devices.nodered_gui_brightness_color_temp.KEY_BRIGHTNESS,
84
-                                                 None, self.bed_light_di_tradfri.set_brightness_mcb)
85
-        self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_br_ct_bed_light_di.set_enable_mcb)
86
-        self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_br_ct_bed_light_di.set_brightness_mcb)
80
+        self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_bed_light_di.set_enable_mcb)
81
+        self.gui_bed_light_di.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.bed_light_di_tradfri.set_brightness_mcb)
82
+        self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_bed_light_di.set_enable_mcb)
83
+        self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_bed_light_di.set_brightness_mcb)
87
 
84
 
88
     def all_off(self, device=None, key=None, data=None):
85
     def all_off(self, device=None, key=None, data=None):
89
         super().all_off(device, key, data)
86
         super().all_off(device, key, data)
93
 class first_floor_east_living(room_shelly_tradfri_light):
90
 class first_floor_east_living(room_shelly_tradfri_light):
94
     def __init__(self, mqtt_client):
91
     def __init__(self, mqtt_client):
95
         # http://shelly1l-3C6105E3F910
92
         # http://shelly1l-3C6105E3F910
96
-        super().__init__(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_GUI_SWITCH,
97
-                         config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_GUI_BR_CT)
93
+        super().__init__(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY,
94
+                         config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_GUI, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE)
98
         for i in range(1, 7):
95
         for i in range(1, 7):
99
             setattr(self, 'floorlamp_tradfri_%d' % i, devices.tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i))
96
             setattr(self, 'floorlamp_tradfri_%d' % i, devices.tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i))
100
         #
97
         #
102
             self.powerplug_xmas_tree = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)
99
             self.powerplug_xmas_tree = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)
103
             self.powerplug_xmas_star = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)
100
             self.powerplug_xmas_star = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)
104
         #
101
         #
105
-        self.gui_switch_floorlamp = devices.nodered_gui_switch(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_GUI_SWITCH)
106
-        self.gui_br_ct_floorlamp = devices.nodered_gui_brightness_color_temp(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_GUI_BR_CT)
102
+        self.gui_floorlamp = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_GUI)
107
         #
103
         #
108
         if config.CHRISTMAS:
104
         if config.CHRISTMAS:
109
-            self.gui_switch_xmas_tree = devices.nodered_gui_switch(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_GUI_SWITCH)
105
+            self.gui_xmas_tree = devices.nodered_gui_switch(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_GUI)
110
         #
106
         #
111
         # Callback initialisation
107
         # Callback initialisation
112
         #
108
         #
114
         # floor lamp
110
         # floor lamp
115
         for device in self.__floorlamp_devices__():
111
         for device in self.__floorlamp_devices__():
116
             self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, device.set_output_0_mcb, True)
112
             self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, device.set_output_0_mcb, True)
117
-            self.gui_switch_floorlamp.add_callback(devices.nodered_gui_switch.KEY_STATE, None, device.set_output_0_mcb)
118
-            self.gui_br_ct_floorlamp.add_callback(devices.nodered_gui_brightness_color_temp.KEY_BRIGHTNESS, None, device.set_brightness_mcb)
119
-            self.gui_br_ct_floorlamp.add_callback(devices.nodered_gui_brightness_color_temp.KEY_COLOR_TEMP, None, device.set_color_temp_mcb)
120
-        self.floorlamp_tradfri_1.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_switch_floorlamp.set_state_mcb)
121
-        self.floorlamp_tradfri_1.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_br_ct_floorlamp.set_enable_mcb)
122
-        self.floorlamp_tradfri_1.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_br_ct_floorlamp.set_brightness_mcb)
123
-        self.floorlamp_tradfri_1.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_br_ct_floorlamp.set_color_temp_mcb)
113
+            self.gui_floorlamp.add_callback(devices.nodered_gui_light.KEY_STATE, None, device.set_output_0_mcb)
114
+            self.gui_floorlamp.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, device.set_brightness_mcb)
115
+            self.gui_floorlamp.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, device.set_color_temp_mcb)
116
+        self.floorlamp_tradfri_1.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_floorlamp.set_state_mcb)
117
+        self.floorlamp_tradfri_1.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_floorlamp.set_enable_mcb)
118
+        self.floorlamp_tradfri_1.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_floorlamp.set_brightness_mcb)
119
+        self.floorlamp_tradfri_1.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_floorlamp.set_color_temp_mcb)
124
         #
120
         #
125
         if config.CHRISTMAS:
121
         if config.CHRISTMAS:
126
-            self.powerplug_xmas_tree.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.gui_switch_xmas_tree.set_state_mcb)
127
-            self.gui_switch_xmas_tree.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_xmas_tree.set_output_0_mcb)
122
+            self.powerplug_xmas_tree.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.gui_xmas_tree.set_state_mcb)
123
+            self.gui_xmas_tree.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_xmas_tree.set_output_0_mcb)
128
             #
124
             #
129
             self.powerplug_xmas_tree.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.powerplug_xmas_star.set_output_0_mcb)
125
             self.powerplug_xmas_tree.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.powerplug_xmas_star.set_output_0_mcb)
130
 
126
 

+ 2
- 3
function/first_floor_west.py 查看文件

16
 class first_floor_west_julian(room_shelly_tradfri_light):
16
 class first_floor_west_julian(room_shelly_tradfri_light):
17
     # http://shelly1l-3C6105E43452
17
     # http://shelly1l-3C6105E43452
18
     def __init__(self, mqtt_client):
18
     def __init__(self, mqtt_client):
19
-        super().__init__(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_GUI_SWITCH,
20
-                         config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_GUI_BR_CT)
19
+        super().__init__(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_GUI, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE)
21
 
20
 
22
 
21
 
23
 class first_floor_west_living(room_shelly):
22
 class first_floor_west_living(room_shelly):
24
     # http://shelly1l-84CCA8ACE6A1
23
     # http://shelly1l-84CCA8ACE6A1
25
     def __init__(self, mqtt_client):
24
     def __init__(self, mqtt_client):
26
-        super().__init__(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_GUI_SWITCH)
25
+        super().__init__(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_GUI)

+ 20
- 25
function/ground_floor_west.py 查看文件

19
 class ground_floor_west_floor(room_shelly_silvercrest_light):
19
 class ground_floor_west_floor(room_shelly_silvercrest_light):
20
     # http://shelly1l-84CCA8AD1148
20
     # http://shelly1l-84CCA8AD1148
21
     def __init__(self, mqtt_client):
21
     def __init__(self, mqtt_client):
22
-        super().__init__(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_GUI_SWITCH,
23
-                         config.TOPIC_GFW_FLOOR_MAIN_LIGHT_1_ZIGBEE, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_GUI_BR_CT)
22
+        super().__init__(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_GUI, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_1_ZIGBEE)
24
         #
23
         #
25
         # Callback initialisation
24
         # Callback initialisation
26
         #
25
         #
36
 class ground_floor_west_marion(room_shelly):
35
 class ground_floor_west_marion(room_shelly):
37
     # http://shelly1l-E8DB84A1E067
36
     # http://shelly1l-E8DB84A1E067
38
     def __init__(self, mqtt_client):
37
     def __init__(self, mqtt_client):
39
-        super().__init__(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY, config.TOPIC_GFW_MARION_MAIN_LIGHT_GUI_SWITCH)
38
+        super().__init__(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY, config.TOPIC_GFW_MARION_MAIN_LIGHT_GUI)
40
 
39
 
41
 
40
 
42
 class ground_floor_west_dirk(room_shelly_tradfri_light):
41
 class ground_floor_west_dirk(room_shelly_tradfri_light):
60
 
59
 
61
     # http://shelly1l-3C6105E44F27
60
     # http://shelly1l-3C6105E44F27
62
     def __init__(self, mqtt_client):
61
     def __init__(self, mqtt_client):
63
-        super().__init__(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY, config.TOPIC_GFW_DIRK_MAIN_LIGHT_GUI_SWITCH,
64
-                         config.TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE, config.TOPIC_GFW_DIRK_MAIN_LIGHT_GUI_BR_CT)
62
+        super().__init__(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY, config.TOPIC_GFW_DIRK_MAIN_LIGHT_GUI, config.TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE)
65
         #
63
         #
66
         self.powerplug_common = devices.my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG)
64
         self.powerplug_common = devices.my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG)
67
         self.desk_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE)
65
         self.desk_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE)
68
         self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_GFW_DIRK_INPUT_DEVICE)
66
         self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_GFW_DIRK_INPUT_DEVICE)
69
         #
67
         #
70
-        self.gui_switch_desk_light = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_GUI_SWITCH)
71
-        self.gui_br_cr_desk_light = devices.nodered_gui_brightness_color_temp(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_GUI_BR_CT)
68
+        self.gui_desk_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_GUI)
72
         #
69
         #
73
-        self.gui_switch_amplifier = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_GUI_SWITCH)
74
-        self.gui_switch_cd_player = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_GUI_SWITCH)
75
-        self.gui_switch_pc_dock = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_GUI_SWITCH)
70
+        self.gui_amplifier = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_GUI)
71
+        self.gui_cd_player = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_GUI)
72
+        self.gui_pc_dock = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_GUI)
76
         #
73
         #
77
         self.remote_amplifier = devices.remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
74
         self.remote_amplifier = devices.remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
78
         #
75
         #
97
         # switch
94
         # switch
98
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT,
95
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT,
99
                                          self.powerplug_common.toggle_output_1_mcb)
96
                                          self.powerplug_common.toggle_output_1_mcb)
100
-        self.gui_switch_desk_light.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_1_mcb)
101
-        self.powerplug_common.add_callback(self.KEY_POWERPLUG_DESK_LIGHT, None, self.gui_switch_desk_light.set_state_mcb)
97
+        self.gui_desk_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.powerplug_common.set_output_1_mcb)
98
+        self.powerplug_common.add_callback(self.KEY_POWERPLUG_DESK_LIGHT, None, self.gui_desk_light.set_state_mcb)
102
         # brightness and color temp
99
         # brightness and color temp
103
-        self.gui_br_cr_desk_light.add_callback(devices.nodered_gui_brightness_color_temp.KEY_BRIGHTNESS,
104
-                                               None, self.desk_light_tradfri.set_brightness_mcb)
105
-        self.gui_br_cr_desk_light.add_callback(devices.nodered_gui_brightness_color_temp.KEY_COLOR_TEMP,
106
-                                               None, self.desk_light_tradfri.set_color_temp_mcb)
107
-        self.powerplug_common.add_callback(self.KEY_POWERPLUG_DESK_LIGHT, None, self.gui_br_cr_desk_light.set_enable_mcb)
108
-        self.desk_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_br_cr_desk_light.set_brightness_mcb)
109
-        self.desk_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_br_cr_desk_light.set_color_temp_mcb)
100
+        self.gui_desk_light.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.desk_light_tradfri.set_brightness_mcb)
101
+        self.gui_desk_light.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.desk_light_tradfri.set_color_temp_mcb)
102
+        self.powerplug_common.add_callback(self.KEY_POWERPLUG_DESK_LIGHT, None, self.gui_desk_light.set_enable_mcb)
103
+        self.desk_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_desk_light.set_brightness_mcb)
104
+        self.desk_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_desk_light.set_color_temp_mcb)
110
 
105
 
111
         # amplifier
106
         # amplifier
112
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT_LONG,
107
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT_LONG,
113
                                          self.powerplug_common.toggle_output_0_mcb)
108
                                          self.powerplug_common.toggle_output_0_mcb)
114
-        self.gui_switch_amplifier.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_0_mcb)
115
-        self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, None, self.gui_switch_amplifier.set_state_mcb)
109
+        self.gui_amplifier.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_0_mcb)
110
+        self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, None, self.gui_amplifier.set_state_mcb)
116
         # amplifier auto on
111
         # amplifier auto on
117
         self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.cd_amplifier_synchronisation, True)
112
         self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.cd_amplifier_synchronisation, True)
118
         self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation, True)
113
         self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation, True)
127
         # cd player
122
         # cd player
128
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG,
123
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG,
129
                                          self.powerplug_common.toggle_output_2_mcb)
124
                                          self.powerplug_common.toggle_output_2_mcb)
130
-        self.gui_switch_cd_player.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_2_mcb)
131
-        self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.gui_switch_cd_player.set_state_mcb)
125
+        self.gui_cd_player.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_2_mcb)
126
+        self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.gui_cd_player.set_state_mcb)
132
 
127
 
133
         # pc dock
128
         # pc dock
134
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT,
129
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT,
135
                                          self.powerplug_common.toggle_output_3_mcb)
130
                                          self.powerplug_common.toggle_output_3_mcb)
136
-        self.gui_switch_pc_dock.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_3_mcb)
137
-        self.powerplug_common.add_callback(self.KEY_POWERPLUG_PC_DOCK, None, self.gui_switch_pc_dock.set_state_mcb)
131
+        self.gui_pc_dock.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_3_mcb)
132
+        self.powerplug_common.add_callback(self.KEY_POWERPLUG_PC_DOCK, None, self.gui_pc_dock.set_state_mcb)
138
 
133
 
139
     def all_off(self, device=None, key=None, data=None):
134
     def all_off(self, device=None, key=None, data=None):
140
         super().all_off(device, key, data)
135
         super().all_off(device, key, data)

+ 17
- 20
function/rooms.py 查看文件

21
 
21
 
22
 
22
 
23
 class room_shelly(room):
23
 class room_shelly(room):
24
-    def __init__(self, mqtt_client, topic_shelly, topic_gui_switch):
24
+    def __init__(self, mqtt_client, topic_shelly, topic_gui):
25
         super().__init__(mqtt_client)
25
         super().__init__(mqtt_client)
26
-        self.main_light_shelly = devices.shelly(mqtt_client, topic=topic_shelly)
26
+        self.main_light_shelly = devices.shelly(mqtt_client, topic_shelly)
27
         #
27
         #
28
-        self.gui_switch_main_light = devices.nodered_gui_switch(mqtt_client, topic=topic_gui_switch)
28
+        self.gui_main_light = devices.nodered_gui_light(mqtt_client, topic_gui)
29
         #
29
         #
30
         # Callback initialisation
30
         # Callback initialisation
31
         #
31
         #
32
-        self.gui_switch_main_light.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
33
-        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_switch_main_light.set_state_mcb)
32
+        self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
33
+        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
34
         #
34
         #
35
         self.block_all_off = False
35
         self.block_all_off = False
36
         self.last_flash_data = None
36
         self.last_flash_data = None
59
 
59
 
60
 
60
 
61
 class room_shelly_motion_sensor(room_shelly):
61
 class room_shelly_motion_sensor(room_shelly):
62
-    def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_motion_sensor_1, topic_motion_sensor_2=None, timer_value=config.DEFAULT_ON_TIME_LIGHT):
63
-        super().__init__(mqtt_client, topic_shelly, topic_gui_switch)
62
+    def __init__(self, mqtt_client, topic_shelly, topic_gui, topic_motion_sensor_1, topic_motion_sensor_2=None, timer_value=config.DEFAULT_ON_TIME_LIGHT):
63
+        super().__init__(mqtt_client, topic_shelly, topic_gui)
64
         self.timer_value = timer_value
64
         self.timer_value = timer_value
65
         #
65
         #
66
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.reload_timer, True)
66
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.reload_timer, True)
108
 
108
 
109
 
109
 
110
 class room_shelly_tradfri_light(room_shelly):
110
 class room_shelly_tradfri_light(room_shelly):
111
-    def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_br_ct):
112
-        super().__init__(mqtt_client, topic_shelly, topic_gui_switch)
111
+    def __init__(self, mqtt_client, topic_shelly, topic_gui, topic_tradfri_light):
112
+        super().__init__(mqtt_client, topic_shelly, topic_gui)
113
         self.main_light_tradfri = devices.tradfri_light(mqtt_client, topic_tradfri_light)
113
         self.main_light_tradfri = devices.tradfri_light(mqtt_client, topic_tradfri_light)
114
         #
114
         #
115
-        self.gui_br_ct_main_light = devices.nodered_gui_brightness_color_temp(mqtt_client, topic_gui_br_ct)
116
-        #
117
         # Callback initialisation
115
         # Callback initialisation
118
         #
116
         #
119
-        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_br_ct_main_light.set_enable_mcb)
120
-        self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_br_ct_main_light.set_brightness_mcb)
121
-        self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_br_ct_main_light.set_color_temp_mcb)
122
-        self.gui_br_ct_main_light.add_callback(devices.nodered_gui_brightness_color_temp.KEY_BRIGHTNESS,
123
-                                               None, self.main_light_tradfri.set_brightness_mcb)
124
-        self.gui_br_ct_main_light.add_callback(devices.nodered_gui_brightness_color_temp.KEY_COLOR_TEMP,
125
-                                               None, self.main_light_tradfri.set_color_temp_mcb)
117
+        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
118
+        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_enable_mcb)
119
+        self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_main_light.set_brightness_mcb)
120
+        self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_main_light.set_color_temp_mcb)
121
+        self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.main_light_tradfri.set_brightness_mcb)
122
+        self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.main_light_tradfri.set_color_temp_mcb)
126
 
123
 
127
 
124
 
128
 class room_shelly_silvercrest_light(room_shelly_tradfri_light):
125
 class room_shelly_silvercrest_light(room_shelly_tradfri_light):
129
-    def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_br_ct):
130
-        super().__init__(mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_br_ct)
126
+    def __init__(self, mqtt_client, topic_shelly, topic_gui, topic_tradfri_light):
127
+        super().__init__(mqtt_client, topic_shelly, topic_gui, topic_tradfri_light)
131
         #
128
         #
132
         # Callback initialisation
129
         # Callback initialisation
133
         #
130
         #

+ 1
- 1
function/stairway.py 查看文件

16
 class stairway(room_shelly_motion_sensor):
16
 class stairway(room_shelly_motion_sensor):
17
     def __init__(self, mqtt_client):
17
     def __init__(self, mqtt_client):
18
         # http://shelly1-3494546A9364
18
         # http://shelly1-3494546A9364
19
-        super().__init__(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_GUI_SWITCH,
19
+        super().__init__(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_GUI,
20
                          config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF,
20
                          config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF,
21
                          config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MIN_ON_TIME)
21
                          config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MIN_ON_TIME)

+ 9
- 1
house_n_gui_sim.py 查看文件

4
 import readline
4
 import readline
5
 import report
5
 import report
6
 from __simulation__.rooms import house
6
 from __simulation__.rooms import house
7
+from __simulation__.test import test_smarthome
7
 import time
8
 import time
8
 
9
 
9
 if __name__ == "__main__":
10
 if __name__ == "__main__":
12
     mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
13
     mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
13
                           password=config.MQTT_PASSWORD, name=config.APP_NAME + '_simulation')
14
                           password=config.MQTT_PASSWORD, name=config.APP_NAME + '_simulation')
14
     #
15
     #
15
-    COMMANDS = ['quit', 'help']
16
+    COMMANDS = ['quit', 'help', 'test.smoke', 'test.full']
16
     #
17
     #
17
     h = house(mc)
18
     h = house(mc)
18
     for name in h.getmembers():
19
     for name in h.getmembers():
20
         for c in d.capabilities():
21
         for c in d.capabilities():
21
             COMMANDS.append(name + '.' + c)
22
             COMMANDS.append(name + '.' + c)
22
     #
23
     #
24
+    ts = test_smarthome(h)
23
 
25
 
24
     def reduced_list(text):
26
     def reduced_list(text):
25
         """
27
         """
56
 
58
 
57
     readline.parse_and_bind("tab: complete")
59
     readline.parse_and_bind("tab: complete")
58
     readline.set_completer(completer)
60
     readline.set_completer(completer)
61
+    time.sleep(0.3)
59
     print("\nEnter command: ")
62
     print("\nEnter command: ")
63
+
60
     while True:
64
     while True:
61
         userfeedback = input('')
65
         userfeedback = input('')
62
         command = userfeedback.split(' ')[0]
66
         command = userfeedback.split(' ')[0]
64
             break
68
             break
65
         elif userfeedback == 'help':
69
         elif userfeedback == 'help':
66
             print("Help is not yet implemented!")
70
             print("Help is not yet implemented!")
71
+        elif userfeedback == 'test.full':
72
+            ts.full()
73
+        elif userfeedback == 'test.smoke':
74
+            ts.smoke()
67
         elif command in COMMANDS[2:]:
75
         elif command in COMMANDS[2:]:
68
             h.command(userfeedback)
76
             h.command(userfeedback)
69
         elif userfeedback != "":
77
         elif userfeedback != "":

Loading…
取消
儲存