7static const char *
const TAG =
"climate";
15 ESP_LOGD(TAG,
" Mode: %s", LOG_STR_ARG(mode_s));
24 ESP_LOGD(TAG,
" Fan: %s", LOG_STR_ARG(fan_mode_s));
33 ESP_LOGD(TAG,
" Preset: %s", LOG_STR_ARG(preset_s));
37 ESP_LOGD(TAG,
" Swing: %s", LOG_STR_ARG(swing_mode_s));
57 if (!traits.supports_mode(
mode)) {
65 ESP_LOGW(TAG,
" Fan Mode %s is not supported by this device!",
custom_fan_mode.c_str());
70 if (!traits.supports_fan_mode(
fan_mode)) {
71 ESP_LOGW(TAG,
" Fan Mode %s is not supported by this device!",
79 ESP_LOGW(TAG,
" Preset %s is not supported by this device!",
custom_preset.c_str());
84 if (!traits.supports_preset(
preset)) {
92 ESP_LOGW(TAG,
" Swing Mode %s is not supported by this device!",
99 if (traits.get_supports_two_point_target_temperature()) {
100 ESP_LOGW(TAG,
" Cannot set target temperature for climate device "
101 "with two-point target temperature!");
103 }
else if (std::isnan(target)) {
104 ESP_LOGW(TAG,
" Target temperature must not be NAN!");
109 if (!traits.get_supports_two_point_target_temperature()) {
110 ESP_LOGW(TAG,
" Cannot set low/high target temperature for this device!");
116 ESP_LOGW(TAG,
" Target temperature low must not be NAN!");
120 ESP_LOGW(TAG,
" Target temperature low must not be NAN!");
127 ESP_LOGW(TAG,
" Target temperature low %.2f must be smaller than target temperature high %.2f!", low, high);
188 ESP_LOGW(TAG,
"'%s' - Unrecognized fan mode %s", this->
parent_->
get_name().
c_str(), fan_mode.c_str());
226 ESP_LOGW(TAG,
"'%s' - Unrecognized preset %s", this->
parent_->
get_name().
c_str(), preset.c_str());
251 ESP_LOGW(TAG,
"'%s' - Unrecognized swing mode %s", this->
parent_->
get_name().
c_str(), swing_mode.c_str());
327static const uint32_t RESTORE_STATE_VERSION = 0x848EA6ADUL;
331 RESTORE_STATE_VERSION);
338#if (defined(USE_ESP_IDF) || (defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE >= VERSION_CODE(3, 0, 0))) && \
340#pragma GCC diagnostic ignored "-Wclass-memaccess"
341#define TEMP_IGNORE_MEMACCESS
346#ifdef TEMP_IGNORE_MEMACCESS
347#pragma GCC diagnostic pop
348#undef TEMP_IGNORE_MEMACCESS
363 state.uses_custom_fan_mode =
false;
367 state.uses_custom_fan_mode =
true;
369 std::vector<std::string> vec{supported.begin(), supported.end()};
371 if (it != vec.end()) {
372 state.custom_fan_mode = std::distance(vec.begin(), it);
376 state.uses_custom_preset =
false;
380 state.uses_custom_preset =
true;
382 std::vector<std::string> vec{supported.begin(), supported.end()};
385 if (it != vec.cend()) {
386 state.custom_preset = std::distance(vec.begin(), it);
396 ESP_LOGD(TAG,
"'%s' - Sending state:", this->
name_.
c_str());
484 call.set_mode(this->
mode);
485 if (traits.get_supports_two_point_target_temperature()) {
491 if (traits.get_supports_target_humidity()) {
494 if (traits.get_supports_fan_modes() || !traits.get_supported_custom_fan_modes().empty()) {
497 if (traits.get_supports_presets() || !traits.get_supported_custom_presets().empty()) {
498 call.set_preset(this->
preset);
500 if (traits.get_supports_swing_modes()) {
508 if (traits.get_supports_two_point_target_temperature()) {
514 if (traits.get_supports_target_humidity()) {
517 if (traits.get_supports_fan_modes() && !this->uses_custom_fan_mode) {
520 if (!traits.get_supported_custom_fan_modes().empty() && this->uses_custom_fan_mode) {
522 const auto &modes = traits.get_supported_custom_fan_modes();
523 std::vector<std::string> modes_vec{modes.begin(), modes.end()};
528 if (traits.get_supports_presets() && !this->uses_custom_preset) {
533 const auto &presets = traits.get_supported_custom_presets();
534 std::vector<std::string> presets_vec{presets.begin(), presets.end()};
539 if (traits.get_supports_swing_modes()) {
548 if (is_changed || dst != src) {
571 ESP_LOGCONFIG(tag,
"ClimateTraits:");
572 ESP_LOGCONFIG(tag,
" [x] Visual settings:");
575 ESP_LOGCONFIG(tag,
" - Temperature step:");
585 ESP_LOGCONFIG(tag,
" [x] Supports two-point target temperature");
588 ESP_LOGCONFIG(tag,
" [x] Supports current temperature");
591 ESP_LOGCONFIG(tag,
" [x] Supports target humidity");
594 ESP_LOGCONFIG(tag,
" [x] Supports current humidity");
597 ESP_LOGCONFIG(tag,
" [x] Supports action");
600 ESP_LOGCONFIG(tag,
" [x] Supported modes:");
605 ESP_LOGCONFIG(tag,
" [x] Supported fan modes:");
610 ESP_LOGCONFIG(tag,
" [x] Supported custom fan modes:");
612 ESP_LOGCONFIG(tag,
" - %s", s.c_str());
615 ESP_LOGCONFIG(tag,
" [x] Supported presets:");
620 ESP_LOGCONFIG(tag,
" [x] Supported custom presets:");
622 ESP_LOGCONFIG(tag,
" - %s", s.c_str());
625 ESP_LOGCONFIG(tag,
" [x] Supported swing modes:");
BedjetMode mode
BedJet operating mode.
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
uint32_t get_object_id_hash()
const StringRef & get_name() const
constexpr const char * c_str() const
This class is used to encode all control actions on a climate device.
const optional< ClimateSwingMode > & get_swing_mode() const
optional< float > target_temperature_high_
const optional< float > & get_target_humidity() const
ClimateCall & set_target_temperature(float target_temperature)
Set the target temperature of the climate device.
const optional< std::string > & get_custom_preset() const
const optional< float > & get_target_temperature_low() const
ClimateCall & set_swing_mode(ClimateSwingMode swing_mode)
Set the swing mode of the climate device.
optional< ClimateFanMode > fan_mode_
ClimateCall & set_target_temperature_low(float target_temperature_low)
Set the low point target temperature of the climate device.
optional< float > target_temperature_
const optional< float > & get_target_temperature() const
const optional< ClimatePreset > & get_preset() const
optional< std::string > custom_fan_mode_
optional< ClimateSwingMode > swing_mode_
optional< ClimateMode > mode_
ClimateCall & set_preset(ClimatePreset preset)
Set the preset of the climate device.
const optional< float > & get_target_temperature_high() const
optional< std::string > custom_preset_
const optional< ClimateFanMode > & get_fan_mode() const
optional< float > target_humidity_
ClimateCall & set_fan_mode(ClimateFanMode fan_mode)
Set the fan mode of the climate device.
optional< ClimatePreset > preset_
ClimateCall & set_target_humidity(float target_humidity)
Set the target humidity of the climate device.
optional< float > target_temperature_low_
ClimateCall & set_target_temperature_high(float target_temperature_high)
Set the high point target temperature of the climate device.
ClimateCall & set_mode(ClimateMode mode)
Set the mode of the climate device.
const optional< std::string > & get_custom_fan_mode() const
const optional< ClimateMode > & get_mode() const
ClimateDevice - This is the base class for all climate integrations.
ClimateMode mode
The active mode of the climate device.
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.
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
optional< float > visual_max_humidity_override_
bool set_custom_preset_(const std::string &preset)
Set custom preset. Reset primary preset. Return true if preset has been changed.
ClimateTraits get_traits()
Get the traits of this climate device with all overrides applied.
float target_temperature
The target temperature of the climate device.
float current_humidity
The current humidity of the climate device, as reported from the integration.
void set_visual_min_humidity_override(float visual_min_humidity_override)
optional< float > visual_current_temperature_step_override_
void dump_traits_(const char *tag)
CallbackManager< void(ClimateCall &)> control_callback_
CallbackManager< void(Climate &)> state_callback_
optional< std::string > custom_fan_mode
The active custom fan mode of the climate device.
ClimateSwingMode swing_mode
The active swing mode of the climate device.
optional< float > visual_target_temperature_step_override_
void save_state_()
Internal method to save the state of the climate device to recover memory.
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
void set_visual_max_humidity_override(float visual_max_humidity_override)
void add_on_state_callback(std::function< void(Climate &)> &&callback)
Add a callback for the climate device state, each time the state of the climate device is updated (us...
virtual ClimateTraits traits()=0
Get the default traits of this climate device.
bool set_preset_(ClimatePreset preset)
Set preset. Reset custom preset. Return true if preset has been changed.
optional< std::string > custom_preset
The active custom preset mode of the climate device.
void set_visual_max_temperature_override(float visual_max_temperature_override)
optional< float > visual_min_humidity_override_
optional< float > visual_max_temperature_override_
bool set_fan_mode_(ClimateFanMode mode)
Set fan mode. Reset custom fan mode. Return true if fan mode has been changed.
optional< float > visual_min_temperature_override_
void add_on_control_callback(std::function< void(ClimateCall &)> &&callback)
Add a callback for the climate device configuration; each time the configuration parameters of a clim...
float current_temperature
The current temperature of the climate device, as reported from the integration.
ClimateAction action
The active state of the climate device.
ClimateCall make_call()
Make a climate device control call, this is used to control the climate device, see the ClimateCall d...
virtual void control(const ClimateCall &call)=0
Control the climate device, this is a virtual method that each climate integration must implement.
void publish_state()
Publish the state of the climate device, to be called from integrations.
void set_visual_temperature_step_override(float target, float current)
optional< ClimatePreset > preset
The active preset of the climate device.
void set_visual_min_temperature_override(float visual_min_temperature_override)
optional< ClimateDeviceRestoreState > restore_state_()
Restore the state of the climate device, call this from your setup() method.
float target_humidity
The target humidity of the climate device.
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
This class contains all static data for climate devices.
void set_visual_max_temperature(float visual_max_temperature)
const std::set< climate::ClimatePreset > & get_supported_presets() const
bool get_supports_action() const
float get_visual_min_humidity() const
bool get_supports_current_temperature() const
bool get_supports_swing_modes() const
void set_visual_target_temperature_step(float temperature_step)
float get_visual_current_temperature_step() const
void set_visual_min_temperature(float visual_min_temperature)
bool get_supports_fan_modes() const
float get_visual_target_temperature_step() const
void set_visual_min_humidity(float visual_min_humidity)
bool supports_custom_preset(const std::string &custom_preset) const
bool get_supports_target_humidity() const
void set_visual_current_temperature_step(float temperature_step)
void set_visual_max_humidity(float visual_max_humidity)
float get_visual_max_humidity() const
bool supports_custom_fan_mode(const std::string &custom_fan_mode) const
const std::set< std::string > & get_supported_custom_fan_modes() const
const std::set< std::string > & get_supported_custom_presets() const
bool get_supports_two_point_target_temperature() const
const std::set< ClimateFanMode > & get_supported_fan_modes() const
bool get_supports_presets() const
float get_visual_max_temperature() const
const std::set< ClimateMode > & get_supported_modes() const
const std::set< ClimateSwingMode > & get_supported_swing_modes() const
float get_visual_min_temperature() const
bool get_supports_current_humidity() const
value_type const & value() const
float target_temperature_high
ClimateSwingMode swing_mode
float target_temperature_low
bool set_alternative(optional< T1 > &dst, optional< T2 > &alt, const T1 &src)
const LogString * climate_action_to_string(ClimateAction action)
Convert the given ClimateAction to a human-readable string.
const LogString * climate_swing_mode_to_string(ClimateSwingMode swing_mode)
Convert the given ClimateSwingMode to a human-readable string.
const LogString * climate_preset_to_string(ClimatePreset preset)
Convert the given PresetMode to a human-readable string.
ClimatePreset
Enum for all preset modes.
@ 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.
const LogString * climate_fan_mode_to_string(ClimateFanMode fan_mode)
Convert the given ClimateFanMode to a human-readable string.
ClimateSwingMode
Enum for all modes a climate swing can be in.
@ 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.
ClimateMode
Enum for all modes a climate device can be in.
@ 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.
const LogString * climate_mode_to_string(ClimateMode mode)
Convert the given ClimateMode to a human-readable string.
@ 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.
ESPPreferences * global_preferences
bool str_equals_case_insensitive(const std::string &a, const std::string &b)
Compare strings for equality in case-insensitive manner.
Struct used to save the state of the climate device in restore memory.
ClimateCall to_call(Climate *climate)
Convert this struct to a climate call that can be performed.
float target_temperature_high
void apply(Climate *climate)
Apply these settings to the climate device.
ClimateSwingMode swing_mode
float target_temperature_low