From d9e83a49a1266320df8e5f542b62865ca6de7186 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Wed, 29 Jan 2025 00:55:00 +0100 Subject: [PATCH] Improved long press behaviour when there is no long press callback --- automation_devices/src/hue_switch.rs | 13 ++++++++++++- automation_lib/src/action_callback.rs | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/automation_devices/src/hue_switch.rs b/automation_devices/src/hue_switch.rs index 8805fed..e4174ec 100644 --- a/automation_devices/src/hue_switch.rs +++ b/automation_devices/src/hue_switch.rs @@ -95,9 +95,20 @@ impl OnMqtt for HueSwitch { match action { Action::LeftPressRelease => self.config.left_callback.call(self, &()).await, - Action::LeftHold => self.config.left_hold_callback.call(self, &()).await, Action::RightPressRelease => self.config.right_callback.call(self, &()).await, + Action::LeftHold => self.config.left_hold_callback.call(self, &()).await, Action::RightHold => self.config.right_hold_callback.call(self, &()).await, + // If there is no hold action, the switch will act like a normal release + Action::RightHoldRelease => { + if !self.config.right_hold_callback.is_set() { + self.config.right_callback.call(self, &()).await + } + } + Action::LeftHoldRelease => { + if !self.config.left_hold_callback.is_set() { + self.config.left_callback.call(self, &()).await + } + } _ => {} } } diff --git a/automation_lib/src/action_callback.rs b/automation_lib/src/action_callback.rs index 0d6fa93..a7ac26d 100644 --- a/automation_lib/src/action_callback.rs +++ b/automation_lib/src/action_callback.rs @@ -64,4 +64,8 @@ where _ => todo!("Only functions are currently supported"), } } + + pub fn is_set(&self) -> bool { + self.internal.is_some() + } }