From 2d17ad2c9172ef1ff18fa06f2c032b340b618ac9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 26 Sep 2026 22:45:04 +0100 Subject: [PATCH] [pn532] Use register_apply_condition for pn532.is_writing (#19737) --- esphome/components/pn532/__init__.py | 8 ++------ esphome/components/pn532/pn532.h | 6 ------ tests/components/pn532_i2c/common-actions.yaml | 10 ++++++++++ .../components/pn532_i2c/test-actions.esp8266-ard.yaml | 4 ++++ 4 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 tests/components/pn532_i2c/common-actions.yaml create mode 100644 tests/components/pn532_i2c/test-actions.esp8266-ard.yaml diff --git a/esphome/components/pn532/__init__.py b/esphome/components/pn532/__init__.py index d396050511..b23c4e845a 100644 --- a/esphome/components/pn532/__init__.py +++ b/esphome/components/pn532/__init__.py @@ -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()", ) diff --git a/esphome/components/pn532/pn532.h b/esphome/components/pn532/pn532.h index c518afc491..96013f7d79 100644 --- a/esphome/components/pn532/pn532.h +++ b/esphome/components/pn532/pn532.h @@ -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 class PN532IsWritingCondition final : public Condition, public Parented { - public: - bool check(const Ts &...x) override { return this->parent_->is_writing(); } -}; - } // namespace esphome::pn532 diff --git a/tests/components/pn532_i2c/common-actions.yaml b/tests/components/pn532_i2c/common-actions.yaml new file mode 100644 index 0000000000..2f5bd4aec4 --- /dev/null +++ b/tests/components/pn532_i2c/common-actions.yaml @@ -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 diff --git a/tests/components/pn532_i2c/test-actions.esp8266-ard.yaml b/tests/components/pn532_i2c/test-actions.esp8266-ard.yaml new file mode 100644 index 0000000000..9a41342126 --- /dev/null +++ b/tests/components/pn532_i2c/test-actions.esp8266-ard.yaml @@ -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