1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-14 09:12:19 +01:00

Add on_tag_removed trigger for RC522 (#4742)

This commit is contained in:
Keith Burzinski
2023-04-26 17:47:45 -05:00
committed by GitHub
parent 986dd2ddd2
commit f639f7c280
3 changed files with 27 additions and 5 deletions

View File

@@ -2,7 +2,12 @@ import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import automation, pins
from esphome.components import i2c
from esphome.const import CONF_ON_TAG, CONF_TRIGGER_ID, CONF_RESET_PIN
from esphome.const import (
CONF_ON_TAG,
CONF_ON_TAG_REMOVED,
CONF_TRIGGER_ID,
CONF_RESET_PIN,
)
CODEOWNERS = ["@glmnet"]
AUTO_LOAD = ["binary_sensor"]
@@ -24,6 +29,11 @@ RC522_SCHEMA = cv.Schema(
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(RC522Trigger),
}
),
cv.Optional(CONF_ON_TAG_REMOVED): automation.validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(RC522Trigger),
}
),
}
).extend(cv.polling_component_schema("1s"))
@@ -37,5 +47,10 @@ async def setup_rc522(var, config):
for conf in config.get(CONF_ON_TAG, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
cg.add(var.register_trigger(trigger))
cg.add(var.register_ontag_trigger(trigger))
await automation.build_automation(trigger, [(cg.std_string, "x")], conf)
for conf in config.get(CONF_ON_TAG_REMOVED, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
cg.add(var.register_ontagremoved_trigger(trigger))
await automation.build_automation(trigger, [(cg.std_string, "x")], conf)