mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 16:20:42 +00:00
[pn7150][pn7160] Migrate triggers to callback automation (#15221)
This commit is contained in:
@@ -50,14 +50,6 @@ SetWriteMessageAction = pn7150_ns.class_("SetWriteMessageAction", automation.Act
|
||||
SetWriteModeAction = pn7150_ns.class_("SetWriteModeAction", automation.Action)
|
||||
|
||||
|
||||
PN7150OnEmulatedTagScanTrigger = pn7150_ns.class_(
|
||||
"PN7150OnEmulatedTagScanTrigger", automation.Trigger.template()
|
||||
)
|
||||
|
||||
PN7150OnFinishedWriteTrigger = pn7150_ns.class_(
|
||||
"PN7150OnFinishedWriteTrigger", automation.Trigger.template()
|
||||
)
|
||||
|
||||
PN7150IsWritingCondition = pn7150_ns.class_(
|
||||
"PN7150IsWritingCondition", automation.Condition
|
||||
)
|
||||
@@ -83,20 +75,8 @@ SET_MESSAGE_ACTION_SCHEMA = cv.Schema(
|
||||
PN7150_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(PN7150),
|
||||
cv.Optional(CONF_ON_EMULATED_TAG_SCAN): automation.validate_automation(
|
||||
{
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
|
||||
PN7150OnEmulatedTagScanTrigger
|
||||
),
|
||||
}
|
||||
),
|
||||
cv.Optional(CONF_ON_FINISHED_WRITE): automation.validate_automation(
|
||||
{
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
|
||||
PN7150OnFinishedWriteTrigger
|
||||
),
|
||||
}
|
||||
),
|
||||
cv.Optional(CONF_ON_EMULATED_TAG_SCAN): automation.validate_automation({}),
|
||||
cv.Optional(CONF_ON_FINISHED_WRITE): automation.validate_automation({}),
|
||||
cv.Optional(CONF_ON_TAG): automation.validate_automation(
|
||||
{
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(nfc.NfcOnTagTrigger),
|
||||
@@ -215,12 +195,14 @@ async def setup_pn7150(var, config):
|
||||
)
|
||||
|
||||
for conf in config.get(CONF_ON_EMULATED_TAG_SCAN, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||
await automation.build_automation(trigger, [], conf)
|
||||
await automation.build_callback_automation(
|
||||
var, "add_on_emulated_tag_scan_callback", [], conf
|
||||
)
|
||||
|
||||
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(
|
||||
|
||||
@@ -7,20 +7,6 @@
|
||||
namespace esphome {
|
||||
namespace pn7150 {
|
||||
|
||||
class PN7150OnEmulatedTagScanTrigger : public Trigger<> {
|
||||
public:
|
||||
explicit PN7150OnEmulatedTagScanTrigger(PN7150 *parent) {
|
||||
parent->add_on_emulated_tag_scan_callback([this]() { this->trigger(); });
|
||||
}
|
||||
};
|
||||
|
||||
class PN7150OnFinishedWriteTrigger : public Trigger<> {
|
||||
public:
|
||||
explicit PN7150OnFinishedWriteTrigger(PN7150 *parent) {
|
||||
parent->add_on_finished_write_callback([this]() { this->trigger(); });
|
||||
}
|
||||
};
|
||||
|
||||
template<typename... Ts> class PN7150IsWritingCondition : public Condition<Ts...>, public Parented<PN7150> {
|
||||
public:
|
||||
bool check(const Ts &...x) override { return this->parent_->is_writing(); }
|
||||
|
||||
@@ -52,14 +52,6 @@ SetWriteMessageAction = pn7160_ns.class_("SetWriteMessageAction", automation.Act
|
||||
SetWriteModeAction = pn7160_ns.class_("SetWriteModeAction", automation.Action)
|
||||
|
||||
|
||||
PN7160OnEmulatedTagScanTrigger = pn7160_ns.class_(
|
||||
"PN7160OnEmulatedTagScanTrigger", automation.Trigger.template()
|
||||
)
|
||||
|
||||
PN7160OnFinishedWriteTrigger = pn7160_ns.class_(
|
||||
"PN7160OnFinishedWriteTrigger", automation.Trigger.template()
|
||||
)
|
||||
|
||||
PN7160IsWritingCondition = pn7160_ns.class_(
|
||||
"PN7160IsWritingCondition", automation.Condition
|
||||
)
|
||||
@@ -85,20 +77,8 @@ SET_MESSAGE_ACTION_SCHEMA = cv.Schema(
|
||||
PN7160_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(PN7160),
|
||||
cv.Optional(CONF_ON_EMULATED_TAG_SCAN): automation.validate_automation(
|
||||
{
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
|
||||
PN7160OnEmulatedTagScanTrigger
|
||||
),
|
||||
}
|
||||
),
|
||||
cv.Optional(CONF_ON_FINISHED_WRITE): automation.validate_automation(
|
||||
{
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
|
||||
PN7160OnFinishedWriteTrigger
|
||||
),
|
||||
}
|
||||
),
|
||||
cv.Optional(CONF_ON_EMULATED_TAG_SCAN): automation.validate_automation({}),
|
||||
cv.Optional(CONF_ON_FINISHED_WRITE): automation.validate_automation({}),
|
||||
cv.Optional(CONF_ON_TAG): automation.validate_automation(
|
||||
{
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(nfc.NfcOnTagTrigger),
|
||||
@@ -227,12 +207,14 @@ async def setup_pn7160(var, config):
|
||||
)
|
||||
|
||||
for conf in config.get(CONF_ON_EMULATED_TAG_SCAN, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||
await automation.build_automation(trigger, [], conf)
|
||||
await automation.build_callback_automation(
|
||||
var, "add_on_emulated_tag_scan_callback", [], conf
|
||||
)
|
||||
|
||||
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(
|
||||
|
||||
@@ -7,20 +7,6 @@
|
||||
namespace esphome {
|
||||
namespace pn7160 {
|
||||
|
||||
class PN7160OnEmulatedTagScanTrigger : public Trigger<> {
|
||||
public:
|
||||
explicit PN7160OnEmulatedTagScanTrigger(PN7160 *parent) {
|
||||
parent->add_on_emulated_tag_scan_callback([this]() { this->trigger(); });
|
||||
}
|
||||
};
|
||||
|
||||
class PN7160OnFinishedWriteTrigger : public Trigger<> {
|
||||
public:
|
||||
explicit PN7160OnFinishedWriteTrigger(PN7160 *parent) {
|
||||
parent->add_on_finished_write_callback([this]() { this->trigger(); });
|
||||
}
|
||||
};
|
||||
|
||||
template<typename... Ts> class PN7160IsWritingCondition : public Condition<Ts...>, public Parented<PN7160> {
|
||||
public:
|
||||
bool check(const Ts &...x) override { return this->parent_->is_writing(); }
|
||||
|
||||
Reference in New Issue
Block a user