9static const uint8_t PM_1_0_VALUE_INDEX = 5;
10static const uint8_t PM_2_5_VALUE_INDEX = 6;
11static const uint8_t PM_10_0_VALUE_INDEX = 7;
13void HM3301Component::setup() {
21void HM3301Component::dump_config() {
22 ESP_LOGCONFIG(TAG,
"HM3301:");
25 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
28 LOG_SENSOR(
" ",
"PM1.0", this->pm_1_0_sensor_);
29 LOG_SENSOR(
" ",
"PM2.5", this->pm_2_5_sensor_);
30 LOG_SENSOR(
" ",
"PM10.0", this->pm_10_0_sensor_);
31 LOG_SENSOR(
" ",
"AQI", this->aqi_sensor_);
34void HM3301Component::update() {
36 ESP_LOGW(TAG,
"Read result failed");
42 ESP_LOGW(TAG,
"Checksum validation failed");
47 int16_t pm_1_0_value = -1;
48 if (this->pm_1_0_sensor_ !=
nullptr) {
52 int16_t pm_2_5_value = -1;
53 if (this->pm_2_5_sensor_ !=
nullptr) {
57 int16_t pm_10_0_value = -1;
58 if (this->pm_10_0_sensor_ !=
nullptr) {
62 int16_t aqi_value = -1;
63 if (this->aqi_sensor_ !=
nullptr && pm_2_5_value != -1 && pm_10_0_value != -1) {
65 aqi_value = calculator->
get_aqi(pm_2_5_value, pm_10_0_value,
false);
68 if (pm_1_0_value != -1) {
69 this->pm_1_0_sensor_->publish_state(pm_1_0_value);
71 if (pm_2_5_value != -1) {
72 this->pm_2_5_sensor_->publish_state(pm_2_5_value);
74 if (pm_10_0_value != -1) {
75 this->pm_10_0_sensor_->publish_state(pm_10_0_value);
77 if (aqi_value != -1) {
78 this->aqi_sensor_->publish_state(aqi_value);
constexpr uint8_t sum_bytes(const uint8_t *data, size_t len, uint8_t sum=0)
Add up the bytes of data with size len, truncated to 8 bits: the checksum many serial and IR protocol...