From b635689c291acd1af430d8369f843131a81518e6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 28 Oct 2025 23:01:28 -0500 Subject: [PATCH] make sure no dangling --- esphome/components/fan/fan.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/esphome/components/fan/fan.cpp b/esphome/components/fan/fan.cpp index b5eb1121e3..3a02161cd0 100644 --- a/esphome/components/fan/fan.cpp +++ b/esphome/components/fan/fan.cpp @@ -191,14 +191,15 @@ void Fan::save_state_() { return; } + auto traits = this->get_traits(); + FanRestoreState state{}; state.state = this->state; state.oscillating = this->oscillating; state.speed = this->speed; state.direction = this->direction; - if (this->get_traits().supports_preset_modes() && !this->preset_mode.empty()) { - auto traits = this->get_traits(); + if (traits.supports_preset_modes() && !this->preset_mode.empty()) { const auto &preset_modes = traits.supported_preset_modes(); // Store index of current preset mode size_t i = 0;