Browse Source

bed_light fading implemented

tags/v1.0.0
Dirk Alders 2 years ago
parent
commit
34e7cab818
3 changed files with 43 additions and 19 deletions
  1. 12
    2
      devices/__init__.py
  2. 23
    17
      function/__init__.py
  3. 8
    0
      function/first_floor_east.py

+ 12
- 2
devices/__init__.py View File

@@ -3,7 +3,7 @@
3 3
 #
4 4
 """
5 5
 devices (DEVICES)
6
-===========
6
+=================
7 7
 
8 8
 **Author:**
9 9
 
@@ -369,10 +369,11 @@ class tradfri_light(base):
369 369
     KEY_OUTPUT_0 = "state"
370 370
     KEY_BRIGHTNESS = "brightness"
371 371
     KEY_COLOR_TEMP = "color_temp"
372
+    KEY_BRIGHTNESS_FADE = "brightness_move"
372 373
     #
373 374
     TX_TOPIC = 'set'
374 375
     TX_TYPE = base.TX_DICT
375
-    TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
376
+    TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP, KEY_BRIGHTNESS_FADE]
376 377
     #
377 378
     RX_KEYS = [KEY_LINKQUALITY, KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
378 379
     RX_IGNORE_TOPICS = [TX_TOPIC]
@@ -432,6 +433,15 @@ class tradfri_light(base):
432 433
         """brightness: [0, ..., 100]"""
433 434
         self.pack(self.KEY_BRIGHTNESS, brightness)
434 435
 
436
+    def brightness_inc(self, speed=40):
437
+        self.pack(self.KEY_BRIGHTNESS_FADE, speed)
438
+
439
+    def brightness_dec(self, speed=-40):
440
+        self.brightness_inc(speed)
441
+
442
+    def brightness_stop(self):
443
+        self.brightness_inc(0)
444
+
435 445
     def set_color_temp(self, color_temp):
436 446
         """color_temp: [0, ..., 100]"""
437 447
         self.pack(self.KEY_COLOR_TEMP, color_temp)

+ 23
- 17
function/__init__.py View File

@@ -18,31 +18,35 @@ import inspect
18 18
 
19 19
 class all_functions(object):
20 20
     def __init__(self, mqtt_client):
21
-        self.rooms = {}
22
-        self.__devices__ = None
21
+        self.mqtt_client = mqtt_client
23 22
         #
24
-        # ground floor west
23
+        self.__devices__ = None
25 24
         #
26
-        self.gfw_floor = ground_floor_west_floor(mqtt_client)
27
-        self.gfw_marion = ground_floor_west_marion(mqtt_client)
28
-        self.gfw_dirk = ground_floor_west_dirk(mqtt_client)
25
+        # add rooms
29 26
         #
27
+        # # ground floor west
28
+        self.gfw_floor = ground_floor_west_floor(self.mqtt_client)
29
+        self.gfw_marion = ground_floor_west_marion(self.mqtt_client)
30
+        self.gfw_dirk = ground_floor_west_dirk(self.mqtt_client)
30 31
         # first floor west
31
-        #
32
-        self.ffw_julian = first_floor_west_julian(mqtt_client)
33
-        self.ffw_living = first_floor_west_living(mqtt_client)
34
-        #
32
+        self.ffw_julian = first_floor_west_julian(self.mqtt_client)
33
+        self.ffw_living = first_floor_west_living(self.mqtt_client)
35 34
         # first floor east
35
+        self.ffe_floor = first_floor_east_floor(self.mqtt_client)
36
+        self.ffe_kitchen = first_floor_east_kitchen(self.mqtt_client)
37
+        self.ffe_dining = first_floor_east_dining(self.mqtt_client)
38
+        self.ffe_sleep_madi = first_floor_east_sleep_madi(self.mqtt_client)
39
+        self.ffe_living = first_floor_east_living(self.mqtt_client)
40
+        #
41
+        # additional functionality
36 42
         #
37
-        self.ffe_floor = first_floor_east_floor(mqtt_client)
38
-        self.ffe_kitchen = first_floor_east_kitchen(mqtt_client)
39
-        self.ffe_dining = first_floor_east_dining(mqtt_client)
40
-        self.ffe_sleep_madi = first_floor_east_sleep_madi(mqtt_client)
41
-        self.ffe_living = first_floor_east_living(mqtt_client)
43
+        self.init_input_device_sleep_madi_functionality()
44
+
45
+    def init_input_device_sleep_madi_functionality(self):
42 46
         #
43
-        # Input devices sleep_madi
47
+        self.ffe_button_tradfri_sleep = devices.tradfri_button(
48
+            self.mqtt_client, topic="zigbee_og_e/input_device/og_east")
44 49
         #
45
-        self.ffe_button_tradfri_sleep = devices.tradfri_button(mqtt_client, topic="zigbee_og_e/input_device/og_east")
46 50
         self.ffe_button_tradfri_sleep.add_callback(devices.tradfri_button.KEY_ACTION, "toggle",
47 51
                                                    self.ffe_sleep_madi.toggle_main_light)
48 52
         self.ffe_button_tradfri_sleep.add_callback(devices.tradfri_button.KEY_ACTION, "brightness_up_click",
@@ -51,6 +55,8 @@ class all_functions(object):
51 55
                                                    self.ffe_sleep_madi.toggle_bed_light_di)
52 56
         self.ffe_button_tradfri_sleep.add_callback(devices.tradfri_button.KEY_ACTION, "arrow_right_click",
53 57
                                                    self.ffe_floor.toggle_main_light)
58
+        self.ffe_button_tradfri_sleep.add_callback(devices.tradfri_button.KEY_ACTION, None,
59
+                                                   self.ffe_sleep_madi.fade_bed_light)
54 60
 
55 61
     def devicelist(self):
56 62
         if self.__devices__ is None:

+ 8
- 0
function/first_floor_east.py View File

@@ -92,6 +92,14 @@ class first_floor_east_sleep_madi(room_shelly_tradfri_light):
92 92
         logger.info("Toggeling \"%s\" main light", type(self).__name__)
93 93
         self.main_light_shelly.set_output_0("toggle")
94 94
 
95
+    def fade_bed_light(self, device, topic, data):
96
+        if (data == 'brightness_up_hold'):
97
+            self.bed_light_di_tradfri.brightness_inc()
98
+        elif (data == 'brightness_down_hold'):
99
+            self.bed_light_di_tradfri.brightness_dec()
100
+        elif (data.startswith('brightness') and data.endswith('release')):
101
+            self.bed_light_di_tradfri.brightness_stop()
102
+
95 103
     def gui_switch_command_bed_light_di(self, device, key, data):
96 104
         logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data))
97 105
         self.bed_light_di_tradfri.set_output_0(data)

Loading…
Cancel
Save