mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 16:04:55 +00:00
[ld2450] Use integer dedup for direction text sensor updates (#14386)
This commit is contained in:
@@ -516,10 +516,11 @@ void LD2450Component::handle_periodic_data_() {
|
||||
} else {
|
||||
direction = DIRECTION_STATIONARY;
|
||||
}
|
||||
text_sensor::TextSensor *tsd = this->direction_text_sensors_[index];
|
||||
const auto *dir_str = find_str(ld2450::DIRECTION_BY_UINT, direction);
|
||||
if (tsd != nullptr && (!tsd->has_state() || tsd->get_state() != dir_str)) {
|
||||
tsd->publish_state(dir_str);
|
||||
if (this->direction_dedup_[index].next(direction)) {
|
||||
text_sensor::TextSensor *tsd = this->direction_text_sensors_[index];
|
||||
if (tsd != nullptr) {
|
||||
tsd->publish_state(find_str(ld2450::DIRECTION_BY_UINT, direction));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -194,7 +194,8 @@ class LD2450Component : public Component, public uart::UARTDevice {
|
||||
std::array<SensorWithDedup<uint8_t> *, MAX_ZONES> zone_moving_target_count_sensors_{};
|
||||
#endif
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
std::array<text_sensor::TextSensor *, 3> direction_text_sensors_{};
|
||||
std::array<text_sensor::TextSensor *, MAX_TARGETS> direction_text_sensors_{};
|
||||
std::array<Deduplicator<uint8_t>, MAX_TARGETS> direction_dedup_{};
|
||||
#endif
|
||||
|
||||
LazyCallbackManager<void()> data_callback_;
|
||||
|
||||
Reference in New Issue
Block a user