mirror of
https://github.com/esphome/esphome.git
synced 2026-10-20 04:56:48 +00:00
[ld2420] Use Apply entities for the forwarding buttons and select
This commit is contained in:
@@ -12,12 +12,7 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_LD2420_ID, LD2420Component, ld2420_ns
|
||||
|
||||
LD2420ApplyConfigButton = ld2420_ns.class_("LD2420ApplyConfigButton", button.Button)
|
||||
LD2420RevertConfigButton = ld2420_ns.class_("LD2420RevertConfigButton", button.Button)
|
||||
LD2420RestartModuleButton = ld2420_ns.class_("LD2420RestartModuleButton", button.Button)
|
||||
LD2420FactoryResetButton = ld2420_ns.class_("LD2420FactoryResetButton", button.Button)
|
||||
from .. import CONF_LD2420_ID, LD2420Component
|
||||
|
||||
CONF_APPLY_CONFIG = "apply_config"
|
||||
CONF_REVERT_CONFIG = "revert_config"
|
||||
@@ -27,24 +22,24 @@ CONF_RESTART_MODULE = "restart_module"
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_LD2420_ID): cv.use_id(LD2420Component),
|
||||
cv.Required(CONF_APPLY_CONFIG): button.button_schema(
|
||||
LD2420ApplyConfigButton,
|
||||
button.ApplyButton,
|
||||
device_class=DEVICE_CLASS_RESTART,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_RESTART_ALERT,
|
||||
),
|
||||
cv.Optional(CONF_REVERT_CONFIG): button.button_schema(
|
||||
LD2420RevertConfigButton,
|
||||
button.ApplyButton,
|
||||
device_class=DEVICE_CLASS_RESTART,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_RESTART,
|
||||
),
|
||||
cv.Optional(CONF_RESTART_MODULE): button.button_schema(
|
||||
LD2420RestartModuleButton,
|
||||
button.ApplyButton,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
icon=ICON_DATABASE,
|
||||
),
|
||||
cv.Optional(CONF_FACTORY_RESET): button.button_schema(
|
||||
LD2420FactoryResetButton,
|
||||
button.ApplyButton,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_DATABASE,
|
||||
),
|
||||
@@ -54,7 +49,21 @@ CONFIG_SCHEMA = {
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_LD2420_ID])
|
||||
buttons = button.sub_buttons(config, parent=hub)
|
||||
await buttons(CONF_APPLY_CONFIG, hub.set_apply_config_button)
|
||||
await buttons(CONF_REVERT_CONFIG, hub.set_revert_config_button)
|
||||
await buttons(CONF_RESTART_MODULE, hub.set_restart_module_button)
|
||||
await buttons(CONF_FACTORY_RESET, hub.set_factory_reset_button)
|
||||
await buttons(
|
||||
CONF_APPLY_CONFIG, hub.set_apply_config_button, apply="apply_config_action()"
|
||||
)
|
||||
await buttons(
|
||||
CONF_REVERT_CONFIG,
|
||||
hub.set_revert_config_button,
|
||||
apply="revert_config_action()",
|
||||
)
|
||||
await buttons(
|
||||
CONF_RESTART_MODULE,
|
||||
hub.set_restart_module_button,
|
||||
apply="restart_module_action()",
|
||||
)
|
||||
await buttons(
|
||||
CONF_FACTORY_RESET,
|
||||
hub.set_factory_reset_button,
|
||||
apply="factory_reset_action()",
|
||||
)
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#include "reconfig_buttons.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
ESPHOME_LOG_TAG(TAG, "ld2420.button");
|
||||
|
||||
namespace esphome::ld2420 {
|
||||
|
||||
void LD2420ApplyConfigButton::press_action() { this->parent_->apply_config_action(); }
|
||||
void LD2420RevertConfigButton::press_action() { this->parent_->revert_config_action(); }
|
||||
void LD2420RestartModuleButton::press_action() { this->parent_->restart_module_action(); }
|
||||
void LD2420FactoryResetButton::press_action() { this->parent_->factory_reset_action(); }
|
||||
|
||||
} // namespace esphome::ld2420
|
||||
@@ -1,40 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../ld2420.h"
|
||||
|
||||
namespace esphome::ld2420 {
|
||||
|
||||
class LD2420ApplyConfigButton final : public button::Button, public Parented<LD2420Component> {
|
||||
public:
|
||||
LD2420ApplyConfigButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
class LD2420RevertConfigButton final : public button::Button, public Parented<LD2420Component> {
|
||||
public:
|
||||
LD2420RevertConfigButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
class LD2420RestartModuleButton final : public button::Button, public Parented<LD2420Component> {
|
||||
public:
|
||||
LD2420RestartModuleButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
class LD2420FactoryResetButton final : public button::Button, public Parented<LD2420Component> {
|
||||
public:
|
||||
LD2420FactoryResetButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2420
|
||||
@@ -4,7 +4,7 @@ import esphome.config_validation as cv
|
||||
from esphome.const import ENTITY_CATEGORY_CONFIG
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_LD2420_ID, LD2420Component, ld2420_ns
|
||||
from .. import CONF_LD2420_ID, LD2420Component
|
||||
|
||||
CONF_OPERATING_MODE = "operating_mode"
|
||||
CONF_SELECTS = [
|
||||
@@ -13,12 +13,11 @@ CONF_SELECTS = [
|
||||
"Simple",
|
||||
]
|
||||
|
||||
LD2420Select = ld2420_ns.class_("LD2420Select", select.Select, cg.Component)
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_LD2420_ID): cv.use_id(LD2420Component),
|
||||
cv.Required(CONF_OPERATING_MODE): select.select_schema(
|
||||
LD2420Select,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
),
|
||||
}
|
||||
@@ -28,5 +27,9 @@ async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_LD2420_ID])
|
||||
selects = select.sub_selects(config, parent=hub)
|
||||
await selects(
|
||||
CONF_OPERATING_MODE, hub.set_operating_mode_select, options=CONF_SELECTS
|
||||
CONF_OPERATING_MODE,
|
||||
hub.set_operating_mode_select,
|
||||
options=CONF_SELECTS,
|
||||
apply="set_operating_mode(entity->option_at(index))",
|
||||
publish="before",
|
||||
)
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#include "operating_mode_select.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome::ld2420 {
|
||||
|
||||
ESPHOME_LOG_TAG(TAG, "ld2420.select");
|
||||
|
||||
void LD2420Select::control(size_t index) {
|
||||
this->publish_state(index);
|
||||
this->parent_->set_operating_mode(this->option_at(index));
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2420
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ld2420.h"
|
||||
#include "esphome/components/select/select.h"
|
||||
|
||||
namespace esphome::ld2420 {
|
||||
|
||||
class LD2420Select final : public Component, public select::Select, public Parented<LD2420Component> {
|
||||
public:
|
||||
LD2420Select() = default;
|
||||
|
||||
protected:
|
||||
void control(size_t index) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2420
|
||||
Reference in New Issue
Block a user