ESPHome  2022.11.3
hm3301.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 namespace esphome {
9 namespace hm3301 {
10 
11 static const uint8_t SELECT_COMM_CMD = 0X88;
12 
14  public:
15  HM3301Component() = default;
16 
17  void set_pm_1_0_sensor(sensor::Sensor *pm_1_0_sensor) { pm_1_0_sensor_ = pm_1_0_sensor; }
18  void set_pm_2_5_sensor(sensor::Sensor *pm_2_5_sensor) { pm_2_5_sensor_ = pm_2_5_sensor; }
19  void set_pm_10_0_sensor(sensor::Sensor *pm_10_0_sensor) { pm_10_0_sensor_ = pm_10_0_sensor; }
20  void set_aqi_sensor(sensor::Sensor *aqi_sensor) { aqi_sensor_ = aqi_sensor; }
21 
22  void set_aqi_calculation_type(AQICalculatorType aqi_calc_type) { aqi_calc_type_ = aqi_calc_type; }
23 
24  void setup() override;
25  void dump_config() override;
26  float get_setup_priority() const override;
27  void update() override;
28 
29  protected:
30  enum {
31  NO_ERROR = 0,
33  ERROR_COMM = -2,
34  ERROR_OTHERS = -128,
35  } error_code_{NO_ERROR};
36 
37  uint8_t data_buffer_[30];
38 
43 
46 
47  bool validate_checksum_(const uint8_t *data);
48  uint16_t get_sensor_value_(const uint8_t *data, uint8_t i);
49 };
50 
51 } // namespace hm3301
52 } // namespace esphome
AQICalculatorFactory aqi_calculator_factory_
Definition: hm3301.h:45
sensor::Sensor * pm_2_5_sensor_
Definition: hm3301.h:40
sensor::Sensor * pm_1_0_sensor_
Definition: hm3301.h:39
uint16_t get_sensor_value_(const uint8_t *data, uint8_t i)
Definition: hm3301.cpp:96
sensor::Sensor * pm_10_0_sensor_
Definition: hm3301.h:41
This class simplifies creating components that periodically check a state.
Definition: component.h:267
void set_pm_1_0_sensor(sensor::Sensor *pm_1_0_sensor)
Definition: hm3301.h:17
void set_aqi_calculation_type(AQICalculatorType aqi_calc_type)
Definition: hm3301.h:22
sensor::Sensor * aqi_sensor_
Definition: hm3301.h:42
enum esphome::hm3301::HM3301Component::@62 NO_ERROR
void set_aqi_sensor(sensor::Sensor *aqi_sensor)
Definition: hm3301.h:20
void set_pm_10_0_sensor(sensor::Sensor *pm_10_0_sensor)
Definition: hm3301.h:19
bool validate_checksum_(const uint8_t *data)
Definition: hm3301.cpp:87
float get_setup_priority() const override
Definition: hm3301.cpp:35
AQICalculatorType aqi_calc_type_
Definition: hm3301.h:44
Definition: a4988.cpp:4
void set_pm_2_5_sensor(sensor::Sensor *pm_2_5_sensor)
Definition: hm3301.h:18
Base-class for all sensors.
Definition: sensor.h:48
void dump_config() override
Definition: hm3301.cpp:22