ESPHome  2021.9.3
climate.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/helpers.h"
6 #include "esphome/core/log.h"
7 #include "climate_mode.h"
8 #include "climate_traits.h"
9 
10 namespace esphome {
11 namespace climate {
12 
13 #define LOG_CLIMATE(prefix, type, obj) \
14  if ((obj) != nullptr) { \
15  ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, (obj)->get_name().c_str()); \
16  }
17 
18 class Climate;
19 
32 class ClimateCall {
33  public:
34  explicit ClimateCall(Climate *parent) : parent_(parent) {}
35 
41  ClimateCall &set_mode(const std::string &mode);
66  ESPDEPRECATED("set_away() is deprecated, please use .set_preset(CLIMATE_PRESET_AWAY) instead", "v1.20")
67  ClimateCall &set_away(bool away);
68  ESPDEPRECATED("set_away() is deprecated, please use .set_preset(CLIMATE_PRESET_AWAY) instead", "v1.20")
69  ClimateCall &set_away(optional<bool> away);
75  ClimateCall &set_fan_mode(const std::string &fan_mode);
83  ClimateCall &set_swing_mode(const std::string &swing_mode);
89  ClimateCall &set_preset(const std::string &preset);
92 
93  void perform();
94 
95  const optional<ClimateMode> &get_mode() const;
99  ESPDEPRECATED("get_away() is deprecated, please use .get_preset() instead", "v1.20")
100  optional<bool> get_away() const;
101  const optional<ClimateFanMode> &get_fan_mode() const;
104  const optional<ClimatePreset> &get_preset() const;
106 
107  protected:
108  void validate_();
109 
110  Climate *const parent_;
120 };
121 
126  bool uses_custom_fan_mode{false};
127  union {
130  };
131  bool uses_custom_preset{false};
132  union {
134  uint8_t custom_preset;
135  };
137  union {
139  struct {
142  };
143  };
144 
146  ClimateCall to_call(Climate *climate);
148  void apply(Climate *climate);
149 } __attribute__((packed));
150 
166 class Climate : public Nameable {
167  public:
169  Climate();
171  Climate(const std::string &name);
172 
178  float current_temperature{NAN};
179 
180  union {
183  struct {
188  };
189  };
190 
196  ESPDEPRECATED("away is deprecated, use preset instead", "v1.20")
197  bool away{false};
198 
201 
204 
207 
210 
213 
219  void add_on_state_callback(std::function<void()> &&callback);
220 
225  ClimateCall make_call();
226 
232  void publish_state();
233 
239  ClimateTraits get_traits();
240 
241  void set_visual_min_temperature_override(float visual_min_temperature_override);
242  void set_visual_max_temperature_override(float visual_max_temperature_override);
243  void set_visual_temperature_step_override(float visual_temperature_step_override);
244 
245  protected:
246  friend ClimateCall;
247 
249  bool set_fan_mode_(ClimateFanMode mode);
250 
252  bool set_custom_fan_mode_(const std::string &mode);
253 
255  bool set_preset_(ClimatePreset preset);
256 
258  bool set_custom_preset_(const std::string &preset);
259 
266  virtual ClimateTraits traits() = 0;
267 
276  virtual void control(const ClimateCall &call) = 0;
278  optional<ClimateDeviceRestoreState> restore_state_();
282  void save_state_();
283 
284  uint32_t hash_base() override;
285  void dump_traits_(const char *tag);
286 
287  CallbackManager<void()> state_callback_{};
289  optional<float> visual_min_temperature_override_{};
290  optional<float> visual_max_temperature_override_{};
291  optional<float> visual_temperature_step_override_{};
292 };
293 
294 } // namespace climate
295 } // namespace esphome
This class is used to encode all control actions on a climate device.
Definition: climate.h:32
The climate device is off (inactive or no power)
Definition: climate_mode.h:32
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition: climate.h:203
float target_temperature_low
Definition: climate.h:537
optional< std::string > custom_preset_
Definition: climate.h:119
ClimatePreset
Enum for all modes a climate swing can be in.
Definition: climate_mode.h:79
float target_temperature
The target temperature of the climate device.
Definition: climate.h:182
const optional< ClimateMode > & get_mode() const
Definition: climate.cpp:257
optional< float > target_temperature_
Definition: climate.h:112
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:124
optional< ClimateFanMode > fan_mode_
Definition: climate.h:115
const optional< float > & get_target_temperature_low() const
Definition: climate.cpp:259
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
Definition: climate.h:187
optional< float > target_temperature_high_
Definition: climate.h:114
float target_temperature_high
Definition: climate.h:538
bool uses_custom_fan_mode
Definition: climate.h:523
ClimateCall & set_swing_mode(ClimateSwingMode swing_mode)
Set the swing mode of the climate device.
Definition: climate.cpp:226
ClimateSwingMode swing_mode
Definition: climate.h:533
ClimateSwingMode
Enum for all modes a climate swing can be in.
Definition: climate_mode.h:67
optional< std::string > custom_fan_mode
The active custom fan mode of the climate device.
Definition: climate.h:206
ClimateCall & set_target_temperature_low(float target_temperature_low)
Set the low point target temperature of the climate device.
Definition: climate.cpp:249
const optional< std::string > & get_custom_preset() const
Definition: climate.cpp:269
ClimateCall & set_target_temperature(float target_temperature)
Set the target temperature of the climate device.
Definition: climate.cpp:245
optional< ClimateSwingMode > swing_mode_
Definition: climate.h:116
const optional< ClimatePreset > & get_preset() const
Definition: climate.cpp:268
ESPDEPRECATED("away is deprecated, use preset instead", "v1.20") bool away
Whether the climate device is in away mode.
Definition: climate.h:196
optional< ClimatePreset > preset
The active preset of the climate device.
Definition: climate.h:209
optional< ClimatePreset > preset_
Definition: climate.h:118
ClimateCall & set_preset(ClimatePreset preset)
Set the preset of the climate device.
Definition: climate.cpp:190
ClimateAction
Enum for the current action of the climate device. Values match those of ClimateMode.
Definition: climate_mode.h:30
ClimateCall & set_fan_mode(ClimateFanMode fan_mode)
Set the fan mode of the climate device.
Definition: climate.cpp:150
const optional< std::string > & get_custom_fan_mode() const
Definition: climate.cpp:267
const optional< float > & get_target_temperature() const
Definition: climate.cpp:258
optional< std::string > custom_fan_mode_
Definition: climate.h:117
ClimateMode
Enum for all modes a climate device can be in.
Definition: climate_mode.h:9
The climate device is off.
Definition: climate_mode.h:11
ClimateFanMode fan_mode
Definition: climate.h:525
Helper class that enables naming of objects so that it doesn&#39;t have to be re-implement every time...
Definition: component.h:264
optional< std::string > custom_preset
The active custom preset mode of the climate device.
Definition: climate.h:212
ClimateCall & set_target_temperature_high(float target_temperature_high)
Set the high point target temperature of the climate device.
Definition: climate.cpp:253
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition: climate.h:197
ESPPreferenceObject rtc_
Definition: climate.h:288
const optional< ClimateFanMode > & get_fan_mode() const
Definition: climate.cpp:266
ClimateCall & set_mode(ClimateMode mode)
Set the mode of the climate device.
Definition: climate.cpp:126
ClimateMode mode
Definition: climate.h:522
bool uses_custom_preset
Definition: climate.h:528
const optional< ClimateSwingMode > & get_swing_mode() const
Definition: climate.cpp:270
Library based on https://github.com/miguelbalboa/rfid and adapted to ESPHome by . ...
Definition: a4988.cpp:4
optional< ClimateMode > mode_
Definition: climate.h:111
ClimateCall(Climate *parent)
Definition: climate.h:34
const optional< float > & get_target_temperature_high() const
Definition: climate.cpp:260
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:113
float target_temperature
Definition: climate.h:535
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
Definition: climate.h:185
ClimatePreset preset
Definition: climate.h:530
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:166
Climate *const parent_
Definition: climate.h:110