[pn532] Migrate PN532OnFinishedWriteTrigger to callback automation (#15220)

This commit is contained in:
J. Nick Koston
2026-03-27 08:22:14 -10:00
committed by GitHub
parent 623408bbfe
commit a4a8fa3027
2 changed files with 4 additions and 20 deletions

View File

@@ -19,10 +19,6 @@ CONF_PN532_ID = "pn532_id"
pn532_ns = cg.esphome_ns.namespace("pn532")
PN532 = pn532_ns.class_("PN532", cg.PollingComponent)
PN532OnFinishedWriteTrigger = pn532_ns.class_(
"PN532OnFinishedWriteTrigger", automation.Trigger.template()
)
PN532IsWritingCondition = pn532_ns.class_(
"PN532IsWritingCondition", automation.Condition
)
@@ -35,13 +31,7 @@ PN532_SCHEMA = cv.Schema(
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(nfc.NfcOnTagTrigger),
}
),
cv.Optional(CONF_ON_FINISHED_WRITE): automation.validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
PN532OnFinishedWriteTrigger
),
}
),
cv.Optional(CONF_ON_FINISHED_WRITE): automation.validate_automation({}),
cv.Optional(CONF_ON_TAG_REMOVED): automation.validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(nfc.NfcOnTagTrigger),
@@ -77,8 +67,9 @@ async def setup_pn532(var, config):
)
for conf in config.get(CONF_ON_FINISHED_WRITE, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await automation.build_automation(trigger, [], conf)
await automation.build_callback_automation(
var, "add_on_finished_write_callback", [], conf
)
@automation.register_condition(

View File

@@ -133,13 +133,6 @@ class PN532BinarySensor : public binary_sensor::BinarySensor {
bool found_{false};
};
class PN532OnFinishedWriteTrigger : public Trigger<> {
public:
explicit PN532OnFinishedWriteTrigger(PN532 *parent) {
parent->add_on_finished_write_callback([this]() { this->trigger(); });
}
};
template<typename... Ts> class PN532IsWritingCondition : public Condition<Ts...>, public Parented<PN532> {
public:
bool check(const Ts &...x) override { return this->parent_->is_writing(); }