From 0e142815165ff4caf39a9794107db0a2b8e99240 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 9 May 2026 13:35:32 +0200 Subject: [PATCH] Refactor auto switch handling in SmartSwitch to use dedicated methods for state changes --- apps/smartswitch.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/smartswitch.py b/apps/smartswitch.py index 2d49578..eb6425f 100644 --- a/apps/smartswitch.py +++ b/apps/smartswitch.py @@ -155,8 +155,12 @@ class SmartSwitch(SmartObject): # Timer callback: applies the deferred state set by auto_switch_*_after. def on_auto_switch_after(self, kwargs): self.auto_switch_cb_handle = None - self.log(f"Switching {self.entity_id} {kwargs['new_state']} after {kwargs['autoswitch_delay']}s") - self.set_state(self.entity_id,state = kwargs['new_state']) + new_state = kwargs['new_state'] + self.log(f"Switching {self.entity_id} {new_state} after {kwargs['autoswitch_delay']}s") + if new_state == 'on': + self.switch_on() + else: + self.switch_off() # ------------------------------------------------------------------ # Public switch API