[sgp4x] Fix undefined behavior from mutating entity config at runtime (#14562)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
J. Nick Koston
2026-03-06 08:02:34 -10:00
committed by GitHub
parent 6e3bc7b1dd
commit 65b7c73bf3
+3 -7
View File
@@ -35,13 +35,9 @@ void SGP4xComponent::setup() {
this->self_test_time_ = SPG40_SELFTEST_TIME;
this->measure_time_ = SGP40_MEASURE_TIME;
if (this->nox_sensor_) {
ESP_LOGE(TAG, "SGP41 required for NOx");
// disable the sensor
this->nox_sensor_->set_disabled_by_default(true);
// make sure it's not visible in HA
this->nox_sensor_->set_internal(true);
this->nox_sensor_->state = NAN;
// remove pointer to sensor
ESP_LOGE(TAG, "SGP41 required for NOx, disabling NOx sensor");
// Drop the pointer so update() never publishes to it.
// The entity remains registered but will never receive state updates.
this->nox_sensor_ = nullptr;
}
} else if (featureset == SGP41_FEATURESET) {