[ld2450] Use integer dedup for direction text sensor updates (#14386)

This commit is contained in:
J. Nick Koston
2026-02-28 14:26:31 -10:00
committed by GitHub
parent c0781d3680
commit 80e0761bf1
2 changed files with 7 additions and 5 deletions

View File

@@ -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

View File

@@ -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_;