Sfoglia il codice sorgente

led indicator added for active fade object sleep madi

tags/v1.0.0
Dirk Alders 2 anni fa
parent
commit
4761f0a29e
2 ha cambiato i file con 57 aggiunte e 33 eliminazioni
  1. 36
    32
      function/first_floor_east.py
  2. 21
    1
      function/rooms.py

+ 36
- 32
function/first_floor_east.py Vedi File

4
 
4
 
5
 import config
5
 import config
6
 import devices
6
 import devices
7
+import json
7
 import logging
8
 import logging
8
 from function.rooms import room_shelly, room_shelly_tradfri_light
9
 from function.rooms import room_shelly, room_shelly_tradfri_light
9
 
10
 
19
         # http://shelly1l-3C6105E4E629
20
         # http://shelly1l-3C6105E4E629
20
         super().__init__(mqtt_client, "shellies/floor_madi", "gui/ffe_sw_floor")
21
         super().__init__(mqtt_client, "shellies/floor_madi", "gui/ffe_sw_floor")
21
 
22
 
22
-    def toggle_main_light(self, device, key, data):
23
-        logger.info("Toggeling \"%s\" main light", type(self).__name__)
24
-        self.main_light_shelly.set_output_0("toggle")
25
-
26
 
23
 
27
 class first_floor_east_kitchen(room_shelly):
24
 class first_floor_east_kitchen(room_shelly):
28
     # TODO: add circulation pump (switch, time)
25
     # TODO: add circulation pump (switch, time)
79
         #
76
         #
80
         # Callback initialisation
77
         # Callback initialisation
81
         #
78
         #
79
+        self.init_bed_light_functions()
80
+        self.init_fade_function()
81
+
82
+    # bed light
83
+    def init_bed_light_functions(self):
82
         self.gui_switch_bed_light_di.add_callback(
84
         self.gui_switch_bed_light_di.add_callback(
83
             devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_bed_light_di)
85
             devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_bed_light_di)
84
         self.bed_light_di_tradfri.add_callback(
86
         self.bed_light_di_tradfri.add_callback(
87
             devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_bed_light_di)
89
             devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_bed_light_di)
88
         self.gui_brightness_bed_light_di.add_callback(
90
         self.gui_brightness_bed_light_di.add_callback(
89
             devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_bed_light_di)
91
             devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_bed_light_di)
90
-        #
92
+
93
+    def gui_switch_command_bed_light_di(self, device, key, data):
94
+        logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data))
95
+        self.bed_light_di_tradfri.set_output_0(data)
96
+
97
+    def gui_switch_feedback_bed_light_di(self, device, key, data):
98
+        self.gui_switch_bed_light_di.set_feedback(data)
99
+        self.gui_brightness_bed_light_di.enable(data)
100
+        if data is False:
101
+            self.gui_brightness_bed_light_di.set_feedback(0)
102
+        else:
103
+            self.gui_brightness_bed_light_di.set_feedback(self.bed_light_di_tradfri.brightness)
104
+
105
+    def set_gui_brightness_bed_light_di(self, device, key, data):
106
+        self.gui_brightness_bed_light_di.set_feedback(data)
107
+
108
+    def set_brightness_bed_light_di(self, device, key, data):
109
+        logger.info("Setting brightness \"%s\" bed light dirk: %.1f", type(self).__name__, data)
110
+        self.bed_light_di_tradfri.set_brightness(data)
111
+
112
+    def toggle_bed_light_di(self, device, key, data):
113
+        logger.info("Toggeling \"%s\" bed light dirk", type(self).__name__)
114
+        self.bed_light_di_tradfri.set_output_0("toggle")
115
+
116
+    # fade
117
+    def init_fade_function(self):
91
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.state_machine_last_activated_device)
118
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.state_machine_last_activated_device)
92
         self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0,
119
         self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0,
93
                                                None, self.state_machine_last_activated_device)
120
                                                None, self.state_machine_last_activated_device)
94
         #
121
         #
95
         self.last_activated_device = None
122
         self.last_activated_device = None
96
 
123
 
97
-    def toggle_main_light(self, device, key, data):
98
-        logger.info("Toggeling \"%s\" main light", type(self).__name__)
99
-        self.main_light_shelly.set_output_0("toggle")
100
-
101
     def state_machine_last_activated_device(self, device, topic, data):
124
     def state_machine_last_activated_device(self, device, topic, data):
102
         if data is True:
125
         if data is True:
103
             self.last_activated_device = device.topic
126
             self.last_activated_device = device.topic
108
                 self.last_activated_device = self.main_light_shelly.topic
131
                 self.last_activated_device = self.main_light_shelly.topic
109
             else:
132
             else:
110
                 self.last_activated_device = None
133
                 self.last_activated_device = None
134
+        self.mqtt_client.send("gui/ffe_led_main_light_sleep/set",
135
+                              json.dumps(self.last_activated_device == self.main_light_shelly.topic))
136
+        self.mqtt_client.send("gui/ffe_led_bed_light_sleep_di/set",
137
+                              json.dumps(self.last_activated_device == self.bed_light_di_tradfri.topic))
111
 
138
 
112
     def fade_light(self, device, topic, data):
139
     def fade_light(self, device, topic, data):
113
         if self.last_activated_device == self.main_light_shelly.topic:
140
         if self.last_activated_device == self.main_light_shelly.topic:
126
             logger.info("Stoping brightness change \"%s\" %s", type(self).__name__, target.topic)
153
             logger.info("Stoping brightness change \"%s\" %s", type(self).__name__, target.topic)
127
             target.brightness_stop()
154
             target.brightness_stop()
128
 
155
 
129
-    def gui_switch_command_bed_light_di(self, device, key, data):
130
-        logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data))
131
-        self.bed_light_di_tradfri.set_output_0(data)
132
-
133
-    def gui_switch_feedback_bed_light_di(self, device, key, data):
134
-        self.gui_switch_bed_light_di.set_feedback(data)
135
-        self.gui_brightness_bed_light_di.enable(data)
136
-        if data is False:
137
-            self.gui_brightness_bed_light_di.set_feedback(0)
138
-        else:
139
-            self.gui_brightness_bed_light_di.set_feedback(self.bed_light_di_tradfri.brightness)
140
-
141
-    def set_gui_brightness_bed_light_di(self, device, key, data):
142
-        self.gui_brightness_bed_light_di.set_feedback(data)
143
-
144
-    def set_brightness_bed_light_di(self, device, key, data):
145
-        logger.info("Setting brightness \"%s\" bed light dirk: %.1f", type(self).__name__, data)
146
-        self.bed_light_di_tradfri.set_brightness(data)
147
-
148
-    def toggle_bed_light_di(self, device, key, data):
149
-        logger.info("Toggeling \"%s\" bed light dirk", type(self).__name__)
150
-        self.bed_light_di_tradfri.set_output_0("toggle")
151
-
152
 
156
 
153
 class first_floor_east_living(room_shelly_tradfri_light):
157
 class first_floor_east_living(room_shelly_tradfri_light):
154
     def __init__(self, mqtt_client):
158
     def __init__(self, mqtt_client):

+ 21
- 1
function/rooms.py Vedi File

14
 
14
 
15
 
15
 
16
 class room(object):
16
 class room(object):
17
+    def __init__(self, mqtt_client):
18
+        self.mqtt_client = mqtt_client
19
+
17
     def gui_switch_feedback(self, device, key, data):
20
     def gui_switch_feedback(self, device, key, data):
18
         self.gui_switch_main_light.set_feedback(data)
21
         self.gui_switch_main_light.set_feedback(data)
19
 
22
 
20
 
23
 
21
 class room_shelly(room):
24
 class room_shelly(room):
22
     def __init__(self, mqtt_client, topic_shelly, topic_gui_switch):
25
     def __init__(self, mqtt_client, topic_shelly, topic_gui_switch):
26
+        super().__init__(mqtt_client)
23
         self.main_light_shelly = devices.shelly(mqtt_client, topic=topic_shelly)
27
         self.main_light_shelly = devices.shelly(mqtt_client, topic=topic_shelly)
24
         #
28
         #
25
         self.gui_switch_main_light = devices.nodered_gui(mqtt_client, topic=topic_gui_switch)
29
         self.gui_switch_main_light = devices.nodered_gui(mqtt_client, topic=topic_gui_switch)
29
         self.gui_switch_main_light.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command)
33
         self.gui_switch_main_light.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command)
30
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_switch_feedback)
34
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_switch_feedback)
31
 
35
 
32
-    def all_off(self):
36
+    def all_off(self, device=None, key=None, data=None):
37
+        logger.info("Switching all off \"%s\"", type(self).__name__)
33
         self.main_light_shelly.set_output_0(False)
38
         self.main_light_shelly.set_output_0(False)
34
         self.main_light_shelly.set_output_1(False)
39
         self.main_light_shelly.set_output_1(False)
35
 
40
 
37
         logger.info("Switching \"%s\" main light: %s", type(self).__name__, str(data))
42
         logger.info("Switching \"%s\" main light: %s", type(self).__name__, str(data))
38
         self.main_light_shelly.set_output_0(data)
43
         self.main_light_shelly.set_output_0(data)
39
 
44
 
45
+    def toggle_main_light(self, device, key, data):
46
+        logger.info("Toggeling \"%s\" main light", type(self).__name__)
47
+        self.main_light_shelly.set_output_0("toggle")
48
+
40
 
49
 
41
 class room_shelly_tradfri_light(room_shelly):
50
 class room_shelly_tradfri_light(room_shelly):
42
     def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp):
51
     def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp):
86
         logger.info("Setting color_temp \"%s\" main light: %.1f", type(self).__name__, data)
95
         logger.info("Setting color_temp \"%s\" main light: %.1f", type(self).__name__, data)
87
         self.main_light_tradfri.set_color_temp(data * 10)
96
         self.main_light_tradfri.set_color_temp(data * 10)
88
 
97
 
98
+    def fade_light(self, device, topic, data):
99
+        if (data == 'brightness_up_hold'):
100
+            logger.info("Increasing brightness \"%s\" main light", type(self).__name__)
101
+            self.main_light_tradfri.brightness_inc()
102
+        elif (data == 'brightness_down_hold'):
103
+            logger.info("Decreasing brightness \"%s\" main light", type(self).__name__)
104
+            self.main_light_tradfri.brightness_dec()
105
+        elif (data.startswith('brightness') and data.endswith('release')):
106
+            logger.info("Stoping brightness change \"%s\" main light", type(self).__name__)
107
+            self.main_light_tradfri.brightness_stop()
108
+
89
 
109
 
90
 class room_shelly_silvercrest_light(room_shelly_tradfri_light):
110
 class room_shelly_silvercrest_light(room_shelly_tradfri_light):
91
     def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp):
111
     def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp):

Loading…
Annulla
Salva