1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-16 10:12:21 +01:00

climate: add on_control callbacks (#4511)

This lets downstream components respond to climate configuration
changes, which take place through ClimateCall objects, without also
being notified every time the state changes, which happens every time
the input sensor announces a new value.

FIXES https://github.com/esphome/feature-requests/issues/2136
This commit is contained in:
Nathaniel Wesley Filardo
2023-03-07 04:19:49 +00:00
committed by GitHub
parent 3773c385c7
commit 05ab49a615
6 changed files with 31 additions and 0 deletions

View File

@@ -44,6 +44,7 @@ void ClimateCall::perform() {
if (this->target_temperature_high_.has_value()) {
ESP_LOGD(TAG, " Target Temperature High: %.2f", *this->target_temperature_high_);
}
this->parent_->control_callback_.call();
this->parent_->control(*this);
}
void ClimateCall::validate_() {
@@ -317,6 +318,10 @@ void Climate::add_on_state_callback(std::function<void()> &&callback) {
this->state_callback_.add(std::move(callback));
}
void Climate::add_on_control_callback(std::function<void()> &&callback) {
this->control_callback_.add(std::move(callback));
}
// Random 32bit value; If this changes existing restore preferences are invalidated
static const uint32_t RESTORE_STATE_VERSION = 0x848EA6ADUL;