ESPHome  2021.11.3
demo_climate.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 namespace esphome {
7 namespace demo {
8 
9 enum class DemoClimateType {
10  TYPE_1,
11  TYPE_2,
12  TYPE_3,
13 };
14 
15 class DemoClimate : public climate::Climate, public Component {
16  public:
17  void set_type(DemoClimateType type) { type_ = type; }
18  void setup() override {
19  switch (type_) {
21  this->current_temperature = 20.0;
22  this->target_temperature = 21.0;
24  this->action = climate::CLIMATE_ACTION_HEATING;
25  break;
27  this->target_temperature = 21.5;
29  this->action = climate::CLIMATE_ACTION_COOLING;
31  this->custom_preset = {"My Preset"};
32  break;
34  this->current_temperature = 21.5;
35  this->target_temperature_low = 21.0;
36  this->target_temperature_high = 22.5;
38  this->custom_fan_mode = {"Auto Low"};
41  break;
42  }
43  this->publish_state();
44  }
45 
46  protected:
47  void control(const climate::ClimateCall &call) override {
48  if (call.get_mode().has_value()) {
49  this->mode = *call.get_mode();
50  }
51  if (call.get_target_temperature().has_value()) {
53  }
56  }
59  }
60  if (call.get_fan_mode().has_value()) {
61  this->fan_mode = *call.get_fan_mode();
62  this->custom_fan_mode.reset();
63  }
64  if (call.get_swing_mode().has_value()) {
65  this->swing_mode = *call.get_swing_mode();
66  }
67  if (call.get_custom_fan_mode().has_value()) {
68  this->custom_fan_mode = *call.get_custom_fan_mode();
69  this->fan_mode.reset();
70  }
71  if (call.get_preset().has_value()) {
72  this->preset = *call.get_preset();
73  this->custom_preset.reset();
74  }
75  if (call.get_custom_preset().has_value()) {
76  this->custom_preset = *call.get_custom_preset();
77  this->preset.reset();
78  }
79  this->publish_state();
80  }
82  climate::ClimateTraits traits{};
83  switch (type_) {
85  traits.set_supports_current_temperature(true);
86  traits.set_supported_modes({
89  });
90  traits.set_supports_action(true);
91  traits.set_visual_temperature_step(0.5);
92  break;
94  traits.set_supports_current_temperature(false);
95  traits.set_supported_modes({
102  });
103  traits.set_supports_action(true);
104  traits.set_supported_fan_modes({
114  });
115  traits.set_supported_custom_fan_modes({"Auto Low", "Auto High"});
116  traits.set_supported_swing_modes({
121  });
122  traits.set_supported_custom_presets({"My Preset"});
123  break;
125  traits.set_supports_current_temperature(true);
126  traits.set_supports_two_point_target_temperature(true);
127  traits.set_supported_modes({
132  });
133  traits.set_supported_custom_fan_modes({"Auto Low", "Auto High"});
134  traits.set_supported_swing_modes({
137  });
138  traits.set_supported_presets({
147  });
148  break;
149  }
150  return traits;
151  }
152 
154 };
155 
156 } // namespace demo
157 } // namespace esphome
This class is used to encode all control actions on a climate device.
Definition: climate.h:33
The fan mode is set to Low.
Definition: climate_mode.h:54
float target_temperature_low
Definition: climate.h:549
The fan mode is set to Both.
Definition: climate_mode.h:72
climate::ClimateTraits traits() override
Definition: demo_climate.h:81
Device is in home preset.
Definition: climate_mode.h:84
const optional< ClimateMode > & get_mode() const
Definition: climate.cpp:259
The fan mode is set to Middle.
Definition: climate_mode.h:60
This class contains all static data for climate devices.
The climate device is set to heat to reach the target temperature.
Definition: climate_mode.h:18
void control(const climate::ClimateCall &call) override
Definition: demo_climate.h:47
const optional< float > & get_target_temperature_low() const
Definition: climate.cpp:261
The fan mode is set to Diffuse.
Definition: climate_mode.h:64
bool has_value() const
Definition: optional.h:87
The climate device is set to dry/humidity mode.
Definition: climate_mode.h:22
float target_temperature_high
Definition: climate.h:550
ClimateSwingMode swing_mode
Definition: climate.h:545
Device is prepared for sleep.
Definition: climate_mode.h:94
Device is in away preset.
Definition: climate_mode.h:86
Device is in comfort preset.
Definition: climate_mode.h:90
const optional< std::string > & get_custom_preset() const
Definition: climate.cpp:271
The fan mode is set to Horizontal.
Definition: climate_mode.h:76
The climate device is set to cool to reach the target temperature.
Definition: climate_mode.h:16
Device is reacting to activity (e.g., movement sensors)
Definition: climate_mode.h:96
const optional< ClimatePreset > & get_preset() const
Definition: climate.cpp:270
The fan mode is set to Auto.
Definition: climate_mode.h:52
uint8_t custom_preset
Definition: climate.h:543
uint8_t type
The climate device is adjusting the temperatre dynamically.
Definition: climate_mode.h:27
The climate device is set to heat/cool to reach the target temperature.
Definition: climate_mode.h:14
The fan mode is set to Vertical.
Definition: climate_mode.h:74
The climate device is actively heating.
Definition: climate_mode.h:37
void set_type(DemoClimateType type)
Definition: demo_climate.h:17
The fan mode is set to Focus.
Definition: climate_mode.h:62
const optional< std::string > & get_custom_fan_mode() const
Definition: climate.cpp:269
The fan mode is set to Off.
Definition: climate_mode.h:50
const optional< float > & get_target_temperature() const
Definition: climate.cpp:260
The fan mode is set to High.
Definition: climate_mode.h:58
The swing mode is set to Off.
Definition: climate_mode.h:70
The climate device is off.
Definition: climate_mode.h:12
ClimateFanMode fan_mode
Definition: climate.h:537
const optional< ClimateFanMode > & get_fan_mode() const
Definition: climate.cpp:268
Device is in boost preset.
Definition: climate_mode.h:88
The fan mode is set to On.
Definition: climate_mode.h:48
ClimateMode mode
Definition: climate.h:534
const optional< ClimateSwingMode > & get_swing_mode() const
Definition: climate.cpp:272
Library based on https://github.com/miguelbalboa/rfid and adapted to ESPHome by . ...
Definition: a4988.cpp:4
Device is running an energy-saving preset.
Definition: climate_mode.h:92
The fan mode is set to Medium.
Definition: climate_mode.h:56
const optional< float > & get_target_temperature_high() const
Definition: climate.cpp:262
The climate device only has the fan enabled, no heating or cooling is taking place.
Definition: climate_mode.h:20
The climate device is actively cooling.
Definition: climate_mode.h:35
uint8_t custom_fan_mode
Definition: climate.h:538
float target_temperature
Definition: climate.h:547
ClimatePreset preset
Definition: climate.h:542
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:167