mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Ensure component is ready before update. (#4523)
Co-authored-by: Your Name <you@example.com>
This commit is contained in:
		| @@ -317,7 +317,7 @@ template<typename... Ts> class UpdateComponentAction : public Action<Ts...> { | |||||||
|   UpdateComponentAction(PollingComponent *component) : component_(component) {} |   UpdateComponentAction(PollingComponent *component) : component_(component) {} | ||||||
|  |  | ||||||
|   void play(Ts... x) override { |   void play(Ts... x) override { | ||||||
|     if (this->component_->is_failed()) |     if (!this->component_->is_ready()) | ||||||
|       return; |       return; | ||||||
|     this->component_->update(); |     this->component_->update(); | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -135,6 +135,10 @@ void Component::set_retry(uint32_t initial_wait_time, uint8_t max_attempts, std: | |||||||
|   App.scheduler.set_retry(this, "", initial_wait_time, max_attempts, std::move(f), backoff_increase_factor); |   App.scheduler.set_retry(this, "", initial_wait_time, max_attempts, std::move(f), backoff_increase_factor); | ||||||
| } | } | ||||||
| bool Component::is_failed() { return (this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_FAILED; } | bool Component::is_failed() { return (this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_FAILED; } | ||||||
|  | bool Component::is_ready() { | ||||||
|  |   return (this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP || | ||||||
|  |          (this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_SETUP; | ||||||
|  | } | ||||||
| bool Component::can_proceed() { return true; } | bool Component::can_proceed() { return true; } | ||||||
| bool Component::status_has_warning() { return this->component_state_ & STATUS_LED_WARNING; } | bool Component::status_has_warning() { return this->component_state_ & STATUS_LED_WARNING; } | ||||||
| bool Component::status_has_error() { return this->component_state_ & STATUS_LED_ERROR; } | bool Component::status_has_error() { return this->component_state_ & STATUS_LED_ERROR; } | ||||||
|   | |||||||
| @@ -119,6 +119,8 @@ class Component { | |||||||
|  |  | ||||||
|   bool is_failed(); |   bool is_failed(); | ||||||
|  |  | ||||||
|  |   bool is_ready(); | ||||||
|  |  | ||||||
|   virtual bool can_proceed(); |   virtual bool can_proceed(); | ||||||
|  |  | ||||||
|   bool status_has_warning(); |   bool status_has_warning(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user