ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
climate_ir.cpp
Go to the documentation of this file.
1#include "climate_ir.h"
2#include "esphome/core/log.h"
3
5
6ESPHOME_LOG_TAG(TAG, "climate_ir");
7
26
27void ClimateIR::setup() { this->setup_(this->restore_state_()); }
28
29void ClimateIR::setup_(optional<climate::ClimateDeviceRestoreState> restore) {
30 if (this->sensor_) {
31 this->sensor_->add_on_state_callback([this](float state) {
33 // current temperature changed, publish state
34 this->publish_state();
35 });
36 this->current_temperature = this->sensor_->state;
37 }
38 if (this->humidity_sensor_ != nullptr) {
39 this->humidity_sensor_->add_on_state_callback([this](float state) {
40 this->current_humidity = state;
41 // current humidity changed, publish state
42 this->publish_state();
43 });
45 }
46
47 // restore set points
48 if (restore.has_value()) {
49 restore->apply(this);
50 } else {
51 // restore from defaults
53 // initialize target temperature to some value so that it's not NAN
54 this->target_temperature =
55 roundf(clamp(this->current_temperature, this->minimum_temperature_, this->maximum_temperature_));
59 }
60 // Never send nan to HA
61 if (std::isnan(this->target_temperature))
62 this->target_temperature = 24;
63}
64
66 auto mode = call.get_mode();
67 if (mode.has_value())
68 this->mode = *mode;
70 if (target_temperature.has_value())
72 auto fan_mode = call.get_fan_mode();
73 if (fan_mode.has_value())
74 this->fan_mode = fan_mode;
75 auto swing_mode = call.get_swing_mode();
76 if (swing_mode.has_value())
77 this->swing_mode = *swing_mode;
78 auto preset = call.get_preset();
79 if (preset.has_value())
80 this->preset = preset;
81 this->transmit_state();
82 this->publish_state();
83}
85 LOG_CLIMATE("", "IR Climate", this);
86 ESP_LOGCONFIG(TAG,
87 " Min. Temperature: %.1f°C\n"
88 " Max. Temperature: %.1f°C\n"
89 " Supports HEAT: %s\n"
90 " Supports COOL: %s\n"
91 " Supports HEAT_COOL: %s",
96}
97
98} // namespace esphome::climate_ir
constexpr size_t count(ValueType value) const
Check if the set contains a specific value (std::set compatibility) Returns 1 if present,...
This class is used to encode all control actions on a climate device.
Definition climate.h:31
const optional< ClimateSwingMode > & get_swing_mode() const
Definition climate.cpp:317
const optional< float > & get_target_temperature() const
Definition climate.cpp:310
const optional< ClimatePreset > & get_preset() const
Definition climate.cpp:318
const optional< ClimateFanMode > & get_fan_mode() const
Definition climate.cpp:316
ClimateMode mode
The active mode of the climate device.
Definition climate.h:317
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:311
float target_temperature
The target temperature of the climate device.
Definition climate.h:298
float current_humidity
The current humidity of the climate device, as reported from the integration.
Definition climate.h:294
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:323
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition climate.h:291
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:432
optional< ClimatePreset > preset
The active preset of the climate device.
Definition climate.h:314
optional< ClimateDeviceRestoreState > restore_state_()
Restore the state of the climate device, call this from your setup() method.
Definition climate.cpp:365
void set_visual_max_temperature(float visual_max_temperature)
void add_feature_flags(uint32_t feature_flags)
void set_visual_temperature_step(float temperature_step)
void set_supported_presets(ClimatePresetMask presets)
void set_supported_swing_modes(ClimateSwingModeMask modes)
void set_visual_min_temperature(float visual_min_temperature)
void set_supported_modes(ClimateModeMask modes)
void set_supported_fan_modes(ClimateFanModeMask modes)
climate::ClimatePresetMask presets_
Definition climate_ir.h:84
climate::ClimateFanModeMask fan_modes_
Definition climate_ir.h:82
climate::ClimateSwingModeMask swing_modes_
Definition climate_ir.h:83
void control(const climate::ClimateCall &call) override
Override control to change settings of the climate device.
sensor::Sensor * humidity_sensor_
Definition climate_ir.h:87
climate::ClimateTraits traits() override
Return the traits of this controller.
Definition climate_ir.cpp:8
virtual void transmit_state()=0
Transmit via IR the state of this climate controller.
void setup_(optional< climate::ClimateDeviceRestoreState > restore)
setup() with the restored state already loaded, for subclasses that read it first.
climate::ClimateModeMask modes_
Definition climate_ir.h:81
void add_on_state_callback(F &&callback)
Add a callback that will be called every time a filtered value arrives.
Definition sensor.h:121
float state
This member variable stores the last state that has passed through all filters.
Definition sensor.h:140
bool state
Definition fan.h:2
ESPHOME_LOG_TAG(TAG, "climate_ir")
@ CLIMATE_SUPPORTS_CURRENT_HUMIDITY
@ CLIMATE_SUPPORTS_CURRENT_TEMPERATURE
@ CLIMATE_PRESET_NONE
No preset is active.
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
@ CLIMATE_MODE_HEAT
The climate device is set to heat to reach the target temperature.
@ CLIMATE_MODE_COOL
The climate device is set to cool to reach the target temperature.
@ CLIMATE_MODE_HEAT_COOL
The climate device is set to heat/cool to reach the target temperature.
@ CLIMATE_MODE_OFF
The climate device is off.
@ CLIMATE_FAN_AUTO
The fan mode is set to Auto.