From c586df82429546fba56ab10b579bf225bb33ebb2 Mon Sep 17 00:00:00 2001 From: Zitrium31 <123826842+Zitrium31@users.noreply.github.com> Date: Fri, 3 Jan 2025 20:58:39 +0100 Subject: [PATCH] feat: Home Assistant: support endpoints for locks (#25359) Co-authored-by: Koen Kanters --- lib/extension/homeassistant.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/extension/homeassistant.ts b/lib/extension/homeassistant.ts index 4accd72c09..f321cfa14c 100644 --- a/lib/extension/homeassistant.ts +++ b/lib/extension/homeassistant.ts @@ -747,22 +747,25 @@ export default class HomeAssistant extends Extension { break; } case 'lock': { - assert(!endpoint, `Endpoint not supported for lock type`); const state = (firstExpose as zhc.Lock).features.filter(isBinaryExpose).find((f) => f.name === 'state'); - assert(state?.property === 'state', "Lock property must be 'state'"); + assert(state?.name === 'state', "Lock expose must have a 'state'"); const discoveryEntry: DiscoveryEntry = { type: 'lock', - object_id: 'lock', + /* v8 ignore next */ + object_id: endpoint ? `lock_${endpoint}` : 'lock', mockProperties: [{property: state.property, value: null}], discovery_payload: { - name: null, + /* v8 ignore next */ + name: endpoint ? utils.capitalize(endpoint) : null, + command_topic_prefix: endpoint, command_topic: true, value_template: `{{ value_json.${state.property} }}`, state_locked: state.value_on, state_unlocked: state.value_off, + /* v8 ignore next */ + command_topic_postfix: endpoint ? state.property : null, }, }; - discoveryEntries.push(discoveryEntry); break; }