From b79ab0164024e5148ba37521e49c91add2d8a84c Mon Sep 17 00:00:00 2001 From: Ilia Sotnikov Date: Fri, 20 Sep 2024 09:43:23 +0300 Subject: [PATCH 1/2] fix: Removed status indicator, ensure display is ready before updating * `display.yaml`: Ensure display is ready before updating, on recent ESPHome versions the lambdas performing diplay updates might get called before display component is ready, leading to creash * `indicator.yaml`: Removed status indicator, seemingly leading to crash on newer ESPHome versions since it is handled by WiFi controller. It is suspected the processing might now have some concurrency issues or race condition * `schedule.yaml`: Allowed to be optional * `rtc.yaml`, `time.yaml`, `display.yaml`: Updated to allow excluding those (using dereference operator instead of `id`, otherwise ESPHome will claim it can't resolve referenced symbol) --- controllers.yaml | 16 ++++++++++------ display.yaml | 12 +++++++----- indicators.yaml | 5 ----- main.yaml | 4 ++-- script_rain_water_tank_sensors_action.yaml | 8 ++++++-- script_refill_tank.yaml | 8 ++++++-- status_sensors.yaml | 4 ++-- time.yaml | 2 +- 8 files changed, 34 insertions(+), 25 deletions(-) diff --git a/controllers.yaml b/controllers.yaml index 7917e03..c3684f0 100644 --- a/controllers.yaml +++ b/controllers.yaml @@ -15,8 +15,10 @@ sprinkler: on_turn_on: - lambda: |- #ifdef HAS_DISPLAY - id(${display_id}).show_page(${display_page_when_active}); - id(${display_backlight_id}).turn_on(); + if (${display_id}->is_ready()) { + ${display_id}->show_page(${display_page_when_active}); + } + ${display_backlight_id}->turn_on(); #endif - light.turn_on: ${led_id} on_turn_off: @@ -31,7 +33,7 @@ sprinkler: - light.turn_off: ${led_id} - lambda: |- #ifdef HAS_DISPLAY - id(${display_backlight_id}).turn_off(); + ${display_backlight_id}->turn_off(); #endif auto_advance_switch: "Lawn sprinklers Auto Advance" standby_switch: @@ -111,8 +113,10 @@ sprinkler: on_turn_on: - lambda: |- #ifdef HAS_DISPLAY - id(${display_id}).show_page(${display_page_when_active}); - id(${display_backlight_id}).turn_on(); + if (${display_id}->is_ready()) { + ${display_id}->show_page(${display_page_when_active}); + } + ${display_backlight_id}->turn_on(); #endif - light.turn_on: ${led_id} on_turn_off: @@ -127,7 +131,7 @@ sprinkler: - light.turn_off: ${led_id} - lambda: |- #ifdef HAS_DISPLAY - id(${display_backlight_id}).turn_off(); + ${display_backlight_id}->turn_off(); #endif auto_advance_switch: "Flowerbed sprinklers Auto Advance" standby_switch: diff --git a/display.yaml b/display.yaml index 98fefb6..641aaab 100644 --- a/display.yaml +++ b/display.yaml @@ -97,7 +97,7 @@ display: // Day of week and time it.strftime( 84, 0, primary, TextAlign::TOP_RIGHT, "%a %H:%M", - id(${rtc_id}).now() + ${rtc_id}->now() ); // Symbol indicating if a client is connected over API @@ -116,10 +116,11 @@ display: ); // Run time remaining + #ifdef HAS_SCHEDULE auto time_remaining = max( - id(lawn_sprinklers).time_remaining_active_valve().value_or(0), - id(flowerbed_sprinklers).time_remaining_active_valve().value_or(0) + lawn_sprinklers->time_remaining_active_valve().value_or(0), + flowerbed_sprinklers->time_remaining_active_valve().value_or(0) ); if (time_remaining > 0) { @@ -139,9 +140,9 @@ display: it.print(0, 12, material_small, TextAlign::TOP_LEFT, "\U0000e089"); auto lawn_next_schedule = - id(lawn_schedule).get_next_schedule(); + lawn_schedule->get_next_schedule(); auto flowerbed_next_schedule = - id(flowerbed_schedule).get_next_schedule(); + flowerbed_schedule->get_next_schedule(); if (!lawn_next_schedule.has_value() && !flowerbed_next_schedule.has_value()) { @@ -163,6 +164,7 @@ display: ); } } + #endif - id: display_page2 lambda: |- diff --git a/indicators.yaml b/indicators.yaml index bd952b8..f4af540 100644 --- a/indicators.yaml +++ b/indicators.yaml @@ -53,8 +53,3 @@ light: return; }; id(${led_id}).turn_on(); - -status_led: - pin: - number: LED - inverted: true diff --git a/main.yaml b/main.yaml index 58be798..c5334df 100644 --- a/main.yaml +++ b/main.yaml @@ -29,7 +29,7 @@ substitutions: packages: outputs: !include outputs.yaml inputs: !include inputs.yaml - schedule: !include schedule.yaml + schedule: !include schedule.yaml # Optional display: !include display.yaml # Optional indicators: !include indicators.yaml controllers: !include controllers.yaml @@ -39,4 +39,4 @@ packages: # 2024.3.0 addresses security vulnerability esphome: - min_version: '2024.3.0' + min_version: '2024.3.0' \ No newline at end of file diff --git a/script_rain_water_tank_sensors_action.yaml b/script_rain_water_tank_sensors_action.yaml index 30255cf..7818885 100644 --- a/script_rain_water_tank_sensors_action.yaml +++ b/script_rain_water_tank_sensors_action.yaml @@ -54,7 +54,9 @@ id(lawn_sprinklers_standby_switch).turn_on(); #ifdef HAS_DISPLAY - id(${display_id}).update(); + if (${display_id}->is_ready()) { + ${display_id}->update(); + } #endif // Any active condition above is terminating, i.e. if one sensor is active @@ -86,7 +88,9 @@ #endif #ifdef HAS_DISPLAY - id(${display_id}).update(); + if (${display_id}->is_ready()) { + ${display_id}->update(); + } #endif // Preprocessor macros lack scope so undefine the macro for another script diff --git a/script_refill_tank.yaml b/script_refill_tank.yaml index 12d2ac7..258bb78 100644 --- a/script_refill_tank.yaml +++ b/script_refill_tank.yaml @@ -23,11 +23,15 @@ if: - switch.turn_on: ${relay} - lambda: |- #ifdef HAS_DISPLAY - id(${display_id}).update(); + if (${display_id}->is_ready()) { + ${display_id}->update(); + } #endif - delay: ${peripherals_power_refill_pulse_duration} - switch.turn_off: ${relay} - lambda: |- #ifdef HAS_DISPLAY - id(${display_id}).update(); + if (${display_id}->is_ready()) { + ${display_id}->update(); + } #endif diff --git a/status_sensors.yaml b/status_sensors.yaml index cea0b23..c828060 100644 --- a/status_sensors.yaml +++ b/status_sensors.yaml @@ -48,7 +48,7 @@ text_sensor: entity_category: diagnostic lambda: |- #ifdef HAS_SCHEDULE - auto next_schedule = id(lawn_schedule).get_next_schedule(); + auto next_schedule = lawn_schedule->get_next_schedule(); if (next_schedule.has_value()) return { next_schedule.value().strftime("%c") }; #endif @@ -61,7 +61,7 @@ text_sensor: entity_category: diagnostic lambda: |- #ifdef HAS_SCHEDULE - auto next_schedule = id(flowerbed_schedule).get_next_schedule(); + auto next_schedule = flowerbed_schedule->get_next_schedule(); if (next_schedule.has_value()) return { next_schedule.value().strftime("%c") }; #endif diff --git a/time.yaml b/time.yaml index 86aba48..0f4db9d 100644 --- a/time.yaml +++ b/time.yaml @@ -8,5 +8,5 @@ time: on_time_sync: - lambda: |- #ifdef HAS_RTC - id(${rtc_id}).write_time(); + ${rtc_id}->write_time(); #endif From 6a61160e295b6fb247380d79712cdfd76bb2ab8f Mon Sep 17 00:00:00 2001 From: Ilia Sotnikov Date: Fri, 20 Sep 2024 09:50:22 +0300 Subject: [PATCH 2/2] * Linting fixes --- main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.yaml b/main.yaml index c5334df..e07f055 100644 --- a/main.yaml +++ b/main.yaml @@ -39,4 +39,4 @@ packages: # 2024.3.0 addresses security vulnerability esphome: - min_version: '2024.3.0' \ No newline at end of file + min_version: '2024.3.0'