ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
automation.h
Go to the documentation of this file.
1#pragma once
2
4#include "climate.h"
5
6namespace esphome::climate {
7
8// All configured fields are baked into a single stateless lambda whose
9// constants live in flash. The action only stores one function pointer
10// plus one parent pointer, regardless of how many fields the user set.
11// Trigger args are forwarded to the apply function so user lambdas
12// (e.g. `target_temperature: !lambda "return x;"`) keep working.
13//
14// Trigger args are normalized to `const std::remove_cvref_t<Ts> &...` so
15// the codegen can emit a matching parameter list for both the apply lambda
16// and any inner field lambdas without producing invalid C++ source text
17// (e.g. `const T & &` if Ts already carries a reference, or `const const
18// T &` if Ts already carries a const). This keeps trigger args no-copy
19// regardless of whether the trigger supplies `T`, `T &`, or `const T &`.
20template<typename... Ts> class ControlAction : public Action<Ts...> {
21 public:
22 using ApplyFn = void (*)(ClimateCall &, const std::remove_cvref_t<Ts> &...);
24
25 void play(const Ts &...x) override {
26 auto call = this->climate_->make_call();
27 this->apply_(call, x...);
28 call.perform();
29 }
30
31 protected:
34};
35
36class ControlTrigger : public Trigger<ClimateCall &> {
37 public:
39 climate->add_on_control_callback([this](ClimateCall &x) { this->trigger(x); });
40 }
41};
42
43class StateTrigger : public Trigger<Climate &> {
44 public:
46 climate->add_on_state_callback([this](Climate &x) { this->trigger(x); });
47 }
48};
49
50} // namespace esphome::climate
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Definition automation.h:482
This class is used to encode all control actions on a climate device.
Definition climate.h:34
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:187
void add_on_control_callback(F &&callback)
Add a callback for the climate device configuration; each time the configuration parameters of a clim...
Definition climate.h:206
void add_on_state_callback(F &&callback)
Add a callback for the climate device state, each time the state of the climate device is updated (us...
Definition climate.h:196
ClimateCall make_call()
Make a climate device control call, this is used to control the climate device, see the ClimateCall d...
Definition climate.cpp:537
void(*)(ClimateCall &, const std::remove_cvref_t< Ts > &...) ApplyFn
Definition automation.h:22
ControlAction(Climate *climate, ApplyFn apply)
Definition automation.h:23
void play(const Ts &...x) override
Definition automation.h:25
ControlTrigger(Climate *climate)
Definition automation.h:38
StateTrigger(Climate *climate)
Definition automation.h:45
void apply(Climate *climate)
Apply these settings to the climate device.
uint16_t x
Definition tt21100.cpp:5