From 76c9f5530e7f41f5a82f98a31acaf01f53e086ec Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Thu, 2 May 2024 16:04:36 +1200 Subject: [PATCH] Remove custom api code --- esphome/components/ld2450/ld2450.cpp | 32 +++++----------------------- esphome/components/ld2450/ld2450.h | 22 ++++++------------- 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/esphome/components/ld2450/ld2450.cpp b/esphome/components/ld2450/ld2450.cpp index 97f6c75e43..b3e6c2be6f 100644 --- a/esphome/components/ld2450/ld2450.cpp +++ b/esphome/components/ld2450/ld2450.cpp @@ -28,27 +28,6 @@ void LD2450Component::setup() { ESP_LOGCONFIG(TAG, "Mac Address: %s", const_cast(this->mac_.c_str())); ESP_LOGCONFIG(TAG, "Firmware Version: %s", const_cast(this->version_.c_str())); ESP_LOGCONFIG(TAG, "HLK-LD2450 setup complete"); -#ifdef USE_API - ESP_LOGCONFIG(TAG, "Registering services"); - CustomAPIDevice::register_service(&::esphome::ld2450::LD2450Component::on_set_radar_zone_, "set_radar_zone", - { - "zone_type", - "zone1_x1", - "zone1_y1", - "zone1_x2", - "zone1_y2", - "zone2_x1", - "zone2_y1", - "zone2_x2", - "zone2_y2", - "zone3_x1", - "zone3_y1", - "zone3_x2", - "zone3_y2", - }); - CustomAPIDevice::register_service(&::esphome::ld2450::LD2450Component::on_reset_radar_zone_, "reset_radar_zone"); - ESP_LOGCONFIG(TAG, "Services registration complete"); -#endif } void LD2450Component::dump_config() { @@ -154,7 +133,7 @@ uint8_t LD2450Component::count_targets_in_zone_(const Zone &zone, bool is_moving } // Service reset_radar_zone -void LD2450Component::on_reset_radar_zone_() { +void LD2450Component::reset_radar_zone() { this->zone_type_ = 0; for (auto &i : zone_config_) { i.x1 = 0; @@ -165,11 +144,10 @@ void LD2450Component::on_reset_radar_zone_() { this->send_set_zone_command_(); } -// Service set_radar_zone -void LD2450Component::on_set_radar_zone_(int32_t zone_type, int32_t zone1_x1, int32_t zone1_y1, int32_t zone1_x2, - int32_t zone1_y2, int32_t zone2_x1, int32_t zone2_y1, int32_t zone2_x2, - int32_t zone2_y2, int32_t zone3_x1, int32_t zone3_y1, int32_t zone3_x2, - int32_t zone3_y2) { +void LD2450Component::set_radar_zone(int32_t zone_type, int32_t zone1_x1, int32_t zone1_y1, int32_t zone1_x2, + int32_t zone1_y2, int32_t zone2_x1, int32_t zone2_y1, int32_t zone2_x2, + int32_t zone2_y2, int32_t zone3_x1, int32_t zone3_y1, int32_t zone3_x2, + int32_t zone3_y2) { this->zone_type_ = zone_type; int zone_parameters[12] = {zone1_x1, zone1_y1, zone1_x2, zone1_y2, zone2_x1, zone2_y1, zone2_x2, zone2_y2, zone3_x1, zone3_y1, zone3_x2, zone3_y2}; diff --git a/esphome/components/ld2450/ld2450.h b/esphome/components/ld2450/ld2450.h index f4e0c1feeb..2dc4abb5a7 100644 --- a/esphome/components/ld2450/ld2450.h +++ b/esphome/components/ld2450/ld2450.h @@ -1,13 +1,13 @@ #pragma once +#include #include #include -#include +#include "esphome/components/uart/uart.h" +#include "esphome/core/component.h" #include "esphome/core/defines.h" #include "esphome/core/helpers.h" -#include "esphome/core/component.h" #include "esphome/core/preferences.h" -#include "esphome/components/uart/uart.h" #ifdef USE_SENSOR #include "esphome/components/sensor/sensor.h" #endif @@ -23,9 +23,6 @@ #ifdef USE_SELECT #include "esphome/components/select/select.h" #endif -#ifdef USE_API -#include "esphome/components/api/custom_api_device.h" -#endif #ifdef USE_TEXT_SENSOR #include "esphome/components/text_sensor/text_sensor.h" #endif @@ -117,12 +114,7 @@ enum PeriodicDataStructure : uint8_t { enum PeriodicDataValue : uint8_t { HEAD = 0XAA, END = 0x55, CHECK = 0x00 }; enum AckDataStructure : uint8_t { COMMAND = 6, COMMAND_STATUS = 7 }; -// Use CustomAPIDevice if API is defined in YAML - used for service calls to set/reset zone -#ifdef USE_API -class LD2450Component : public Component, public uart::UARTDevice, public esphome::api::CustomAPIDevice { -#else class LD2450Component : public Component, public uart::UARTDevice { -#endif #ifdef USE_SENSOR SUB_SENSOR(target_count) SUB_SENSOR(still_target_count) @@ -191,6 +183,10 @@ class LD2450Component : public Component, public uart::UARTDevice { void set_zone_still_target_count_sensor(int zone, sensor::Sensor *s); void set_zone_moving_target_count_sensor(int zone, sensor::Sensor *s); #endif + void reset_radar_zone(); + void set_radar_zone(int32_t zone_type, int32_t zone1_x1, int32_t zone1_y1, int32_t zone1_x2, int32_t zone1_y2, + int32_t zone2_x1, int32_t zone2_y1, int32_t zone2_x2, int32_t zone2_y2, int32_t zone3_x1, + int32_t zone3_y1, int32_t zone3_x2, int32_t zone3_y2); protected: ESPPreferenceObject pref_; @@ -207,14 +203,10 @@ class LD2450Component : public Component, public uart::UARTDevice { void restart_(); void send_set_zone_command_(); void convert_int_values_to_hex_(const int *values, uint8_t *bytes); - void on_reset_radar_zone_(); void save_to_flash_(float value); float restore_from_flash_(); Target target_info_[MAX_TARGETS]; Zone zone_config_[MAX_ZONES]; - void on_set_radar_zone_(int32_t zone_type, int32_t zone1_x1, int32_t zone1_y1, int32_t zone1_x2, int32_t zone1_y2, - int32_t zone2_x1, int32_t zone2_y1, int32_t zone2_x2, int32_t zone2_y2, int32_t zone3_x1, - int32_t zone3_y1, int32_t zone3_x2, int32_t zone3_y2); int16_t decode_coordinate_(uint8_t low_byte, uint8_t high_byte) { int16_t coordinate = (high_byte & 0x7F) << 8 | low_byte; if ((high_byte & 0x80) == 0)