From e862b4f5fdf76654d44d9ecb9fe5025c59cb3db8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 7 Apr 2026 11:23:37 -1000 Subject: [PATCH] reduce --- esphome/components/light/automation.h | 34 ++++++++++----------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/esphome/components/light/automation.h b/esphome/components/light/automation.h index 0b570ab752..7f6c48b29d 100644 --- a/esphome/components/light/automation.h +++ b/esphome/components/light/automation.h @@ -53,34 +53,26 @@ template class LightControlAction : public Action { X(float, warm_white) \ X(uint32_t, effect) -#define LIGHT_CONTROL_SETTER_(type, name) \ - template void set_##name(F f) { \ - static_assert(std::convertible_to, \ - "LightControlAction: only stateless lambdas are supported"); \ - this->name##_ = static_cast(f); \ - } - -#define APPLY_LIGHT_FIELD_(type, name) \ - if (this->name##_) call.set_##name(this->name##_(x...)); +#define LIGHT_FIELD_SETTER_(type, name) void set_##name(type (*f)(Ts...)) { this->name##_ = f; } +#define LIGHT_FIELD_APPLY_(type, name) if (this->name##_) call.set_##name(this->name##_(x...)); +#define LIGHT_FIELD_DECL_(type, name) type (*name##_)(Ts...){nullptr}; // clang-format on - protected: -#define LIGHT_CONTROL_FIELD_DECL_(type, name) type (*name##_)(Ts...){nullptr}; - - LightState *parent_; - LIGHT_CONTROL_FIELDS(LIGHT_CONTROL_FIELD_DECL_) -#undef LIGHT_CONTROL_FIELD_DECL_ - - public: - LIGHT_CONTROL_FIELDS(LIGHT_CONTROL_SETTER_) -#undef LIGHT_CONTROL_SETTER_ + LIGHT_CONTROL_FIELDS(LIGHT_FIELD_SETTER_) void play(const Ts &...x) override { auto call = this->parent_->make_call(); - LIGHT_CONTROL_FIELDS(APPLY_LIGHT_FIELD_) + LIGHT_CONTROL_FIELDS(LIGHT_FIELD_APPLY_) call.perform(); } -#undef APPLY_LIGHT_FIELD_ + + protected: + LightState *parent_; + LIGHT_CONTROL_FIELDS(LIGHT_FIELD_DECL_) + +#undef LIGHT_FIELD_DECL_ +#undef LIGHT_FIELD_APPLY_ +#undef LIGHT_FIELD_SETTER_ #undef LIGHT_CONTROL_FIELDS };