ESPHome  2023.8.3
Go to the documentation of this file.
1 #pragma once
4 #include "climate.h"
6 namespace esphome {
7 namespace climate {
9 template<typename... Ts> class ControlAction : public Action<Ts...> {
10  public:
11  explicit ControlAction(Climate *climate) : climate_(climate) {}
17  TEMPLATABLE_VALUE(bool, away)
21  TEMPLATABLE_VALUE(std::string, custom_preset)
24  void play(Ts... x) override {
25  auto call = this->climate_->make_call();
26  call.set_mode(this->mode_.optional_value(x...));
27  call.set_target_temperature(this->target_temperature_.optional_value(x...));
28  call.set_target_temperature_low(this->target_temperature_low_.optional_value(x...));
29  call.set_target_temperature_high(this->target_temperature_high_.optional_value(x...));
30  if (away_.has_value()) {
31  call.set_preset(away_.value(x...) ? CLIMATE_PRESET_AWAY : CLIMATE_PRESET_HOME);
32  }
33  call.set_fan_mode(this->fan_mode_.optional_value(x...));
34  call.set_fan_mode(this->custom_fan_mode_.optional_value(x...));
35  call.set_preset(this->preset_.optional_value(x...));
36  call.set_preset(this->custom_preset_.optional_value(x...));
37  call.set_swing_mode(this->swing_mode_.optional_value(x...));
38  call.perform();
39  }
41  protected:
43 };
45 class ControlTrigger : public Trigger<ClimateCall &> {
46  public:
47  ControlTrigger(Climate *climate) {
48  climate->add_on_control_callback([this](ClimateCall &x) { this->trigger(x); });
49  }
50 };
52 class StateTrigger : public Trigger<Climate &> {
53  public:
54  StateTrigger(Climate *climate) {
55  climate->add_on_state_callback([this](Climate &x) { this->trigger(x); });
56  }
57 };
59 } // namespace climate
60 } // namespace esphome
This class is used to encode all control actions on a climate device.
Definition: climate.h:33
float target_temperature_low
Definition: climate.h:543
Enum for all preset modes.
Definition: climate_mode.h:82
Device is in home preset.
Definition: climate_mode.h:86
uint16_t x
Definition: tt21100.cpp:17
void add_on_control_callback(std::function< void(ClimateCall &)> &&callback)
Add a callback for the climate device configuration; each time the configuration parameters of a clim...
Definition: climate.cpp:307
float target_temperature_high
Definition: climate.h:544
ClimateCall & set_swing_mode(ClimateSwingMode swing_mode)
Set the swing mode of the climate device.
Definition: climate.cpp:232
ClimateSwingMode swing_mode
Definition: climate.h:539
Enum for all modes a climate swing can be in.
Definition: climate_mode.h:70
Device is in away preset.
Definition: climate_mode.h:88
ClimateCall & set_target_temperature_low(float target_temperature_low)
Set the low point target temperature of the climate device.
Definition: climate.cpp:255
StateTrigger(Climate *climate)
Definition: automation.h:54
ClimateCall make_call()
Make a climate device control call, this is used to control the climate device, see the ClimateCall d...
Definition: climate.cpp:443
ClimateCall & set_target_temperature(float target_temperature)
Set the target temperature of the climate device.
Definition: climate.cpp:251
uint8_t custom_preset
Definition: climate.h:537
ClimateCall & set_preset(ClimatePreset preset)
Set the preset of the climate device.
Definition: climate.cpp:196
BedjetMode mode
BedJet operating mode.
Definition: bedjet_codec.h:151
ClimateCall & set_fan_mode(ClimateFanMode fan_mode)
Set the fan mode of the climate device.
Definition: climate.cpp:154
ControlTrigger(Climate *climate)
Definition: automation.h:47
Enum for all modes a climate device can be in.
Definition: climate_mode.h:10
ClimateFanMode fan_mode
Definition: climate.h:531
void add_on_state_callback(std::function< void(Climate &)> &&callback)
Add a callback for the climate device state, each time the state of the climate device is updated (us...
Definition: climate.cpp:303
ControlAction(Climate *climate)
Definition: automation.h:11
ClimateCall & set_target_temperature_high(float target_temperature_high)
Set the high point target temperature of the climate device.
Definition: climate.cpp:259
ClimateCall & set_mode(ClimateMode mode)
Set the mode of the climate device.
Definition: climate.cpp:130
target_temperature target_temperature_high fan_mode preset swing_mode void play(Ts... x) override
Definition: automation.h:24
uint8_t custom_fan_mode
Definition: climate.h:532
float target_temperature
Definition: climate.h:541
ClimatePreset preset
Definition: climate.h:536
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:161