Ensure component is ready before update. (#4523)

Co-authored-by: Your Name <you@example.com>
This commit is contained in:
Fabian 2023-03-07 05:16:42 +01:00 committed by GitHub
parent 3227ef4bca
commit 3773c385c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 1 deletions

View File

@ -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();
}

View File

@ -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; }

View File

@ -119,6 +119,8 @@ class Component {
bool is_failed();
bool is_ready();
virtual bool can_proceed();
bool status_has_warning();