From 7f97f4255226472fce6be0d02898e70c1d1b8545 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 26 Jan 2023 02:09:38 +0300 Subject: [PATCH] Fix BME280 initialization before wifi setup (#4190) fixes https://github.com/esphome/issues/issues/3530 --- esphome/components/bme280/bme280.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/esphome/components/bme280/bme280.cpp b/esphome/components/bme280/bme280.cpp index d8124f5dc3..786fc01d28 100644 --- a/esphome/components/bme280/bme280.cpp +++ b/esphome/components/bme280/bme280.cpp @@ -88,7 +88,10 @@ void BME280Component::setup() { // Mark as not failed before initializing. Some devices will turn off sensors to save on batteries // and when they come back on, the COMPONENT_STATE_FAILED bit must be unset on the component. - this->component_state_ &= ~COMPONENT_STATE_FAILED; + if ((this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_FAILED) { + this->component_state_ &= ~COMPONENT_STATE_MASK; + this->component_state_ |= COMPONENT_STATE_CONSTRUCTION; + } if (!this->read_byte(BME280_REGISTER_CHIPID, &chip_id)) { this->error_code_ = COMMUNICATION_FAILED;