Rename LazySensorWithDedup to SensorWithDedup

There is no lazy allocation to justify the name — it's just inline
with a null check. Drop the Lazy prefix.
This commit is contained in:
J. Nick Koston
2026-04-12 12:36:10 -10:00
parent 66a3e3a705
commit 931ef66a2f
4 changed files with 16 additions and 17 deletions
+2 -2
View File
@@ -129,8 +129,8 @@ class LD2410Component : public Component, public uart::UARTDevice {
std::array<number::Number *, TOTAL_GATES> gate_still_threshold_numbers_{};
#endif
#ifdef USE_SENSOR
std::array<LazySensorWithDedup<uint8_t>, TOTAL_GATES> gate_move_sensors_{};
std::array<LazySensorWithDedup<uint8_t>, TOTAL_GATES> gate_still_sensors_{};
std::array<SensorWithDedup<uint8_t>, TOTAL_GATES> gate_move_sensors_{};
std::array<SensorWithDedup<uint8_t>, TOTAL_GATES> gate_still_sensors_{};
#endif
};
+2 -2
View File
@@ -133,8 +133,8 @@ class LD2412Component : public Component, public uart::UARTDevice {
std::array<number::Number *, TOTAL_GATES> gate_still_threshold_numbers_{};
#endif
#ifdef USE_SENSOR
std::array<LazySensorWithDedup<uint8_t>, TOTAL_GATES> gate_move_sensors_{};
std::array<LazySensorWithDedup<uint8_t>, TOTAL_GATES> gate_still_sensors_{};
std::array<SensorWithDedup<uint8_t>, TOTAL_GATES> gate_move_sensors_{};
std::array<SensorWithDedup<uint8_t>, TOTAL_GATES> gate_still_sensors_{};
#endif
};
+9 -9
View File
@@ -182,15 +182,15 @@ class LD2450Component : public Component, public uart::UARTDevice {
ZoneOfNumbers zone_numbers_[MAX_ZONES];
#endif
#ifdef USE_SENSOR
std::array<LazySensorWithDedup<int16_t>, MAX_TARGETS> move_x_sensors_{};
std::array<LazySensorWithDedup<int16_t>, MAX_TARGETS> move_y_sensors_{};
std::array<LazySensorWithDedup<int16_t>, MAX_TARGETS> move_speed_sensors_{};
std::array<LazySensorWithDedup<float>, MAX_TARGETS> move_angle_sensors_{};
std::array<LazySensorWithDedup<uint16_t>, MAX_TARGETS> move_distance_sensors_{};
std::array<LazySensorWithDedup<uint16_t>, MAX_TARGETS> move_resolution_sensors_{};
std::array<LazySensorWithDedup<uint8_t>, MAX_ZONES> zone_target_count_sensors_{};
std::array<LazySensorWithDedup<uint8_t>, MAX_ZONES> zone_still_target_count_sensors_{};
std::array<LazySensorWithDedup<uint8_t>, MAX_ZONES> zone_moving_target_count_sensors_{};
std::array<SensorWithDedup<int16_t>, MAX_TARGETS> move_x_sensors_{};
std::array<SensorWithDedup<int16_t>, MAX_TARGETS> move_y_sensors_{};
std::array<SensorWithDedup<int16_t>, MAX_TARGETS> move_speed_sensors_{};
std::array<SensorWithDedup<float>, MAX_TARGETS> move_angle_sensors_{};
std::array<SensorWithDedup<uint16_t>, MAX_TARGETS> move_distance_sensors_{};
std::array<SensorWithDedup<uint16_t>, MAX_TARGETS> move_resolution_sensors_{};
std::array<SensorWithDedup<uint8_t>, MAX_ZONES> zone_target_count_sensors_{};
std::array<SensorWithDedup<uint8_t>, MAX_ZONES> zone_still_target_count_sensors_{};
std::array<SensorWithDedup<uint8_t>, MAX_ZONES> zone_moving_target_count_sensors_{};
#endif
#ifdef USE_TEXT_SENSOR
std::array<text_sensor::TextSensor *, MAX_TARGETS> direction_text_sensors_{};
+3 -4
View File
@@ -11,7 +11,7 @@
#define SUB_SENSOR_WITH_DEDUP(name, dedup_type) \
protected: \
ld24xx::LazySensorWithDedup<dedup_type> name##_sensor_{}; \
ld24xx::SensorWithDedup<dedup_type> name##_sensor_{}; \
\
public: \
void set_##name##_sensor(sensor::Sensor *sensor) { this->name##_sensor_.set_sensor(sensor); }
@@ -69,9 +69,8 @@ inline void format_version_str(const uint8_t *version, std::span<char, 20> buffe
#ifdef USE_SENSOR
/// Sensor with deduplication — sensor may be null, null check is internal.
/// Analogous to LazyCallbackManager: does nothing when no sensor is set,
/// avoids heap allocation by storing everything inline.
template<typename T> class LazySensorWithDedup {
/// Stored inline, no heap allocation. Does nothing when no sensor is set.
template<typename T> class SensorWithDedup {
public:
void set_sensor(sensor::Sensor *sens) { this->sens_ = sens; }