ESPHome 2025.5.0
Loading...
Searching...
No Matches
demo_climate.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace esphome {
7namespace demo {
8
9enum class DemoClimateType {
10 TYPE_1,
11 TYPE_2,
12 TYPE_3,
13};
14
15class DemoClimate : public climate::Climate, public Component {
16 public:
18 void setup() override {
19 switch (type_) {
21 this->current_temperature = 20.0;
22 this->target_temperature = 21.0;
25 break;
27 this->target_temperature = 21.5;
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 }
54 if (call.get_target_temperature_low().has_value()) {
56 }
57 if (call.get_target_temperature_high().has_value()) {
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()) {
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 }
83 switch (type_) {
89 });
92 break;
102 });
115 });
116 traits.set_supported_custom_fan_modes({"Auto Low", "Auto High"});
122 });
124 break;
133 });
134 traits.set_supported_custom_fan_modes({"Auto Low", "Auto High"});
138 });
148 });
149 break;
150 }
151 return traits;
152 }
153
155};
156
157} // namespace demo
158} // namespace esphome
This class is used to encode all control actions on a climate device.
Definition climate.h:33
const optional< ClimateSwingMode > & get_swing_mode() const
Definition climate.cpp:282
const optional< std::string > & get_custom_preset() const
Definition climate.cpp:281
const optional< float > & get_target_temperature_low() const
Definition climate.cpp:275
const optional< float > & get_target_temperature() const
Definition climate.cpp:274
const optional< ClimatePreset > & get_preset() const
Definition climate.cpp:280
const optional< float > & get_target_temperature_high() const
Definition climate.cpp:276
const optional< ClimateFanMode > & get_fan_mode() const
Definition climate.cpp:278
const optional< std::string > & get_custom_fan_mode() const
Definition climate.cpp:279
const optional< ClimateMode > & get_mode() const
Definition climate.cpp:273
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:168
ClimateMode mode
The active mode of the climate device.
Definition climate.h:173
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:199
float target_temperature
The target temperature of the climate device.
Definition climate.h:186
optional< std::string > custom_fan_mode
The active custom fan mode of the climate device.
Definition climate.h:205
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:202
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:189
optional< std::string > custom_preset
The active custom preset mode of the climate device.
Definition climate.h:211
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition climate.h:179
ClimateAction action
The active state of the climate device.
Definition climate.h:176
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:395
optional< ClimatePreset > preset
The active preset of the climate device.
Definition climate.h:208
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:191
This class contains all static data for climate devices.
void set_supported_modes(std::set< ClimateMode > modes)
void set_supported_custom_fan_modes(std::set< std::string > supported_custom_fan_modes)
void set_supports_action(bool supports_action)
void set_supported_custom_presets(std::set< std::string > supported_custom_presets)
void set_visual_temperature_step(float temperature_step)
void set_supports_two_point_target_temperature(bool supports_two_point_target_temperature)
void set_supported_swing_modes(std::set< ClimateSwingMode > modes)
void set_supported_presets(std::set< ClimatePreset > presets)
void set_supported_fan_modes(std::set< ClimateFanMode > modes)
void set_supports_current_temperature(bool supports_current_temperature)
void set_type(DemoClimateType type)
climate::ClimateTraits traits() override
void control(const climate::ClimateCall &call) override
bool has_value() const
Definition optional.h:87
uint8_t type
@ CLIMATE_PRESET_NONE
No preset is active.
@ CLIMATE_PRESET_COMFORT
Device is in comfort preset.
@ CLIMATE_PRESET_AWAY
Device is in away preset.
@ CLIMATE_PRESET_BOOST
Device is in boost preset.
@ CLIMATE_PRESET_ACTIVITY
Device is reacting to activity (e.g., movement sensors)
@ CLIMATE_PRESET_SLEEP
Device is prepared for sleep.
@ CLIMATE_PRESET_HOME
Device is in home preset.
@ CLIMATE_PRESET_ECO
Device is running an energy-saving preset.
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
@ CLIMATE_SWING_HORIZONTAL
The fan mode is set to Horizontal.
@ CLIMATE_SWING_VERTICAL
The fan mode is set to Vertical.
@ CLIMATE_SWING_BOTH
The fan mode is set to Both.
@ 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_MODE_AUTO
The climate device is adjusting the temperature dynamically.
@ CLIMATE_ACTION_HEATING
The climate device is actively heating.
@ CLIMATE_ACTION_COOLING
The climate device is actively cooling.
@ CLIMATE_FAN_MEDIUM
The fan mode is set to Medium.
@ CLIMATE_FAN_DIFFUSE
The fan mode is set to Diffuse.
@ CLIMATE_FAN_ON
The fan mode is set to On.
@ CLIMATE_FAN_AUTO
The fan mode is set to Auto.
@ CLIMATE_FAN_FOCUS
The fan mode is set to Focus.
@ CLIMATE_FAN_LOW
The fan mode is set to Low.
@ CLIMATE_FAN_MIDDLE
The fan mode is set to Middle.
@ CLIMATE_FAN_QUIET
The fan mode is set to Quiet.
@ CLIMATE_FAN_OFF
The fan mode is set to Off.
@ CLIMATE_FAN_HIGH
The fan mode is set to High.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7