mirror of
https://github.com/esphome/esphome.git
synced 2026-09-11 23:37:34 +00:00
[light] Take trigger args as const ref in ApplyFn; drop hard-coded byte sizes
This commit is contained in:
@@ -32,13 +32,13 @@ template<bool HasTransitionLength, typename... Ts> 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<typename... Ts> class LightControlAction : public Action<Ts...> {
|
||||
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 {
|
||||
|
||||
@@ -230,10 +230,11 @@ async def light_control_to_code(config, action_id, template_arg, args):
|
||||
f"call.set_effect(static_cast<uint32_t>({_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)],
|
||||
|
||||
Reference in New Issue
Block a user