Update home page when notification changes

Solves #1136
This commit is contained in:
Edward Firmo
2023-10-03 14:37:46 +02:00
parent b6a5ea76c0
commit 742e2a243d

View File

@@ -242,6 +242,7 @@ api:
ESP_LOGV("service.notification_show", "Starting");
id(disp1).send_command_printf("is_notification=1");
if (id(current_page).state.c_str() == "home") id(disp1).show_component("bt_notific");
id(disp1).goto_page("notification");
id(disp1).set_component_text_printf("notification.notifi_label", "%s", label.c_str());
@@ -264,6 +265,7 @@ api:
- &notification_clear
lambda: |-
id(disp1).send_command_printf("is_notification=0");
if (id(current_page).state.c_str() == "home") id(disp1).hide_component("bt_notific");
id(notification_label).publish_state("");
id(notification_text).publish_state("");
- switch.turn_off: notification_unread
@@ -330,7 +332,7 @@ api:
entity: string
then:
- lambda: |-
if (id(current_page).state == "climate") id(entity_id) = entity;
if (id(current_page).state.c_str() == "climate") id(entity_id) = entity;
- script.execute:
id: set_climate
@@ -376,7 +378,7 @@ api:
reset_timer: bool
then:
- lambda: |-
if (id(current_page).state == "screensaver") id(disp1).goto_page(id(wakeup_page_name).state.c_str());
if (id(current_page).state.c_str() == "screensaver") id(disp1).goto_page(id(wakeup_page_name).state.c_str());
if (reset_timer)
id(timer_reset_all).execute(id(wakeup_page_name).state.c_str());
else
@@ -566,7 +568,7 @@ api:
id(update_alarm_icon).execute("home.bt_alarm", state.c_str());
// Is page Alarm visible?
if (id(current_page).state=="alarm")
if (id(current_page).state.c_str() == "alarm")
{ // Update alarm page
id(entity_id) = entity;
@@ -665,7 +667,7 @@ api:
supported_features: int
then:
- lambda: |-
if (id(current_page).state == "media_player")
if (id(current_page).state.c_str() == "media_player")
{
id(entity_id) = entity;
id(disp1).set_component_text_printf("page_label", "%s", friendly_name.c_str());
@@ -919,7 +921,7 @@ binary_sensor:
- logger.log: "Left button - Long click"
- script.execute:
id: ha_button
page: !lambda return id(current_page).state;
page: !lambda return id(current_page).state.c_str();
component: "hw_bt_left"
command: "long_click"
- timing: &short_click-timing
@@ -941,7 +943,7 @@ binary_sensor:
- switch.toggle: relay_1
- script.execute:
id: ha_button
page: !lambda return id(current_page).state;
page: !lambda return id(current_page).state.c_str();
component: "hw_bt_left"
command: "short_click"
@@ -958,7 +960,7 @@ binary_sensor:
- logger.log: "Right button - Long click"
- script.execute:
id: ha_button
page: !lambda return id(current_page).state;
page: !lambda return id(current_page).state.c_str();
component: "hw_bt_right"
command: "long_click"
- timing: *short_click-timing
@@ -979,7 +981,7 @@ binary_sensor:
- switch.toggle: relay_2
- script.execute:
id: ha_button
page: !lambda return id(current_page).state;
page: !lambda return id(current_page).state.c_str();
component: "hw_bt_right"
command: "short_click"
@@ -1554,12 +1556,12 @@ number:
id(display_brightness_global) = int(x);
id(disp1).send_command_printf("brightness=%i", int(x));
id(disp1).send_command_printf("settings.brightslider.val=%i", int(x));
if (id(current_page).state != "screensaver")
if (id(current_page).state.c_str() != "screensaver")
{
id(disp1).set_backlight_brightness(x/100);
id(timer_dim).execute(id(current_page).state.c_str(), int(id(timeout_dim).state));
id(timer_sleep).execute(id(current_page).state.c_str(), int(id(timeout_sleep).state));
if (id(current_page).state == "settings") id(disp1).set_component_text_printf("bright_text", "%i%%", int(x));
if (id(current_page).state.c_str() == "settings") id(disp1).set_component_text_printf("bright_text", "%i%%", int(x));
}
##### SCREEN BRIGHTNESS DIMMED DOWN #####
@@ -1579,11 +1581,11 @@ number:
id(display_dim_brightness_global) = int(x);
id(disp1).send_command_printf("brightness_dim=%i", int(x));
id(disp1).send_command_printf("settings.dimslider.val=%i", int(x));
if (id(current_page).state != "screensaver" and id(is_dim_brightness))
if (id(current_page).state.c_str() != "screensaver" and id(is_dim_brightness))
{
id(disp1).set_backlight_brightness(x/100);
id(timer_sleep).execute(id(current_page).state.c_str(), int(id(timeout_sleep).state));
if (id(current_page).state == "settings") id(disp1).set_component_text_printf("dim_text", "%i%%", int(x));
if (id(current_page).state.c_str() == "settings") id(disp1).set_component_text_printf("dim_text", "%i%%", int(x));
}
##### Temperature Correction #####
@@ -1757,7 +1759,7 @@ script:
- delay: !lambda return (timeout *1000);
- lambda: |-
ESP_LOGD("script.timer_page", "Timed out on page: %s", id(current_page).state.c_str());
if (id(current_page).state != "screensaver" and id(current_page).state != "boot" and id(current_page).state != "home" and timeout >= 1)
if (id(current_page).state.c_str() != "screensaver" and id(current_page).state.c_str() != "boot" and id(current_page).state.c_str() != "home" and timeout >= 1)
{
ESP_LOGD("script.timer_page", "Fallback to page Home");
id(disp1).goto_page("home");
@@ -1785,7 +1787,7 @@ script:
then:
- delay: !lambda return (timeout *1000);
- lambda: |-
if (id(current_page).state != "screensaver" and id(current_page).state != "blank-screensaver" and id(current_page).state != "boot" and timeout >= 1)
if (id(current_page).state.c_str() != "screensaver" and id(current_page).state.c_str() != "blank-screensaver" and id(current_page).state.c_str() != "boot" and timeout >= 1)
{
ESP_LOGD("script.timer_dim", "Dimming the display to %i%%", id(display_dim_brightness_global));
id(disp1).send_command_printf("dim=%i", id(display_dim_brightness_global));
@@ -1805,7 +1807,7 @@ script:
then:
- delay: !lambda return (timeout *1000);
- lambda: |-
if (id(current_page).state != "screensaver" and id(current_page).state != "boot" and timeout >= 1)
if (id(current_page).state.c_str() != "screensaver" and id(current_page).state.c_str() != "boot" and timeout >= 1)
{
ESP_LOGD("script.timer_sleep", "Going to sleep from page %s", id(current_page).state.c_str());
id(disp1).goto_page("screensaver");
@@ -2312,20 +2314,6 @@ script:
int content_length_ = 0;
int tft_size_ = 0;
int tranfer_size_ = 0;
unsigned long starting_timestamp = 0;
auto remaining_time = [starting_timestamp, tranfer_size_, content_length_]() -> std::string
{
if (content_length_ > tranfer_size_) return "unknown";
long remaining_millis = int(round((millis() - starting_timestamp) * content_length_ / (tranfer_size_ - content_length_)));
int hours = remaining_millis / (1000 * 60 * 60);
int minutes = (remaining_millis / (1000 * 60)) % 60;
int seconds = (remaining_millis / 1000) % 60;
char resp[9];
sprintf(resp, "%02i:%02i:%02i", hours, minutes, seconds);
return std::string(resp);
};
auto power_cycle_display = []()
{
@@ -2662,9 +2650,6 @@ script:
ESP_LOGD("script.upload_tft.upload_tft", "Updating tft from \"%s\" with a file size of %d using %zu chunksize, Heap Size %d",
url.c_str(), content_length_, transfer_buffer_size_, ESP.getFreeHeap());
starting_timestamp = millis();
tranfer_size_ = content_length_;
int result = 0;
while (content_length_ > 0) {
result = upload_by_chunks_(&http, url, result);