[factory_reset] Migrate FastBootTrigger to callback automation (#15232)

This commit is contained in:
J. Nick Koston
2026-03-27 08:24:35 -10:00
committed by GitHub
parent 0d67f91fac
commit 5a8d6931a8
2 changed files with 6 additions and 21 deletions
+6 -15
View File
@@ -1,10 +1,9 @@
from esphome.automation import Trigger, build_automation, validate_automation
from esphome import automation
import esphome.codegen as cg
from esphome.components.esp8266 import CONF_RESTORE_FROM_FLASH, KEY_ESP8266
import esphome.config_validation as cv
from esphome.const import (
CONF_ID,
CONF_TRIGGER_ID,
PLATFORM_BK72XX,
PLATFORM_ESP32,
PLATFORM_ESP8266,
@@ -18,7 +17,6 @@ CODEOWNERS = ["@anatoly-savchenkov"]
factory_reset_ns = cg.esphome_ns.namespace("factory_reset")
FactoryResetComponent = factory_reset_ns.class_("FactoryResetComponent", cg.Component)
FastBootTrigger = factory_reset_ns.class_("FastBootTrigger", Trigger, cg.Component)
CONF_MAX_DELAY = "max_delay"
CONF_RESETS_REQUIRED = "resets_required"
@@ -55,11 +53,7 @@ CONFIG_SCHEMA = cv.All(
),
),
cv.Optional(CONF_RESETS_REQUIRED): cv.positive_not_null_int,
cv.Optional(CONF_ON_INCREMENT): validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(FastBootTrigger),
}
),
cv.Optional(CONF_ON_INCREMENT): automation.validate_automation({}),
}
).extend(cv.COMPONENT_SCHEMA),
_validate,
@@ -88,12 +82,9 @@ async def to_code(config):
)
await cg.register_component(var, config)
for conf in config.get(CONF_ON_INCREMENT, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await build_automation(
trigger,
[
(cg.uint8, "x"),
(cg.uint8, "target"),
],
await automation.build_callback_automation(
var,
"add_increment_callback",
[(cg.uint8, "x"), (cg.uint8, "target")],
conf,
)
@@ -30,12 +30,6 @@ class FactoryResetComponent : public Component {
uint8_t required_count_; // The number of boot attempts before fast boot is enabled
};
class FastBootTrigger : public Trigger<uint8_t, uint8_t> {
public:
explicit FastBootTrigger(FactoryResetComponent *parent) {
parent->add_increment_callback([this](uint8_t current, uint8_t target) { this->trigger(current, target); });
}
};
} // namespace esphome::factory_reset
#endif // !defined(USE_RP2040) && !defined(USE_HOST)