[climate] Avoid duplicate get_traits() in publish_state (#15181)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
J. Nick Koston
2026-03-26 09:01:08 -10:00
committed by GitHub
parent 1edf952dda
commit a008c27fcf
2 changed files with 4 additions and 4 deletions

View File

@@ -367,7 +367,7 @@ optional<ClimateDeviceRestoreState> Climate::restore_state_() {
return recovered;
}
void Climate::save_state_() {
void Climate::save_state_(const ClimateTraits &traits) {
#if (defined(USE_ESP32) || (defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE >= VERSION_CODE(3, 0, 0))) && \
!defined(CLANG_TIDY)
#pragma GCC diagnostic ignored "-Wclass-memaccess"
@@ -382,7 +382,6 @@ void Climate::save_state_() {
#endif
state.mode = this->mode;
auto traits = this->get_traits();
if (traits.has_feature_flags(CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE |
CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE)) {
state.target_temperature_low = this->target_temperature_low;
@@ -480,7 +479,7 @@ void Climate::publish_state() {
ControllerRegistry::notify_climate_update(this);
#endif
// Save state
this->save_state_();
this->save_state_(traits);
}
ClimateTraits Climate::get_traits() {

View File

@@ -335,7 +335,8 @@ class Climate : public EntityBase {
/** Internal method to save the state of the climate device to recover memory. This is automatically
* called from publish_state()
*/
void save_state_();
void save_state_(const ClimateTraits &traits);
void save_state_() { this->save_state_(this->traits()); }
void dump_traits_(const char *tag);