From d2b924b3559176091282b079daa4b643f22fd1e6 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Fri, 22 Mar 2024 11:21:50 +0100 Subject: [PATCH] Disable all services while upload A service call still possible, but the services won't do anything. Helps with #1946 --- esphome/nspanel_esphome_core.yaml | 166 ++++++++++++++++-------------- 1 file changed, 90 insertions(+), 76 deletions(-) diff --git a/esphome/nspanel_esphome_core.yaml b/esphome/nspanel_esphome_core.yaml index eccadab..e6b88fb 100644 --- a/esphome/nspanel_esphome_core.yaml +++ b/esphome/nspanel_esphome_core.yaml @@ -248,9 +248,11 @@ api: visible: bool # Set to true to show the component, or false to hide it. then: - lambda: |- - for (const std::string& component_id : ids) { - if (!id(is_uploading_tft) and !component_id.empty()) { - set_component_visibility->execute(component_id.c_str(), visible); + if (!id(is_uploading_tft)) { + for (const std::string& component_id : ids) { + if (!id(is_uploading_tft) and !component_id.empty()) { + set_component_visibility->execute(component_id.c_str(), visible); + } } } @@ -280,14 +282,16 @@ api: state: bool # State for the button(s) indication: true for active, false for inactive then: - lambda: |- - // Updates the visual state indication for hardware buttons - // Use bitwise AND to check specific bits - if (button_mask & 1) // Checks if the least significant bit is set (left button) - update_bitwise_setting(id(buttons_settings), state, ButtonSettings::ButtonLeft_State); - if (button_mask & 2) // Checks if the second least significant bit is set (right button) - update_bitwise_setting(id(buttons_settings), state, ButtonSettings::ButtonRight_State); - // Refreshes the indication bars on the display - refresh_hardware_buttons_bars->execute(button_mask); + if (!id(is_uploading)) { + // Updates the visual state indication for hardware buttons + // Use bitwise AND to check specific bits + if (button_mask & 1) // Checks if the least significant bit is set (left button) + update_bitwise_setting(id(buttons_settings), state, ButtonSettings::ButtonLeft_State); + if (button_mask & 2) // Checks if the second least significant bit is set (right button) + update_bitwise_setting(id(buttons_settings), state, ButtonSettings::ButtonRight_State); + // Refreshes the indication bars on the display + refresh_hardware_buttons_bars->execute(button_mask); + } # Icon Service - service: icon @@ -317,18 +321,22 @@ api: screensaver_time_color: int[] # RGB color for the screensaver time display, e.g., [165, 42, 42] for reddish-brown. decimal_separator: string # The char to be used as decimal separator. then: - - script.execute: - id: global_settings - blueprint_version: !lambda return blueprint_version; - ent_value_xcen: !lambda return ent_value_xcen; - mui_please_confirm: !lambda return mui_please_confirm; - mui_unavailable: !lambda return mui_unavailable; - screensaver_time: !lambda return screensaver_time; - screensaver_time_font: !lambda return screensaver_time_font; - screensaver_time_color: !lambda return screensaver_time_color; - decimal_separator: !lambda return decimal_separator; - - script.wait: global_settings - - lambda: blueprint_status->publish_state(int(blueprint_status->raw_state) | (1 << 5)); + - if: + condition: + - lambda: return (!id(is_uploading)); + then: + - script.execute: + id: global_settings + blueprint_version: !lambda return blueprint_version; + ent_value_xcen: !lambda return ent_value_xcen; + mui_please_confirm: !lambda return mui_please_confirm; + mui_unavailable: !lambda return mui_unavailable; + screensaver_time: !lambda return screensaver_time; + screensaver_time_font: !lambda return screensaver_time_font; + screensaver_time_color: !lambda return screensaver_time_color; + decimal_separator: !lambda return decimal_separator; + - script.wait: global_settings + - lambda: blueprint_status->publish_state(int(blueprint_status->raw_state) | (1 << 5)); # Configures NSPanel hardware (buttons, relays, etc.) settings - service: init_hardware @@ -350,58 +358,63 @@ api: embedded_climate_friendly_name: string # Friendly name for the climate control feature. embedded_indoor_temperature: bool # Enables indoor temperature display. then: - - script.execute: - id: init_hardware_climate - embedded_climate: !lambda return embedded_climate; - embedded_climate_friendly_name: !lambda return embedded_climate_friendly_name; - embedded_indoor_temperature: !lambda return embedded_indoor_temperature; + - if: + condition: + - lambda: return (!id(is_uploading)); + then: + - script.execute: + id: init_hardware_climate + embedded_climate: !lambda return embedded_climate; + embedded_climate_friendly_name: !lambda return embedded_climate_friendly_name; + embedded_indoor_temperature: !lambda return embedded_indoor_temperature; - - lambda: |- - if (!id(is_uploading_tft)) { - using namespace esphome::display; - // Relay settings - update_bitwise_setting(id(relay_settings), relay1_local_control, RelaySettings::Relay1_Local); - update_bitwise_setting(id(relay_settings), relay1_fallback, RelaySettings::Relay1_Fallback); - update_bitwise_setting(id(relay_settings), relay2_local_control, RelaySettings::Relay2_Local); - update_bitwise_setting(id(relay_settings), relay2_fallback, RelaySettings::Relay2_Fallback); + - lambda: |- + if (!id(is_uploading_tft)) { + using namespace esphome::display; + // Relay settings + update_bitwise_setting(id(relay_settings), relay1_local_control, RelaySettings::Relay1_Local); + update_bitwise_setting(id(relay_settings), relay1_fallback, RelaySettings::Relay1_Fallback); + update_bitwise_setting(id(relay_settings), relay2_local_control, RelaySettings::Relay2_Local); + update_bitwise_setting(id(relay_settings), relay2_fallback, RelaySettings::Relay2_Fallback); - // Relay icons - if (not relay1_icon.empty()) copyStringToCharArray(id(home_relay1_icon), relay1_icon); - if (not relay2_icon.empty()) copyStringToCharArray(id(home_relay2_icon), relay2_icon); + // Relay icons + if (not relay1_icon.empty()) copyStringToCharArray(id(home_relay1_icon), relay1_icon); + if (not relay2_icon.empty()) copyStringToCharArray(id(home_relay2_icon), relay2_icon); - // Relay icon's colors - if (relay1_icon_color.size() == 3) { - id(home_relay1_icon_color) = ColorUtil::color_to_565(esphome::Color(relay1_icon_color[0], - relay1_icon_color[1], - relay1_icon_color[2])); - disp1->set_component_font_color("home.chip_relay1", id(home_relay1_icon_color)); - } - if (relay2_icon_color.size() == 3) { - id(home_relay2_icon_color) = ColorUtil::color_to_565(esphome::Color(relay2_icon_color[0], - relay2_icon_color[1], - relay2_icon_color[2])); - disp1->set_component_font_color("home.chip_relay2", id(home_relay2_icon_color)); - } + // Relay icon's colors + if (relay1_icon_color.size() == 3) { + id(home_relay1_icon_color) = ColorUtil::color_to_565(esphome::Color(relay1_icon_color[0], + relay1_icon_color[1], + relay1_icon_color[2])); + disp1->set_component_font_color("home.chip_relay1", id(home_relay1_icon_color)); + } + if (relay2_icon_color.size() == 3) { + id(home_relay2_icon_color) = ColorUtil::color_to_565(esphome::Color(relay2_icon_color[0], + relay2_icon_color[1], + relay2_icon_color[2])); + disp1->set_component_font_color("home.chip_relay2", id(home_relay2_icon_color)); + } - // Buttons bars settings - id(buttons_bars_pages) = button_bar_pages; - update_bitwise_setting(id(buttons_settings), button_left, ButtonSettings::ButtonLeft_Enabled); - update_bitwise_setting(id(buttons_settings), button_right, ButtonSettings::ButtonRight_Enabled); + // Buttons bars settings + id(buttons_bars_pages) = button_bar_pages; + update_bitwise_setting(id(buttons_settings), button_left, ButtonSettings::ButtonLeft_Enabled); + update_bitwise_setting(id(buttons_settings), button_right, ButtonSettings::ButtonRight_Enabled); - if (button_bar_color_on.size() == 3) - id(buttons_color_on) = ColorUtil::color_to_565(esphome::Color(button_bar_color_on[0], - button_bar_color_on[1], - button_bar_color_on[2])); - if (button_bar_color_off.size() == 3) - id(buttons_color_off) = ColorUtil::color_to_565(esphome::Color(button_bar_color_off[0], - button_bar_color_off[1], - button_bar_color_off[2])); + if (button_bar_color_on.size() == 3) + id(buttons_color_on) = ColorUtil::color_to_565(esphome::Color(button_bar_color_on[0], + button_bar_color_on[1], + button_bar_color_on[2])); + if (button_bar_color_off.size() == 3) + id(buttons_color_off) = ColorUtil::color_to_565(esphome::Color(button_bar_color_off[0], + button_bar_color_off[1], + button_bar_color_off[2])); + + // Refresh relays display + refresh_relays->execute(3); + refresh_hardware_buttons_bars->execute(3); + } + blueprint_status->publish_state(int(blueprint_status->raw_state) | (1 << 4)); - // Refresh relays display - refresh_relays->execute(3); - refresh_hardware_buttons_bars->execute(3); - } - blueprint_status->publish_state(int(blueprint_status->raw_state) | (1 << 4)); # Sets up the "Home" page in ESPHome with customized settings and UI elements as defined in the project blueprint. - service: init_page_home variables: @@ -503,11 +516,13 @@ api: - service: notification_clear then: - lambda: |- - if (current_page->state == "notification") goto_page->execute("home"); - notification_label->publish_state(""); - notification_text->publish_state(""); - notification_unread->turn_off(); - set_component_visibility->execute("home.bt_notific", false); + if (!id(is_uploading)) { + if (current_page->state == "notification") goto_page->execute("home"); + notification_label->publish_state(""); + notification_text->publish_state(""); + notification_unread->turn_off(); + set_component_visibility->execute("home.bt_notific", false); + } # Displays a notification message on the screen, useful for alerts or informational updates. - service: notification_show @@ -772,8 +787,7 @@ api: variables: tone: string # The RTTTL string for the melody to be played. It should follow the RTTTL format, including the melody's name, default settings, and a sequence of notes. then: - - rtttl.play: - rtttl: !lambda return tone; + - lambda: if (!id(is_uploading_tft)) buzzer->play(tone); # Updates an entity to display specific values with dynamic icons, names, and color codes. - service: value