Skip to content

Commit

Permalink
Fix sensor filter compatibility (#25)
Browse files Browse the repository at this point in the history
* Fix sensor filter compatibility
  • Loading branch information
TillFleisch authored Aug 13, 2024
1 parent 6a95645 commit 3a84fd1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 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 @@ -329,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

0 comments on commit 3a84fd1

Please sign in to comment.