Parcourir la source

led indicator added for active fade object sleep madi

tags/v1.0.0
Dirk Alders il y a 2 ans
Parent
révision
4761f0a29e
2 fichiers modifiés avec 57 ajouts et 33 suppressions
  1. 36
    32
      function/first_floor_east.py
  2. 21
    1
      function/rooms.py

+ 36
- 32
function/first_floor_east.py Voir le fichier

@@ -4,6 +4,7 @@
4 4
 
5 5
 import config
6 6
 import devices
7
+import json
7 8
 import logging
8 9
 from function.rooms import room_shelly, room_shelly_tradfri_light
9 10
 
@@ -19,10 +20,6 @@ class first_floor_east_floor(room_shelly):
19 20
         # http://shelly1l-3C6105E4E629
20 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 24
 class first_floor_east_kitchen(room_shelly):
28 25
     # TODO: add circulation pump (switch, time)
@@ -79,6 +76,11 @@ class first_floor_east_sleep_madi(room_shelly_tradfri_light):
79 76
         #
80 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 84
         self.gui_switch_bed_light_di.add_callback(
83 85
             devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_bed_light_di)
84 86
         self.bed_light_di_tradfri.add_callback(
@@ -87,17 +89,38 @@ class first_floor_east_sleep_madi(room_shelly_tradfri_light):
87 89
             devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_bed_light_di)
88 90
         self.gui_brightness_bed_light_di.add_callback(
89 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 118
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.state_machine_last_activated_device)
92 119
         self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0,
93 120
                                                None, self.state_machine_last_activated_device)
94 121
         #
95 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 124
     def state_machine_last_activated_device(self, device, topic, data):
102 125
         if data is True:
103 126
             self.last_activated_device = device.topic
@@ -108,6 +131,10 @@ class first_floor_east_sleep_madi(room_shelly_tradfri_light):
108 131
                 self.last_activated_device = self.main_light_shelly.topic
109 132
             else:
110 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 139
     def fade_light(self, device, topic, data):
113 140
         if self.last_activated_device == self.main_light_shelly.topic:
@@ -126,29 +153,6 @@ class first_floor_east_sleep_madi(room_shelly_tradfri_light):
126 153
             logger.info("Stoping brightness change \"%s\" %s", type(self).__name__, target.topic)
127 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 157
 class first_floor_east_living(room_shelly_tradfri_light):
154 158
     def __init__(self, mqtt_client):

+ 21
- 1
function/rooms.py Voir le fichier

@@ -14,12 +14,16 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
14 14
 
15 15
 
16 16
 class room(object):
17
+    def __init__(self, mqtt_client):
18
+        self.mqtt_client = mqtt_client
19
+
17 20
     def gui_switch_feedback(self, device, key, data):
18 21
         self.gui_switch_main_light.set_feedback(data)
19 22
 
20 23
 
21 24
 class room_shelly(room):
22 25
     def __init__(self, mqtt_client, topic_shelly, topic_gui_switch):
26
+        super().__init__(mqtt_client)
23 27
         self.main_light_shelly = devices.shelly(mqtt_client, topic=topic_shelly)
24 28
         #
25 29
         self.gui_switch_main_light = devices.nodered_gui(mqtt_client, topic=topic_gui_switch)
@@ -29,7 +33,8 @@ class room_shelly(room):
29 33
         self.gui_switch_main_light.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command)
30 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 38
         self.main_light_shelly.set_output_0(False)
34 39
         self.main_light_shelly.set_output_1(False)
35 40
 
@@ -37,6 +42,10 @@ class room_shelly(room):
37 42
         logger.info("Switching \"%s\" main light: %s", type(self).__name__, str(data))
38 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 50
 class room_shelly_tradfri_light(room_shelly):
42 51
     def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp):
@@ -86,6 +95,17 @@ class room_shelly_tradfri_light(room_shelly):
86 95
         logger.info("Setting color_temp \"%s\" main light: %.1f", type(self).__name__, data)
87 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 110
 class room_shelly_silvercrest_light(room_shelly_tradfri_light):
91 111
     def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_brightness, topic_gui_color_temp):

Chargement…
Annuler
Enregistrer