fix retain_contiion behavior which use to start the retain timer when the condition is true instead of when its false

This commit is contained in:
Pierre committed 2026-09-26 16:43:08 +02:00
1 parent 3e7ae7550b
commit a387a13fa2
2 files changed
+109 -5

No files matched your search

+12 -5
View File
@@ -480,13 +480,20 @@ class RetainCondition(VirtualSensorBase):
def on_condition_succeed(self):
if self.output_sensor.get_state() != 'on':
self.output_sensor.set_state(state = 'on')
if self.reset_retain_time_on_new_success:
self.cancel_callback()
self.register_callback()
if self.reset_retain_time_on_new_success:
# A returning signal cancels the pending off transition.
self.cancel_callback()
else:
# Preserve the fixed window when resetting is explicitly disabled.
self.register_callback()
def on_condition_fail(self):
# we don't want to set the sensor to off during the timer
if self.cb_handle == None:
if self.reset_retain_time_on_new_success:
# Retain for the full delay after the condition becomes false,
# even when it has been true for longer than retain_time.
if self.output_sensor.get_state() == 'on':
self.register_callback()
elif self.cb_handle == None:
if self.output_sensor.get_state() != 'off':
self.output_sensor.set_state(state = 'off')