Fix display in Fahrenheit when Blueprint fails the first time
Solves #1678
This commit is contained in:
@@ -82,29 +82,31 @@ script:
|
||||
- id: !extend change_climate_state
|
||||
then:
|
||||
- lambda: |-
|
||||
auto FahrenheitToCelsius = [](float fahrenheit) -> float {
|
||||
return (fahrenheit - 32.0) * 5.0 / 9.0;
|
||||
};
|
||||
|
||||
if (embedded) {
|
||||
static const char *const TAG = "addon_climate_base.script.change_climate_state";
|
||||
id(is_addon_climate_visible) = true;
|
||||
disp1->set_component_value("climate.embedded", 1);
|
||||
auto FahrenheitToCelsius = [](float fahrenheit) -> float {
|
||||
return (fahrenheit - 32.0) * 5.0 / 9.0;
|
||||
};
|
||||
std::string temp_units = "${temp_units}";
|
||||
bool temp_unit_fahrenheit = (temp_units == "°F" || temp_units == "F" || temp_units == "°f" || temp_units == "f");
|
||||
auto call = thermostat_embedded->make_call();
|
||||
float temperature;
|
||||
|
||||
id(is_addon_climate_visible) = true;
|
||||
disp1->set_component_value("climate.embedded", 1);
|
||||
if (key == "temperature") {
|
||||
temperature = stof(value) / 10;
|
||||
if (id(temp_unit_fahrenheit)) temperature = FahrenheitToCelsius(temperature);
|
||||
if (temp_unit_fahrenheit) temperature = FahrenheitToCelsius(temperature);
|
||||
ESP_LOGD(TAG, "set_target_temperature(%f)", temperature);
|
||||
call.set_target_temperature(temperature);
|
||||
} else if (key == "target_temp_high") {
|
||||
temperature = stof(value) / 10;
|
||||
if (id(temp_unit_fahrenheit)) temperature = FahrenheitToCelsius(temperature);
|
||||
if (temp_unit_fahrenheit) temperature = FahrenheitToCelsius(temperature);
|
||||
ESP_LOGD(TAG, "set_target_temperature_high(%f)", temperature);
|
||||
call.set_target_temperature_high(temperature);
|
||||
} else if (key == "target_temp_low") {
|
||||
temperature = stof(value) / 10;
|
||||
if (id(temp_unit_fahrenheit)) temperature = FahrenheitToCelsius(temperature);
|
||||
if (temp_unit_fahrenheit) temperature = FahrenheitToCelsius(temperature);
|
||||
ESP_LOGD(TAG, "set_target_temperature_low(%f)", temperature);
|
||||
call.set_target_temperature_low(temperature);
|
||||
} else if (key == "hvac_mode") {
|
||||
@@ -133,18 +135,20 @@ script:
|
||||
- id: !extend page_climate
|
||||
then:
|
||||
- lambda: |-
|
||||
auto CelsiusToFahrenheit = [](float celsius) -> float {
|
||||
return (celsius * 9 / 5) + 32;
|
||||
};
|
||||
|
||||
id(is_addon_climate_visible) = (current_page->state == "climate" and detailed_entity->state == "embedded_climate");
|
||||
if (id(is_addon_climate_visible)) {
|
||||
static const char *const TAG = "addon_climate_base.script.page_climate";
|
||||
auto CelsiusToFahrenheit = [](float celsius) -> float {
|
||||
return (celsius * 9 / 5) + 32;
|
||||
};
|
||||
std::string temp_units = "${temp_units}";
|
||||
bool temp_unit_fahrenheit = (temp_units == "°F" || temp_units == "F" || temp_units == "°f" || temp_units == "f");
|
||||
ClimateTraits traits = thermostat_embedded->get_traits();
|
||||
|
||||
ESP_LOGV(TAG, "Climate page constructor:");
|
||||
ESP_LOGV(TAG, " Add-on mode: %s", (${addon_climate_dual}) ? "Dual" : ((${addon_climate_heat}) ? "Heat" : ((${addon_climate_cool}) ? "Cool" : "Unknown")));
|
||||
ESP_LOGV(TAG, " Temp. units: %s", id(temp_unit_fahrenheit) ? "Fahrenheit" : "Celsius");
|
||||
ESP_LOGV(TAG, " Temp. units: %s", temp_unit_fahrenheit ? "Fahrenheit" : "Celsius");
|
||||
disp1->set_component_text_printf("page_label", id(addon_climate_friendly_name).c_str());
|
||||
ClimateTraits traits = thermostat_embedded->get_traits();
|
||||
float temp_step = traits.get_visual_target_temperature_step();
|
||||
float temp_offset = traits.get_visual_min_temperature();
|
||||
float temp_max = traits.get_visual_max_temperature();
|
||||
@@ -152,7 +156,7 @@ script:
|
||||
float temp_target_high = thermostat_embedded->target_temperature_high;
|
||||
float temp_target_low = thermostat_embedded->target_temperature_low;
|
||||
float temp_current = thermostat_embedded->current_temperature;
|
||||
if (id(temp_unit_fahrenheit)) {
|
||||
if (temp_unit_fahrenheit) {
|
||||
//temp_step = CelsiusToFahrenheit(temp_step);
|
||||
temp_step = temp_step * 1.8;
|
||||
temp_offset = CelsiusToFahrenheit(temp_offset);
|
||||
|
||||
@@ -322,7 +322,7 @@ api:
|
||||
embedded_climate: bool
|
||||
embedded_climate_friendly_name: string
|
||||
embedded_indoor_temperature: bool
|
||||
temperature_unit_is_fahrenheit: bool
|
||||
temperature_unit_is_fahrenheit: bool # Deprecated
|
||||
mui_please_confirm: string
|
||||
mui_unavailable: string
|
||||
screensaver_time: bool
|
||||
@@ -334,7 +334,7 @@ api:
|
||||
embedded_climate: !lambda "return embedded_climate;"
|
||||
embedded_climate_friendly_name: !lambda "return embedded_climate_friendly_name;"
|
||||
embedded_indoor_temperature: !lambda "return embedded_indoor_temperature;"
|
||||
temperature_unit_is_fahrenheit: !lambda "return temperature_unit_is_fahrenheit;"
|
||||
# temperature_unit_is_fahrenheit: !lambda "return temperature_unit_is_fahrenheit;" # Deprecated
|
||||
mui_please_confirm: !lambda "return mui_please_confirm;"
|
||||
mui_unavailable: !lambda "return mui_unavailable;"
|
||||
screensaver_time: !lambda "return screensaver_time;"
|
||||
@@ -832,12 +832,6 @@ globals:
|
||||
restore_value: true
|
||||
initial_value: 'false'
|
||||
|
||||
##### Temperature unit #####
|
||||
- id: temp_unit_fahrenheit
|
||||
type: bool
|
||||
restore_value: true
|
||||
initial_value: 'false'
|
||||
|
||||
##### Date/time formats #####
|
||||
- id: home_date_color
|
||||
type: uint
|
||||
@@ -1857,9 +1851,10 @@ script:
|
||||
- lambda: |-
|
||||
if (id(embedded_indoor_temp) or (!wifi_component->is_connected()) or (!api_server->is_connected())) {
|
||||
float unit_based_temperature = temp_nspanel->state;
|
||||
if (id(temp_unit_fahrenheit))
|
||||
std::string temp_units = "${temp_units}";
|
||||
if (temp_units == "°F" || temp_units == "F" || temp_units == "°f" || temp_units == "f")
|
||||
unit_based_temperature = (unit_based_temperature * 9 / 5) + 32;
|
||||
disp1->set_component_text_printf("home.current_temp", "%.1f°%s", unit_based_temperature, id(temp_unit_fahrenheit) ? "F" : "C");
|
||||
disp1->set_component_text_printf("home.current_temp", "%.1f${temp_units}", unit_based_temperature);
|
||||
}
|
||||
|
||||
- id: display_wrapped_text
|
||||
@@ -1922,7 +1917,7 @@ script:
|
||||
embedded_climate: bool
|
||||
embedded_climate_friendly_name: string
|
||||
embedded_indoor_temperature: bool
|
||||
temperature_unit_is_fahrenheit: bool
|
||||
# temperature_unit_is_fahrenheit: bool # Deprecated
|
||||
mui_please_confirm: string
|
||||
mui_unavailable: string
|
||||
screensaver_time: bool
|
||||
@@ -1942,7 +1937,6 @@ script:
|
||||
// Indoor temperature
|
||||
ESP_LOGV(TAG, "Set indoor temperature");
|
||||
id(embedded_indoor_temp) = embedded_indoor_temperature;
|
||||
id(temp_unit_fahrenheit) = temperature_unit_is_fahrenheit;
|
||||
display_embedded_temp->execute();
|
||||
|
||||
// MUI strings
|
||||
|
||||
Reference in New Issue
Block a user