diff --git a/esphome/components/lock/__init__.py b/esphome/components/lock/__init__.py index fb9a79f81fe..af12fc61b28 100644 --- a/esphome/components/lock/__init__.py +++ b/esphome/components/lock/__init__.py @@ -32,8 +32,6 @@ LockCall = lock_ns.class_("LockCall") LockPublishAction = lock_ns.class_("LockPublishAction", automation.Action) -LockStateForwarder = lock_ns.class_("LockStateForwarder") - LockState = lock_ns.enum("LockState") LOCK_STATES = LockState.options( @@ -90,12 +88,16 @@ _CALLBACK_AUTOMATIONS = ( automation.CallbackAutomation( CONF_ON_LOCK, "add_on_state_callback", - forwarder=LockStateForwarder.template(LockState.LOCK_STATE_LOCKED), + params=[(LockState, "state")], + forward=[], + when="state == lock::LOCK_STATE_LOCKED", ), automation.CallbackAutomation( CONF_ON_UNLOCK, "add_on_state_callback", - forwarder=LockStateForwarder.template(LockState.LOCK_STATE_UNLOCKED), + params=[(LockState, "state")], + forward=[], + when="state == lock::LOCK_STATE_UNLOCKED", ), ) diff --git a/esphome/components/lock/automation.h b/esphome/components/lock/automation.h deleted file mode 100644 index e578a056439..00000000000 --- a/esphome/components/lock/automation.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "esphome/components/lock/lock.h" -#include "esphome/core/automation.h" -#include "esphome/core/component.h" - -namespace esphome::lock { - -/// Callback forwarder that triggers an Automation<> only when a specific lock state is entered. -/// Pointer-sized (single Automation* field) to fit inline in Callback::ctx_. -template struct LockStateForwarder { - Automation<> *automation; - void operator()(LockState state) const { - if (state == State) - this->automation->trigger(); - } -}; - -static_assert(sizeof(LockStateForwarder) <= sizeof(void *)); -static_assert(std::is_trivially_copyable_v>); - -} // namespace esphome::lock