mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 08:28:12 +01:00
Fix SM300D2 sensor component routines so they correctly read the sensor output (#2159)
This commit is contained in:
parent
4e308f551c
commit
c6109024aa
2 changed files with 7 additions and 5 deletions
|
@ -72,13 +72,13 @@ CONFIG_SCHEMA = cv.All(
|
|||
),
|
||||
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_CELSIUS,
|
||||
accuracy_decimals=0,
|
||||
accuracy_decimals=1,
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_PERCENT,
|
||||
accuracy_decimals=0,
|
||||
accuracy_decimals=1,
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
|
|
|
@ -9,10 +9,12 @@ static const uint8_t SM300D2_RESPONSE_LENGTH = 17;
|
|||
|
||||
void SM300D2Sensor::update() {
|
||||
uint8_t response[SM300D2_RESPONSE_LENGTH];
|
||||
uint8_t peeked;
|
||||
|
||||
while (this->available() > 0 && this->peek_byte(&peeked) && peeked != 0x3C)
|
||||
this->read();
|
||||
|
||||
flush();
|
||||
bool read_success = read_array(response, SM300D2_RESPONSE_LENGTH);
|
||||
flush();
|
||||
|
||||
if (!read_success) {
|
||||
ESP_LOGW(TAG, "Reading data from SM300D2 failed!");
|
||||
|
@ -63,7 +65,7 @@ void SM300D2Sensor::update() {
|
|||
if (this->pm_2_5_sensor_ != nullptr)
|
||||
this->pm_2_5_sensor_->publish_state(pm_2_5);
|
||||
|
||||
ESP_LOGD(TAG, "Received pm_10_0: %u µg/m³", pm_10_0);
|
||||
ESP_LOGD(TAG, "Received PM10: %u µg/m³", pm_10_0);
|
||||
if (this->pm_10_0_sensor_ != nullptr)
|
||||
this->pm_10_0_sensor_->publish_state(pm_10_0);
|
||||
|
||||
|
|
Loading…
Reference in a new issue