[pn532] Use register_apply_condition for pn532.is_writing (#19737)

This commit is contained in:
J. Nick Koston
2026-09-26 16:45:04 -05:00
committed by GitHub
parent 7dd26ba9cc
commit 2d17ad2c91
4 changed files with 16 additions and 12 deletions
+2 -6
View File
@@ -20,10 +20,6 @@ CONF_PN532_ID = "pn532_id"
pn532_ns = cg.esphome_ns.namespace("pn532")
PN532 = pn532_ns.class_("PN532", cg.PollingComponent)
PN532IsWritingCondition = pn532_ns.class_(
"PN532IsWritingCondition", automation.Condition
)
PN532_SCHEMA = cv.Schema(
{
cv.GenerateID(): cv.declare_id(PN532),
@@ -77,12 +73,12 @@ async def setup_pn532(var: MockObj, config: ConfigType) -> None:
await automation.build_callback_automations(var, config, _CALLBACK_AUTOMATIONS)
automation.register_parented_condition(
automation.register_apply_condition(
"pn532.is_writing",
PN532IsWritingCondition,
cv.Schema(
{
cv.GenerateID(): cv.use_id(PN532),
}
),
"is_writing()",
)
-6
View File
@@ -1,7 +1,6 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/core/automation.h"
#include "esphome/components/binary_sensor/binary_sensor.h"
#include "esphome/components/nfc/nfc_tag.h"
#include "esphome/components/nfc/nfc.h"
@@ -156,9 +155,4 @@ class PN532BinarySensor final : public binary_sensor::BinarySensor {
bool found_{false};
};
template<typename... Ts> class PN532IsWritingCondition final : public Condition<Ts...>, public Parented<PN532> {
public:
bool check(const Ts &...x) override { return this->parent_->is_writing(); }
};
} // namespace esphome::pn532
@@ -0,0 +1,10 @@
button:
- platform: template
name: PN532 write state
on_press:
- if:
condition:
pn532.is_writing:
id: pn532_nfcc_i2c
then:
- logger.log: Writing
@@ -0,0 +1,4 @@
packages:
i2c: !include ../../test_build_components/common/i2c/esp8266-ard.yaml
pn532_i2c: !include common.yaml
actions: !include common-actions.yaml