ESPHome 2025.12.1
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
4namespace esphome {
5namespace climate_ir {
6
7static const char *const TAG = "climate_ir";
8
35
37 if (this->sensor_) {
38 this->sensor_->add_on_state_callback([this](float state) {
40 // current temperature changed, publish state
41 this->publish_state();
42 });
43 this->current_temperature = this->sensor_->state;
44 }
45 if (this->humidity_sensor_ != nullptr) {
46 this->humidity_sensor_->add_on_state_callback([this](float state) {
47 this->current_humidity = state;
48 // current humidity changed, publish state
49 this->publish_state();
50 });
52 }
53
54 // restore set points
55 auto restore = this->restore_state_();
56 if (restore.has_value()) {
57 restore->apply(this);
58 } else {
59 // restore from defaults
61 // initialize target temperature to some value so that it's not NAN
62 this->target_temperature =
63 roundf(clamp(this->current_temperature, this->minimum_temperature_, this->maximum_temperature_));
67 }
68 // Never send nan to HA
69 if (std::isnan(this->target_temperature))
70 this->target_temperature = 24;
71}
72
74 if (call.get_mode().has_value())
75 this->mode = *call.get_mode();
76 if (call.get_target_temperature().has_value())
78 if (call.get_fan_mode().has_value())
79 this->fan_mode = *call.get_fan_mode();
80 if (call.get_swing_mode().has_value())
81 this->swing_mode = *call.get_swing_mode();
82 if (call.get_preset().has_value())
83 this->preset = *call.get_preset();
84 this->transmit_state();
85 this->publish_state();
86}
88 LOG_CLIMATE("", "IR Climate", this);
89 ESP_LOGCONFIG(TAG,
90 " Min. Temperature: %.1f°C\n"
91 " Max. Temperature: %.1f°C\n"
92 " Supports HEAT: %s\n"
93 " Supports COOL: %s",
95 YESNO(this->supports_cool_));
96}
97
98} // namespace climate_ir
99} // namespace esphome
This class is used to encode all control actions on a climate device.
Definition climate.h:32
const optional< ClimateSwingMode > & get_swing_mode() const
Definition climate.cpp:293
const optional< float > & get_target_temperature() const
Definition climate.cpp:286
const optional< ClimatePreset > & get_preset() const
Definition climate.cpp:294
const optional< ClimateFanMode > & get_fan_mode() const
Definition climate.cpp:292
const optional< ClimateMode > & get_mode() const
Definition climate.cpp:291
ClimateMode mode
The active mode of the climate device.
Definition climate.h:255
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:249
float target_temperature
The target temperature of the climate device.
Definition climate.h:236
float current_humidity
The current humidity of the climate device, as reported from the integration.
Definition climate.h:232
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:261
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition climate.h:229
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:425
optional< ClimatePreset > preset
The active preset of the climate device.
Definition climate.h:252
optional< ClimateDeviceRestoreState > restore_state_()
Restore the state of the climate device, call this from your setup() method.
Definition climate.cpp:349
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 add_supported_mode(ClimateMode mode)
void set_supported_fan_modes(ClimateFanModeMask modes)
climate::ClimatePresetMask presets_
Definition climate_ir.h:68
climate::ClimateFanModeMask fan_modes_
Definition climate_ir.h:66
climate::ClimateSwingModeMask swing_modes_
Definition climate_ir.h:67
void control(const climate::ClimateCall &call) override
Override control to change settings of the climate device.
sensor::Sensor * humidity_sensor_
Definition climate_ir.h:71
climate::ClimateTraits traits() override
Return the traits of this controller.
Definition climate_ir.cpp:9
virtual void transmit_state()=0
Transmit via IR the state of this climate controller.
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:92
float state
This member variable stores the last state that has passed through all filters.
Definition sensor.h:117
bool state
Definition fan.h:0
@ 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_DRY
The climate device is set to dry/humidity mode.
@ CLIMATE_MODE_FAN_ONLY
The climate device only has the fan enabled, no heating or cooling is taking place.
@ 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.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7