mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Ensure component is ready before update. (#4523)
Co-authored-by: Your Name <you@example.com>
This commit is contained in:
parent
3227ef4bca
commit
3773c385c7
3 changed files with 7 additions and 1 deletions
|
@ -317,7 +317,7 @@ template<typename... Ts> class UpdateComponentAction : public Action<Ts...> {
|
|||
UpdateComponentAction(PollingComponent *component) : component_(component) {}
|
||||
|
||||
void play(Ts... x) override {
|
||||
if (this->component_->is_failed())
|
||||
if (!this->component_->is_ready())
|
||||
return;
|
||||
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);
|
||||
}
|
||||
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::status_has_warning() { return this->component_state_ & STATUS_LED_WARNING; }
|
||||
bool Component::status_has_error() { return this->component_state_ & STATUS_LED_ERROR; }
|
||||
|
|
|
@ -119,6 +119,8 @@ class Component {
|
|||
|
||||
bool is_failed();
|
||||
|
||||
bool is_ready();
|
||||
|
||||
virtual bool can_proceed();
|
||||
|
||||
bool status_has_warning();
|
||||
|
|
Loading…
Reference in a new issue