ESPHome  2021.9.0
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
esphome::climate::Climate Class Referenceabstract

ClimateDevice - This is the base class for all climate integrations. More...

#include <climate.h>

Inheritance diagram for esphome::climate::Climate:
esphome::Nameable esphome::midea::ApplianceBase< dudanov::midea::ac::AirConditioner > esphome::anova::Anova esphome::bang_bang::BangBangClimate esphome::climate_ir::ClimateIR esphome::demo::DemoClimate esphome::midea::ApplianceBase< T > esphome::pid::PIDClimate esphome::thermostat::ThermostatClimate esphome::tuya::TuyaClimate esphome::yashima::YashimaClimate

Public Member Functions

 Climate ()
 Construct a climate device with empty name (will be set later). More...
 
 Climate (const std::string &name)
 Construct a climate device with a name. More...
 
 ESPDEPRECATED ("away is deprecated, use preset instead", "v1.20") bool away
 Whether the climate device is in away mode. More...
 
void add_on_state_callback (std::function< void()> &&callback)
 Add a callback for the climate device state, each time the state of the climate device is updated (using publish_state), this callback will be called. More...
 
ClimateCall make_call ()
 Make a climate device control call, this is used to control the climate device, see the ClimateCall description for more info. More...
 
void publish_state ()
 Publish the state of the climate device, to be called from integrations. More...
 
ClimateTraits get_traits ()
 Get the traits of this climate device with all overrides applied. More...
 
void set_visual_min_temperature_override (float visual_min_temperature_override)
 
void set_visual_max_temperature_override (float visual_max_temperature_override)
 
void set_visual_temperature_step_override (float visual_temperature_step_override)
 
- Public Member Functions inherited from esphome::Nameable
 Nameable ()
 
 Nameable (std::string name)
 
const std::string & get_name () const
 
void set_name (const std::string &name)
 
const std::string & get_object_id ()
 Get the sanitized name of this nameable as an ID. Caching it internally. More...
 
uint32_t get_object_id_hash ()
 
bool is_internal () const
 
void set_internal (bool internal)
 
bool is_disabled_by_default () const
 Check if this object is declared to be disabled by default. More...
 
void set_disabled_by_default (bool disabled_by_default)
 

Data Fields

ClimateMode mode {CLIMATE_MODE_OFF}
 The active mode of the climate device. More...
 
ClimateAction action {CLIMATE_ACTION_OFF}
 The active state of the climate device. More...
 
float current_temperature {NAN}
 The current temperature of the climate device, as reported from the integration. More...
 
union {
   float   target_temperature
 The target temperature of the climate device. More...
 
   struct {
      float   target_temperature_low
 The minimum target temperature of the climate device, for climate devices with split target temperature. More...
 
      float   target_temperature_high
 The maximum target temperature of the climate device, for climate devices with split target temperature. More...
 
   } 
 
}; 
 
optional< ClimateFanModefan_mode
 The active fan mode of the climate device. More...
 
ClimateSwingMode swing_mode
 The active swing mode of the climate device. More...
 
optional< std::string > custom_fan_mode
 The active custom fan mode of the climate device. More...
 
optional< ClimatePresetpreset
 The active preset of the climate device. More...
 
optional< std::string > custom_preset
 The active custom preset mode of the climate device. More...
 

Protected Member Functions

bool set_fan_mode_ (ClimateFanMode mode)
 Set fan mode. Reset custom fan mode. Return true if fan mode has been changed. More...
 
bool set_custom_fan_mode_ (const std::string &mode)
 Set custom fan mode. Reset primary fan mode. Return true if fan mode has been changed. More...
 
bool set_preset_ (ClimatePreset preset)
 Set preset. Reset custom preset. Return true if preset has been changed. More...
 
bool set_custom_preset_ (const std::string &preset)
 Set custom preset. Reset primary preset. Return true if preset has been changed. More...
 
virtual ClimateTraits traits ()=0
 Get the default traits of this climate device. More...
 
virtual void control (const ClimateCall &call)=0
 Control the climate device, this is a virtual method that each climate integration must implement. More...
 
optional< ClimateDeviceRestoreStaterestore_state_ ()
 Restore the state of the climate device, call this from your setup() method. More...
 
void save_state_ ()
 Internal method to save the state of the climate device to recover memory. More...
 
uint32_t hash_base () override
 
void dump_traits_ (const char *tag)
 
- Protected Member Functions inherited from esphome::Nameable
void calc_object_id_ ()
 

Protected Attributes

friend ClimateCall
 
CallbackManager< void()> state_callback_ {}
 
ESPPreferenceObject rtc_
 
optional< float > visual_min_temperature_override_ {}
 
optional< float > visual_max_temperature_override_ {}
 
optional< float > visual_temperature_step_override_ {}
 
- Protected Attributes inherited from esphome::Nameable
std::string name_
 
std::string object_id_
 
uint32_t object_id_hash_
 
bool internal_ {false}
 
bool disabled_by_default_ {false}
 

Detailed Description

ClimateDevice - This is the base class for all climate integrations.

Each integration needs to extend this class and implement two functions:

To write data to the frontend, the integration must first set the properties using this->property = value; (for example this->current_temperature = 42.0;); then the integration must call this->publish_state(); to send the entire state to the frontend.

The entire state of the climate device is encoded in public properties of the base class (current_temperature, mode etc). These are read-only for the user and rw for integrations. The reason these are public is for simple access to them from lambdas if (id(my_climate).mode == climate::CLIMATE_MODE_HEAT_COOL) ...

Definition at line 166 of file climate.h.

Constructor & Destructor Documentation

◆ Climate() [1/2]

esphome::climate::Climate::Climate ( )

Construct a climate device with empty name (will be set later).

Definition at line 436 of file climate.cpp.

◆ Climate() [2/2]

esphome::climate::Climate::Climate ( const std::string &  name)

Construct a climate device with a name.

Definition at line 435 of file climate.cpp.

Member Function Documentation

◆ add_on_state_callback()

void esphome::climate::Climate::add_on_state_callback ( std::function< void()> &&  callback)

Add a callback for the climate device state, each time the state of the climate device is updated (using publish_state), this callback will be called.

Parameters
callbackThe callback to call.

Definition at line 311 of file climate.cpp.

◆ control()

virtual void esphome::climate::Climate::control ( const ClimateCall call)
protectedpure virtual

Control the climate device, this is a virtual method that each climate integration must implement.

See more info in ClimateCall. The integration should check all of its values in this method and set them accordingly. At the end of the call, the integration must call publish_state() to notify the frontend of a changed state.

Parameters
callThe ClimateCall instance encoding all attribute changes.

Implemented in esphome::thermostat::ThermostatClimate, esphome::pid::PIDClimate, esphome::climate_ir::ClimateIR, esphome::demo::DemoClimate, esphome::anova::Anova, esphome::bang_bang::BangBangClimate, esphome::tuya::TuyaClimate, esphome::whirlpool::WhirlpoolClimate, esphome::midea::AirConditioner, esphome::yashima::YashimaClimate, esphome::climate_ir_lg::LgIrClimate, and esphome::coolix::CoolixClimate.

◆ dump_traits_()

void esphome::climate::Climate::dump_traits_ ( const char *  tag)
protected

Definition at line 521 of file climate.cpp.

◆ ESPDEPRECATED()

esphome::climate::Climate::ESPDEPRECATED ( "away is  deprecated,
use preset instead"  ,
"v1.20"   
)
inline

Whether the climate device is in away mode.

Away allows climate devices to have two different target temperature configs: one for normal mode and one for away mode.

Definition at line 196 of file climate.h.

◆ get_traits()

ClimateTraits esphome::climate::Climate::get_traits ( )

Get the traits of this climate device with all overrides applied.

Traits are static data that encode the capabilities and static data for a climate device such as supported modes, temperature range etc.

Definition at line 412 of file climate.cpp.

◆ hash_base()

uint32_t esphome::climate::Climate::hash_base ( )
overrideprotectedvirtual

Implements esphome::Nameable.

Definition at line 410 of file climate.cpp.

◆ make_call()

ClimateCall esphome::climate::Climate::make_call ( )

Make a climate device control call, this is used to control the climate device, see the ClimateCall description for more info.

Returns
A new ClimateCall instance targeting this climate device.

Definition at line 437 of file climate.cpp.

◆ publish_state()

void esphome::climate::Climate::publish_state ( )

Publish the state of the climate device, to be called from integrations.

This will schedule the climate device to publish its state to all listeners and save the current state to recover memory.

Definition at line 372 of file climate.cpp.

◆ restore_state_()

optional< ClimateDeviceRestoreState > esphome::climate::Climate::restore_state_ ( )
protected

Restore the state of the climate device, call this from your setup() method.

Definition at line 318 of file climate.cpp.

◆ save_state_()

void esphome::climate::Climate::save_state_ ( )
protected

Internal method to save the state of the climate device to recover memory.

This is automatically called from publish_state()

Definition at line 326 of file climate.cpp.

◆ set_custom_fan_mode_()

bool esphome::climate::Climate::set_custom_fan_mode_ ( const std::string &  mode)
protected

Set custom fan mode. Reset primary fan mode. Return true if fan mode has been changed.

Definition at line 511 of file climate.cpp.

◆ set_custom_preset_()

bool esphome::climate::Climate::set_custom_preset_ ( const std::string &  preset)
protected

Set custom preset. Reset primary preset. Return true if preset has been changed.

Definition at line 517 of file climate.cpp.

◆ set_fan_mode_()

bool esphome::climate::Climate::set_fan_mode_ ( ClimateFanMode  mode)
protected

Set fan mode. Reset custom fan mode. Return true if fan mode has been changed.

Definition at line 507 of file climate.cpp.

◆ set_preset_()

bool esphome::climate::Climate::set_preset_ ( ClimatePreset  preset)
protected

Set preset. Reset custom preset. Return true if preset has been changed.

Definition at line 515 of file climate.cpp.

◆ set_visual_max_temperature_override()

void esphome::climate::Climate::set_visual_max_temperature_override ( float  visual_max_temperature_override)

Definition at line 429 of file climate.cpp.

◆ set_visual_min_temperature_override()

void esphome::climate::Climate::set_visual_min_temperature_override ( float  visual_min_temperature_override)

Definition at line 426 of file climate.cpp.

◆ set_visual_temperature_step_override()

void esphome::climate::Climate::set_visual_temperature_step_override ( float  visual_temperature_step_override)

Definition at line 432 of file climate.cpp.

◆ traits()

virtual ClimateTraits esphome::climate::Climate::traits ( )
protectedpure virtual

Get the default traits of this climate device.

Traits are static data that encode the capabilities and static data for a climate device such as supported modes, temperature range etc. Each integration must implement this method and the return value must be constant during all of execution time.

Implemented in esphome::thermostat::ThermostatClimate, esphome::demo::DemoClimate, esphome::pid::PIDClimate, esphome::climate_ir::ClimateIR, esphome::bang_bang::BangBangClimate, esphome::tuya::TuyaClimate, esphome::midea::AirConditioner, esphome::anova::Anova, and esphome::yashima::YashimaClimate.

Field Documentation

◆ @21

union { ... }

◆ action

ClimateAction esphome::climate::Climate::action {CLIMATE_ACTION_OFF}

The active state of the climate device.

Definition at line 176 of file climate.h.

◆ ClimateCall

friend esphome::climate::Climate::ClimateCall
protected

Definition at line 246 of file climate.h.

◆ current_temperature

float esphome::climate::Climate::current_temperature {NAN}

The current temperature of the climate device, as reported from the integration.

Definition at line 178 of file climate.h.

◆ custom_fan_mode

optional<std::string> esphome::climate::Climate::custom_fan_mode

The active custom fan mode of the climate device.

Definition at line 206 of file climate.h.

◆ custom_preset

optional<std::string> esphome::climate::Climate::custom_preset

The active custom preset mode of the climate device.

Definition at line 212 of file climate.h.

◆ fan_mode

optional<ClimateFanMode> esphome::climate::Climate::fan_mode

The active fan mode of the climate device.

Definition at line 197 of file climate.h.

◆ mode

ClimateMode esphome::climate::Climate::mode {CLIMATE_MODE_OFF}

The active mode of the climate device.

Definition at line 174 of file climate.h.

◆ preset

optional<ClimatePreset> esphome::climate::Climate::preset

The active preset of the climate device.

Definition at line 209 of file climate.h.

◆ rtc_

ESPPreferenceObject esphome::climate::Climate::rtc_
protected

Definition at line 288 of file climate.h.

◆ state_callback_

CallbackManager<void()> esphome::climate::Climate::state_callback_ {}
protected

Definition at line 287 of file climate.h.

◆ swing_mode

ClimateSwingMode esphome::climate::Climate::swing_mode

The active swing mode of the climate device.

Definition at line 203 of file climate.h.

◆ target_temperature

float esphome::climate::Climate::target_temperature

The target temperature of the climate device.

Definition at line 182 of file climate.h.

◆ target_temperature_high

float esphome::climate::Climate::target_temperature_high

The maximum target temperature of the climate device, for climate devices with split target temperature.

Definition at line 187 of file climate.h.

◆ target_temperature_low

float esphome::climate::Climate::target_temperature_low

The minimum target temperature of the climate device, for climate devices with split target temperature.

Definition at line 185 of file climate.h.

◆ visual_max_temperature_override_

optional<float> esphome::climate::Climate::visual_max_temperature_override_ {}
protected

Definition at line 290 of file climate.h.

◆ visual_min_temperature_override_

optional<float> esphome::climate::Climate::visual_min_temperature_override_ {}
protected

Definition at line 289 of file climate.h.

◆ visual_temperature_step_override_

optional<float> esphome::climate::Climate::visual_temperature_step_override_ {}
protected

Definition at line 291 of file climate.h.


The documentation for this class was generated from the following files: