Skip to content

Commit

Permalink
feat: Home Assistant: support endpoints for locks (#25359)
Browse files Browse the repository at this point in the history
Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
  • Loading branch information
Zitrium31 and Koenkk authored Jan 3, 2025
1 parent 7cf01e9 commit c586df8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/extension/homeassistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c586df8

Please sign in to comment.