From cbdb870ce367727df9ba6c2ce0df9244d61bea9c Mon Sep 17 00:00:00 2001 From: tronikos Date: Mon, 9 Feb 2026 12:25:32 -0800 Subject: [PATCH] Add get_away and get_on --- .../water_heater/template_water_heater.cpp | 10 ++++------ esphome/components/water_heater/water_heater.h | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/esphome/components/template/water_heater/template_water_heater.cpp b/esphome/components/template/water_heater/template_water_heater.cpp index 4babb44625..57c76286a0 100644 --- a/esphome/components/template/water_heater/template_water_heater.cpp +++ b/esphome/components/template/water_heater/template_water_heater.cpp @@ -112,16 +112,14 @@ void TemplateWaterHeater::control(const water_heater::WaterHeaterCall &call) { } } - if ((call.get_state_mask() & water_heater::WATER_HEATER_STATE_AWAY) != 0) { + if (call.get_away().has_value()) { if (this->optimistic_) { - this->set_state_flag_(water_heater::WATER_HEATER_STATE_AWAY, - (call.get_state() & water_heater::WATER_HEATER_STATE_AWAY) != 0); + this->set_state_flag_(water_heater::WATER_HEATER_STATE_AWAY, *call.get_away()); } } - if ((call.get_state_mask() & water_heater::WATER_HEATER_STATE_ON) != 0) { + if (call.get_on().has_value()) { if (this->optimistic_) { - this->set_state_flag_(water_heater::WATER_HEATER_STATE_ON, - (call.get_state() & water_heater::WATER_HEATER_STATE_ON) != 0); + this->set_state_flag_(water_heater::WATER_HEATER_STATE_ON, *call.get_on()); } } diff --git a/esphome/components/water_heater/water_heater.h b/esphome/components/water_heater/water_heater.h index 93fcf5f401..070ae99575 100644 --- a/esphome/components/water_heater/water_heater.h +++ b/esphome/components/water_heater/water_heater.h @@ -90,9 +90,22 @@ class WaterHeaterCall { float get_target_temperature_low() const { return this->target_temperature_low_; } float get_target_temperature_high() const { return this->target_temperature_high_; } /// Get state flags value + ESPDEPRECATED("get_state() is deprecated, use get_away() and get_on() instead. (Removed in 2026.8.0)", "2026.2.0") uint32_t get_state() const { return this->state_; } - /// Get mask of state flags that are being changed - uint32_t get_state_mask() const { return this->state_mask_; } + + optional get_away() const { + if (this->state_mask_ & WATER_HEATER_STATE_AWAY) { + return (this->state_ & WATER_HEATER_STATE_AWAY) != 0; + } + return {}; + } + + optional get_on() const { + if (this->state_mask_ & WATER_HEATER_STATE_ON) { + return (this->state_ & WATER_HEATER_STATE_ON) != 0; + } + return {}; + } protected: void validate_();