diff --git a/components/nspanel_ha_blueprint_upload_tft/upload_tft.h b/components/nspanel_ha_blueprint_upload_tft/upload_tft.h index a26edec..8ffe34d 100644 --- a/components/nspanel_ha_blueprint_upload_tft/upload_tft.h +++ b/components/nspanel_ha_blueprint_upload_tft/upload_tft.h @@ -42,4 +42,40 @@ namespace nspanel_ha_blueprint_upload_tft { return url; // Return the constructed URL } + /** + * @brief Generates a descriptive text for the NSPanel based on the given display mode and charset. + * + * This function maps numeric codes for the display mode and charset to a human-readable + * description of an NSPanel configuration. It supports different geographic regions and language + * character sets. If the inputs do not match any predefined configuration, the function returns + * an empty string, allowing for easy detection of unexpected or invalid inputs. + * + * @param displayMode An integer representing the display mode of the NSPanel: + * 1 for "EU", 2 for "US", and 3 for "US Landscape". + * @param charset An integer indicating the character set used: + * 1 for "International (original)" and 2 for "CJK languages". + * @return std::string A string describing the NSPanel configuration based on the inputs. + * Returns an empty string if the inputs do not match any known configuration. + */ + std::string getNSPanelText(int displayMode, int charset) { + + if (displayMode < 1 or displayMode > 3 or charset < 1 or charset > 2) return ""; + + std::string text; + // Determine the base text based on the display mode + switch(displayMode) { + case 1: text = "NSPanel EU"; break; + case 2: text = "NSPanel US"; break; + case 3: text = "NSPanel US Landscape"; break; + default: return ""; // Return an empty string for unmatched display modes + } + + // Append the charset text if necessary + if (charset == 2) { + text += " (CJK languages)"; + } + + return text; + } + } // namespace nspanel_ha_blueprint_upload_tft diff --git a/esphome/nspanel_esphome_addon_upload_tft.yaml b/esphome/nspanel_esphome_addon_upload_tft.yaml index ebe4ec4..80399a9 100644 --- a/esphome/nspanel_esphome_addon_upload_tft.yaml +++ b/esphome/nspanel_esphome_addon_upload_tft.yaml @@ -19,7 +19,7 @@ external_components: - source: type: git url: https://github.com/Blackymas/NSPanel_HA_Blueprint - # ref: main + ref: dev components: - nspanel_ha_blueprint_upload_tft refresh: 300s @@ -166,6 +166,15 @@ script: App.feed_wdt(); } + - id: select_tft_file_model + mode: restart + then: + - lambda: |- + if (!isnan(display_mode->state) and !isnan(display_charset->state)) { + std::string PanelModel = getNSPanelText(int(display_mode->state), int(display_charset->state)); + if (!PanelModel.empty() and tft_file_model->state != PanelModel) tft_file_model->publish_state(PanelModel); + } + - id: !extend stop_all then: - lambda: |- @@ -413,16 +422,22 @@ select: icon: mdi:swap-horizontal sensor: + - id: !extend display_charset + on_value: + then: + - script.execute: select_tft_file_model + - id: !extend display_mode on_value: then: - lambda: |- - static const char *const TAG = "addon_upload_tft.sensor.display_mode"; - id(tft_is_valid) = (display_mode->state > 0 and display_mode->state < 4); - if (id(tft_is_valid)) - ESP_LOGD(TAG, "Valid TFT: True"); - else { - ESP_LOGW(TAG, "Display mode: %i", int(display_mode->state)); - ESP_LOGW(TAG, "Valid TFT: False"); - } + - lambda: |- + static const char *const TAG = "addon_upload_tft.sensor.display_mode"; + id(tft_is_valid) = (display_mode->state > 0 and display_mode->state < 4); + if (id(tft_is_valid)) { + ESP_LOGD(TAG, "Valid TFT: True"); + select_tft_file_model->execute(); + } else { + ESP_LOGW(TAG, "Display mode: %i", int(display_mode->state)); + ESP_LOGW(TAG, "Valid TFT: False"); + } ... diff --git a/esphome/nspanel_esphome_core.yaml b/esphome/nspanel_esphome_core.yaml index e297f99..325b1c5 100644 --- a/esphome/nspanel_esphome_core.yaml +++ b/esphome/nspanel_esphome_core.yaml @@ -33,7 +33,7 @@ external_components: - source: type: git url: https://github.com/edwardtfn/esphome - ref: nextion-v431 + ref: nextion-v432 components: - nextion # Change this when that PR#6192 gets released (2024.4?) refresh: 300s @@ -892,13 +892,11 @@ display: - id: disp1 platform: nextion uart_id: tf_uart - start_up_page: 0 # Boot page on_setup: lambda: |- if (!id(is_uploading_tft)) { nextion_init->publish_state(true); version_tft->update(); - goto_page->execute("boot"); } on_page: @@ -1572,6 +1570,17 @@ sensor: internal: false disabled_by_default: false + ##### Charset (1 = International (original), 2 = CJK languages) + - id: display_charset + name: Display charset + platform: nextion + variable_name: charset + precision: 0 + accuracy_decimals: 0 + internal: false + icon: mdi:translate + entity_category: diagnostic + ##### Display mode (1 = EU, 2 = US, 3 = US Landscape) - id: display_mode name: Display mode @@ -1583,17 +1592,6 @@ sensor: icon: mdi:phone-rotate-portrait entity_category: diagnostic - ##### Charset (1 = International (original), 2 = CJK languages) - - name: Display charset - id: display_charset - platform: nextion - variable_name: charset - precision: 0 - accuracy_decimals: 0 - internal: false - icon: mdi:translate - entity_category: diagnostic - ##### Wi-Fi Signal stregth - name: RSSI id: wifi_rssi @@ -1693,13 +1691,6 @@ switch: restore_mode: ALWAYS_ON internal: true disabled_by_default: false - on_turn_on: - - wait_until: - condition: - - lambda: !lambda return disp1->is_setup(); - timeout: 20s - - lambda: |- - goto_page->execute("boot"); on_turn_off: - lambda: |- nextion_init->publish_state(false); @@ -1909,6 +1900,37 @@ text_sensor: ### Scripts ###### script: + - id: boot_event + mode: restart + parameters: + init: bool + then: + - lambda: |- + if (init) { + esphome::api::CustomAPIDevice ha_event; + ha_event.fire_homeassistant_event("esphome.nspanel_ha_blueprint", + { + {"device_name", device_name->state.c_str()}, + {"type", "boot"}, + {"step", "start"} + }); + } + - while: + condition: + - lambda: return (blueprint_status->state < 99); + then: + - delay: 10s + - lambda: |- + if (blueprint_status->state < 99) { + esphome::api::CustomAPIDevice ha_event; + ha_event.fire_homeassistant_event("esphome.nspanel_ha_blueprint", + { + {"device_name", device_name->state.c_str()}, + {"type", "boot"}, + {"step", "timeout"} + }); + } + - id: boot_progress mode: restart parameters: @@ -2039,32 +2061,32 @@ script: decimal_separator: string then: - lambda: |- - if (id(is_uploading_tft)) global_settings->stop(); - if (blueprint_status->state <= 99) goto_page->execute("boot"); - // Blueprint version - version_blueprint->publish_state(blueprint_version.c_str()); - disp1->set_component_text("boot.bluep_version", blueprint_version.c_str()); - check_versions->execute(); + if (!id(is_uploading_tft)) { + // Blueprint version + version_blueprint->publish_state(blueprint_version.c_str()); + disp1->set_component_text("boot.bluep_version", blueprint_version.c_str()); + check_versions->execute(); - // MUI strings - id(mui_please_confirm_global) = mui_please_confirm; - id(mui_unavailable_global) = mui_unavailable; + // MUI strings + id(mui_please_confirm_global) = mui_please_confirm; + id(mui_unavailable_global) = mui_unavailable; - // Screen saver page (sleep) - id(screensaver_display_time) = screensaver_time; - id(screensaver_display_time_font) = screensaver_time_font; - id(screensaver_display_time_color) = rgbTo565(screensaver_time_color); - page_screensaver->execute(); + // Screen saver page (sleep) + id(screensaver_display_time) = screensaver_time; + id(screensaver_display_time_font) = screensaver_time_font; + id(screensaver_display_time_color) = rgbTo565(screensaver_time_color); + page_screensaver->execute(); - // Entities pages alignment - id(page_entity_value_horizontal_alignment) = ent_value_xcen; + // Entities pages alignment + id(page_entity_value_horizontal_alignment) = ent_value_xcen; - // Decimal separator - if (not decimal_separator.empty()) id(mui_decimal_separator) = decimal_separator[0]; + // Decimal separator + if (not decimal_separator.empty()) id(mui_decimal_separator) = decimal_separator[0]; - if (current_page->state != "boot") { - // Update current page - page_changed->execute(); + if (current_page->state != "boot") { + // Update current page + page_changed->execute(); + } } - id: goto_page @@ -2195,15 +2217,7 @@ script: - logger.log: API connected - lambda: |- boot_progress->execute(4); - if (blueprint_status->state <= 99) { - esphome::api::CustomAPIDevice ha_event; - ha_event.fire_homeassistant_event("esphome.nspanel_ha_blueprint", - { - {"device_name", device_name->state.c_str()}, - {"type", "boot"}, - {"step", "start"} - }); - } + if (blueprint_status->state <= 99) boot_event->execute(true); - wait_until: condition: - lambda: return (wifi_component->is_connected() and api_server->is_connected() and blueprint_status->state > 99); @@ -2806,6 +2820,7 @@ script: mode: restart then: - lambda: |- + boot_event->stop(); boot_progress->stop(); change_climate_state->stop(); check_versions->stop(); @@ -3135,13 +3150,7 @@ script: ESP_LOGW(TAG, " Init steps: %i (%0.1f%%)", int(blueprint_status->raw_state), blueprint_status->state); ESP_LOGW(TAG, " State: %s", (wifi_connected and api_connected) ? "Pending" : "DISCONNECTED"); ESP_LOGI(TAG, "Requesting blueprint settings"); - esphome::api::CustomAPIDevice ha_event; - ha_event.fire_homeassistant_event("esphome.nspanel_ha_blueprint", - { - {"device_name", device_name->state.c_str()}, - {"type", "boot"}, - {"step", "timeout"} - }); + boot_event->execute(false); } // Report ESPHome diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index 38c7e9d..bcfe81e 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -4161,7 +4161,7 @@ trigger: # yamllint disable rule:line-length condition: - - '{{ trigger.id == "nspanel_event" or has_value(device_name_sensor) }}' + - '{{ trigger.id in ["automation_reloaded", "ha_started", "nspanel_event"] or has_value(device_name_sensor) }}' - > # Update page Home only when visible or home_page_background_update is enabled {{ trigger.id not in ["home_values_state", "trigger_chip_state"] or @@ -8466,6 +8466,7 @@ action: - if: > {{ buttons_pages.labels[event_page] != None and + buttons_pages.labels[event_page] != [] and (buttons_pages.labels[event_page] | string) | length > 0 }} then: @@ -10596,7 +10597,7 @@ action: id: home_values_state sequence: - repeat: - for_each: '{{ home_page.entity_value | selectattr("entity", "defined") | selectattr("entity", "eq", trigger.event.data.entity_id) | list }}' + for_each: '{{ home_page.entity_value | selectattr("entity", "defined") | selectattr("entity", "eq", trigger.entity_id) | list }}' sequence: - *display_value