mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 17:05:21 +01:00
Fix climate restore schema changed resulting in invalid restore (#2068)
Co-authored-by: Stefan Agner <stefan@agner.ch>
This commit is contained in:
parent
790d6ef94c
commit
3ffa59f0cd
2 changed files with 6 additions and 1 deletions
|
@ -312,8 +312,12 @@ void Climate::add_on_state_callback(std::function<void()> &&callback) {
|
||||||
this->state_callback_.add(std::move(callback));
|
this->state_callback_.add(std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Random 32bit value; If this changes existing restore preferences are invalidated
|
||||||
|
static const uint32_t RESTORE_STATE_VERSION = 0x848EA6ADUL;
|
||||||
|
|
||||||
optional<ClimateDeviceRestoreState> Climate::restore_state_() {
|
optional<ClimateDeviceRestoreState> Climate::restore_state_() {
|
||||||
this->rtc_ = global_preferences.make_preference<ClimateDeviceRestoreState>(this->get_object_id_hash());
|
this->rtc_ =
|
||||||
|
global_preferences.make_preference<ClimateDeviceRestoreState>(this->get_object_id_hash() ^ RESTORE_STATE_VERSION);
|
||||||
ClimateDeviceRestoreState recovered{};
|
ClimateDeviceRestoreState recovered{};
|
||||||
if (!this->rtc_.load(&recovered))
|
if (!this->rtc_.load(&recovered))
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -120,6 +120,7 @@ class ClimateCall {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Struct used to save the state of the climate device in restore memory.
|
/// Struct used to save the state of the climate device in restore memory.
|
||||||
|
/// Make sure to update RESTORE_STATE_VERSION when changing the struct entries.
|
||||||
struct ClimateDeviceRestoreState {
|
struct ClimateDeviceRestoreState {
|
||||||
ClimateMode mode;
|
ClimateMode mode;
|
||||||
bool uses_custom_fan_mode{false};
|
bool uses_custom_fan_mode{false};
|
||||||
|
|
Loading…
Reference in a new issue