From 12997451f686724efd33b22146fa547041a80093 Mon Sep 17 00:00:00 2001 From: Thomas Rupprecht Date: Thu, 29 May 2025 04:57:20 +0200 Subject: [PATCH] particle matter improvements (#8846) --- esphome/components/pm1006/pm1006.cpp | 6 +++--- esphome/components/pm2005/pm2005.cpp | 8 ++++---- esphome/components/pm2005/sensor.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/esphome/components/pm1006/pm1006.cpp b/esphome/components/pm1006/pm1006.cpp index 1a89307eee..f28c647721 100644 --- a/esphome/components/pm1006/pm1006.cpp +++ b/esphome/components/pm1006/pm1006.cpp @@ -55,8 +55,8 @@ uint8_t PM1006Component::pm1006_checksum_(const uint8_t *command_data, uint8_t l } optional PM1006Component::check_byte_() const { - uint8_t index = this->data_index_; - uint8_t byte = this->data_[index]; + const uint8_t index = this->data_index_; + const uint8_t byte = this->data_[index]; // index 0..2 are the fixed header if (index < sizeof(PM1006_RESPONSE_HEADER)) { @@ -86,7 +86,7 @@ optional PM1006Component::check_byte_() const { } void PM1006Component::parse_data_() { - const int pm_2_5_concentration = this->get_16_bit_uint_(5); + const uint16_t pm_2_5_concentration = this->get_16_bit_uint_(5); ESP_LOGD(TAG, "Got PM2.5 Concentration: %d µg/m³", pm_2_5_concentration); diff --git a/esphome/components/pm2005/pm2005.cpp b/esphome/components/pm2005/pm2005.cpp index 847ee8c4cd..affa35f926 100644 --- a/esphome/components/pm2005/pm2005.cpp +++ b/esphome/components/pm2005/pm2005.cpp @@ -82,10 +82,10 @@ void PM2005Component::update() { return; } - uint16_t pm1 = get_sensor_value(this->data_buffer_, this->pm_1_0_value_index_); - uint16_t pm25 = get_sensor_value(this->data_buffer_, this->pm_2_5_value_index_); - uint16_t pm10 = get_sensor_value(this->data_buffer_, this->pm_10_0_value_index_); - uint16_t sensor_measuring_mode = get_sensor_value(this->data_buffer_, this->measuring_value_index_); + const uint16_t pm1 = get_sensor_value(this->data_buffer_, this->pm_1_0_value_index_); + const uint16_t pm25 = get_sensor_value(this->data_buffer_, this->pm_2_5_value_index_); + const uint16_t pm10 = get_sensor_value(this->data_buffer_, this->pm_10_0_value_index_); + const uint16_t sensor_measuring_mode = get_sensor_value(this->data_buffer_, this->measuring_value_index_); ESP_LOGD(TAG, "PM1.0: %d, PM2.5: %d, PM10: %d, Measuring mode: %s.", pm1, pm25, pm10, LOG_STR_ARG(pm2005_get_measuring_mode_string(sensor_measuring_mode))); diff --git a/esphome/components/pm2005/sensor.py b/esphome/components/pm2005/sensor.py index 66f630f8ff..3a650560a0 100644 --- a/esphome/components/pm2005/sensor.py +++ b/esphome/components/pm2005/sensor.py @@ -1,8 +1,8 @@ """PM2005/2105 Sensor component for ESPHome.""" import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_PM_1_0,