ESPHome  2021.11.3
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 (supports_cool_)
15  if (supports_heat_)
17  if (supports_dry_)
28  return traits;
29 }
32  if (this->sensor_) {
33  this->sensor_->add_on_state_callback([this](float state) {
34  this->current_temperature = state;
35  // current temperature changed, publish state
36  this->publish_state();
37  });
38  this->current_temperature = this->sensor_->state;
39  } else
40  this->current_temperature = NAN;
41  // restore set points
42  auto restore = this->restore_state_();
43  if (restore.has_value()) {
44  restore->apply(this);
45  } else {
46  // restore from defaults
48  // initialize target temperature to some value so that it's not NAN
49  this->target_temperature =
53  }
54  // Never send nan to HA
55  if (std::isnan(this->target_temperature))
56  this->target_temperature = 24;
57 }
60  if (call.get_mode().has_value())
61  this->mode = *call.get_mode();
62  if (call.get_target_temperature().has_value())
64  if (call.get_fan_mode().has_value())
65  this->fan_mode = *call.get_fan_mode();
66  if (call.get_swing_mode().has_value())
67  this->swing_mode = *call.get_swing_mode();
68  this->transmit_state();
69  this->publish_state();
70 }
72  LOG_CLIMATE("", "IR Climate", this);
73  ESP_LOGCONFIG(TAG, " Min. Temperature: %.1f°C", this->minimum_temperature_);
74  ESP_LOGCONFIG(TAG, " Max. Temperature: %.1f°C", this->maximum_temperature_);
75  ESP_LOGCONFIG(TAG, " Supports HEAT: %s", YESNO(this->supports_heat_));
76  ESP_LOGCONFIG(TAG, " Supports COOL: %s", YESNO(this->supports_cool_));
77 }
79 } // namespace climate_ir
80 } // 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:63
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition: climate.h:204
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:71
void set_visual_temperature_step(float temperature_step)
float target_temperature
The target temperature of the climate device.
Definition: climate.h:183
const optional< ClimateMode > & get_mode() const
Definition: climate.cpp:259
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:175
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 control(const climate::ClimateCall &call) override
Override control to change settings of the climate device.
Definition: climate_ir.cpp:59
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:132
void set_supported_fan_modes(std::set< ClimateFanMode > modes)
The fan mode is set to Auto.
Definition: climate_mode.h:52
void set_supported_modes(std::set< ClimateMode > modes)
T clamp(const T val, const T min, const T max)
Clamp the value between min and max.
Definition: helpers.cpp:321
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:260
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition: climate.cpp:380
The swing mode is set to Off.
Definition: climate_mode.h:70
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:198
const optional< ClimateFanMode > & get_fan_mode() const
Definition: climate.cpp:268
const optional< ClimateSwingMode > & get_swing_mode() const
Definition: climate.cpp:272
Library based on and adapted to ESPHome by . ...
Definition: a4988.cpp:4
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:320
void set_supports_current_temperature(bool supports_current_temperature)
std::set< climate::ClimateFanMode > fan_modes_
Definition: climate_ir.h:62
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:66
void add_supported_mode(ClimateMode mode)