Rename button, sort vars

This commit is contained in:
Keith Burzinski 2025-07-07 03:33:21 -05:00
parent c934e84e21
commit 79686239d3
No known key found for this signature in database
GPG Key ID: 802564C5F0EEFFBE
6 changed files with 32 additions and 32 deletions

View File

@ -13,13 +13,13 @@ from esphome.const import (
from .. import CONF_LD2450_ID, LD2450Component, ld2450_ns from .. import CONF_LD2450_ID, LD2450Component, ld2450_ns
ResetButton = ld2450_ns.class_("ResetButton", button.Button) FactoryResetButton = ld2450_ns.class_("FactoryResetButton", button.Button)
RestartButton = ld2450_ns.class_("RestartButton", button.Button) RestartButton = ld2450_ns.class_("RestartButton", button.Button)
CONFIG_SCHEMA = { CONFIG_SCHEMA = {
cv.GenerateID(CONF_LD2450_ID): cv.use_id(LD2450Component), cv.GenerateID(CONF_LD2450_ID): cv.use_id(LD2450Component),
cv.Optional(CONF_FACTORY_RESET): button.button_schema( cv.Optional(CONF_FACTORY_RESET): button.button_schema(
ResetButton, FactoryResetButton,
device_class=DEVICE_CLASS_RESTART, device_class=DEVICE_CLASS_RESTART,
entity_category=ENTITY_CATEGORY_CONFIG, entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_RESTART_ALERT, icon=ICON_RESTART_ALERT,
@ -38,7 +38,7 @@ async def to_code(config):
if factory_reset_config := config.get(CONF_FACTORY_RESET): if factory_reset_config := config.get(CONF_FACTORY_RESET):
b = await button.new_button(factory_reset_config) b = await button.new_button(factory_reset_config)
await cg.register_parented(b, config[CONF_LD2450_ID]) await cg.register_parented(b, config[CONF_LD2450_ID])
cg.add(ld2450_component.set_reset_button(b)) cg.add(ld2450_component.set_factory_reset_button(b))
if restart_config := config.get(CONF_RESTART): if restart_config := config.get(CONF_RESTART):
b = await button.new_button(restart_config) b = await button.new_button(restart_config)
await cg.register_parented(b, config[CONF_LD2450_ID]) await cg.register_parented(b, config[CONF_LD2450_ID])

View File

@ -0,0 +1,9 @@
#include "factory_reset_button.h"
namespace esphome {
namespace ld2450 {
void FactoryResetButton::press_action() { this->parent_->factory_reset(); }
} // namespace ld2450
} // namespace esphome

View File

@ -6,9 +6,9 @@
namespace esphome { namespace esphome {
namespace ld2450 { namespace ld2450 {
class ResetButton : public button::Button, public Parented<LD2450Component> { class FactoryResetButton : public button::Button, public Parented<LD2450Component> {
public: public:
ResetButton() = default; FactoryResetButton() = default;
protected: protected:
void press_action() override; void press_action() override;

View File

@ -1,9 +0,0 @@
#include "reset_button.h"
namespace esphome {
namespace ld2450 {
void ResetButton::press_action() { this->parent_->factory_reset(); }
} // namespace ld2450
} // namespace esphome

View File

@ -226,9 +226,6 @@ void LD2450Component::dump_config() {
for (sensor::Sensor *s : this->move_y_sensors_) { for (sensor::Sensor *s : this->move_y_sensors_) {
LOG_SENSOR(" ", "TargetY", s); LOG_SENSOR(" ", "TargetY", s);
} }
for (sensor::Sensor *s : this->move_speed_sensors_) {
LOG_SENSOR(" ", "TargetSpeed", s);
}
for (sensor::Sensor *s : this->move_angle_sensors_) { for (sensor::Sensor *s : this->move_angle_sensors_) {
LOG_SENSOR(" ", "TargetAngle", s); LOG_SENSOR(" ", "TargetAngle", s);
} }
@ -238,15 +235,18 @@ void LD2450Component::dump_config() {
for (sensor::Sensor *s : this->move_resolution_sensors_) { for (sensor::Sensor *s : this->move_resolution_sensors_) {
LOG_SENSOR(" ", "TargetResolution", s); LOG_SENSOR(" ", "TargetResolution", s);
} }
for (sensor::Sensor *s : this->move_speed_sensors_) {
LOG_SENSOR(" ", "TargetSpeed", s);
}
for (sensor::Sensor *s : this->zone_target_count_sensors_) { for (sensor::Sensor *s : this->zone_target_count_sensors_) {
LOG_SENSOR(" ", "ZoneTargetCount", s); LOG_SENSOR(" ", "ZoneTargetCount", s);
} }
for (sensor::Sensor *s : this->zone_still_target_count_sensors_) {
LOG_SENSOR(" ", "ZoneStillTargetCount", s);
}
for (sensor::Sensor *s : this->zone_moving_target_count_sensors_) { for (sensor::Sensor *s : this->zone_moving_target_count_sensors_) {
LOG_SENSOR(" ", "ZoneMovingTargetCount", s); LOG_SENSOR(" ", "ZoneMovingTargetCount", s);
} }
for (sensor::Sensor *s : this->zone_still_target_count_sensors_) {
LOG_SENSOR(" ", "ZoneStillTargetCount", s);
}
#endif #endif
#ifdef USE_TEXT_SENSOR #ifdef USE_TEXT_SENSOR
ESP_LOGCONFIG(TAG, "Text Sensors:"); ESP_LOGCONFIG(TAG, "Text Sensors:");
@ -278,7 +278,7 @@ void LD2450Component::dump_config() {
#endif #endif
#ifdef USE_BUTTON #ifdef USE_BUTTON
ESP_LOGCONFIG(TAG, "Buttons:"); ESP_LOGCONFIG(TAG, "Buttons:");
LOG_BUTTON(" ", "Reset", this->reset_button_); LOG_BUTTON(" ", "FactoryReset", this->factory_reset_button_);
LOG_BUTTON(" ", "Restart", this->restart_button_); LOG_BUTTON(" ", "Restart", this->restart_button_);
#endif #endif
} }

View File

@ -75,19 +75,22 @@ struct ZoneOfNumbers {
#endif #endif
class LD2450Component : public Component, public uart::UARTDevice { class LD2450Component : public Component, public uart::UARTDevice {
#ifdef USE_SENSOR
SUB_SENSOR(target_count)
SUB_SENSOR(still_target_count)
SUB_SENSOR(moving_target_count)
#endif
#ifdef USE_BINARY_SENSOR #ifdef USE_BINARY_SENSOR
SUB_BINARY_SENSOR(target)
SUB_BINARY_SENSOR(moving_target) SUB_BINARY_SENSOR(moving_target)
SUB_BINARY_SENSOR(still_target) SUB_BINARY_SENSOR(still_target)
SUB_BINARY_SENSOR(target)
#endif
#ifdef USE_SENSOR
SUB_SENSOR(moving_target_count)
SUB_SENSOR(still_target_count)
SUB_SENSOR(target_count)
#endif #endif
#ifdef USE_TEXT_SENSOR #ifdef USE_TEXT_SENSOR
SUB_TEXT_SENSOR(version)
SUB_TEXT_SENSOR(mac) SUB_TEXT_SENSOR(mac)
SUB_TEXT_SENSOR(version)
#endif
#ifdef USE_NUMBER
SUB_NUMBER(presence_timeout)
#endif #endif
#ifdef USE_SELECT #ifdef USE_SELECT
SUB_SELECT(baud_rate) SUB_SELECT(baud_rate)
@ -98,12 +101,9 @@ class LD2450Component : public Component, public uart::UARTDevice {
SUB_SWITCH(multi_target) SUB_SWITCH(multi_target)
#endif #endif
#ifdef USE_BUTTON #ifdef USE_BUTTON
SUB_BUTTON(reset) SUB_BUTTON(factory_reset)
SUB_BUTTON(restart) SUB_BUTTON(restart)
#endif #endif
#ifdef USE_NUMBER
SUB_NUMBER(presence_timeout)
#endif
public: public:
void setup() override; void setup() override;