mirror of
https://github.com/esphome/esphome.git
synced 2025-03-26 20:48:19 +00:00
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: Marcus Better <marcus@better.se> Co-authored-by: Trevor Schirmer <24777085+TrevorSchirmer@users.noreply.github.com> Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
import esphome.codegen as cg
|
|
from esphome.components import button
|
|
import esphome.config_validation as cv
|
|
from esphome.const import (
|
|
CONF_FACTORY_RESET,
|
|
CONF_RESTART,
|
|
DEVICE_CLASS_RESTART,
|
|
ENTITY_CATEGORY_CONFIG,
|
|
ENTITY_CATEGORY_DIAGNOSTIC,
|
|
ICON_RESTART,
|
|
ICON_RESTART_ALERT,
|
|
)
|
|
|
|
from .. import CONF_LD2450_ID, LD2450Component, ld2450_ns
|
|
|
|
ResetButton = ld2450_ns.class_("ResetButton", button.Button)
|
|
RestartButton = ld2450_ns.class_("RestartButton", button.Button)
|
|
|
|
CONFIG_SCHEMA = {
|
|
cv.GenerateID(CONF_LD2450_ID): cv.use_id(LD2450Component),
|
|
cv.Optional(CONF_FACTORY_RESET): button.button_schema(
|
|
ResetButton,
|
|
device_class=DEVICE_CLASS_RESTART,
|
|
entity_category=ENTITY_CATEGORY_CONFIG,
|
|
icon=ICON_RESTART_ALERT,
|
|
),
|
|
cv.Optional(CONF_RESTART): button.button_schema(
|
|
RestartButton,
|
|
device_class=DEVICE_CLASS_RESTART,
|
|
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
|
icon=ICON_RESTART,
|
|
),
|
|
}
|
|
|
|
|
|
async def to_code(config):
|
|
ld2450_component = await cg.get_variable(config[CONF_LD2450_ID])
|
|
if factory_reset_config := config.get(CONF_FACTORY_RESET):
|
|
b = await button.new_button(factory_reset_config)
|
|
await cg.register_parented(b, config[CONF_LD2450_ID])
|
|
cg.add(ld2450_component.set_reset_button(b))
|
|
if restart_config := config.get(CONF_RESTART):
|
|
b = await button.new_button(restart_config)
|
|
await cg.register_parented(b, config[CONF_LD2450_ID])
|
|
cg.add(ld2450_component.set_restart_button(b))
|