mirror of
https://github.com/esphome/esphome.git
synced 2025-09-02 03:12:20 +01:00
[senseair] Discard 0 ppm readings with "Out Of Range" bit set. (#10275)
This commit is contained in:
@@ -53,10 +53,14 @@ void SenseAirComponent::update() {
|
|||||||
|
|
||||||
this->status_clear_warning();
|
this->status_clear_warning();
|
||||||
const uint8_t length = response[2];
|
const uint8_t length = response[2];
|
||||||
const uint16_t status = (uint16_t(response[3]) << 8) | response[4];
|
const uint16_t status = encode_uint16(response[3], response[4]);
|
||||||
const int16_t ppm = int16_t((response[length + 1] << 8) | response[length + 2]);
|
const uint16_t ppm = encode_uint16(response[length + 1], response[length + 2]);
|
||||||
|
|
||||||
ESP_LOGD(TAG, "SenseAir Received CO₂=%dppm Status=0x%02X", ppm, status);
|
ESP_LOGD(TAG, "SenseAir Received CO₂=%uppm Status=0x%02X", ppm, status);
|
||||||
|
if (ppm == 0 && (status & SenseAirStatus::OUT_OF_RANGE_ERROR) != 0) {
|
||||||
|
ESP_LOGD(TAG, "Discarding 0 ppm reading with out-of-range status.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this->co2_sensor_ != nullptr)
|
if (this->co2_sensor_ != nullptr)
|
||||||
this->co2_sensor_->publish_state(ppm);
|
this->co2_sensor_->publish_state(ppm);
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,17 @@
|
|||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace senseair {
|
namespace senseair {
|
||||||
|
|
||||||
|
enum SenseAirStatus : uint8_t {
|
||||||
|
FATAL_ERROR = 1 << 0,
|
||||||
|
OFFSET_ERROR = 1 << 1,
|
||||||
|
ALGORITHM_ERROR = 1 << 2,
|
||||||
|
OUTPUT_ERROR = 1 << 3,
|
||||||
|
SELF_DIAGNOSTIC_ERROR = 1 << 4,
|
||||||
|
OUT_OF_RANGE_ERROR = 1 << 5,
|
||||||
|
MEMORY_ERROR = 1 << 6,
|
||||||
|
RESERVED = 1 << 7
|
||||||
|
};
|
||||||
|
|
||||||
class SenseAirComponent : public PollingComponent, public uart::UARTDevice {
|
class SenseAirComponent : public PollingComponent, public uart::UARTDevice {
|
||||||
public:
|
public:
|
||||||
void set_co2_sensor(sensor::Sensor *co2_sensor) { co2_sensor_ = co2_sensor; }
|
void set_co2_sensor(sensor::Sensor *co2_sensor) { co2_sensor_ = co2_sensor; }
|
||||||
|
Reference in New Issue
Block a user