ESPHome  1.14.3
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::bang_bang::BangBangClimate esphome::climate_ir::ClimateIR esphome::yashima::YashimaClimate esphome::coolix::CoolixClimate esphome::fujitsu_general::FujitsuGeneralClimate esphome::tcl112::Tcl112Climate

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...
 
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 (const 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)
 

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...
 
   } 
 
}; 
 
bool away {false}
 Whether the climate device is in away mode. More...
 

Protected Member Functions

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
 
- 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}
 

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_AUTO) ...

Definition at line 120 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 223 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 222 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 141 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::climate_ir::ClimateIR, esphome::bang_bang::BangBangClimate, and esphome::yashima::YashimaClimate.

◆ 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 199 of file climate.cpp.

◆ hash_base()

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

Implements esphome::Nameable.

Definition at line 197 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 224 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 171 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 145 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 152 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 216 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 213 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 219 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::climate_ir::ClimateIR, esphome::bang_bang::BangBangClimate, and esphome::yashima::YashimaClimate.

Field Documentation

◆ @9

union { ... }

◆ action

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

The active state of the climate device.

Definition at line 130 of file climate.h.

◆ away

bool esphome::climate::Climate::away {false}

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 150 of file climate.h.

◆ ClimateCall

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

Definition at line 184 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 132 of file climate.h.

◆ mode

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

The active mode of the climate device.

Definition at line 128 of file climate.h.

◆ rtc_

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

Definition at line 213 of file climate.h.

◆ state_callback_

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

Definition at line 212 of file climate.h.

◆ target_temperature

float esphome::climate::Climate::target_temperature

The target temperature of the climate device.

Definition at line 136 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 141 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 139 of file climate.h.

◆ visual_max_temperature_override_

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

Definition at line 215 of file climate.h.

◆ visual_min_temperature_override_

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

Definition at line 214 of file climate.h.

◆ visual_temperature_step_override_

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

Definition at line 216 of file climate.h.


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