mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-29 07:08:56 +00:00
Add multi endpoint support for Home Assistant cover. https://github.com/Koenkk/zigbee2mqtt/issues/8712
This commit is contained in:
@@ -280,33 +280,35 @@ class HomeAssistant extends Extension {
|
||||
|
||||
discoveryEntries.push(discoveryEntry);
|
||||
} else if (firstExpose.type === 'cover') {
|
||||
assert(!endpoint, `Endpoint not supported for cover type`);
|
||||
const hasPosition = exposes.find((expose) => expose.features.find((e) => e.name === 'position'));
|
||||
const position = exposes.find((expose) => expose.features.find((e) => e.name === 'position'));
|
||||
const hasTilt = exposes.find((expose) => expose.features.find((e) => e.name === 'tilt'));
|
||||
|
||||
const discoveryEntry = {
|
||||
type: 'cover',
|
||||
object_id: 'cover',
|
||||
object_id: endpoint ? `cover_${endpoint}` : 'cover',
|
||||
discovery_payload: {
|
||||
command_topic: true,
|
||||
state_topic: !hasPosition,
|
||||
state_topic: !position,
|
||||
command_topic_prefix: endpoint,
|
||||
},
|
||||
};
|
||||
|
||||
if (!hasPosition && !hasTilt) {
|
||||
if (!position && !hasTilt) {
|
||||
discoveryEntry.discovery_payload.optimistic = true;
|
||||
}
|
||||
|
||||
if (hasPosition) {
|
||||
if (position) {
|
||||
const p = position.features.find((f) => f.name === 'position');
|
||||
discoveryEntry.discovery_payload = {...discoveryEntry.discovery_payload,
|
||||
position_template: '{{ value_json.position }}',
|
||||
set_position_template: '{ "position": {{ position }} }',
|
||||
position_template: `{{ value_json.${getProperty(p)} }}`,
|
||||
set_position_template: `{ "${getProperty(p)}": {{ position }} }`,
|
||||
set_position_topic: true,
|
||||
position_topic: true,
|
||||
};
|
||||
}
|
||||
|
||||
if (hasTilt) {
|
||||
assert(!endpoint, `Endpoint with tilt not supported for cover type`);
|
||||
discoveryEntry.discovery_payload = {...discoveryEntry.discovery_payload,
|
||||
tilt_command_topic: true,
|
||||
tilt_status_topic: true,
|
||||
|
||||
Reference in New Issue
Block a user