diff --git a/esphome/components/dfrobot_sen0395/dfrobot_sen0395.h b/esphome/components/dfrobot_sen0395/dfrobot_sen0395.h index d3b2ecedc3..893519a414 100644 --- a/esphome/components/dfrobot_sen0395/dfrobot_sen0395.h +++ b/esphome/components/dfrobot_sen0395/dfrobot_sen0395.h @@ -7,12 +7,17 @@ #ifdef USE_BINARY_SENSOR #include "esphome/components/binary_sensor/binary_sensor.h" #endif +#ifdef USE_SENSOR +#include "esphome/components/sensor/sensor.h" +#endif #ifdef USE_SWITCH #include "esphome/components/switch/switch.h" #endif #include "commands.h" +#define TARGET_COUNT 9 + namespace esphome { namespace dfrobot_sen0395 { @@ -94,12 +99,29 @@ class DfrobotSen0395Component : public uart::UARTDevice, public Component { } #endif +#ifdef USE_SENSOR + void set_detected_target_distance_sensor(int target, sensor::Sensor *detected_target_distance_sensor) { + if (is_valid_target_(target)) { + detected_targets_distance_sensors_[target - 1] = detected_target_distance_sensor; + } + } + void set_detected_target_snr_sensor(int target, sensor::Sensor *detected_target_snr_sensor) { + if (is_valid_target_(target)) { + detected_targets_snr_sensors_[target - 1] = detected_target_snr_sensor; + } + } +#endif + int8_t enqueue(std::unique_ptr cmd); protected: #ifdef USE_BINARY_SENSOR binary_sensor::BinarySensor *detected_binary_sensor_{nullptr}; #endif +#ifdef USE_SENSOR + sensor::Sensor *detected_targets_distance_sensors_[TARGET_COUNT]{nullptr}; + sensor::Sensor *detected_targets_snr_sensors_[TARGET_COUNT]{nullptr}; +#endif bool detected_{false}; bool active_{false}; @@ -117,6 +139,8 @@ class DfrobotSen0395Component : public uart::UARTDevice, public Component { void set_detected_(bool detected); + bool is_valid_target_(int target) { return target >= 1 && target <= TARGET_COUNT; } + friend class Command; friend class ReadStateCommand; };