From 34de46ececaf5ddac857358cf706c83f56fe6d03 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 6 Jan 2026 14:08:58 -1000 Subject: [PATCH] [sun] Eliminate heap allocation in text sensor --- esphome/components/sun/text_sensor/sun_text_sensor.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/esphome/components/sun/text_sensor/sun_text_sensor.h b/esphome/components/sun/text_sensor/sun_text_sensor.h index ce7d21fb86..5cb8fb001d 100644 --- a/esphome/components/sun/text_sensor/sun_text_sensor.h +++ b/esphome/components/sun/text_sensor/sun_text_sensor.h @@ -28,7 +28,13 @@ class SunTextSensor : public text_sensor::TextSensor, public PollingComponent { return; } - this->publish_state(res->strftime(this->format_)); + char buf[128]; + size_t len = res->strftime(buf, sizeof(buf), this->format_.c_str()); + if (len > 0) { + this->publish_state(buf, len); + } else { + this->publish_state("ERROR"); + } } void dump_config() override;