Skip to content

Commit

Permalink
Yaml to lambda
Browse files Browse the repository at this point in the history
Supports #2323
  • Loading branch information
edwardtfn committed Oct 16, 2024
1 parent bf54387 commit 579390e
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 204 deletions.
97 changes: 68 additions & 29 deletions esphome/nspanel_esphome_addon_climate_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ substitutions:
heat_deadband: "0.5" # Temperature delta before engaging heat
heat_overrun: "0.5" # Temperature delta before disengaging heat

##### DO NOT CHANGE THIS #####
addon_climate_cool: "false"
addon_climate_heat: "false"
addon_climate_dual: "false"
##############################

esphome:
platformio_options:
build_flags:
Expand Down Expand Up @@ -59,18 +53,39 @@ climate:
- script.execute: page_climate
- script.execute: page_home

display:
- id: !extend disp1
on_touch:
then:
- lambda: |-
if (
page_id == 1 // Page Home
and id(is_climate)
and (
component_id == 4 // indr_temp
or component_id == 27 // indr_temp_icon
)
) {
detailed_entity->publish_state((id(is_embedded_thermostat)) ? "embedded_climate" : "");
set_component_value->execute("climate", "embedded", id(is_embedded_thermostat) ? 1 : 0);
}
globals:
##### Is embedded thermostat visible on climate page? #####
- id: is_addon_climate_visible
- id: is_addon_climate_visible # Is embedded thermostat visible on climate page?
type: bool
restore_value: false
initial_value: 'false'
##### Embeded climate friendly name #####
- id: addon_climate_friendly_name

- id: addon_climate_friendly_name # Embeded climate friendly name
type: std::string
restore_value: false
initial_value: '"${name} Thermostat"'

- id: is_embedded_thermostat # Is embedded thermostat set as main climate entity?
type: bool
restore_value: true
initial_value: 'false'

logger:
logs:
climate: INFO
Expand Down Expand Up @@ -182,33 +197,57 @@ script:
}
float total_steps = (temp_max-temp_offset)/temp_step;
set_climate->execute (
temp_current, // current_temp
0, // supported_features
((${addon_climate_dual}) ? -999 : temp_target), // target_temp
((${addon_climate_dual}) ? temp_target_high : -999), // target_temp_high
((${addon_climate_dual}) ? temp_target_low : -999), // target_temp_low
int(round(temp_step*10)), // temp_step
int(round(total_steps)), // total_steps
int(round(temp_offset*10)), // temp_offset
"", // climate_icon
true // embedded_climate
temp_current, // current_temp
0, // supported_features
#if defined(NSPANEL_HA_BLUEPRINT_ADDON_CLIMATE_DUAL)
-999, // target_temp
temp_target_high, // target_temp_high
temp_target_low, // target_temp_low
#else
temp_target, // target_temp
-999, // target_temp_high
-999, // target_temp_low
#endif
int(round(temp_step*10)), // temp_step
int(round(total_steps)), // total_steps
int(round(temp_offset*10)), // temp_offset
"", // climate_icon
true // embedded_climate
);
update_climate_icon->execute("climate", "target_icon", int(thermostat_embedded->action), int(thermostat_embedded->mode));
set_component_visibility->execute("climate", "button01", false);
set_component_visibility->execute("climate", "button02", ${addon_climate_dual});
set_component_visibility->execute("climate", "button03", ${addon_climate_dual} or ${addon_climate_heat}); // Heat
set_component_visibility->execute("climate", "button04", ${addon_climate_dual} or ${addon_climate_cool}); // Cool
#if defined(NSPANEL_HA_BLUEPRINT_ADDON_CLIMATE_DUAL)
set_component_visibility->execute("climate", "button02", true);
set_component_font_color->execute("climate", "button02", thermostat_embedded->mode == climate::CLIMATE_MODE_HEAT_COOL ?
65535 : 48631);
#else
set_component_visibility->execute("climate", "button02", false);
set_component_font_color->execute("climate", "button02", thermostat_embedded->mode == climate::CLIMATE_MODE_HEAT_COOL ?
65535 : 6339);
#endif
#if defined(NSPANEL_HA_BLUEPRINT_ADDON_CLIMATE_DUAL) or defined(NSPANEL_HA_BLUEPRINT_ADDON_CLIMATE_HEAT)
set_component_visibility->execute("climate", "button03", true); // Heat
set_component_font_color->execute("climate", "button03", thermostat_embedded->mode == climate::CLIMATE_MODE_HEAT ?
64164 : 48631);
#else
set_component_visibility->execute("climate", "button03", false); // Heat
set_component_font_color->execute("climate", "button03", thermostat_embedded->mode == climate::CLIMATE_MODE_HEAT ?
64164 : 6339);
#endif
#if defined(NSPANEL_HA_BLUEPRINT_ADDON_CLIMATE_DUAL) or defined(NSPANEL_HA_BLUEPRINT_ADDON_CLIMATE_COOL)
set_component_visibility->execute("climate", "button04", true); // Cool
set_component_font_color->execute("climate", "button04", thermostat_embedded->mode == climate::CLIMATE_MODE_COOL ?
1055 : 48631);
#else
set_component_visibility->execute("climate", "button04", false); // Cool
set_component_font_color->execute("climate", "button04", thermostat_embedded->mode == climate::CLIMATE_MODE_COOL ?
1055 : 6339);
#endif
set_component_visibility->execute("climate", "button05", false);
set_component_visibility->execute("climate", "button06", false);
set_component_visibility->execute("climate", "button07", true); // Off
set_component_font_color->execute("climate", "button01", 6339);
set_component_font_color->execute("climate", "button02", thermostat_embedded->mode == climate::CLIMATE_MODE_HEAT_COOL ? 65535 :
(${addon_climate_dual} ? 48631 : 6339));
set_component_font_color->execute("climate", "button03", thermostat_embedded->mode == climate::CLIMATE_MODE_HEAT ? 64164 :
((${addon_climate_dual} or ${addon_climate_heat}) ? 48631 : 6339));
set_component_font_color->execute("climate", "button04", thermostat_embedded->mode == climate::CLIMATE_MODE_COOL ? 1055 :
((${addon_climate_dual} or ${addon_climate_cool}) ? 48631 : 6339));
set_component_font_color->execute("climate", "button05", 6339);
set_component_font_color->execute("climate", "button06", 6339);
set_component_font_color->execute("climate", "button07", thermostat_embedded->mode == climate::CLIMATE_MODE_OFF ? 10597 : 35921);
Expand Down
4 changes: 0 additions & 4 deletions esphome/nspanel_esphome_addon_climate_cool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ substitutions:
### Local thermostat defaults ###
temp_min: "15"

##### DO NOT CHANGE THIS #####
addon_climate_cool: "true"
##############################

esphome:
platformio_options:
build_flags:
Expand Down
5 changes: 0 additions & 5 deletions esphome/nspanel_esphome_addon_climate_dual.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
##### ATTENTION: This will add climate elements to the core system and requires the core part. #####
#####################################################################################################
---
substitutions:
##### DO NOT CHANGE THIS #####
addon_climate_dual: "true"
##############################

esphome:
platformio_options:
build_flags:
Expand Down
4 changes: 0 additions & 4 deletions esphome/nspanel_esphome_addon_climate_heat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ substitutions:
### Local thermostat defaults ###
temp_max: "25"

##### DO NOT CHANGE THIS #####
addon_climate_heat: "true"
##############################

esphome:
platformio_options:
build_flags:
Expand Down
68 changes: 22 additions & 46 deletions esphome/nspanel_esphome_addon_upload_tft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,75 +160,51 @@ script:
- delay: 2s
- logger.log: Starting TFT upload
- lambda: |-
ESP_LOGI("script.nextion_upload", "Starting TFT upload");
id(tft_upload_result) = disp1->upload_tft(baud_rate, !disp1->is_setup());
ESP_LOGD("script.nextion_upload", "TFT upload: %s", YESNO(id(tft_upload_result)));
ESP_LOGI("script.nextion_upload", "TFT upload: %s", YESNO(id(tft_upload_result)));
- id: open_upload_dialog
mode: restart
then:
- logger.log: Showing upload dialog page
- script.execute:
id: goto_page
page: confirm
- lambda: |-
ESP_LOGD("script.open_upload_dialog", "Showing upload dialog page");
goto_page->execute("confirm");
- wait_until:
condition:
- text_sensor.state:
id: current_page
state: confirm
timeout: 2s
- if:
condition:
- text_sensor.state:
id: current_page
state: confirm
then:
- script.execute:
id: set_component_visibility
page: confirm
component: bclose
show: false
- script.execute:
id: set_component_visibility
page: confirm
component: bt_accept
show: false
- script.execute:
id: set_component_visibility
page: confirm
component: bt_clear
show: false
- script.execute:
id: set_component_text
page: confirm
component: title
text: Upload TFT
- lambda: |-
set_component_visibility->execute("confirm", "bclose", false);
set_component_visibility->execute("confirm", "bt_accept", false);
set_component_visibility->execute("confirm", "bt_clear", false);
set_component_text->execute("confirm", "title", "Upload TFT");
- id: report_upload_progress
mode: restart
parameters:
message: string
then:
- lambda: |-
ESP_LOGD("script.report_upload_progress", message.c_str());
ESP_LOGI("script.report_upload_progress", message.c_str());
disp1->set_backlight_brightness(1);
- if:
condition:
- lambda: return id(tft_is_valid);
then:
- if:
- lambda: |-
if (current_page->state != "confirm")
open_upload_dialog->execute();
- wait_until:
condition:
- not:
- text_sensor.state:
id: current_page
state: confirm
then:
- script.execute: open_upload_dialog
- script.execute:
id: display_wrapped_text
page: confirm
component: body
text_to_display: !lambda return message.c_str();
line_length_limit: 18
- lambda: disp1->set_backlight_brightness(1);
- text_sensor.state:
id: current_page
state: confirm
timeout: 2s
- lambda: |-
display_wrapped_text->execute("confirm", "body", message.c_str(), 18);
- id: select_tft_file_model
mode: restart
Expand Down
20 changes: 5 additions & 15 deletions esphome/nspanel_esphome_core_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,6 @@ external_components:
- nspanel_ha_blueprint
refresh: 30s

globals:
##### Add-on Climate #####
- id: is_embedded_thermostat # Is embedded thermostat set as main climate entity?
type: bool
restore_value: true
initial_value: 'false'

logger:
id: logger_std
baud_rate: 0
Expand Down Expand Up @@ -274,14 +267,11 @@ script:
component: string
val: bool
then:
- if:
condition:
- lambda: return component == "is_embedded_thermostat";
then:
- script.execute:
id: boot_progress
step: ${BOOT_STEP_BASE}
step_name: Base
- lambda: |-
if (component == "is_embedded_thermostat") {
id(is_embedded_thermostat) = val;
boot_progress->execute(${BOOT_STEP_BASE}, "Base");
}
- id: set_var_int
mode: queued
Expand Down
Loading

0 comments on commit 579390e

Please sign in to comment.