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)],