From 24cc9bdb13c9f351f1b2480cbe8c0cc02316f714 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 26 Mar 2026 12:30:58 -1000 Subject: [PATCH 1/3] Update copy lock to accept LockState callback parameter --- esphome/components/copy/lock/copy_lock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/copy/lock/copy_lock.cpp b/esphome/components/copy/lock/copy_lock.cpp index 25bd8c33ef..652da1918b 100644 --- a/esphome/components/copy/lock/copy_lock.cpp +++ b/esphome/components/copy/lock/copy_lock.cpp @@ -7,7 +7,7 @@ namespace copy { static const char *const TAG = "copy.lock"; void CopyLock::setup() { - source_->add_on_state_callback([this]() { this->publish_state(source_->state); }); + source_->add_on_state_callback([this](LockState state) { this->publish_state(state); }); traits.set_assumed_state(source_->traits.get_assumed_state()); traits.set_requires_code(source_->traits.get_requires_code()); From 854e8d90cb38ed3a7f112ed98e9062314334a4f5 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 26 Mar 2026 12:39:44 -1000 Subject: [PATCH 2/3] Fix copy lock namespace qualification for LockState --- esphome/components/copy/lock/copy_lock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/copy/lock/copy_lock.cpp b/esphome/components/copy/lock/copy_lock.cpp index 652da1918b..c846954510 100644 --- a/esphome/components/copy/lock/copy_lock.cpp +++ b/esphome/components/copy/lock/copy_lock.cpp @@ -7,7 +7,7 @@ namespace copy { static const char *const TAG = "copy.lock"; void CopyLock::setup() { - source_->add_on_state_callback([this](LockState state) { this->publish_state(state); }); + source_->add_on_state_callback([this](lock::LockState state) { this->publish_state(state); }); traits.set_assumed_state(source_->traits.get_assumed_state()); traits.set_requires_code(source_->traits.get_requires_code()); From 618ace880ac0116485d4b5fd7824b7e213b4c804 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 26 Mar 2026 19:11:11 -1000 Subject: [PATCH 3/3] Use codegen enum expressions and fix stale doc comment --- esphome/components/lock/__init__.py | 6 +++--- esphome/components/lock/lock.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/esphome/components/lock/__init__.py b/esphome/components/lock/__init__.py index 31626ef6eb..0df4b20cba 100644 --- a/esphome/components/lock/__init__.py +++ b/esphome/components/lock/__init__.py @@ -84,8 +84,8 @@ def lock_schema( @setup_entity("lock") async def _setup_lock_core(var, config): for conf_key, state_enum in ( - (CONF_ON_LOCK, "lock::LockState::LOCK_STATE_LOCKED"), - (CONF_ON_UNLOCK, "lock::LockState::LOCK_STATE_UNLOCKED"), + (CONF_ON_LOCK, LockState.LOCK_STATE_LOCKED), + (CONF_ON_UNLOCK, LockState.LOCK_STATE_UNLOCKED), ): for conf in config.get(conf_key, []): await automation.build_callback_automation( @@ -93,7 +93,7 @@ async def _setup_lock_core(var, config): "add_on_state_callback", [], conf, - forwarder=LockStateForwarder.template(cg.RawExpression(state_enum)), + forwarder=LockStateForwarder.template(state_enum), ) if mqtt_id := config.get(CONF_MQTT_ID): diff --git a/esphome/components/lock/lock.h b/esphome/components/lock/lock.h index 666fbe36f9..543a4b51a8 100644 --- a/esphome/components/lock/lock.h +++ b/esphome/components/lock/lock.h @@ -148,7 +148,7 @@ class Lock : public EntityBase { /** Set callback for state changes. * - * @param callback The void(bool) callback. + * @param callback The void(LockState) callback. */ template void add_on_state_callback(F &&callback) { this->state_callback_.add(std::forward(callback));