Sfoglia il codice sorgente

room_shelly_motion_sensor: logging and reliability improvements

tags/v1.0.0
Dirk Alders 2 anni fa
parent
commit
bc1c30cd3f
1 ha cambiato i file con 9 aggiunte e 3 eliminazioni
  1. 9
    3
      function/rooms.py

+ 9
- 3
function/rooms.py Vedi File

@@ -62,6 +62,7 @@ class room_shelly_motion_sensor(room_shelly):
62 62
         self.timer_value = timer_value
63 63
         #
64 64
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.reload_timer, True)
65
+        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, False, self.reset_timer, True)
65 66
         #
66 67
         self.motion_sensor_silvercrest_1 = devices.silvercrest_motion_sensor(mqtt_client, topic_motion_sensor_1)
67 68
         self.motion_sensor_silvercrest_1.add_callback(devices.silvercrest_motion_sensor.KEY_OCCUPANCY, None, self.set_motion_detected)
@@ -70,9 +71,7 @@ class room_shelly_motion_sensor(room_shelly):
70 71
             self.motion_sensor_silvercrest_2 = devices.silvercrest_motion_sensor(mqtt_client, topic_motion_sensor_2)
71 72
             self.motion_sensor_silvercrest_2.add_callback(devices.silvercrest_motion_sensor.KEY_OCCUPANCY, None, self.set_motion_detected)
72 73
         #
73
-        self.motion_detected_1 = False
74
-        self.motion_detected_2 = False
75
-        self.main_light_timer = None
74
+        self.reset_timer()
76 75
         #
77 76
         cyclic_task = task.periodic(1, self.cyclic_task)
78 77
         cyclic_task.run()
@@ -83,15 +82,22 @@ class room_shelly_motion_sensor(room_shelly):
83 82
         elif device == self.motion_sensor_silvercrest_2:
84 83
             self.motion_detected_2 = data
85 84
         if data is True:
85
+            logger.info("%s: Motion detected - Switching on main light %s", device.topic, self.main_light_shelly.topic)
86 86
             self.main_light_shelly.set_output_0(True)
87 87
 
88 88
     def reload_timer(self, device, key, data):
89 89
         self.main_light_timer = self.timer_value
90 90
 
91
+    def reset_timer(self, device=None, key=None, data=None):
92
+        self.main_light_timer = None
93
+        self.motion_detected_1 = False
94
+        self.motion_detected_2 = False
95
+
91 96
     def cyclic_task(self, cyclic_task):
92 97
         if self.main_light_timer is not None:
93 98
             if self.main_light_timer <= 0:
94 99
                 if not self.motion_detected_1 and not self.motion_detected_2:
100
+                    logger.info("No motion and time ran out - Switching off main light %s", self.main_light_shelly.topic)
95 101
                     self.main_light_shelly.set_output_0(False)
96 102
                     self.main_light_timer = None
97 103
             else:

Loading…
Annulla
Salva