[seeed_mr24hpc1] Use Apply buttons

This commit is contained in:
J. Nick Koston
2026-10-16 13:46:02 -10:00
parent f1dda7da41
commit def600ff6a
5 changed files with 9 additions and 54 deletions
@@ -9,23 +9,20 @@ from esphome.const import (
)
from esphome.types import ConfigType
from .. import CONF_MR24HPC1_ID, MR24HPC1Component, mr24hpc1_ns
RestartButton = mr24hpc1_ns.class_("RestartButton", button.Button)
CustomSetEndButton = mr24hpc1_ns.class_("CustomSetEndButton", button.Button)
from .. import CONF_MR24HPC1_ID, MR24HPC1Component
CONF_CUSTOM_SET_END = "custom_set_end"
CONFIG_SCHEMA = {
cv.GenerateID(CONF_MR24HPC1_ID): cv.use_id(MR24HPC1Component),
cv.Optional(CONF_RESTART): button.button_schema(
RestartButton,
button.ApplyButton,
device_class=DEVICE_CLASS_RESTART,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_RESTART_ALERT,
),
cv.Optional(CONF_CUSTOM_SET_END): button.button_schema(
CustomSetEndButton,
button.ApplyButton,
entity_category=ENTITY_CATEGORY_CONFIG,
icon="mdi:cog",
),
@@ -35,5 +32,9 @@ CONFIG_SCHEMA = {
async def to_code(config: ConfigType) -> None:
hub = await cg.get_variable(config[CONF_MR24HPC1_ID])
buttons = button.sub_buttons(config, parent=hub)
await buttons(CONF_RESTART, hub.set_restart_button)
await buttons(CONF_CUSTOM_SET_END, hub.set_custom_set_end_button)
await buttons(CONF_RESTART, hub.set_restart_button, apply="set_restart()")
await buttons(
CONF_CUSTOM_SET_END,
hub.set_custom_set_end_button,
apply="set_custom_end_mode()",
)
@@ -1,7 +0,0 @@
#include "custom_mode_end_button.h"
namespace esphome::seeed_mr24hpc1 {
void CustomSetEndButton::press_action() { this->parent_->set_custom_end_mode(); }
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/button/button.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class CustomSetEndButton final : public button::Button, public Parented<MR24HPC1Component> {
public:
CustomSetEndButton() = default;
protected:
void press_action() override;
};
} // namespace esphome::seeed_mr24hpc1
@@ -1,7 +0,0 @@
#include "restart_button.h"
namespace esphome::seeed_mr24hpc1 {
void RestartButton::press_action() { this->parent_->set_restart(); }
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/button/button.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class RestartButton final : public button::Button, public Parented<MR24HPC1Component> {
public:
RestartButton() = default;
protected:
void press_action() override;
};
} // namespace esphome::seeed_mr24hpc1