ESPHome  2024.5.4
Go to the documentation of this file.
1 #include "climate_ir.h"
2 #include "esphome/core/log.h"
4 namespace esphome {
5 namespace climate_ir {
7 static const char *const TAG = "climate_ir";
13  if (this->supports_cool_)
15  if (this->supports_heat_)
17  if (this->supports_dry_)
19  if (this->supports_fan_only_)
29  return traits;
30 }
33  if (this->sensor_) {
34  this->sensor_->add_on_state_callback([this](float state) {
35  this->current_temperature = state;
36  // current temperature changed, publish state
37  this->publish_state();
38  });
39  this->current_temperature = this->sensor_->state;
40  } else
41  this->current_temperature = NAN;
42  // restore set points
43  auto restore = this->restore_state_();
44  if (restore.has_value()) {
45  restore->apply(this);
46  } else {
47  // restore from defaults
49  // initialize target temperature to some value so that it's not NAN
50  this->target_temperature =
55  }
56  // Never send nan to HA
57  if (std::isnan(this->target_temperature))
58  this->target_temperature = 24;
59 }
62  if (call.get_mode().has_value())
63  this->mode = *call.get_mode();
64  if (call.get_target_temperature().has_value())
66  if (call.get_fan_mode().has_value())
67  this->fan_mode = *call.get_fan_mode();
68  if (call.get_swing_mode().has_value())
69  this->swing_mode = *call.get_swing_mode();
70  if (call.get_preset().has_value())
71  this->preset = *call.get_preset();
72  this->transmit_state();
73  this->publish_state();
74 }
76  LOG_CLIMATE("", "IR Climate", this);
77  ESP_LOGCONFIG(TAG, " Min. Temperature: %.1f°C", this->minimum_temperature_);
78  ESP_LOGCONFIG(TAG, " Max. Temperature: %.1f°C", this->maximum_temperature_);
79  ESP_LOGCONFIG(TAG, " Supports HEAT: %s", YESNO(this->supports_heat_));
80  ESP_LOGCONFIG(TAG, " Supports COOL: %s", YESNO(this->supports_cool_));
81 }
83 } // namespace climate_ir
84 } // namespace esphome
This class is used to encode all control actions on a climate device.
Definition: climate.h:33
std::set< climate::ClimateSwingMode > swing_modes_
Definition: climate_ir.h:64
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition: climate.h:202
void add_on_state_callback(std::function< void(float)> &&callback)
Add a callback that will be called every time a filtered value arrives.
Definition: sensor.cpp:52
void set_visual_temperature_step(float temperature_step)
float target_temperature
The target temperature of the climate device.
Definition: climate.h:186
const optional< ClimateMode > & get_mode() const
Definition: climate.cpp:273
This class contains all static data for climate devices.
void set_visual_min_temperature(float visual_min_temperature)
The climate device is set to heat to reach the target temperature.
Definition: climate_mode.h:18
virtual void transmit_state()=0
Transmit via IR the state of this climate controller.
ClimateMode mode
The active mode of the climate device.
Definition: climate.h:173
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition: climate.h:179
bool has_value() const
Definition: optional.h:87
The climate device is set to dry/humidity mode.
Definition: climate_mode.h:22
void set_supported_presets(std::set< ClimatePreset > presets)
void control(const climate::ClimateCall &call) override
Override control to change settings of the climate device.
Definition: climate_ir.cpp:61
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
Definition: helpers.h:92
The climate device is set to cool to reach the target temperature.
Definition: climate_mode.h:16
float state
This member variable stores the last state that has passed through all filters.
Definition: sensor.h:131
const optional< ClimatePreset > & get_preset() const
Definition: climate.cpp:280
void set_supported_fan_modes(std::set< ClimateFanMode > modes)
The fan mode is set to Auto.
Definition: climate_mode.h:52
optional< ClimatePreset > preset
The active preset of the climate device.
Definition: climate.h:208
void set_supported_modes(std::set< ClimateMode > modes)
std::set< climate::ClimatePreset > presets_
Definition: climate_ir.h:65
void set_visual_max_temperature(float visual_max_temperature)
The climate device is set to heat/cool to reach the target temperature.
Definition: climate_mode.h:14
const optional< float > & get_target_temperature() const
Definition: climate.cpp:274
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition: climate.cpp:395
The swing mode is set to Off.
Definition: climate_mode.h:72
The climate device is off.
Definition: climate_mode.h:12
climate::ClimateTraits traits() override
Return the traits of this controller.
Definition: climate_ir.cpp:9
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition: climate.h:199
const optional< ClimateFanMode > & get_fan_mode() const
Definition: climate.cpp:278
const optional< ClimateSwingMode > & get_swing_mode() const
Definition: climate.cpp:282
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
void set_supported_swing_modes(std::set< ClimateSwingMode > modes)
void set_supports_two_point_target_temperature(bool supports_two_point_target_temperature)
optional< ClimateDeviceRestoreState > restore_state_()
Restore the state of the climate device, call this from your setup() method.
Definition: climate.cpp:329
void set_supports_current_temperature(bool supports_current_temperature)
std::set< climate::ClimateFanMode > fan_modes_
Definition: climate_ir.h:63
The climate device only has the fan enabled, no heating or cooling is taking place.
Definition: climate_mode.h:20
sensor::Sensor * sensor_
Definition: climate_ir.h:67
void add_supported_mode(ClimateMode mode)
bool state
Definition: fan.h:34