Skip to content

Commit

Permalink
use power topic
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaskalov committed Nov 13, 2022
1 parent bcddc55 commit fc173e8
Showing 1 changed file with 11 additions and 25 deletions.
36 changes: 11 additions & 25 deletions src/zigbee2MQTTAcessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,22 @@ export class Zigbee2MQTTAcessory {
const path = (propertyPath !== undefined ? propertyPath + '.' : '') + exposed.property;
if ((exposed.access & 2) === 2) {
characteristic.onGet = () => {
this.get(path);
if (path === 'state' && this.device.powerTopic !== undefined) {
this.platform.mqttClient.publish('cmnd/' + this.device.powerTopic, '');
} else {
this.get(path);
}
return undefined;
};
}
if ((exposed.access & 3) === 3) {
characteristic.onSet = value => {
this.set(path, this.mapSetValue(exposed.property, value));
const mappedValue = this.mapSetValue(exposed.property, value);
if (path === 'state' && this.device.powerTopic !== undefined) {
this.platform.mqttClient.publish('cmnd/' + this.device.powerTopic, mappedValue as string);
} else {
this.set(path, mappedValue);
}
};
}
//this.log('characteristic: %s (%s)', characteristicName, path);
Expand Down Expand Up @@ -250,29 +259,6 @@ export class Zigbee2MQTTAcessory {
);
}

/*
registerStateHandler() {
const state = new Zigbee2MQTTCharacteristic(this.platform, this.accessory, this.service, 'On', false);
state.onGet = () => {
if (this.powerTopic !== undefined) {
this.platform.mqttClient.publish('cmnd/' + this.powerTopic, '');
} else {
this.get('state');
}
return undefined;
};
state.onSet = value => {
const state = value ? 'ON' : 'OFF';
if (this.powerTopic !== undefined) {
this.platform.mqttClient.publish('cmnd/' + this.powerTopic, state);
} else {
this.set('state', state);
}
};
this.characteristics['state'] = state;
}
*/

getObjectByPath(obj: object, path: string): object | undefined {
return path.split('.').reduce((a, v) => a ? a[v] : undefined, obj);
}
Expand Down

0 comments on commit fc173e8

Please sign in to comment.