mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	RestoringGlobalsComponent: Store value on shutdown (#3586)
This commit is contained in:
		| @@ -44,7 +44,14 @@ template<typename T> class RestoringGlobalsComponent : public Component { | ||||
|  | ||||
|   float get_setup_priority() const override { return setup_priority::HARDWARE; } | ||||
|  | ||||
|   void loop() override { | ||||
|   void loop() override { store_value_(); } | ||||
|  | ||||
|   void on_shutdown() override { store_value_(); } | ||||
|  | ||||
|   void set_name_hash(uint32_t name_hash) { this->name_hash_ = name_hash; } | ||||
|  | ||||
|  protected: | ||||
|   void store_value_() { | ||||
|     int diff = memcmp(&this->value_, &this->prev_value_, sizeof(T)); | ||||
|     if (diff != 0) { | ||||
|       this->rtc_.save(&this->value_); | ||||
| @@ -52,9 +59,6 @@ template<typename T> class RestoringGlobalsComponent : public Component { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   void set_name_hash(uint32_t name_hash) { this->name_hash_ = name_hash; } | ||||
|  | ||||
|  protected: | ||||
|   T value_{}; | ||||
|   T prev_value_{}; | ||||
|   uint32_t name_hash_{}; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user