From 6d0c61dc738c46b8ccaedd47d309bd4da606b2e2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 7 Apr 2026 14:17:41 -1000 Subject: [PATCH] [core] Use TemplatableStorage alias to select TemplatableFn or TemplatableValue TEMPLATABLE_VALUE macro now uses TemplatableStorage which selects TemplatableFn for non-string types (4 bytes) and TemplatableValue for std::string (full PROGMEM/FlashStringHelper support). Fixes ESP8266 compile failure where __FlashStringHelper* couldn't assign to TemplatableFn. --- esphome/core/automation.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/esphome/core/automation.h b/esphome/core/automation.h index 3b04373fc6..d286782293 100644 --- a/esphome/core/automation.h +++ b/esphome/core/automation.h @@ -62,9 +62,18 @@ template class TemplatableFn { T (*f_)(X...){nullptr}; }; +// Forward declaration for TemplatableValue (string specialization needs it) +template class TemplatableValue; + +/// Selects TemplatableFn (4 bytes) for non-string types, TemplatableValue (8 bytes) for std::string. +/// std::string needs TemplatableValue for const char*, __FlashStringHelper*, and PROGMEM support. +template +using TemplatableStorage = + std::conditional_t, TemplatableValue, TemplatableFn>; + #define TEMPLATABLE_VALUE_(type, name) \ protected: \ - TemplatableFn name##_{}; \ + TemplatableStorage name##_{}; \ \ public: \ template void set_##name(V name) { this->name##_ = name; }