[safe_mode] Use register_apply_action for safe_mode.mark_successful (#19605)

This commit is contained in:
J. Nick Koston
2026-09-25 10:21:18 -04:00
committed by GitHub
parent 28343e1bc9
commit 898ab7c701
3 changed files with 7 additions and 28 deletions
+4 -16
View File
@@ -10,8 +10,8 @@ from esphome.const import (
CONF_STORAGE,
KEY_PAST_SAFE_MODE,
)
from esphome.core import CORE, ID, CoroPriority, coroutine_with_priority
from esphome.cpp_generator import MockObj, RawExpression, TemplateArgsType
from esphome.core import CORE, CoroPriority, coroutine_with_priority
from esphome.cpp_generator import RawExpression
from esphome.types import ConfigType
CODEOWNERS = ["@paulmonigatti", "@jsuanet", "@kbx81"]
@@ -22,7 +22,6 @@ CONF_ON_SAFE_MODE = "on_safe_mode"
safe_mode_ns = cg.esphome_ns.namespace("safe_mode")
SafeModeComponent = safe_mode_ns.class_("SafeModeComponent", cg.Component)
MarkSuccessfulAction = safe_mode_ns.class_("MarkSuccessfulAction", automation.Action)
def _remove_id_if_disabled(value: ConfigType) -> ConfigType:
@@ -53,26 +52,15 @@ CONFIG_SCHEMA = cv.All(
)
@automation.register_action(
automation.register_apply_action(
"safe_mode.mark_successful",
MarkSuccessfulAction,
cv.Schema(
{
cv.GenerateID(): cv.use_id(SafeModeComponent),
}
),
synchronous=True,
automation.ApplyCall("mark_successful()"),
)
async def safe_mode_mark_successful_to_code(
config: ConfigType,
action_id: ID,
template_arg: cg.TemplateArguments,
args: TemplateArgsType,
) -> MockObj:
parent = await cg.get_variable(config[CONF_ID])
var = cg.new_Pvariable(action_id, template_arg)
cg.add(var.set_parent(parent))
return var
_CALLBACK_AUTOMATIONS = (
-12
View File
@@ -1,12 +0,0 @@
#pragma once
#include "esphome/core/automation.h"
#include "safe_mode.h"
namespace esphome::safe_mode {
template<typename... Ts> class MarkSuccessfulAction final : public Action<Ts...>, public Parented<SafeModeComponent> {
public:
void play(const Ts &...x) override { this->parent_->mark_successful(); }
};
} // namespace esphome::safe_mode
@@ -3,6 +3,7 @@ wifi:
password: password1
safe_mode:
id: safe_mode_1
boot_is_good_after: 2min
num_attempts: 3
reboot_timeout: 2min
@@ -20,3 +21,5 @@ switch:
esphome:
on_boot:
- safe_mode.mark_successful
- safe_mode.mark_successful:
id: safe_mode_1