From be0fc353f6bdfa5e2372322c714d3fec57628902 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Sun, 22 Dec 2024 02:03:35 +0100 Subject: [PATCH] Simplify relay handler --- ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml | 2 +- ...-Ultimate-Easy-ESPHome_core_hw_relays.yaml | 62 ++++++++++--------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml b/ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml index 12ecd7d..5911a02 100644 --- a/ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml +++ b/ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml @@ -74,7 +74,7 @@ improv_serial: id: serial_improv logger: - level: INFO + level: DEBUG ota: platform: esphome diff --git a/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_relays.yaml b/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_relays.yaml index e639876..dc59f0a 100644 --- a/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_relays.yaml +++ b/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_relays.yaml @@ -113,34 +113,40 @@ script: - id: !extend button_click_event then: - lambda: |- - if (click_count == 1) { // Single click - if (!bs_multi_touch->state and - !bs_swipe_left->state and - !bs_swipe_down->state and - !bs_swipe_right->state) { // Ignore if other events are active - switch (button_id) { - case 1: - if (sl_button_1_action->active_index().has_value() and - sl_button_1_action->active_index().value() == 1) - sw_relay_1->toggle(); - break; - case 2: - if (sl_button_2_action->active_index().has_value() and - sl_button_2_action->active_index().value() == 1) - sw_relay_2->toggle(); - break; - case 3: - if (sl_button_3_action->active_index().has_value() and - sl_button_3_action->active_index().value() == 1) - sw_relay_3->toggle(); - break; - case 4: - if (sl_button_4_action->active_index().has_value() and - sl_button_4_action->active_index().value() == 1) - sw_relay_4->toggle(); - break; - } - } + // Handle only single clicks + if (click_count != 1) + return; + + // Ignore if other touch events are active + if (bs_multi_touch->state || + bs_swipe_left->state || + bs_swipe_down->state || + bs_swipe_right->state) { + return; + } + + // Toggle relay if corresponding button action is enabled + switch (button_id) { + case 1: + if (sl_button_1_action->active_index().has_value() and + sl_button_1_action->active_index().value() == 1) + sw_relay_1->toggle(); + break; + case 2: + if (sl_button_2_action->active_index().has_value() and + sl_button_2_action->active_index().value() == 1) + sw_relay_2->toggle(); + break; + case 3: + if (sl_button_3_action->active_index().has_value() and + sl_button_3_action->active_index().value() == 1) + sw_relay_3->toggle(); + break; + case 4: + if (sl_button_4_action->active_index().has_value() and + sl_button_4_action->active_index().value() == 1) + sw_relay_4->toggle(); + break; } - id: show_relay_status