Просмотр исходного кода

room auto off implemented and used for ffe/floor

tags/v1.0.0
Dirk Alders 2 лет назад
Родитель
Сommit
4e4a6a2a01
3 измененных файлов: 56 добавлений и 3 удалений
  1. 30
    1
      devices/__init__.py
  2. 4
    2
      function/first_floor_east.py
  3. 22
    0
      function/rooms.py

+ 30
- 1
devices/__init__.py Просмотреть файл

@@ -179,7 +179,7 @@ class base(dict):
179 179
             if self.warning_callback is not None:
180 180
                 self.warning_callback(self, warn_txt)
181 181
 
182
-    def warning_text(self, data):
182
+    def warning_text(self):
183 183
         return "default warning text - replace parent warning_text function"
184 184
 
185 185
     def previous_value(self, key):
@@ -336,6 +336,35 @@ class silvercrest_powerplug(base):
336 336
         self.set_output_0('toggle')
337 337
 
338 338
 
339
+class silvercrest_motion_sensor(base):
340
+    KEY_BATTERY = "battery"
341
+    KEY_BATTERY_LOW = "battery_low"
342
+    KEY_LINKQUALITY = "linkquality"
343
+    KEY_OCCUPANCY = "occupancy"
344
+    KEY_UNMOUNTED = "tamper"
345
+    KEY_VOLTAGE = "voltage"
346
+    #
347
+    RX_KEYS = [KEY_BATTERY, KEY_BATTERY_LOW, KEY_LINKQUALITY, KEY_OCCUPANCY, KEY_UNMOUNTED, KEY_VOLTAGE]
348
+
349
+    def __init__(self, mqtt_client, topic):
350
+        super().__init__(mqtt_client, topic)
351
+
352
+    def warning_call_condition(self):
353
+        return self.get(self.KEY_BATTERY_LOW)
354
+
355
+    def warning_text(self, data):
356
+        return "Battery low: level=%d" % self.get(self.KEY_BATTERY)
357
+
358
+    #
359
+    # RX
360
+    #
361
+
362
+    @property
363
+    def linkquality(self):
364
+        """rv: numeric value"""
365
+        return self.get(self.KEY_LINKQUALITY)
366
+
367
+
339 368
 class my_powerplug(base):
340 369
     KEY_OUTPUT_0 = "output/1"
341 370
     KEY_OUTPUT_1 = "output/2"

+ 4
- 2
function/first_floor_east.py Просмотреть файл

@@ -6,7 +6,7 @@ import config
6 6
 import devices
7 7
 import json
8 8
 import logging
9
-from function.rooms import room_shelly, room_shelly_tradfri_light
9
+from function.rooms import room_shelly, room_shelly_auto_off, room_shelly_tradfri_light
10 10
 from function.helpers import changed_value_indicator
11 11
 try:
12 12
     from config import APP_NAME as ROOT_LOGGER_NAME
@@ -15,10 +15,12 @@ except ImportError:
15 15
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
16 16
 
17 17
 
18
-class first_floor_east_floor(room_shelly):
18
+class first_floor_east_floor(room_shelly_auto_off):
19 19
     def __init__(self, mqtt_client):
20 20
         # http://shelly1l-3C6105E4E629
21 21
         super().__init__(mqtt_client, "shellies/ffe/floor/main_light", "gui/ffe/floor/main_light/switch")
22
+        self.motion_sensor_silvercrest = devices.silvercrest_motion_sensor(mqtt_client, "zigbee/ffe/floor/motion_sensor")
23
+        self.motion_sensor_silvercrest.add_callback(devices.silvercrest_motion_sensor.KEY_OCCUPANCY, True, self.main_light_shelly.set_output_0_mcb)
22 24
 
23 25
 
24 26
 class first_floor_east_kitchen(room_shelly):

+ 22
- 0
function/rooms.py Просмотреть файл

@@ -56,6 +56,28 @@ class room_shelly(room):
56 56
         self.last_flash_data = data
57 57
 
58 58
 
59
+class room_shelly_auto_off(room_shelly):
60
+    def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, timer_value=30):
61
+        super().__init__(mqtt_client, topic_shelly, topic_gui_switch)
62
+        self.timer_value = timer_value
63
+        self.main_light_timer = None
64
+        #
65
+        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.reload_timer, True)
66
+        #
67
+        cyclic_task = task.periodic(1, self.cyclic_task)
68
+        cyclic_task.run()
69
+
70
+    def reload_timer(self, device, key, data):
71
+        self.main_light_timer = self.timer_value
72
+
73
+    def cyclic_task(self, cyclic_task):
74
+        if self.main_light_timer is not None:
75
+            self.main_light_timer -= cyclic_task.cycle_time
76
+            if self.main_light_timer <= 0:
77
+                self.main_light_shelly.set_output_0(False)
78
+                self.main_light_timer = None
79
+
80
+
59 81
 class room_shelly_tradfri_light(room_shelly):
60 82
     def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_tradfri_light, topic_gui_br_ct):
61 83
         super().__init__(mqtt_client, topic_shelly, topic_gui_switch)

Загрузка…
Отмена
Сохранить