ESPHome  2024.11.1
ld2420_sensor.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../ld2420.h"
5 
6 namespace esphome {
7 namespace ld2420 {
8 
10  public:
11  void dump_config() override;
13  void on_distance(uint16_t distance) override {
14  if (this->distance_sensor_ != nullptr) {
15  if (this->distance_sensor_->get_state() != distance) {
16  this->distance_sensor_->publish_state(distance);
17  }
18  }
19  }
20  void on_energy(uint16_t *gate_energy, size_t size) override {
21  for (size_t active = 0; active < size; active++) {
22  if (this->energy_sensors_[active] != nullptr) {
23  this->energy_sensors_[active]->publish_state(gate_energy[active]);
24  }
25  }
26  }
27 
28  protected:
30  std::vector<sensor::Sensor *> energy_sensors_ = std::vector<sensor::Sensor *>(LD2420_TOTAL_GATES);
31 };
32 
33 } // namespace ld2420
34 } // namespace esphome
void on_distance(uint16_t distance) override
Definition: ld2420_sensor.h:13
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:39
void set_distance_sensor(sensor::Sensor *sensor)
Definition: ld2420_sensor.h:12
std::vector< sensor::Sensor * > energy_sensors_
Definition: ld2420_sensor.h:30
float get_state() const
Getter-syntax for .state.
Definition: sensor.cpp:86
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base-class for all sensors.
Definition: sensor.h:57
sensor::Sensor * distance_sensor_
Definition: ld2420_sensor.h:29
void on_energy(uint16_t *gate_energy, size_t size) override
Definition: ld2420_sensor.h:20
esphome::sensor::Sensor * sensor
Definition: statsd.h:38