Rebuild embedded climate changing calls

Solves #1613
Solves #1627
This commit is contained in:
Edward Firmo
2024-01-16 09:43:26 +01:00
parent c34018c021
commit 59cc6a536e
2 changed files with 60 additions and 45 deletions

View File

@@ -79,17 +79,34 @@ switch:
optimistic: true optimistic: true
script: script:
- id: !extend addon_climate_service_call - id: !extend change_climate_state
then: then:
- lambda: |- - lambda: |-
id(is_addon_climate_visible) = true; if (embedded) {
disp1->set_component_value("climate.embedded", 1); static const char *const TAG = "addon_climate_base.script.change_climate_state";
auto call = thermostat_embedded->make_call(); id(is_addon_climate_visible) = true;
if (key == "set_temperature") disp1->set_component_value("climate.embedded", 1);
call.set_target_temperature(stof(value) / 10); auto call = thermostat_embedded->make_call();
else if (key == "hvac_mode") if (key == "temperature") {
call.set_mode(value); ESP_LOGD(TAG, "set_target_temperature(%f)", (stof(value) / 10));
call.perform(); call.set_target_temperature(stof(value) / 10);
} else if (key == "target_temp_high") {
ESP_LOGD(TAG, "set_target_temperature_high(%f)", (stof(value) / 10));
call.set_target_temperature_high(stof(value) / 10);
} else if (key == "target_temp_low") {
ESP_LOGD(TAG, "set_target_temperature_low(%f)", (stof(value) / 10));
call.set_target_temperature_low(stof(value) / 10);
} else if (key == "hvac_mode") {
ESP_LOGD(TAG, "hvac_mode(%s)", value.c_str());
call.set_mode(value);
} else {
ESP_LOGE(TAG, "Invalid call:");
ESP_LOGE(TAG, " Embedded: %s", embedded ? "True" : "False");
ESP_LOGE(TAG, " Key: %s", key.c_str());
ESP_LOGE(TAG, " Value: %s", value.c_str());
}
call.perform();
}
- id: !extend global_settings - id: !extend global_settings
then: then:

View File

@@ -1637,42 +1637,32 @@ text_sensor:
else service_call_alarm_control_panel->execute(entity.c_str(), key.c_str(), code_format.c_str(), ""); else service_call_alarm_control_panel->execute(entity.c_str(), key.c_str(), code_format.c_str(), "");
} }
else if (page == "climate") { else if (page == "climate") {
if (embedded==1) change_climate_state->execute((embedded==1), key.c_str(), value.c_str());
addon_climate_service_call->execute(key.c_str(), value.c_str());
else if (key == "temperature" or key == "target_temp_high" or key == "target_temp_low")
ha_call_service->execute("climate.set_temperature", key.c_str(), to_string(stof(value) / 10), entity.c_str());
else if (key == "hvac_mode")
ha_call_service->execute("climate.set_hvac_mode", key.c_str(), value.c_str(), entity.c_str());
} }
else if (page == "cover") else if (page == "cover") {
{ if (key == "position") ha_call_service->execute("cover.set_cover_position", key.c_str(), value.c_str(), entity.c_str());
if (key == "position") ha_call_service->execute("cover.set_cover_position", key.c_str(), value.c_str(), entity.c_str()); else ha_call_service->execute((std::string("cover.") + key.c_str()), "", "", entity.c_str());
else ha_call_service->execute((std::string("cover.") + key.c_str()), "", "", entity.c_str()); }
} else if (page == "fan") {
else if (page == "fan") if (key == "stop" or value == "0") ha_call_service->execute("fan.turn_off", "", "", entity.c_str());
{ else ha_call_service->execute("fan.turn_on", key.c_str(), value.c_str(), entity.c_str());
if (key == "stop" or value == "0") ha_call_service->execute("fan.turn_off", "", "", entity.c_str()); }
else ha_call_service->execute("fan.turn_on", key.c_str(), value.c_str(), entity.c_str()); else if (page == "keyb_num") {
} std::string base_domain = doc["base_domain"];
else if (page == "keyb_num") if (base_domain == "alarm") {
{ std::string code_format = doc["code_format"];
std::string base_domain = doc["base_domain"]; std::string pin = doc["pin"];
if (base_domain == "alarm") service_call_alarm_control_panel->execute(entity.c_str(), key.c_str(), code_format.c_str(), pin.c_str());
{
std::string code_format = doc["code_format"];
std::string pin = doc["pin"];
service_call_alarm_control_panel->execute(entity.c_str(), key.c_str(), code_format.c_str(), pin.c_str());
}
else if (base_domain == "" or base_domain.empty()) base_domain = "home";
disp1->goto_page(base_domain.c_str());
} }
else if (base_domain == "" or base_domain.empty()) base_domain = "home";
disp1->goto_page(base_domain.c_str());
}
else if (page == "light") ha_call_service->execute("light.turn_on", key.c_str(), value.c_str(), entity.c_str()); else if (page == "light") ha_call_service->execute("light.turn_on", key.c_str(), value.c_str(), entity.c_str());
else if (page == "media_player") else if (page == "media_player") {
{ if (key == "volume_mute") ha_call_service->execute("media_player.volume_mute", "is_volume_muted", value.c_str(), entity.c_str());
if (key == "volume_mute") ha_call_service->execute("media_player.volume_mute", "is_volume_muted", value.c_str(), entity.c_str()); else if (key == "volume_set") ha_call_service->execute("media_player.volume_set", "volume_level", to_string(stof(value) / 100), entity.c_str());
else if (key == "volume_set") ha_call_service->execute("media_player.volume_set", "volume_level", to_string(stof(value) / 100), entity.c_str()); else if (not key.empty()) ha_call_service->execute((std::string("media_player.") + key.c_str()), "", "", entity.c_str());
else if (not key.empty()) ha_call_service->execute((std::string("media_player.") + key.c_str()), "", "", entity.c_str()); }
}
- id: version_tft - id: version_tft
name: ${name} TFT version name: ${name} TFT version
@@ -1693,12 +1683,20 @@ text_sensor:
### Scripts ###### ### Scripts ######
script: script:
- id: addon_climate_service_call - id: change_climate_state
mode: restart mode: restart
parameters: parameters:
embedded: bool
key: string key: string
value: string value: string
then: # Reserved for Add-on Climate then:
- lambda: |-
if (!embedded) {
if (key == "temperature" or key == "target_temp_high" or key == "target_temp_low")
ha_call_service->execute("climate.set_temperature", key.c_str(), to_string(stof(value) / 10), detailed_entity->state.c_str());
else if (key == "hvac_mode")
ha_call_service->execute("climate.set_hvac_mode", key.c_str(), value.c_str(), detailed_entity->state.c_str());
}
- id: check_versions - id: check_versions
mode: restart mode: restart
@@ -2805,7 +2803,7 @@ script:
- lambda: |- - lambda: |-
static const char *const TAG = "script.stop_all"; static const char *const TAG = "script.stop_all";
ESP_LOGD(TAG, "Stopping scripts..."); ESP_LOGD(TAG, "Stopping scripts...");
addon_climate_service_call->stop(); change_climate_state->stop();
check_versions->stop(); check_versions->stop();
display_embedded_temp->stop(); display_embedded_temp->stop();
display_wrapped_text->stop(); display_wrapped_text->stop();