mirror of
https://github.com/esphome/esphome.git
synced 2026-09-17 18:18:43 +00:00
Add NOLINT for precondition-based get_state() access
get_state() requires callers to check has_state() first. This is a documented precondition, not an unchecked access. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
4e1b7c440e
commit
529293b5be
@@ -69,7 +69,7 @@ optional<size_t> SelectCall::calculate_target_index_(const char *name) {
|
||||
ESP_LOGW(TAG, "'%s' - No option set", name);
|
||||
return {};
|
||||
}
|
||||
return this->index_.value();
|
||||
return this->index_;
|
||||
}
|
||||
|
||||
// SELECT_OP_NEXT or SELECT_OP_PREVIOUS
|
||||
|
||||
@@ -252,7 +252,7 @@ void log_entity_unit_of_measurement(const char *tag, const char *prefix, const E
|
||||
template<typename T> class StatefulEntityBase : public EntityBase {
|
||||
public:
|
||||
virtual bool has_state() const { return this->state_.has_value(); }
|
||||
virtual const T &get_state() const { return *this->state_; }
|
||||
virtual const T &get_state() const { return this->state_.value(); } // NOLINT(bugprone-unchecked-optional-access)
|
||||
virtual T get_state_default(T default_value) const { return this->state_.value_or(default_value); }
|
||||
void invalidate_state() { this->set_new_state({}); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user