7 static const char *
const TAG =
"hm3301.sensor";
9 static const uint8_t PM_1_0_VALUE_INDEX = 5;
10 static const uint8_t PM_2_5_VALUE_INDEX = 6;
11 static const uint8_t PM_10_0_VALUE_INDEX = 7;
14 ESP_LOGCONFIG(TAG,
"Setting up HM3301...");
23 ESP_LOGCONFIG(TAG,
"HM3301:");
26 ESP_LOGE(TAG,
"Communication with HM3301 failed!");
39 ESP_LOGW(TAG,
"Read result failed");
45 ESP_LOGW(TAG,
"Checksum validation failed");
50 int16_t pm_1_0_value = -1;
55 int16_t pm_2_5_value = -1;
60 int16_t pm_10_0_value = -1;
65 int16_t aqi_value = -1;
66 if (this->
aqi_sensor_ !=
nullptr && pm_2_5_value != -1 && pm_10_0_value != -1) {
68 aqi_value = calculator->
get_aqi(pm_2_5_value, pm_10_0_value);
71 if (pm_1_0_value != -1) {
74 if (pm_2_5_value != -1) {
77 if (pm_10_0_value != -1) {
80 if (aqi_value != -1) {
89 for (
int i = 0; i < 28; i++) {
93 return sum == data[28];
97 return (uint16_t) data[i * 2] << 8 | data[i * 2 + 1];
AbstractAQICalculator * get_calculator(AQICalculatorType type)
const float DATA
For components that import data from directly connected sensors like DHT.
AQICalculatorFactory aqi_calculator_factory_
void status_set_warning(const char *message="unspecified")
sensor::Sensor * pm_2_5_sensor_
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
sensor::Sensor * pm_1_0_sensor_
uint16_t get_sensor_value_(const uint8_t *data, uint8_t i)
sensor::Sensor * pm_10_0_sensor_
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
sensor::Sensor * aqi_sensor_
No error found during execution of method.
void status_clear_warning()
virtual uint16_t get_aqi(uint16_t pm2_5_value, uint16_t pm10_0_value)=0
void publish_state(float state)
Publish a new state to the front-end.
bool validate_checksum_(const uint8_t *data)
float get_setup_priority() const override
AQICalculatorType aqi_calc_type_
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
void dump_config() override