Merge branch 'safe-mode-trigger-trampoline' into integration

This commit is contained in:
J. Nick Koston
2026-03-26 10:37:01 -10:00
2 changed files with 4 additions and 19 deletions
+4 -9
View File
@@ -7,7 +7,6 @@ from esphome.const import (
CONF_NUM_ATTEMPTS,
CONF_REBOOT_TIMEOUT,
CONF_SAFE_MODE,
CONF_TRIGGER_ID,
KEY_PAST_SAFE_MODE,
)
from esphome.core import CORE, CoroPriority, coroutine_with_priority
@@ -20,7 +19,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)
SafeModeTrigger = safe_mode_ns.class_("SafeModeTrigger", automation.Trigger.template())
MarkSuccessfulAction = safe_mode_ns.class_("MarkSuccessfulAction", automation.Action)
@@ -43,11 +41,7 @@ CONFIG_SCHEMA = cv.All(
cv.Optional(
CONF_REBOOT_TIMEOUT, default="5min"
): cv.positive_time_period_milliseconds,
cv.Optional(CONF_ON_SAFE_MODE): automation.validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SafeModeTrigger),
}
),
cv.Optional(CONF_ON_SAFE_MODE): automation.validate_automation({}),
}
).extend(cv.COMPONENT_SCHEMA),
_remove_id_if_disabled,
@@ -80,8 +74,9 @@ async def to_code(config):
if on_safe_mode_config := config.get(CONF_ON_SAFE_MODE):
cg.add_define("USE_SAFE_MODE_CALLBACK")
for conf in on_safe_mode_config:
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await automation.build_automation(trigger, [], conf)
await automation.build_callback_automation(
var, "add_on_safe_mode_callback", [], conf
)
condition = var.should_enter_safe_mode(
config[CONF_NUM_ATTEMPTS],
-10
View File
@@ -1,19 +1,9 @@
#pragma once
#include "esphome/core/defines.h"
#include "esphome/core/automation.h"
#include "safe_mode.h"
namespace esphome::safe_mode {
#ifdef USE_SAFE_MODE_CALLBACK
class SafeModeTrigger final : public Trigger<> {
public:
explicit SafeModeTrigger(SafeModeComponent *parent) {
parent->add_on_safe_mode_callback([this]() { trigger(); });
}
};
#endif // USE_SAFE_MODE_CALLBACK
template<typename... Ts> class MarkSuccessfulAction : public Action<Ts...>, public Parented<SafeModeComponent> {
public:
void play(const Ts &...x) override { this->parent_->mark_successful(); }