User defined decimal separator for embedded temperature

Solves #1161
This commit is contained in:
Edward Firmo
2024-02-27 11:43:03 +01:00
parent ea474098c8
commit 455e1f06e4
2 changed files with 8 additions and 9 deletions

View File

@@ -1810,13 +1810,15 @@ script:
mode: restart
then:
- lambda: |-
if (id(embedded_indoor_temp) or (!wifi_component->is_connected()) or (!api_server->is_connected())) {
float unit_based_temperature = temp_nspanel->state;
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.indr_temp", "%.1f${temp_units}", unit_based_temperature);
float unit_based_temperature = id(temp_nspanel).state;
char buffer[15]; // Buffer for formatted temperature string
if ("${temp_units}"[0] == 'F' || "${temp_units}"[0] == 'f') {
unit_based_temperature = (unit_based_temperature * 9.0 / 5.0) + 32; // Convert to Fahrenheit if necessary
snprintf(buffer, sizeof(buffer), "%.0f°F", unit_based_temperature); // Fahrenheit with no decimal
} else {
snprintf(buffer, sizeof(buffer), "%.1f°C", unit_based_temperature); // Celsius with one decimal
}
id(disp1)->set_component_text("home.indr_temp", adjustDecimalSeparator(buffer, id(mui_decimal_separator)).c_str());
- id: display_wrapped_text
mode: parallel