From 455e1f06e40db49e585789e945be5007f7585fff Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Tue, 27 Feb 2024 11:43:03 +0100 Subject: [PATCH] User defined decimal separator for embedded temperature Solves #1161 --- esphome/nspanel_esphome_core.yaml | 14 ++++++++------ nspanel_blueprint.yaml | 3 --- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/esphome/nspanel_esphome_core.yaml b/esphome/nspanel_esphome_core.yaml index 9938c6f..16fe753 100644 --- a/esphome/nspanel_esphome_core.yaml +++ b/esphome/nspanel_esphome_core.yaml @@ -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 diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index 231e22c..8ac2e3f 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -3237,13 +3237,10 @@ blueprint: *SYSTEM settings* *Choose the decimal separator for displaying numbers.* - - *For custom separators not listed, please type your preferred character directly.* default: '.' selector: select: multiple: false - custom_value: true options: - label: '. (Dot)' value: '.'