ESPHome  2022.6.3
climate_ir.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <utility>
4 
9 
10 namespace esphome {
11 namespace climate_ir {
12 
13 /* A base for climate which works by sending (and receiving) IR codes
14 
15  To send IR codes implement
16  void ClimateIR::transmit_state_()
17 
18  Likewise to decode a IR into the AC state, implement
19  bool RemoteReceiverListener::on_receive(remote_base::RemoteReceiveData data) and return true
20 */
22  public:
23  ClimateIR(float minimum_temperature, float maximum_temperature, float temperature_step = 1.0f,
24  bool supports_dry = false, bool supports_fan_only = false, std::set<climate::ClimateFanMode> fan_modes = {},
25  std::set<climate::ClimateSwingMode> swing_modes = {}, std::set<climate::ClimatePreset> presets = {}) {
26  this->minimum_temperature_ = minimum_temperature;
27  this->maximum_temperature_ = maximum_temperature;
28  this->temperature_step_ = temperature_step;
29  this->supports_dry_ = supports_dry;
30  this->supports_fan_only_ = supports_fan_only;
31  this->fan_modes_ = std::move(fan_modes);
32  this->swing_modes_ = std::move(swing_modes);
33  this->presets_ = std::move(presets);
34  }
35 
36  void setup() override;
37  void dump_config() override;
39  this->transmitter_ = transmitter;
40  }
41  void set_supports_cool(bool supports_cool) { this->supports_cool_ = supports_cool; }
42  void set_supports_heat(bool supports_heat) { this->supports_heat_ = supports_heat; }
43  void set_sensor(sensor::Sensor *sensor) { this->sensor_ = sensor; }
44 
45  protected:
47 
49  void control(const climate::ClimateCall &call) override;
51  climate::ClimateTraits traits() override;
52 
54  virtual void transmit_state() = 0;
55 
56  // Dummy implement on_receive so implementation is optional for inheritors
57  bool on_receive(remote_base::RemoteReceiveData data) override { return false; };
58 
59  bool supports_cool_{true};
60  bool supports_heat_{true};
61  bool supports_dry_{false};
62  bool supports_fan_only_{false};
63  std::set<climate::ClimateFanMode> fan_modes_ = {};
64  std::set<climate::ClimateSwingMode> swing_modes_ = {};
65  std::set<climate::ClimatePreset> presets_ = {};
66 
69 };
70 
71 } // namespace climate_ir
72 } // 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
void set_sensor(sensor::Sensor *sensor)
Definition: climate_ir.h:43
This class contains all static data for climate devices.
virtual void transmit_state()=0
Transmit via IR the state of this climate controller.
void control(const climate::ClimateCall &call) override
Override control to change settings of the climate device.
Definition: climate_ir.cpp:61
std::set< climate::ClimatePreset > presets_
Definition: climate_ir.h:65
ClimateIR(float minimum_temperature, float maximum_temperature, float temperature_step=1.0f, bool supports_dry=false, bool supports_fan_only=false, std::set< climate::ClimateFanMode > fan_modes={}, std::set< climate::ClimateSwingMode > swing_modes={}, std::set< climate::ClimatePreset > presets={})
Definition: climate_ir.h:23
void set_supports_heat(bool supports_heat)
Definition: climate_ir.h:42
void set_transmitter(remote_transmitter::RemoteTransmitterComponent *transmitter)
Definition: climate_ir.h:38
climate::ClimateTraits traits() override
Return the traits of this controller.
Definition: climate_ir.cpp:9
bool on_receive(remote_base::RemoteReceiveData data) override
Definition: climate_ir.h:57
Definition: a4988.cpp:4
std::set< climate::ClimateFanMode > fan_modes_
Definition: climate_ir.h:63
Base-class for all sensors.
Definition: sensor.h:47
remote_transmitter::RemoteTransmitterComponent * transmitter_
Definition: climate_ir.h:67
sensor::Sensor * sensor_
Definition: climate_ir.h:68
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:167
void set_supports_cool(bool supports_cool)
Definition: climate_ir.h:41