Add get_away and get_on

This commit is contained in:
tronikos
2026-02-09 12:25:32 -08:00
parent 2cf853d6a1
commit cbdb870ce3
2 changed files with 19 additions and 8 deletions

View File

@@ -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());
}
}

View File

@@ -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<bool> get_away() const {
if (this->state_mask_ & WATER_HEATER_STATE_AWAY) {
return (this->state_ & WATER_HEATER_STATE_AWAY) != 0;
}
return {};
}
optional<bool> get_on() const {
if (this->state_mask_ & WATER_HEATER_STATE_ON) {
return (this->state_ & WATER_HEATER_STATE_ON) != 0;
}
return {};
}
protected:
void validate_();