Move page constructors to TFT

To reduce comms between ESPHome and Nextion, which could help with some sync issues found with 921600 bps.
This commit is contained in:
Edward Firmo
2023-12-17 12:44:12 +01:00
parent bd99afa14b
commit a2dc5913fa
130 changed files with 665 additions and 701 deletions

View File

@@ -46,7 +46,9 @@ climate:
internal: false
on_state:
- logger.log: Climate state changed - Start
- script.execute: addon_climate_update_page_climate
- script.execute:
id: page_climate
construct_page: false
- script.execute: addon_climate_update_page_home
- logger.log: Climate state changed - End
@@ -100,7 +102,7 @@ script:
- lambda: |-
id(is_addon_climate_visible) = embedded_climate;
- id: !extend addon_climate_update_page_climate
- id: !extend page_climate
then:
- lambda: |-
if (current_page->state == "climate" and id(is_addon_climate_visible))

View File

@@ -357,7 +357,7 @@ api:
// Update home page
ESP_LOGV(TAG, "Update home page");
page_home->execute(false);
page_home->execute();
ESP_LOGV(TAG, "Current page: %s", current_page->state.c_str());
@@ -1555,7 +1555,7 @@ text_sensor:
}
else service_call_alarm_control_panel->execute(entity.c_str(), key.c_str(), code_format.c_str(), "");
}
else if (page == "blank") page_blank->execute(true);
else if (page == "blank") page_blank->execute();
else if (page == "boot")
{
// Detect display mode
@@ -1577,7 +1577,7 @@ text_sensor:
}
// Contruct page boot
page_boot->execute(true);
page_boot->execute();
// Detect TFT version
if (doc.containsKey("version"))
@@ -2261,194 +2261,162 @@ script:
addon_climate_set_climate->execute(page == "climate" and detailed_entity->state == "embedded_climate");
// Call page constructor
if (page == "alarm") page_alarm->execute(true);
else if (page == "blank") page_blank->execute(true);
else if (page == "boot") page_boot->execute(true);
else if (page == "buttonpage01") page_buttonpage->execute(true, 1);
else if (page == "buttonpage02") page_buttonpage->execute(true, 2);
else if (page == "buttonpage03") page_buttonpage->execute(true, 3);
else if (page == "buttonpage04") page_buttonpage->execute(true, 4);
else if (page == "climate") page_climate->execute(true);
else if (page == "confirm") page_confirm->execute(true);
else if (page == "cover") page_cover->execute(true);
else if (page == "entitypage01") page_entitypage->execute(true, 1);
else if (page == "entitypage02") page_entitypage->execute(true, 2);
else if (page == "entitypage03") page_entitypage->execute(true, 3);
else if (page == "entitypage04") page_entitypage->execute(true, 4);
else if (page == "fan") page_fan->execute(true);
else if (page == "home") page_home->execute(true);
else if (page == "keyb_num") page_keyb_num->execute(true);
else if (page == "light") page_light->execute(true);
else if (page == "media_player") page_media_player->execute(true);
else if (page == "notification") page_notification->execute(true);
else if (page == "qrcode") page_qrcode->execute(true);
else if (page == "screensaver") page_screensaver->execute(true);
else if (page == "settings") page_settings->execute(true);
else if (page == "weather01") page_weather->execute(true, 1);
else if (page == "weather02") page_weather->execute(true, 2);
else if (page == "weather03") page_weather->execute(true, 3);
else if (page == "weather04") page_weather->execute(true, 4);
else if (page == "weather05") page_weather->execute(true, 5);
if (page == "alarm") page_alarm->execute();
else if (page == "blank") page_blank->execute();
else if (page == "boot") page_boot->execute();
else if (page == "buttonpage01") page_buttonpage01->execute();
else if (page == "buttonpage02") page_buttonpage02->execute();
else if (page == "buttonpage03") page_buttonpage03->execute();
else if (page == "buttonpage04") page_buttonpage04->execute();
else if (page == "climate") page_climate->execute();
else if (page == "confirm") page_confirm->execute();
else if (page == "cover") page_cover->execute();
else if (page == "entitypage01") page_entitypage01->execute();
else if (page == "entitypage02") page_entitypage02->execute();
else if (page == "entitypage03") page_entitypage03->execute();
else if (page == "entitypage04") page_entitypage04->execute();
else if (page == "fan") page_fan->execute();
else if (page == "home") page_home->execute();
else if (page == "keyb_num") page_keyb_num->execute();
else if (page == "light") page_light->execute();
else if (page == "media_player") page_media_player->execute();
else if (page == "notification") page_notification->execute();
else if (page == "qrcode") page_qrcode->execute();
else if (page == "screensaver") page_screensaver->execute();
else if (page == "settings") page_settings->execute();
else if (page == "weather01") page_weather01->execute();
else if (page == "weather02") page_weather02->execute();
else if (page == "weather03") page_weather03->execute();
else if (page == "weather04") page_weather04->execute();
else if (page == "weather05") page_weather05->execute();
- id: page_alarm
mode: restart
parameters:
construct_page: bool
then:
- lambda: |-
static const char *const TAG = "script.page_alarm";
if (construct_page) {
ESP_LOGV(TAG, "Construct alarm page");
if (current_page->state == "alarm") {
// Alarm page - Button's icons
disp1->set_component_text_printf("bt_home_icon", "\uE689"); //mdi:shield-home
disp1->set_component_text_printf("bt_away_icon", "\uE99C"); //mdi:shield-lock
disp1->set_component_text_printf("bt_night_icon", "\uF827"); //mdi:shield-moon
disp1->set_component_text_printf("bt_vacat_icon", "\uE6BA"); //mdi:shield-airplane
disp1->set_component_text_printf("bt_bypass_icon", "\uE77F"); //mdi:shield-half-full
disp1->set_component_text_printf("bt_disarm_icon", "\uE99D"); //mdi:shield-off
}
}
# There's nothing to do here so far
- id: page_blank
mode: restart
parameters:
construct_page: bool
then:
- lambda: |-
static const char *const TAG = "script.page_blank";
if (construct_page) {
ESP_LOGV(TAG, "Construct blank page");
std::string framework = "unknown";
#ifdef ARDUINO
framework = "arduino";
#elif defined(USE_ESP_IDF)
framework = "esp-idf";
#endif
disp1->set_component_text_printf("esp_version", "ESP: ${version}"); // ESPHome version
disp1->set_component_text_printf("framework", framework.c_str()); // ESPHome framework
disp1->send_command_printf("tm_esphome.en=0");
disp1->send_command_printf("tm_pageid.en=0");
}
ESP_LOGV(TAG, "Construct blank page");
std::string framework = "unknown";
#ifdef ARDUINO
framework = "arduino";
#elif defined(USE_ESP_IDF)
framework = "esp-idf";
#endif
disp1->set_component_text_printf("esp_version", "ESP: ${version}"); // ESPHome version
disp1->set_component_text_printf("framework", framework.c_str()); // ESPHome framework
disp1->send_command_printf("tm_esphome.en=0");
disp1->send_command_printf("tm_pageid.en=0");
- id: page_boot
mode: restart
parameters:
construct_page: bool
then:
- lambda: |-
static const char *const TAG = "script.page_boot";
if (construct_page) {
ESP_LOGV(TAG, "Construct boot page");
set_brightness->execute(100);
ESP_LOGV(TAG, "Construct boot page");
set_brightness->execute(100);
std::string framework = "unknown";
#ifdef ARDUINO
framework = "arduino";
#elif defined(USE_ESP_IDF)
framework = "esp-idf";
#endif
disp1->set_component_text_printf("esph_version", "${version}"); // ESPHome version
disp1->set_component_text_printf("framework", framework.c_str()); // ESPHome framework
disp1->show_component("bt_reboot");
}
std::string framework = "unknown";
#ifdef ARDUINO
framework = "arduino";
#elif defined(USE_ESP_IDF)
framework = "esp-idf";
#endif
disp1->set_component_text_printf("esph_version", "${version}"); // ESPHome version
disp1->set_component_text_printf("framework", framework.c_str()); // ESPHome framework
disp1->show_component("bt_reboot");
- id: page_buttonpage
mode: restart
parameters:
construct_page: bool
page_number: uint
then:
- lambda: |-
static const char *const TAG = "script.page_buttonpage";
if (construct_page) {
ESP_LOGV(TAG, "Construct button page");
page_index_indicator->execute(page_number, 4);
}
# There's nothing to do here so far
- id: page_buttonpage01
mode: restart
then:
- script.execute:
id: page_buttonpage
page_number: 1
- id: page_buttonpage02
mode: restart
then:
- script.execute:
id: page_buttonpage
page_number: 2
- id: page_buttonpage03
mode: restart
then:
- script.execute:
id: page_buttonpage
page_number: 3
- id: page_buttonpage04
mode: restart
then:
- script.execute:
id: page_buttonpage
page_number: 4
- id: page_climate
mode: restart
parameters:
construct_page: bool
then:
- lambda: |-
static const char *const TAG = "script.page_climate";
if (construct_page) {
ESP_LOGV(TAG, "Construct climate page");
disp1->set_component_text_printf("climate.button01", "%s", "\uEE8D"); //mdi:calendar-sync
disp1->set_component_text_printf("climate.button02", "%s", "\uE069"); //mdi:autorenew
disp1->set_component_text_printf("climate.button03", "%s", "\uE237"); //mdi:fire
disp1->set_component_text_printf("climate.button04", "%s", "\uE716"); //mdi:snowflake
disp1->set_component_text_printf("climate.button05", "%s", "\uE58D"); //mdi:water-percent
disp1->set_component_text_printf("climate.button06", "%s", "\uE20F"); //mdi:fan
disp1->set_component_text_printf("climate.button07", "%s", "\uE424"); //mdi:power
}
addon_climate_update_page_climate->execute();
# There's nothing to do here so far
- id: page_confirm
mode: restart
parameters:
construct_page: bool
then:
- lambda: |-
static const char *const TAG = "script.page_confirm";
if (construct_page) {
ESP_LOGV(TAG, "Construct confirm page");
}
# There's nothing to do here so far
- id: page_cover
mode: restart
parameters:
construct_page: bool
then:
- lambda: |-
static const char *const TAG = "script.page_cover";
if (construct_page) {
ESP_LOGV(TAG, "Construct cover page");
disp1->set_component_text_printf("cover.cover_stop", "%s", "\uE666"); //mdi:stop-circle-outline
// In the future this will be dynamically contructed based on the device_class
disp1->set_component_text_printf("cover.cover_open", "%s", "\uF11D"); //mdi:window-shutter-open
disp1->set_component_text_printf("cover.cover_close", "%s", "\uF11B"); //mdi:window-shutter
}
# There's nothing to do here so far
- id: page_entitypage
mode: restart
parameters:
construct_page: bool
page_number: uint
then:
- lambda: |-
static const char *const TAG = "script.page_entitypage";
if (construct_page) {
ESP_LOGV(TAG, "Construct entity page");
page_index_indicator->execute(page_number, 4);
}
# There's nothing to do here so far
- id: page_entitypage01
mode: restart
then:
- script.execute:
id: page_entitypage
page_number: 1
- id: page_entitypage02
mode: restart
then:
- script.execute:
id: page_entitypage
page_number: 2
- id: page_entitypage03
mode: restart
then:
- script.execute:
id: page_entitypage
page_number: 3
- id: page_entitypage04
mode: restart
then:
- script.execute:
id: page_entitypage
page_number: 4
- id: page_fan
mode: restart
parameters:
construct_page: bool
then:
- lambda: |-
static const char *const TAG = "script.page_fan";
if (construct_page) {
ESP_LOGV(TAG, "Construct fan page");
disp1->set_component_text_printf("fan.button_on", "%s", "\uE20F"); //mdi:fan
disp1->set_component_text_printf("fan.button_off", "%s", "\uE81C"); //mdi:fan-off
disp1->set_component_text_printf("fan.button_up", "%s", "\uF46D"); //mdi:fan-chevron-up
disp1->set_component_text_printf("fan.button_down", "%s", "\uF46C"); //mdi:fan-chevron-down
}
# There's nothing to do here so far
- id: page_home
mode: restart
parameters:
construct_page: bool
then:
- lambda: |-
static const char *const TAG = "script.page_home";
if (construct_page) {
ESP_LOGV(TAG, "Construct home page");
}
if (current_page->state == "home") { // Is home page visible?
ESP_LOGV(TAG, "Update home page");
refresh_relays->execute();
@@ -2461,78 +2429,35 @@ script:
- id: page_keyb_num
mode: restart
parameters:
construct_page: bool
then:
- lambda: |-
static const char *const TAG = "script.page_keyb_num";
if (construct_page) {
ESP_LOGV(TAG, "Construct keyb_num page");
disp1->set_component_text_printf("keyb_num.bview", "%s", "\uE207"); //mdi:eye
disp1->set_component_text_printf("keyb_num.bclose", "%s", "\uE158"); //mdi:close-circle
disp1->set_component_text_printf("keyb_num.bclear", "%s", "\uE641"); //mdi:eraser-variant
disp1->set_component_text_printf("keyb_num.benter", "%s", "\uE12B"); //mdi:check
}
# There's nothing to do here so far
- id: page_light
mode: restart
parameters:
construct_page: bool
then:
- lambda: |-
static const char *const TAG = "script.page_light";
if (construct_page) {
ESP_LOGV(TAG, "Construct light page");
}
# There's nothing to do here so far
- id: page_media_player
mode: restart
parameters:
construct_page: bool
then:
- logger.log: Page media_player
- lambda: |-
static const char *const TAG = "script.page_media_player";
if (construct_page) {
ESP_LOGV(TAG, "Construct media_player page");
disp1->set_component_text_printf("bt_on_off", "%s", "\uE424"); //mdi:power
disp1->set_component_text_printf("bt_prev", "%s", "\uE4AD"); //mdi:skip-previous
disp1->set_component_text_printf("bt_next", "%s", "\uE4AC"); //mdi:skip-next
disp1->set_component_text_printf("bt_play_pause", "%s", "\uE40D"); //mdi:play-pause
//disp1->set_component_text_printf("bt_stop", "%s", "\uE4DA"); //mdi:stop
disp1->set_component_text_printf("bt_mute", "%s", "\uE75E"); //mdi:volume-mute
disp1->set_component_text_printf("bt_vol_down", "%s", "\uE75D"); //mdi:volume-minus
disp1->set_component_text_printf("bt_vol_up", "%s", "\uE75C"); //mdi:volume-plus
}
# There's nothing to do here so far
- id: page_notification
mode: restart
parameters:
construct_page: bool
then:
- lambda: |-
static const char *const TAG = "script.page_notification";
if (construct_page) {
ESP_LOGV(TAG, "Construct notification page");
disp1->set_component_text_printf("notification.notifi_label", "%s", notification_label->state.c_str());
display_wrapped_text->execute("notification.notifi_text01", notification_text->state.c_str(), id(display_mode) == 2 ? 23 : 32);
}
ESP_LOGV(TAG, "Updating notification page");
disp1->set_component_text_printf("notification.notifi_label", "%s", notification_label->state.c_str());
display_wrapped_text->execute("notification.notifi_text01", notification_text->state.c_str(), id(display_mode) == 2 ? 23 : 32);
- id: page_qrcode
mode: restart
parameters:
construct_page: bool
then:
- lambda: |-
static const char *const TAG = "script.page_qrcode";
if (construct_page) {
ESP_LOGV(TAG, "Construct qrcode page");
}
# There's nothing to do here so far
- id: page_screensaver
mode: restart
parameters:
construct_page: bool
then:
- lambda: |-
static const char *const TAG = "script.page_screensaver";
@@ -2546,9 +2471,6 @@ script:
return 0u; // Return 0 (home page) if not found
};
if (construct_page) {
ESP_LOGV(TAG, "Construct screensaver page");
}
if (current_page->state == "screensaver") { // Is screensaver page visible?
ESP_LOGV(TAG, "Update screensaver page");
disp1->set_component_value("orign", pageIndex(wakeup_page_name->state));
@@ -2556,49 +2478,50 @@ script:
- id: page_settings
mode: restart
parameters:
construct_page: bool
then:
- lambda: |-
static const char *const TAG = "script.page_settings";
if (construct_page) {
ESP_LOGV(TAG, "Construct settings page");
//disp1->set_component_text_printf("bt_sleep", "%s", (id(sleep_mode).state) ? "\uEA19" : "\uEA18"); //mdi:toggle-switch-outline or mdi:toggle-switch-off-outline
disp1->hide_component("lbl_sleep");
disp1->hide_component("bt_sleep");
}
ESP_LOGV(TAG, "Construct settings page");
//disp1->set_component_text_printf("bt_sleep", "%s", (id(sleep_mode).state) ? "\uEA19" : "\uEA18"); //mdi:toggle-switch-outline or mdi:toggle-switch-off-outline
disp1->hide_component("lbl_sleep");
disp1->hide_component("bt_sleep");
- id: page_weather
mode: restart
parameters:
construct_page: bool
page_number: uint
then:
- lambda: |-
static const char *const TAG = "script.page_weather";
if (construct_page) {
ESP_LOGV(TAG, "Construct weather page");
page_index_indicator->execute(page_number, 5);
}
- id: page_index_indicator
# There's nothing to do here so far
- id: page_weather01
mode: restart
parameters:
page_number: uint
page_total: uint
then:
- lambda: |-
static const char *const TAG = "script.page_index_indicator";
ESP_LOGV(TAG, "Show page number indicator");
std::string indicator = "";
for (int i = 0; i < page_total; ++i) {
if (i == page_number - 1) {
indicator += "●";
} else {
indicator += "○";
}
}
disp1->set_component_text_printf("page_index", "%s", indicator.c_str());
- script.execute:
id: page_weather
page_number: 1
- id: page_weather02
mode: restart
then:
- script.execute:
id: page_weather
page_number: 2
- id: page_weather03
mode: restart
then:
- script.execute:
id: page_weather
page_number: 3
- id: page_weather04
mode: restart
then:
- script.execute:
id: page_weather
page_number: 4
- id: page_weather05
mode: restart
then:
- script.execute:
id: page_weather
page_number: 5
- id: exit_reparse
mode: restart
@@ -2626,7 +2549,7 @@ script:
if (current_page->state == "boot") {
disp1->send_command_printf("tm_esphome.en=0");
disp1->send_command_printf("tm_pageid.en=0");
page_boot->execute(true);
page_boot->execute();
}
timer_reset_all->execute("boot");
- lambda: |-
@@ -2724,12 +2647,6 @@ script:
- lambda: |-
ESP_LOGV("script.addon_climate_set_climate", "Check for addon_climate");
ESP_LOGV("script.addon_climate_set_climate", "embedded_climate: %s", embedded_climate ? "True" : "False");
- id: addon_climate_update_page_climate
mode: restart
then:
# Reserved for Add-on Climate
- lambda: |-
ESP_LOGV("script.addon_climate_update_page_climate", "Check for addon_climate");
- id: addon_climate_set_climate_friendly_name
mode: restart
parameters:
@@ -2771,10 +2688,18 @@ script:
page_alarm->stop();
page_blank->stop();
page_boot->stop();
page_buttonpage01->stop();
page_buttonpage02->stop();
page_buttonpage03->stop();
page_buttonpage04->stop();
page_buttonpage->stop();
page_climate->stop();
page_confirm->stop();
page_cover->stop();
page_entitypage01->stop();
page_entitypage02->stop();
page_entitypage03->stop();
page_entitypage04->stop();
page_entitypage->stop();
page_fan->stop();
page_home->stop();
@@ -2785,8 +2710,12 @@ script:
page_qrcode->stop();
page_screensaver->stop();
page_settings->stop();
page_weather01->stop();
page_weather02->stop();
page_weather03->stop();
page_weather04->stop();
page_weather05->stop();
page_weather->stop();
page_index_indicator->stop();
exit_reparse->stop();
boot_sequence->stop();
notification_clear->stop();
@@ -2794,6 +2723,5 @@ script:
addon_climate_service_call->stop();
addon_climate_update_page_home->stop();
addon_climate_set_climate->stop();
addon_climate_update_page_climate->stop();
addon_climate_set_climate_friendly_name->stop();
ESP_LOGD(TAG, "Finished");