Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for climate integrations to support eco mode #1075

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions esphome/components/climate/automation.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ template<typename... Ts> class ControlAction : public Action<Ts...> {
TEMPLATABLE_VALUE(float, target_temperature_low)
TEMPLATABLE_VALUE(float, target_temperature_high)
TEMPLATABLE_VALUE(bool, away)
TEMPLATABLE_VALUE(bool, eco_mode)
TEMPLATABLE_VALUE(ClimateFanMode, fan_mode)
TEMPLATABLE_VALUE(ClimateSwingMode, swing_mode)

Expand All @@ -25,6 +26,7 @@ template<typename... Ts> class ControlAction : public Action<Ts...> {
call.set_target_temperature_low(this->target_temperature_low_.optional_value(x...));
call.set_target_temperature_high(this->target_temperature_high_.optional_value(x...));
call.set_away(this->away_.optional_value(x...));
call.set_eco_mode(this->eco_mode_.optional_value(x...));
call.set_fan_mode(this->fan_mode_.optional_value(x...));
call.set_swing_mode(this->swing_mode_.optional_value(x...));
call.perform();
Expand Down
30 changes: 30 additions & 0 deletions esphome/components/climate/climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ void ClimateCall::perform() {
if (this->away_.has_value()) {
ESP_LOGD(TAG, " Away Mode: %s", ONOFF(*this->away_));
}
if (this->eco_mode_.has_value()) {
ESP_LOGD(TAG, " Eco Mode: %s", ONOFF(*this->eco_mode_));
}
this->parent_->control(*this);
}
void ClimateCall::validate_() {
Expand Down Expand Up @@ -99,6 +102,12 @@ void ClimateCall::validate_() {
this->away_.reset();
}
}
if (this->eco_mode_.has_value()) {
if (!traits.get_supports_eco_mode()) {
ESP_LOGW(TAG, " Cannot set eco mode for this device!");
this->eco_mode_.reset();
}
}
}
ClimateCall &ClimateCall::set_mode(ClimateMode mode) {
this->mode_ = mode;
Expand Down Expand Up @@ -187,6 +196,7 @@ const optional<float> &ClimateCall::get_target_temperature() const { return this
const optional<float> &ClimateCall::get_target_temperature_low() const { return this->target_temperature_low_; }
const optional<float> &ClimateCall::get_target_temperature_high() const { return this->target_temperature_high_; }
const optional<bool> &ClimateCall::get_away() const { return this->away_; }
const optional<bool> &ClimateCall::get_eco_mode() const { return this->eco_mode_; }
const optional<ClimateFanMode> &ClimateCall::get_fan_mode() const { return this->fan_mode_; }
const optional<ClimateSwingMode> &ClimateCall::get_swing_mode() const { return this->swing_mode_; }
ClimateCall &ClimateCall::set_away(bool away) {
Expand All @@ -197,6 +207,14 @@ ClimateCall &ClimateCall::set_away(optional<bool> away) {
this->away_ = away;
return *this;
}
ClimateCall &ClimateCall::set_eco_mode(bool eco_mode) {
this->eco_mode_ = eco_mode;
return *this;
}
ClimateCall &ClimateCall::set_eco_mode(optional<bool> eco_mode) {
this->eco_mode_ = eco_mode;
return *this;
}
ClimateCall &ClimateCall::set_target_temperature_high(optional<float> target_temperature_high) {
this->target_temperature_high_ = target_temperature_high;
return *this;
Expand Down Expand Up @@ -249,6 +267,9 @@ void Climate::save_state_() {
if (traits.get_supports_away()) {
state.away = this->away;
}
if (traits.get_supports_eco_mode()) {
state.eco_mode = this->eco_mode;
}
if (traits.get_supports_fan_modes()) {
state.fan_mode = this->fan_mode;
}
Expand Down Expand Up @@ -284,6 +305,9 @@ void Climate::publish_state() {
if (traits.get_supports_away()) {
ESP_LOGD(TAG, " Away: %s", ONOFF(this->away));
}
if (traits.get_supports_eco_mode()) {
ESP_LOGD(TAG, " Eco Mode: %s", ONOFF(this->eco_mode));
}

// Send state to frontend
this->state_callback_.call();
Expand Down Expand Up @@ -332,6 +356,9 @@ ClimateCall ClimateDeviceRestoreState::to_call(Climate *climate) {
if (traits.get_supports_away()) {
call.set_away(this->away);
}
if (traits.get_supports_eco_mode()) {
call.set_eco_mode(this->eco_mode);
}
if (traits.get_supports_fan_modes()) {
call.set_fan_mode(this->fan_mode);
}
Expand All @@ -352,6 +379,9 @@ void ClimateDeviceRestoreState::apply(Climate *climate) {
if (traits.get_supports_away()) {
climate->away = this->away;
}
if (traits.get_supports_eco_mode()) {
climate->eco_mode = this->eco_mode;
}
if (traits.get_supports_fan_modes()) {
climate->fan_mode = this->fan_mode;
}
Expand Down
11 changes: 11 additions & 0 deletions esphome/components/climate/climate.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class ClimateCall {
ClimateCall &set_target_temperature_high(optional<float> target_temperature_high);
ClimateCall &set_away(bool away);
ClimateCall &set_away(optional<bool> away);
ClimateCall &set_eco_mode(bool eco_mode);
ClimateCall &set_eco_mode(optional<bool> eco_mode);
/// Set the fan mode of the climate device.
ClimateCall &set_fan_mode(ClimateFanMode fan_mode);
/// Set the fan mode of the climate device.
Expand All @@ -84,6 +86,7 @@ class ClimateCall {
const optional<float> &get_target_temperature_low() const;
const optional<float> &get_target_temperature_high() const;
const optional<bool> &get_away() const;
const optional<bool> &get_eco_mode() const;
const optional<ClimateFanMode> &get_fan_mode() const;
const optional<ClimateSwingMode> &get_swing_mode() const;

Expand All @@ -96,6 +99,7 @@ class ClimateCall {
optional<float> target_temperature_low_;
optional<float> target_temperature_high_;
optional<bool> away_;
optional<bool> eco_mode_;
optional<ClimateFanMode> fan_mode_;
optional<ClimateSwingMode> swing_mode_;
};
Expand All @@ -104,6 +108,7 @@ class ClimateCall {
struct ClimateDeviceRestoreState {
ClimateMode mode;
bool away;
bool eco_mode;
ClimateFanMode fan_mode;
ClimateSwingMode swing_mode;
union {
Expand Down Expand Up @@ -167,6 +172,12 @@ class Climate : public Nameable {
*/
bool away{false};

/** Whether the climate device is in eco mode.
*
* Eco allows climate devices to output using less energy.
*/
bool eco_mode{false};

/// The active fan mode of the climate device.
ClimateFanMode fan_mode;

Expand Down
2 changes: 2 additions & 0 deletions esphome/components/climate/climate_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void ClimateTraits::set_supports_fan_only_mode(bool supports_fan_only_mode) {
}
void ClimateTraits::set_supports_dry_mode(bool supports_dry_mode) { supports_dry_mode_ = supports_dry_mode; }
void ClimateTraits::set_supports_away(bool supports_away) { supports_away_ = supports_away; }
void ClimateTraits::set_supports_eco_mode(bool supports_eco_mode) { supports_eco_mode_ = supports_eco_mode; }
void ClimateTraits::set_supports_action(bool supports_action) { supports_action_ = supports_action; }
float ClimateTraits::get_visual_min_temperature() const { return visual_min_temperature_; }
void ClimateTraits::set_visual_min_temperature(float visual_min_temperature) {
Expand All @@ -61,6 +62,7 @@ int8_t ClimateTraits::get_temperature_accuracy_decimals() const {
}
void ClimateTraits::set_visual_temperature_step(float temperature_step) { visual_temperature_step_ = temperature_step; }
bool ClimateTraits::get_supports_away() const { return supports_away_; }
bool ClimateTraits::get_supports_eco_mode() const { return supports_eco_mode_; }
bool ClimateTraits::get_supports_action() const { return supports_action_; }

void ClimateTraits::set_supports_fan_mode_on(bool supports_fan_mode_on) {
Expand Down
4 changes: 4 additions & 0 deletions esphome/components/climate/climate_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace climate {
* - fan mode (only turns on fan)
* - supports away - away mode means that the climate device supports two different
* target temperature settings: one target temp setting for "away" mode and one for non-away mode.
* - supports eco mode - eco mode means that the climate device supports outputting less energy.
* - supports action - if the climate device supports reporting the active
* current action of the device with the action property.
* - supports fan modes - optionally, if it has a fan which can be configured in different ways:
Expand All @@ -51,6 +52,8 @@ class ClimateTraits {
void set_supports_dry_mode(bool supports_dry_mode);
void set_supports_away(bool supports_away);
bool get_supports_away() const;
void set_supports_eco_mode(bool supports_eco_mode);
bool get_supports_eco_mode() const;
void set_supports_action(bool supports_action);
bool get_supports_action() const;
bool supports_mode(ClimateMode mode) const;
Expand Down Expand Up @@ -89,6 +92,7 @@ class ClimateTraits {
bool supports_fan_only_mode_{false};
bool supports_dry_mode_{false};
bool supports_away_{false};
bool supports_eco_mode_{false};
bool supports_action_{false};
bool supports_fan_mode_on_{false};
bool supports_fan_mode_off_{false};
Expand Down