From 83a634b58d66c515ff6a0ecfa2a214f69931abf9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 29 Apr 2026 06:52:29 -0500 Subject: [PATCH] [light] Take trigger args as const ref in ApplyFn; drop hard-coded byte sizes --- esphome/components/light/automation.h | 10 +++++----- esphome/components/light/automation.py | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/esphome/components/light/automation.h b/esphome/components/light/automation.h index 296042fe42..a5c73997b0 100644 --- a/esphome/components/light/automation.h +++ b/esphome/components/light/automation.h @@ -32,13 +32,13 @@ template class ToggleAction : public A }; // All configured fields are baked into a single stateless lambda whose -// constants live in flash. The action only stores a function pointer -// (4 bytes) plus the parent (4 bytes), regardless of how many fields the -// user set. Trigger args are forwarded to the apply function so user -// lambdas (e.g. `brightness: !lambda "return x;"`) keep working. +// constants live in flash. The action only stores one function pointer +// plus one parent pointer, regardless of how many fields the user set. +// Trigger args are forwarded to the apply function so user lambdas +// (e.g. `brightness: !lambda "return x;"`) keep working. template class LightControlAction : public Action { public: - using ApplyFn = void (*)(LightState *, LightCall &, Ts...); + using ApplyFn = void (*)(LightState *, LightCall &, const Ts &...); LightControlAction(LightState *parent, ApplyFn apply) : parent_(parent), apply_(apply) {} void play(const Ts &...x) override { diff --git a/esphome/components/light/automation.py b/esphome/components/light/automation.py index 18de37150b..ca4018a975 100644 --- a/esphome/components/light/automation.py +++ b/esphome/components/light/automation.py @@ -230,10 +230,11 @@ async def light_control_to_code(config, action_id, template_arg, args): f"call.set_effect(static_cast({_resolve_effect_index(config)}));" ) + # Match LightControlAction::ApplyFn signature: const Ts &... for trigger args. apply_args = [ (LightState.operator("ptr"), "parent"), (LightCall.operator("ref"), "call"), - *args, + *((t.operator("const").operator("ref"), n) for t, n in args), ] apply_lambda = LambdaExpression( ["\n".join(body_lines)],