ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
climate_ir.h
Go to the documentation of this file.
1#pragma once
2
3#include <utility>
4
9
10namespace esphome::climate_ir {
11
12/* A base for climate which works by sending (and receiving) IR codes
13
14 To send IR codes implement
15 void ClimateIR::transmit_state_()
16
17 Likewise to decode a IR into the AC state, implement
18 bool RemoteReceiverListener::on_receive(remote_base::RemoteReceiveData data) and return true
19*/
20class ClimateIR : public Component,
21 public climate::Climate,
24 SUB_SENSOR(humidity)
25
26 public:
27 ClimateIR(float minimum_temperature, float maximum_temperature, float temperature_step = 1.0f,
28 bool supports_dry = false, bool supports_fan_only = false,
32 this->minimum_temperature_ = minimum_temperature;
33 this->maximum_temperature_ = maximum_temperature;
34 this->temperature_step_ = temperature_step;
35 if (supports_dry)
37 if (supports_fan_only)
39 this->fan_modes_ = fan_modes;
40 this->swing_modes_ = swing_modes;
41 this->presets_ = presets;
42 }
43
44 void setup() override;
45 void dump_config() override;
46 void set_supports_cool(bool supports_cool) { this->set_mode_supported_(climate::CLIMATE_MODE_COOL, supports_cool); }
47 void set_supports_heat(bool supports_heat) { this->set_mode_supported_(climate::CLIMATE_MODE_HEAT, supports_heat); }
48 void set_supports_heat_cool(bool supports_heat_cool) {
50 }
51 void set_sensor(sensor::Sensor *sensor) { this->sensor_ = sensor; }
52
53 protected:
55
57 void control(const climate::ClimateCall &call) override;
60
62 virtual void transmit_state() = 0;
63
66 void setup_(optional<climate::ClimateDeviceRestoreState> restore);
67
68 // Dummy implement on_receive so implementation is optional for inheritors
69 bool on_receive(remote_base::RemoteReceiveData data) override { return false; };
70
71 ESPHOME_ALWAYS_INLINE void set_mode_supported_(climate::ClimateMode mode, bool supported) {
72 if (supported) {
73 this->modes_.insert(mode);
74 } else {
75 this->modes_.erase(mode);
76 }
77 }
78
79 // The HEAT_COOL default (supports_cool && supports_heat) is resolved during code generation.
86
88};
89
90} // namespace esphome::climate_ir
constexpr void insert(ValueType value)
Add a single value to the set (std::set compatibility)
constexpr void erase(ValueType value)
Remove a value from the set (std::set compatibility)
This class is used to encode all control actions on a climate device.
Definition climate.h:31
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:192
ClimateMode mode
The active mode of the climate device.
Definition climate.h:317
climate::ClimatePresetMask presets_
Definition climate_ir.h:85
climate::ClimateFanModeMask fan_modes_
Definition climate_ir.h:83
climate::ClimateSwingModeMask swing_modes_
Definition climate_ir.h:84
static constexpr climate::ClimateModeMask DEFAULT_MODES
Definition climate_ir.h:80
void control(const climate::ClimateCall &call) override
Override control to change settings of the climate device.
ESPHOME_ALWAYS_INLINE void set_mode_supported_(climate::ClimateMode mode, bool supported)
Definition climate_ir.h:71
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.
bool on_receive(remote_base::RemoteReceiveData data) override
Definition climate_ir.h:69
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:82
Base-class for all sensors.
Definition sensor.h:48
ClimateMode
Enum for all modes a climate device can be in.
@ 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.