Ver código fonte

room_shelly_motion_sensor: logging and reliability improvements

tags/v1.0.0
Dirk Alders 2 anos atrás
pai
commit
bc1c30cd3f
1 arquivos alterados com 9 adições e 3 exclusões
  1. 9
    3
      function/rooms.py

+ 9
- 3
function/rooms.py Ver arquivo

62
         self.timer_value = timer_value
62
         self.timer_value = timer_value
63
         #
63
         #
64
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.reload_timer, True)
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
         self.motion_sensor_silvercrest_1 = devices.silvercrest_motion_sensor(mqtt_client, topic_motion_sensor_1)
67
         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
         self.motion_sensor_silvercrest_1.add_callback(devices.silvercrest_motion_sensor.KEY_OCCUPANCY, None, self.set_motion_detected)
70
             self.motion_sensor_silvercrest_2 = devices.silvercrest_motion_sensor(mqtt_client, topic_motion_sensor_2)
71
             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
             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
         cyclic_task = task.periodic(1, self.cyclic_task)
76
         cyclic_task = task.periodic(1, self.cyclic_task)
78
         cyclic_task.run()
77
         cyclic_task.run()
83
         elif device == self.motion_sensor_silvercrest_2:
82
         elif device == self.motion_sensor_silvercrest_2:
84
             self.motion_detected_2 = data
83
             self.motion_detected_2 = data
85
         if data is True:
84
         if data is True:
85
+            logger.info("%s: Motion detected - Switching on main light %s", device.topic, self.main_light_shelly.topic)
86
             self.main_light_shelly.set_output_0(True)
86
             self.main_light_shelly.set_output_0(True)
87
 
87
 
88
     def reload_timer(self, device, key, data):
88
     def reload_timer(self, device, key, data):
89
         self.main_light_timer = self.timer_value
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
     def cyclic_task(self, cyclic_task):
96
     def cyclic_task(self, cyclic_task):
92
         if self.main_light_timer is not None:
97
         if self.main_light_timer is not None:
93
             if self.main_light_timer <= 0:
98
             if self.main_light_timer <= 0:
94
                 if not self.motion_detected_1 and not self.motion_detected_2:
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
                     self.main_light_shelly.set_output_0(False)
101
                     self.main_light_shelly.set_output_0(False)
96
                     self.main_light_timer = None
102
                     self.main_light_timer = None
97
             else:
103
             else:

Carregando…
Cancelar
Salvar