[tfluna] Use Apply buttons

This commit is contained in:
J. Nick Koston
2026-10-16 13:46:03 -10:00
parent ab2383e7c5
commit d0d79d5c54
5 changed files with 5 additions and 47 deletions
+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()")
@@ -1,7 +0,0 @@
#include "reset_button.h"
namespace esphome::tfluna {
void ResetButton::press_action() { this->parent_->factory_reset(); }
} // namespace esphome::tfluna
@@ -1,13 +0,0 @@
#pragma once
#include "esphome/components/button/button.h"
#include "../tfluna.h"
namespace esphome::tfluna {
class ResetButton : public button::Button, public Parented<TFLuna> {
protected:
void press_action() override;
};
} // namespace esphome::tfluna
@@ -1,7 +0,0 @@
#include "restart_button.h"
namespace esphome::tfluna {
void RestartButton::press_action() { this->parent_->restart(); }
} // namespace esphome::tfluna
@@ -1,13 +0,0 @@
#pragma once
#include "esphome/components/button/button.h"
#include "../tfluna.h"
namespace esphome::tfluna {
class RestartButton : public button::Button, public Parented<TFLuna> {
protected:
void press_action() override;
};
} // namespace esphome::tfluna