ESPHome  2021.10.2
climate.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "esphome/core/helpers.h"
7 #include "esphome/core/log.h"
8 #include "climate_mode.h"
9 #include "climate_traits.h"
10 
11 namespace esphome {
12 namespace climate {
13 
14 #define LOG_CLIMATE(prefix, type, obj) \
15  if ((obj) != nullptr) { \
16  ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
17  }
18 
19 class Climate;
20 
33 class ClimateCall {
34  public:
35  explicit ClimateCall(Climate *parent) : parent_(parent) {}
36 
42  ClimateCall &set_mode(const std::string &mode);
67  ESPDEPRECATED("set_away() is deprecated, please use .set_preset(CLIMATE_PRESET_AWAY) instead", "v1.20")
68  ClimateCall &set_away(bool away);
69  ESPDEPRECATED("set_away() is deprecated, please use .set_preset(CLIMATE_PRESET_AWAY) instead", "v1.20")
70  ClimateCall &set_away(optional<bool> away);
76  ClimateCall &set_fan_mode(const std::string &fan_mode);
84  ClimateCall &set_swing_mode(const std::string &swing_mode);
90  ClimateCall &set_preset(const std::string &preset);
93 
94  void perform();
95 
96  const optional<ClimateMode> &get_mode() const;
100  ESPDEPRECATED("get_away() is deprecated, please use .get_preset() instead", "v1.20")
101  optional<bool> get_away() const;
102  const optional<ClimateFanMode> &get_fan_mode() const;
105  const optional<ClimatePreset> &get_preset() const;
107 
108  protected:
109  void validate_();
110 
111  Climate *const parent_;
121 };
122 
127  bool uses_custom_fan_mode{false};
128  union {
131  };
132  bool uses_custom_preset{false};
133  union {
135  uint8_t custom_preset;
136  };
138  union {
140  struct {
143  };
144  };
145 
147  ClimateCall to_call(Climate *climate);
149  void apply(Climate *climate);
150 } __attribute__((packed));
151 
167 class Climate : public EntityBase {
168  public:
170  Climate();
172  Climate(const std::string &name);
173 
179  float current_temperature{NAN};
180 
181  union {
184  struct {
189  };
190  };
191 
197  ESPDEPRECATED("away is deprecated, use preset instead", "v1.20")
198  bool away{false};
199 
202 
205 
208 
211 
214 
220  void add_on_state_callback(std::function<void()> &&callback);
221 
226  ClimateCall make_call();
227 
233  void publish_state();
234 
240  ClimateTraits get_traits();
241 
242  void set_visual_min_temperature_override(float visual_min_temperature_override);
243  void set_visual_max_temperature_override(float visual_max_temperature_override);
244  void set_visual_temperature_step_override(float visual_temperature_step_override);
245 
246  protected:
247  friend ClimateCall;
248 
250  bool set_fan_mode_(ClimateFanMode mode);
251 
253  bool set_custom_fan_mode_(const std::string &mode);
254 
256  bool set_preset_(ClimatePreset preset);
257 
259  bool set_custom_preset_(const std::string &preset);
260 
267  virtual ClimateTraits traits() = 0;
268 
277  virtual void control(const ClimateCall &call) = 0;
279  optional<ClimateDeviceRestoreState> restore_state_();
283  void save_state_();
284 
285  uint32_t hash_base() override;
286  void dump_traits_(const char *tag);
287 
288  CallbackManager<void()> state_callback_{};
290  optional<float> visual_min_temperature_override_{};
291  optional<float> visual_max_temperature_override_{};
292  optional<float> visual_temperature_step_override_{};
293 };
294 
295 } // namespace climate
296 } // namespace esphome
This class is used to encode all control actions on a climate device.
Definition: climate.h:33
The climate device is off (inactive or no power)
Definition: climate_mode.h:33
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition: climate.h:204
float target_temperature_low
Definition: climate.h:549
optional< std::string > custom_preset_
Definition: climate.h:120
ClimatePreset
Enum for all modes a climate swing can be in.
Definition: climate_mode.h:80
float target_temperature
The target temperature of the climate device.
Definition: climate.h:183
const optional< ClimateMode > & get_mode() const
Definition: climate.cpp:259
optional< float > target_temperature_
Definition: climate.h:113
This class contains all static data for climate devices.
void apply(Climate *climate)
Apply these settings to the climate device.
Struct used to save the state of the climate device in restore memory.
Definition: climate.h:125
optional< ClimateFanMode > fan_mode_
Definition: climate.h:116
const optional< float > & get_target_temperature_low() const
Definition: climate.cpp:261
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
Definition: climate.h:188
optional< float > target_temperature_high_
Definition: climate.h:115
float target_temperature_high
Definition: climate.h:550
bool uses_custom_fan_mode
Definition: climate.h:535
ClimateCall & set_swing_mode(ClimateSwingMode swing_mode)
Set the swing mode of the climate device.
Definition: climate.cpp:228
ClimateSwingMode swing_mode
Definition: climate.h:545
ClimateSwingMode
Enum for all modes a climate swing can be in.
Definition: climate_mode.h:68
optional< std::string > custom_fan_mode
The active custom fan mode of the climate device.
Definition: climate.h:207
ClimateCall & set_target_temperature_low(float target_temperature_low)
Set the low point target temperature of the climate device.
Definition: climate.cpp:251
const optional< std::string > & get_custom_preset() const
Definition: climate.cpp:271
ClimateCall & set_target_temperature(float target_temperature)
Set the target temperature of the climate device.
Definition: climate.cpp:247
optional< ClimateSwingMode > swing_mode_
Definition: climate.h:117
const optional< ClimatePreset > & get_preset() const
Definition: climate.cpp:270
ESPDEPRECATED("away is deprecated, use preset instead", "v1.20") bool away
Whether the climate device is in away mode.
Definition: climate.h:197
optional< ClimatePreset > preset
The active preset of the climate device.
Definition: climate.h:210
optional< ClimatePreset > preset_
Definition: climate.h:119
ClimateCall & set_preset(ClimatePreset preset)
Set the preset of the climate device.
Definition: climate.cpp:192
ClimateAction
Enum for the current action of the climate device. Values match those of ClimateMode.
Definition: climate_mode.h:31
ClimateCall & set_fan_mode(ClimateFanMode fan_mode)
Set the fan mode of the climate device.
Definition: climate.cpp:152
const optional< std::string > & get_custom_fan_mode() const
Definition: climate.cpp:269
const optional< float > & get_target_temperature() const
Definition: climate.cpp:260
optional< std::string > custom_fan_mode_
Definition: climate.h:118
ClimateMode
Enum for all modes a climate device can be in.
Definition: climate_mode.h:10
The climate device is off.
Definition: climate_mode.h:12
ClimateFanMode fan_mode
Definition: climate.h:537
optional< std::string > custom_preset
The active custom preset mode of the climate device.
Definition: climate.h:213
ClimateCall & set_target_temperature_high(float target_temperature_high)
Set the high point target temperature of the climate device.
Definition: climate.cpp:255
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition: climate.h:198
ESPPreferenceObject rtc_
Definition: climate.h:289
const optional< ClimateFanMode > & get_fan_mode() const
Definition: climate.cpp:268
ClimateCall & set_mode(ClimateMode mode)
Set the mode of the climate device.
Definition: climate.cpp:128
ClimateMode mode
Definition: climate.h:534
bool uses_custom_preset
Definition: climate.h:540
const optional< ClimateSwingMode > & get_swing_mode() const
Definition: climate.cpp:272
Library based on https://github.com/miguelbalboa/rfid and adapted to ESPHome by . ...
Definition: a4988.cpp:4
optional< ClimateMode > mode_
Definition: climate.h:112
ClimateCall(Climate *parent)
Definition: climate.h:35
const optional< float > & get_target_temperature_high() const
Definition: climate.cpp:262
ESPDEPRECATED("set_away() is deprecated, please use .set_preset(CLIMATE_PRESET_AWAY) instead", "v1.20") ClimateCall &set_away(bool away)
ClimateCall to_call(Climate *climate)
Convert this struct to a climate call that can be performed.
esphome::climate::Climate __attribute__
optional< float > target_temperature_low_
Definition: climate.h:114
float target_temperature
Definition: climate.h:547
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
Definition: climate.h:186
ClimatePreset preset
Definition: climate.h:542
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:167
Climate *const parent_
Definition: climate.h:111