From fed899b486e320f1a86dffcdfaec479b30195ab7 Mon Sep 17 00:00:00 2001 From: Hareesh M U Date: Sun, 5 Nov 2023 20:47:01 +0000 Subject: [PATCH] Add USE checks --- esphome/components/ld2450/ld2450.cpp | 11 ++++++++--- esphome/components/ld2450/ld2450.h | 2 +- esphome/components/ld2450/number/__init__.py | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/esphome/components/ld2450/ld2450.cpp b/esphome/components/ld2450/ld2450.cpp index baa091a925..ee20607b05 100644 --- a/esphome/components/ld2450/ld2450.cpp +++ b/esphome/components/ld2450/ld2450.cpp @@ -20,8 +20,10 @@ LD2450Component::LD2450Component() {} void LD2450Component::setup() { ESP_LOGCONFIG(TAG, "Setting up HLK-LD2450"); +#ifdef USE_NUMBER this->pref_ = global_preferences->make_preference(this->presence_timeout_number_->get_object_id_hash()); this->set_presence_timeout(); +#endif this->read_all_info(); ESP_LOGCONFIG(TAG, "Mac Address : %s", const_cast(this->mac_.c_str())); ESP_LOGCONFIG(TAG, "Firmware Version : %s", const_cast(this->version_.c_str())); @@ -387,9 +389,8 @@ void LD2450Component::handle_periodic_data_(uint8_t *buffer, int len) { #endif } // End loop thru targets - still_target_count = target_count - moving_target_count; - #ifdef USE_SENSOR + still_target_count = target_count - moving_target_count; // Target Count if (this->target_count_sensor_ != nullptr) { if (this->target_count_sensor_->get_state() != target_count) { @@ -444,6 +445,7 @@ void LD2450Component::handle_periodic_data_(uint8_t *buffer, int len) { } } #endif +#ifdef USE_SENSOR // For presence timeout check if (target_count > 0) { this->presence_millis_ = millis(); @@ -454,6 +456,7 @@ void LD2450Component::handle_periodic_data_(uint8_t *buffer, int len) { if (still_target_count > 0) { this->still_presence_millis_ = millis(); } +#endif } const char VERSION_FMT[] = "%u.%02X.%02X%02X%02X%02X"; @@ -708,6 +711,8 @@ void LD2450Component::set_move_distance_sensor(int target, sensor::Sensor *s) { void LD2450Component::set_move_resolution_sensor(int target, sensor::Sensor *s) { this->move_resolution_sensors_[target] = s; } +#endif +#ifdef USE_TEXT_SENSOR void LD2450Component::set_direction_text_sensor(int target, text_sensor::TextSensor *s) { this->direction_text_sensors_[target] = s; } @@ -751,7 +756,6 @@ void LD2450Component::set_presence_timeout() { } } } -#endif // Save Presence Timeout to flash void LD2450Component::save_to_flash_(float value) { this->pref_.save(&value); } @@ -764,6 +768,7 @@ float LD2450Component::restore_from_flash_() { } return value; } +#endif } // namespace ld2450 } // namespace esphome diff --git a/esphome/components/ld2450/ld2450.h b/esphome/components/ld2450/ld2450.h index 3a1bc725d2..4c67c20380 100644 --- a/esphome/components/ld2450/ld2450.h +++ b/esphome/components/ld2450/ld2450.h @@ -248,7 +248,7 @@ class LD2450Component : public Component, public uart::UARTDevice { int32_t still_presence_millis_ = 0; int32_t moving_presence_millis_ = 0; uint16_t throttle_; - uint16_t timeout_; + uint16_t timeout_ = 5; uint8_t zone_type_ = 0; std::string version_; std::string mac_; diff --git a/esphome/components/ld2450/number/__init__.py b/esphome/components/ld2450/number/__init__.py index 65cb514e03..e5c0331696 100644 --- a/esphome/components/ld2450/number/__init__.py +++ b/esphome/components/ld2450/number/__init__.py @@ -26,7 +26,7 @@ ZoneCoordinateNumber = ld2450_ns.class_("ZoneCoordinateNumber", number.Number) CONFIG_SCHEMA = cv.Schema( { cv.GenerateID(CONF_LD2450_ID): cv.use_id(LD2450Component), - cv.Optional(CONF_PRESENCE_TIMEOUT): number.number_schema( + cv.Required(CONF_PRESENCE_TIMEOUT): number.number_schema( PresenceTimeoutNumber, unit_of_measurement=UNIT_SECOND, entity_category=ENTITY_CATEGORY_CONFIG,