From c9db3048878c68735476eb2f56c32d5e8e16eebb Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 29 Apr 2026 06:32:11 -0500 Subject: [PATCH] [climate] Pass codegen-known length for static custom_fan_mode/custom_preset --- esphome/components/climate/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/esphome/components/climate/__init__.py b/esphome/components/climate/__init__.py index b033776f27..0f8bdb8ab0 100644 --- a/esphome/components/climate/__init__.py +++ b/esphome/components/climate/__init__.py @@ -515,6 +515,11 @@ async def climate_control_to_code(config, action_id, template_arg, args): if isinstance(value, Lambda): inner = await cg.process_lambda(value, args, return_type=type_) body_lines.append(f"call.{setter}(({inner})({fwd_args}));") + elif type_ is cg.std_string: + # Static custom strings: emit a flash literal and pass the codegen-known + # length to skip the runtime strlen inside set_fan_mode/set_preset. + literal = cg.safe_exp(value) + body_lines.append(f"call.{setter}({literal}, {len(value)});") else: body_lines.append(f"call.{setter}({cg.safe_exp(value)});")