瀏覽代碼

room_shelly_motion_sensor adapted to fit to silvercrest functionality

tags/v1.0.0
Dirk Alders 2 年之前
父節點
當前提交
6a7f17feff
共有 2 個檔案被更改,包括 29 行新增11 行删除
  1. 3
    5
      function/first_floor_east.py
  2. 26
    6
      function/rooms.py

+ 3
- 5
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_auto_off, room_shelly_tradfri_light
9
+from function.rooms import room_shelly, room_shelly_motion_sensor, 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,12 +15,10 @@ except ImportError:
15 15
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
16 16
 
17 17
 
18
-class first_floor_east_floor(room_shelly_auto_off):
18
+class first_floor_east_floor(room_shelly_motion_sensor):
19 19
     def __init__(self, mqtt_client):
20 20
         # http://shelly1l-3C6105E4E629
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)
21
+        super().__init__(mqtt_client, "shellies/ffe/floor/main_light", "gui/ffe/floor/main_light/switch", "zigbee/ffe/floor/motion_sensor")
24 22
 
25 23
 
26 24
 class first_floor_east_kitchen(room_shelly):

+ 26
- 6
function/rooms.py 查看文件

@@ -56,26 +56,46 @@ 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):
59
+class room_shelly_motion_sensor(room_shelly):
60
+    def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_motion_sensor_1, topic_motion_sensor_2=None, timer_value=30):
61 61
         super().__init__(mqtt_client, topic_shelly, topic_gui_switch)
62 62
         self.timer_value = timer_value
63
-        self.main_light_timer = None
64 63
         #
65 64
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.reload_timer, True)
66 65
         #
66
+        self.motion_sensor_silvercrest_1 = devices.silvercrest_motion_sensor(mqtt_client, topic_motion_sensor_1)
67
+        self.motion_sensor_silvercrest_1.add_callback(devices.silvercrest_motion_sensor.KEY_OCCUPANCY, None, self.set_motion_detected)
68
+        #
69
+        if topic_motion_sensor_2 is not None:
70
+            self.motion_sensor_silvercrest_2 = devices.silvercrest_motion_sensor(mqtt_client, topic_motion_sensor_2)
71
+            self.motion_sensor_silvercrest_2.add_callback(devices.silvercrest_motion_sensor.KEY_OCCUPANCY, None, self.set_motion_detected)
72
+        #
73
+        self.motion_detected_1 = False
74
+        self.motion_detected_2 = False
75
+        self.main_light_timer = None
76
+        #
67 77
         cyclic_task = task.periodic(1, self.cyclic_task)
68 78
         cyclic_task.run()
69 79
 
80
+    def set_motion_detected(self, device, key, data):
81
+        if device == self.motion_sensor_silvercrest_1:
82
+            self.motion_detected_1 = data
83
+        elif device == self.motion_sensor_silvercrest_2:
84
+            self.motion_detected_2 = data
85
+        if data is True:
86
+            self.main_light_shelly.set_output_0(True)
87
+
70 88
     def reload_timer(self, device, key, data):
71 89
         self.main_light_timer = self.timer_value
72 90
 
73 91
     def cyclic_task(self, cyclic_task):
74 92
         if self.main_light_timer is not None:
75
-            self.main_light_timer -= cyclic_task.cycle_time
76 93
             if self.main_light_timer <= 0:
77
-                self.main_light_shelly.set_output_0(False)
78
-                self.main_light_timer = None
94
+                if not self.motion_detected_1 and not self.motion_detected_2:
95
+                    self.main_light_shelly.set_output_0(False)
96
+                    self.main_light_timer = None
97
+            else:
98
+                self.main_light_timer -= cyclic_task.cycle_time
79 99
 
80 100
 
81 101
 class room_shelly_tradfri_light(room_shelly):

Loading…
取消
儲存