[core] Inline trivial Component state accessors (#14425)

This commit is contained in:
J. Nick Koston
2026-03-03 07:05:15 -10:00
committed by GitHub
parent 4f69c487da
commit b209c903bb
2 changed files with 6 additions and 14 deletions
-8
View File
@@ -233,7 +233,6 @@ void Component::call_dump_config_() {
}
}
uint8_t Component::get_component_state() const { return this->component_state_; }
void Component::call() {
uint8_t state = this->component_state_ & COMPONENT_STATE_MASK;
switch (state) {
@@ -339,9 +338,6 @@ void Component::reset_to_construction_state() {
this->status_clear_error();
}
}
bool Component::is_in_loop_state() const {
return (this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP;
}
void Component::defer(std::function<void()> &&f) { // NOLINT
App.scheduler.set_timeout(this, static_cast<const char *>(nullptr), 0, std::move(f));
}
@@ -380,16 +376,12 @@ 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);
#pragma GCC diagnostic pop
}
bool Component::is_failed() const { return (this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_FAILED; }
bool Component::is_ready() const {
return (this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP ||
(this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP_DONE ||
(this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_SETUP;
}
bool Component::is_idle() const { return (this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP_DONE; }
bool Component::can_proceed() { return true; }
bool Component::status_has_warning() const { return this->component_state_ & STATUS_LED_WARNING; }
bool Component::status_has_error() const { return this->component_state_ & STATUS_LED_ERROR; }
bool Component::set_status_flag_(uint8_t flag) {
if ((this->component_state_ & flag) != 0)
return false;
+6 -6
View File
@@ -142,7 +142,7 @@ class Component {
*/
virtual void on_powerdown() {}
uint8_t get_component_state() const;
uint8_t get_component_state() const { return this->component_state_; }
/** Reset this component back to the construction state to allow setup to run again.
*
@@ -154,7 +154,7 @@ class Component {
*
* @return True if in loop state, false otherwise.
*/
bool is_in_loop_state() const;
bool is_in_loop_state() const { return (this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP; }
/** Check if this component is idle.
* Being idle means being in LOOP_DONE state.
@@ -162,7 +162,7 @@ class Component {
*
* @return True if the component is idle
*/
bool is_idle() const;
bool is_idle() const { return (this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP_DONE; }
/** Mark this component as failed. Any future timeouts/intervals/setup/loop will no longer be called.
*
@@ -230,15 +230,15 @@ class Component {
*/
void enable_loop_soon_any_context();
bool is_failed() const;
bool is_failed() const { return (this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_FAILED; }
bool is_ready() const;
virtual bool can_proceed();
bool status_has_warning() const;
bool status_has_warning() const { return this->component_state_ & STATUS_LED_WARNING; }
bool status_has_error() const;
bool status_has_error() const { return this->component_state_ & STATUS_LED_ERROR; }
void status_set_warning(const char *message = nullptr);
void status_set_warning(const LogString *message);