Fix cover state publishing of multi-endpoint devices (#14200)

* Fix cover state publishing of multi-endpoint devices

* WIP testing

* WIP test for multiEndpoint cover device

* WIP zigfred plus test

* WIP zigfred plus test

* Remove zigfred plus meta testing flag

* Working zigfred plus integration into bridge test

* Working integration of zigfred plus in tests

* WIP zigfred plus testing

* Add working test for multi-cover devices. Working cover state for multi-cover + multi-light devices.

* Fix republishing of cover state

* Fix cover position and tilt readout with postfix topic

* Fix homeassistant.test.js for zigfred plus cover

* Fix cover value template to support multi-cover devices

* Update homeassistant.ts

Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
This commit is contained in:
Markus Wegmann
2022-09-28 20:21:30 +02:00
committed by GitHub
co-authored by Koen Kanters
parent a95d47fef9
commit 3b60a8e02a
6 changed files with 79 additions and 8 deletions
+11 -5
View File
@@ -392,12 +392,13 @@ export default class HomeAssistant extends Extension {
const discoveryEntry: DiscoveryEntry = {
type: 'cover',
mockProperties: [],
mockProperties: [{property: state.property, value: null}],
object_id: endpoint ? `cover_${endpoint}` : 'cover',
discovery_payload: {
command_topic_prefix: endpoint,
command_topic: true,
state_topic: true,
state_topic_postfix: endpoint,
},
};
@@ -425,7 +426,8 @@ export default class HomeAssistant extends Extension {
`stopped {% else %} {% if value_json.${position.property} > 0 %} closing {% else %} ` +
`opening {% endif %} {% endif %}`;
} else {
discoveryEntry.discovery_payload.value_template = `{{ value_json.${getProperty(state)} }}`,
discoveryEntry.discovery_payload.value_template =
`{{ value_json.${featurePropertyWithoutEndpoint(state)} }}`,
discoveryEntry.discovery_payload.state_open = 'OPEN';
discoveryEntry.discovery_payload.state_closed = 'CLOSE';
}
@@ -436,7 +438,7 @@ export default class HomeAssistant extends Extension {
if (position) {
discoveryEntry.discovery_payload = {...discoveryEntry.discovery_payload,
position_template: `{{ value_json.${getProperty(position)} }}`,
position_template: `{{ value_json.${featurePropertyWithoutEndpoint(position)} }}`,
set_position_template: `{ "${getProperty(position)}": {{ position }} }`,
set_position_topic: true,
position_topic: true,
@@ -447,7 +449,7 @@ export default class HomeAssistant extends Extension {
discoveryEntry.discovery_payload = {...discoveryEntry.discovery_payload,
tilt_command_topic: true,
tilt_status_topic: true,
tilt_status_template: `{{ value_json.${getProperty(tilt)} }}`,
tilt_status_template: `{{ value_json.${featurePropertyWithoutEndpoint(tilt)} }}`,
};
}
@@ -891,7 +893,11 @@ export default class HomeAssistant extends Extension {
const entity = this.zigbee.resolveEntity(data.entity.name);
if (entity.isDevice() && this.discovered[entity.ieeeAddr]) {
for (const objectID of this.discovered[entity.ieeeAddr].objectIDs) {
const match = /light_(.*)/.exec(objectID);
const lightMatch = /light_(.*)/.exec(objectID);
const coverMatch = /cover_(.*)/.exec(objectID);
const match = lightMatch || coverMatch;
if (match) {
const endpoint = match[1];
const endpointRegExp = new RegExp(`(.*)_${endpoint}`);