[tfluna] Use Apply entities for the buttons

This commit is contained in:
J. Nick Koston
2026-10-16 10:48:31 -10:00
parent 87de7d679e
commit 776a7f68d8
+5 -7
View File
@@ -14,23 +14,21 @@ from esphome.const import (
import esphome.final_validate as fv
from esphome.types import ConfigType
from .. import CONF_TFLUNA_ID, FACTORY_DEFAULT_ADDRESS, TFLunaComponent, tfluna_ns
from .. import CONF_TFLUNA_ID, FACTORY_DEFAULT_ADDRESS, TFLunaComponent
DEPENDENCIES = ["tfluna"]
ResetButton = tfluna_ns.class_("ResetButton", button.Button)
RestartButton = tfluna_ns.class_("RestartButton", button.Button)
CONFIG_SCHEMA = {
cv.GenerateID(CONF_TFLUNA_ID): cv.use_id(TFLunaComponent),
cv.Optional(CONF_FACTORY_RESET): button.button_schema(
ResetButton,
button.ApplyButton,
device_class=DEVICE_CLASS_RESTART,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_RESTART_ALERT,
),
cv.Optional(CONF_RESTART): button.button_schema(
RestartButton,
button.ApplyButton,
device_class=DEVICE_CLASS_RESTART,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
icon=ICON_RESTART,
@@ -63,5 +61,5 @@ FINAL_VALIDATE_SCHEMA = _final_validate
async def to_code(config: ConfigType) -> None:
hub = await cg.get_variable(config[CONF_TFLUNA_ID])
buttons = button.sub_buttons(config, parent=hub)
await buttons(CONF_FACTORY_RESET, hub.set_reset_button)
await buttons(CONF_RESTART, hub.set_restart_button)
await buttons(CONF_FACTORY_RESET, hub.set_reset_button, apply="factory_reset()")
await buttons(CONF_RESTART, hub.set_restart_button, apply="restart()")