From dbef2e24b302a6ee5728cee9bd39316318839088 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 9 Feb 2026 11:58:40 -0600 Subject: [PATCH] Fix variables returning non-string types, use identity check for std_string - Revert variables templatable output_type back to None since variable lambdas can return any type (float, int, etc.), not just strings. - Use lazy import identity check (output_type is std_string) instead of brittle string comparison in templatable(). - Clarify ESP8266 populate_service_map comment explaining why STATIC_STRING fast path is not needed (all codegen strings are FLASH_STRING on ESP8266). --- esphome/components/api/homeassistant_service.h | 9 +++++---- esphome/cpp_generator.py | 9 +++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/esphome/components/api/homeassistant_service.h b/esphome/components/api/homeassistant_service.h index cb19dd19a4f..1b8dfbe4121 100644 --- a/esphome/components/api/homeassistant_service.h +++ b/esphome/components/api/homeassistant_service.h @@ -232,10 +232,11 @@ template class HomeAssistantServiceCallAction : public Action cpp_types). + # Identity check (is) avoids brittle string comparison. + if isinstance(value, str) and output_type is not None: + from esphome.cpp_types import std_string + + if output_type is std_string: + return FlashStringLiteral(value) return value if isinstance(to_exp, dict): return to_exp[value]