Skip to content

Commit

Permalink
add generic 'command' to all devices (Koenkk#3775)
Browse files Browse the repository at this point in the history
* add generic 'command' to all devices

* fix linter errors
  • Loading branch information
zivillian authored Jan 31, 2022
1 parent 52fb868 commit 8d5d008
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions converters/toZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ const converters = {
meta.logger.info(`Wrote '${JSON.stringify(value.payload)}' to '${value.cluster}'`);
},
},
command: {
key: ['command'],
convertSet: async (entity, key, value, meta) => {
const options = utils.getOptions(meta.mapped, entity);
await entity.command(value.cluster, value.command, (value.hasOwnProperty('payload') ? value.payload : {}), options);
meta.logger.info(`Invoked '${value.cluster}.${value.command}' with payload '${JSON.stringify(value.payload)}'`);
},
},
factory_reset: {
key: ['reset'],
convertSet: async (entity, key, value, meta) => {
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ function addDefinition(definition) {
};
}

definition.toZigbee.push(tz.scene_store, tz.scene_recall, tz.scene_add, tz.scene_remove, tz.scene_remove_all, tz.read, tz.write);
definition.toZigbee.push(tz.scene_store, tz.scene_recall, tz.scene_add, tz.scene_remove, tz.scene_remove_all, tz.read, tz.write,
tz.command);

if (definition.exposes && Array.isArray(definition.exposes) && !definition.exposes.find((e) => e.name === 'linkquality')) {
definition.exposes = definition.exposes.concat([exposes.presets.linkquality()]);
Expand Down

0 comments on commit 8d5d008

Please sign in to comment.