Components visibility service to support list of components

To reduce number of calls
This commit is contained in:
Edward Firmo
2024-02-29 18:01:24 +01:00
parent 9c03569925
commit ca6c2db015
3 changed files with 155 additions and 130 deletions

View File

@@ -182,7 +182,7 @@ api:
label: string # Main text label for the button.
then:
- lambda: |-
if (page == current_page->state and not id(is_uploading_tft)) {
if (page == current_page->state and !id(is_uploading_tft)) {
disp1->send_command_printf("%spic.picc=%u", id.c_str(), state ? 47 : 46);
disp1->send_command_printf("%sbri.picc=%u", id.c_str(), state ? 47 : 46);
disp1->send_command_printf("%stext.picc=%u", id.c_str(), state ? 47 : 46);
@@ -207,7 +207,7 @@ api:
cmd: string # Command string to be sent. Refer to the Nextion Instruction Set for supported commands: https://nextion.tech/instruction-set/
then:
- lambda: |-
if (not id(is_uploading_tft))
if (!id(is_uploading_tft))
disp1->send_command_printf("%s", cmd.c_str());
# Changes the foreground color of a specified component on the display.
@@ -217,7 +217,7 @@ api:
color: int[] # New color for the component, specified as an RGB array (e.g., [255, 0, 0] for red).
then:
- lambda: |-
if (not id(is_uploading_tft))
if (!id(is_uploading_tft))
disp1->set_component_font_color(id.c_str(), esphome::display::ColorUtil::color_to_565(esphome::Color(color[0], color[1], color[2])));
# Updates the text of a specified component on the display.
@@ -227,7 +227,7 @@ api:
txt: string # New text content to be displayed. Supports both static and dynamic content.
then:
- lambda: |-
if (not id(is_uploading_tft))
if (!id(is_uploading_tft))
disp1->set_component_text_printf(id.c_str(), "%s", txt.c_str());
# Updates the value of a specified component on the display.
@@ -237,18 +237,21 @@ api:
val: int # New integer value to set for the component. Adjust based on the data type you're displaying.
then:
- lambda: |-
if (not id(is_uploading_tft))
if (!id(is_uploading_tft))
disp1->set_component_value(id.c_str(), val);
# Hides or shows a specified component on the display.
- service: component_visibility
- service: components_visibility
variables:
id: string # Identifier of the component to be hidden/shown. Ensure this matches the component's ID in your display layout.
ids: string[] # Identifier of the component to be hidden/shown. Ensure this matches the component's ID in your display layout.
visible: bool # Set to true to show the component, or false to hide it.
then:
- lambda: |-
if (not id(is_uploading_tft))
set_component_visibility->execute(id.c_str(), visible);
if (!id(is_uploading_tft)) {
for (const std::string& component_id : ids) {
set_component_visibility->execute(component_id.c_str(), visible);
}
}
# Displays detailed information for a specific entity.
- service: entity_details_show
@@ -257,7 +260,7 @@ api:
back_page: string # Specifies the page to return to. Accepts "home" or "buttonpage01" to "buttonpage04".
then:
- lambda: |-
if (not id(is_uploading_tft)) {
if (!id(is_uploading_tft)) {
nspanel_ha_blueprint::HomeAssistantEntity entity_id = nspanel_ha_blueprint::extractHomeAssistantEntity(entity);
if (entity_id.domain != "invalid" or entity == "embedded_climate") {
detailed_entity->publish_state(entity);
@@ -291,7 +294,7 @@ api:
visible: bool # Set to `true` for visible or `false` for hidden.
then:
- lambda: |-
if (not id(is_uploading_tft) and not id.empty()) {
if (!id(is_uploading_tft) and !id.empty()) {
if (not icon.empty()) disp1->set_component_text_printf(id.c_str(), "%s", icon.c_str());
if (icon_color.size() == 3)
disp1->set_component_font_color(id.c_str(), esphome::display::ColorUtil::color_to_565(esphome::Color(icon_color[0], icon_color[1], icon_color[2])));
@@ -349,7 +352,7 @@ api:
embedded_indoor_temperature: !lambda return embedded_indoor_temperature;
- lambda: |-
if (not id(is_uploading_tft)) {
if (!id(is_uploading_tft)) {
using namespace nspanel_ha_blueprint;
using namespace esphome::display;
@@ -417,7 +420,7 @@ api:
outdoor_temp_font: int # Font Id for outdoor temperature indication on the "Home" page.
then:
- lambda: |-
if (not id(is_uploading_tft)) {
if (!id(is_uploading_tft)) {
// Localization
id(mui_time_format) = time_format;
if (meridiem.size() == 2) {
@@ -487,7 +490,7 @@ api:
dim: string # Text label for the dim brightness level slider, signaling a lower light option for energy saving.
then:
- lambda: |-
if (not id(is_uploading_tft)) {
if (!id(is_uploading_tft)) {
if (not reboot.empty()) disp1->set_component_text_printf("settings.lbl_reboot", " %s", reboot.c_str());
disp1->set_component_text_printf("settings.lbl_brightness", " %s", brightness.c_str());
display_wrapped_text->execute("settings.lbl_bright", bright.c_str(), display_mode->state == 2 ? 25 : 10);
@@ -507,7 +510,7 @@ api:
message: string # Detailed message or content of the notification. Include `\r` to insert a line break, allowing for custom formatting.
then:
- lambda: |-
if (not id(is_uploading_tft)) {
if (!id(is_uploading_tft)) {
ESP_LOGV("service.notification_show", "Starting");
goto_page->execute("notification");
@@ -538,7 +541,7 @@ api:
then:
- lambda: |-
// Is page Alarm visible?
if (current_page->state == "alarm" and not id(is_uploading_tft)) // To do: This page constructor should be moved to Blueprint
if (current_page->state == "alarm" and !id(is_uploading_tft)) // To do: This page constructor should be moved to Blueprint
{ // Update alarm page
detailed_entity->publish_state(entity);
@@ -637,7 +640,7 @@ api:
then:
- if:
condition:
lambda: return not id(is_uploading_tft);
lambda: return !id(is_uploading_tft);
then:
- lambda: if (current_page->state == "climate") detailed_entity->publish_state(entity);
- script.execute:
@@ -671,7 +674,7 @@ api:
# https://github.com/home-assistant/core/blob/33ff6b5b6ee3d92f4bb8deb9594d67748ea23d7c/homeassistant/components/media_player/const.py#L23
then:
- lambda: |-
if (current_page->state == "media_player" and not id(is_uploading_tft)) {
if (current_page->state == "media_player" and !id(is_uploading_tft)) {
detailed_entity->publish_state(entity);
disp1->set_component_text_printf("page_label", "%s", friendly_name.c_str());
display_wrapped_text->execute("track", media_title.c_str(), display_mode->state == 2 ? 16 : 27);
@@ -809,7 +812,7 @@ api:
# Setting this to true keeps the display active during user presence, while false retains the current timer settings.
then:
- lambda: |-
if (not id(is_uploading_tft)) {
if (!id(is_uploading_tft)) {
if (current_page->state == "screensaver") goto_page->execute(wakeup_page_name->state.c_str());
if (reset_timer)
timer_reset_all->execute(wakeup_page_name->state.c_str());
@@ -830,7 +833,7 @@ display:
- script.execute: setup_sequence
on_page:
lambda: |-
if (not id(is_uploading_tft)) {
if (!id(is_uploading_tft)) {
page_id->update();
if (current_page->state != page_names[x] or x == 9) {
current_page->publish_state(page_names[x]);
@@ -840,7 +843,7 @@ display:
on_touch:
lambda: |-
if (not id(is_uploading_tft)) {
if (!id(is_uploading_tft)) {
timer_reset_all->execute(page_names[page_id]);
switch (page_id) {
case 10: // light
@@ -1495,7 +1498,7 @@ sensor:
on_value:
then:
- lambda: |-
if (not id(is_uploading_tft) and current_page->state != page_names[x]) {
if (!id(is_uploading_tft) and current_page->state != page_names[x]) {
current_page->publish_state(page_names[x]);
page_changed->execute(page_names[x]);
}
@@ -1798,7 +1801,7 @@ script:
value: string
then:
- lambda: |-
if (not id(is_uploading_tft)) {
if (!id(is_uploading_tft)) {
if (not embedded) {
if (key == "temperature" or key == "target_temp_high" or key == "target_temp_low")
ha_call_service->execute("climate.set_temperature", key.c_str(), to_string(stof(value) / 10), detailed_entity->state.c_str());
@@ -1816,7 +1819,7 @@ script:
return (compare_versions("${version}", version_tft->state.c_str()) and compare_versions("${version}", id(version_blueprint)));
timeout: 60s
- lambda: |-
if (not id(is_uploading_tft)) {
if (!id(is_uploading_tft)) {
ESP_LOGD("script.check_versions", "Versions:");
ESP_LOGD("script.check_versions", " ESPHome: ${version}");
ESP_LOGD("script.check_versions", " TFT: %s", version_tft->state.c_str());
@@ -2002,7 +2005,7 @@ script:
entity: string
then:
- lambda: |-
if (not id(is_uploading_tft)) {
if (!id(is_uploading_tft)) {
if (service != "" and not service.empty()) {
auto ha_event = new esphome::api::CustomAPIDevice();
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
@@ -2035,7 +2038,7 @@ script:
mode: restart
then:
- lambda: |-
if (not id(is_uploading_tft)) {
if (!id(is_uploading_tft)) {
notification_label->publish_state("");
notification_text->publish_state("");
notification_unread->turn_off();
@@ -2190,7 +2193,7 @@ script:
mode: restart
then:
- lambda: |-
if (not id(is_uploading_tft)) display_wrapped_text->execute("confirm.title", id(mui_please_confirm_global).c_str(), 15);
if (!id(is_uploading_tft)) display_wrapped_text->execute("confirm.title", id(mui_please_confirm_global).c_str(), 15);
- id: page_cover
mode: restart
@@ -2274,7 +2277,7 @@ script:
mode: restart
then:
- lambda: |-
if (current_page->state == "screensaver" and not id(is_uploading_tft)) {
if (current_page->state == "screensaver" and !id(is_uploading_tft)) {
disp1->send_command_printf("back_page_id=%" PRIu8, get_page_id(wakeup_page_name->state.c_str()));
if (id(screensaver_display_time)) {
disp1->send_command_printf("screensaver.text.font=%i", id(screensaver_display_time_font));
@@ -2370,7 +2373,7 @@ script:
mode: restart
then:
- lambda: |-
if (not id(is_uploading_tft)) {
if (!id(is_uploading_tft)) {
switch (int(display_mode->state)) {
case 1: // EU model
if (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_Enabled) { // Left button