ESPHome 2025.5.0
Loading...
Searching...
No Matches
ld2420_sensor.h
Go to the documentation of this file.
1#pragma once
2
3#include "../ld2420.h"
5
6namespace esphome {
7namespace ld2420 {
8
10 public:
11 void dump_config() override;
12 void set_distance_sensor(sensor::Sensor *sensor) { this->distance_sensor_ = sensor; }
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 set_distance_sensor(sensor::Sensor *sensor)
void on_distance(uint16_t distance) override
void on_energy(uint16_t *gate_energy, size_t size) override
sensor::Sensor * distance_sensor_
std::vector< sensor::Sensor * > energy_sensors_
Base-class for all sensors.
Definition sensor.h:57
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:39
float get_state() const
Getter-syntax for .state.
Definition sensor.cpp:86
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7