Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sensor filter compatibility #25

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions components/LD2450/LD2450.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ namespace esphome::ld2450

ESP_LOGE(TAG, "LD2450-Sensor stopped sending updates!");

#ifdef USE_BINARY_SENSOR
if (occupancy_binary_sensor_ != nullptr)
occupancy_binary_sensor_->publish_state(false);
#endif
#ifdef USE_SENSOR
if (target_count_sensor_ != nullptr)
target_count_sensor_->publish_state(NAN);
#endif

// Update zones and related components (unavailable)
for (Zone *zone : zones_)
{
Expand Down Expand Up @@ -305,8 +314,6 @@ namespace esphome::ld2450
// Flip x axis if required
x = x * (flip_x_axis_ ? -1 : 1);

targets_[i]->update_values(x, y, speed, distance_resolution);

// Filter targets further than max detection distance and max angle
float angle = -(atan2(y, x) * (180 / M_PI) - 90);
if ((y <= max_detection_distance_ || (targets_[i]->is_present() && y <= max_detection_distance_ + max_distance_margin_)) &&
Expand All @@ -331,11 +338,11 @@ namespace esphome::ld2450
is_occupied_ = target_count > 0;

#ifdef USE_BINARY_SENSOR
if (occupancy_binary_sensor_ != nullptr && occupancy_binary_sensor_->state != is_occupied_)
if (occupancy_binary_sensor_ != nullptr)
occupancy_binary_sensor_->publish_state(is_occupied_);
#endif
#ifdef USE_SENSOR
if (target_count_sensor_ != nullptr && target_count_sensor_->state != target_count)
if (target_count_sensor_ != nullptr && target_count_sensor_->raw_state != target_count)
target_count_sensor_->publish_state(target_count);
#endif

Expand Down
2 changes: 1 addition & 1 deletion components/LD2450/LD2450.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#ifdef USE_BINARY_SENSOR
#include "esphome/components/binary_sensor/binary_sensor.h"
#endif
#ifdef USE_BINARY_SENSOR
#ifdef USE_SENSOR
#include "esphome/components/sensor/sensor.h"
#endif
#ifdef USE_NUMBER
Expand Down
4 changes: 2 additions & 2 deletions components/LD2450/zone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ namespace esphome::ld2450
}

#ifdef USE_BINARY_SENSOR
if (occupancy_binary_sensor_ != nullptr && (occupancy_binary_sensor_->state != (target_count > 0) || !occupancy_binary_sensor_->has_state()))
if (occupancy_binary_sensor_ != nullptr)
occupancy_binary_sensor_->publish_state(target_count > 0);
#endif
#ifdef USE_SENSOR
if (target_count_sensor_ != nullptr && (target_count_sensor_->state != target_count || !target_count_sensor_->has_state()))
if (target_count_sensor_ != nullptr && (target_count_sensor_->raw_state != target_count))
target_count_sensor_->publish_state(target_count);
#endif
}
Expand Down
Loading