From f7c452e7a78cb9460fe168762f5690b45ba05859 Mon Sep 17 00:00:00 2001 From: Max Gramser Date: Sat, 19 Sep 2026 17:24:33 +0200 Subject: [PATCH] Every percentage and unit on the screens spaced like Home Assistant, also the tile values and YAML lambdas The standard tile still joined a unit with a space, and the climate status, cover and light values and the slider overlay wrote their own "%": all go through screen_text::with_unit / percent now (54% in Spanish, 54 % in German). Found on the Guition in the end-to-end test. Co-Authored-By: Claude Opus 5 --- components/smart_display/runtime_tiles.h | 2 +- packages/boards/cyd-2432s028.yaml | 3 +-- packages/boards/guition-4848s040.yaml | 3 +-- packages/core.yaml | 10 +++------- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/components/smart_display/runtime_tiles.h b/components/smart_display/runtime_tiles.h index eafb915..b761479 100644 --- a/components/smart_display/runtime_tiles.h +++ b/components/smart_display/runtime_tiles.h @@ -3164,7 +3164,7 @@ inline void render_slot(size_t slot) { else if (d == "media_player") value = tile_controls::media_state_text(t.state); // A measurement in the screen's number format ("21,5 °C" in Dutch), as Home Assistant writes a state with a unit; a // number without one (a code, a year) stays as it is, as there. - else if (!t.unit.empty() && !watch) value = screen_text::localize(value) + " " + t.unit; + else if (!t.unit.empty() && !watch) value = screen_text::with_unit(screen_text::localize(value), t.unit); else if (!t.unit.empty() || d == "number" || d == "input_number" || d == "counter") value = screen_text::localize(value); bool pending=t.loading(esphome::millis()); if(d=="weather" && std::isfinite(t.current)) {value=screen_text::decimal(t.current,1);if(!watch)value=screen_text::with_unit(value,t.unit);} diff --git a/packages/boards/cyd-2432s028.yaml b/packages/boards/cyd-2432s028.yaml index a52f1fb..3e73e77 100644 --- a/packages/boards/cyd-2432s028.yaml +++ b/packages/boards/cyd-2432s028.yaml @@ -691,9 +691,8 @@ script: // What the device does (Heating), else its mode (Heat); then the room. std::string status = off ? std::string(screen_text::tr(screen_text::txt::ha_off)) : std::string(tile_controls::climate_action_text(lower(id(active_climate_action)))); if (status.empty()) status = tile_controls::climate_mode_text(mode); - char part[32]; if (std::isfinite(id(active_climate_current))) status += " · " + screen_text::fill(screen_text::txt::climate_now, "value", screen_text::decimal(id(active_climate_current), 1) + "°"); - if (id(active_climate_humidity) >= 0) { snprintf(part, sizeof(part), " · %d%%", id(active_climate_humidity)); status += part; } + if (id(active_climate_humidity) >= 0) status += " · " + screen_text::percent(id(active_climate_humidity)); lv_label_set_text(id(climate_current_label), status.c_str()); int target = id(active_climate_target_x10); diff --git a/packages/boards/guition-4848s040.yaml b/packages/boards/guition-4848s040.yaml index ae7205d..6d6a56e 100644 --- a/packages/boards/guition-4848s040.yaml +++ b/packages/boards/guition-4848s040.yaml @@ -925,9 +925,8 @@ script: // What the device does (Heating), else its mode (Heat); then the room. std::string status = off ? std::string(screen_text::tr(screen_text::txt::ha_off)) : std::string(tile_controls::climate_action_text(lower(id(active_climate_action)))); if (status.empty()) status = tile_controls::climate_mode_text(mode); - char part[32]; if (std::isfinite(id(active_climate_current))) status += " · " + screen_text::fill(screen_text::txt::climate_now, "value", screen_text::decimal(id(active_climate_current), 1) + "°"); - if (id(active_climate_humidity) >= 0) { snprintf(part, sizeof(part), " · %d%%", id(active_climate_humidity)); status += part; } + if (id(active_climate_humidity) >= 0) status += " · " + screen_text::percent(id(active_climate_humidity)); lv_label_set_text(id(climate_current_label), status.c_str()); int target = id(active_climate_target_x10); diff --git a/packages/core.yaml b/packages/core.yaml index 3e56a77..e95820a 100644 --- a/packages/core.yaml +++ b/packages/core.yaml @@ -3925,9 +3925,7 @@ script: } else if (pct >= 100) { value_text = open_label; } else { - char buf[40]; - snprintf(buf, sizeof(buf), "%s - %d%%", open_label.c_str(), pct); - value_text = buf; + value_text = open_label + " - " + screen_text::percent(pct); } } else { if (pct <= 0) { @@ -4075,7 +4073,7 @@ script: if (mode == "none") return; id(active_entity) = entity; - id(active_value_suffix) = " %"; + id(active_value_suffix) = screen_text::percent_sign(); id(active_label_off) = label_off; id(active_label_on) = label_on; id(active_title) = title; @@ -4184,9 +4182,7 @@ script: } else if (pct >= 100) { value_text = label_on; } else { - char buf[40]; - snprintf(buf, sizeof(buf), "%s - %d%%", label_on.c_str(), pct); - value_text = buf; + value_text = label_on + " - " + screen_text::percent(pct); } } else { if (pct <= 0) {