Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic zclCommand handler allowing it to be sent from mqtt #7251

Merged
merged 11 commits into from
Mar 25, 2024
10 changes: 10 additions & 0 deletions src/converters/toZigbee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ const converters2 = {
await entity.command('genIdentify', 'identify', {identifytime: identifyTimeout}, utils.getOptions(meta.mapped, entity));
},
} satisfies Tz.Converter,
zcl_command: {
key: ['zclcommand'],
convertSet: async (entity, key, value, meta) => {
utils.assertObject(value, key);
const payload = (value.hasOwnProperty('payload') ? value.payload : {});
utils.assertEndpoint(entity);
await entity.zclCommand(value.cluster, value.command, payload, (value.hasOwnProperty('options') ? value.options : {}));
meta.logger.info(`Invoked ZCL command ${value.cluster}.${value.command} with payload '${JSON.stringify(payload)}'`);
},
} satisfies Tz.Converter,
arm_mode: {
key: ['arm_mode'],
convertSet: async (entity, key, value, meta) => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function prepareDefinition(definition: Definition): Definition {
definition.toZigbee.push(
toZigbee.scene_store, toZigbee.scene_recall, toZigbee.scene_add, toZigbee.scene_remove, toZigbee.scene_remove_all,
toZigbee.scene_rename, toZigbee.read, toZigbee.write,
toZigbee.command, toZigbee.factory_reset);
toZigbee.command, toZigbee.factory_reset, toZigbee.zcl_command);

if (definition.exposes && Array.isArray(definition.exposes) && !definition.exposes.find((e) => e.name === 'linkquality')) {
definition.exposes = definition.exposes.concat([exposesLib.presets.linkquality()]);
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('index.js', () => {
expect(definition.description).toBe('Automatically generated definition');
expect(definition.extend).toBeUndefined();
expect(definition.fromZigbee).toHaveLength(0);
expect(definition.toZigbee).toHaveLength(10);
expect(definition.toZigbee).toHaveLength(11);
expect(definition.exposes).toHaveLength(1);
expect(definition.options).toHaveLength(0);
});
Expand Down
2 changes: 1 addition & 1 deletion test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const MockLogger: Logger = {info: jest.fn(), error: jest.fn(), warn: jest.fn(),

const DefaultTz = [
tz.scene_store, tz.scene_recall, tz.scene_add, tz.scene_remove, tz.scene_remove_all,
tz.scene_rename, tz.read, tz.write, tz.command, tz.factory_reset
tz.scene_rename, tz.read, tz.write, tz.command, tz.factory_reset, tz.zcl_command,
];

export type AssertDefinitionArgs = {
Expand Down