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

Description of additional discover commands. #978

Merged
merged 12 commits into from
Mar 21, 2024
Merged

Conversation

kirovilya
Copy link
Contributor

Allow general commands to be sent through the endpoint.

Later add general device converters and send these commands to the device from the developer console or via MQTT.
This is for developers of new converters so that they can find out the attributes of the clusters.
Unfortunately, devices do not report all of their attributes and commands. Some don't report anything.

For example:

zigbee2mqtt/0xa4c138b8c414612e/1/set {"discover":{"cluster": 6, "options":{}}}

Received 'zcl' data '{"frame":{"Header":{"frameControl":{"frameType":0,"manufacturerSpecific":false,"direction":1,"disableDefaultResponse":true,"reservedBits":0},"transactionSequenceNumber":3,"manufacturerCode":null,"commandIdentifier":13},"Payload":{"discComplete":1,"attrInfos":[{"attrId":65533,"dataType":33},{"attrId":16385,"dataType":33},{"attrId":16386,"dataType":33},{"attrId":32769,"dataType":48},{"attrId":32770,"dataType":48},{"attrId":20480,"dataType":48}]},"Command":{"ID":13,"name":"discoverRsp","parameters":[{"name":"attrId","type":33},{"name":"dataType","type":32}]}},"address":41775,"endpoint":1,"linkquality":255,"groupID":0,"wasBroadcast":false,"destinationEndpoint":1}'


zigbee2mqtt/0xa4c138b8c414612e/2/set {"discoverExt":{"cluster": "manuSpecificTuya_3", "options":{}}}

Received 'zcl' data '{"frame":{"Header":{"frameControl":{"frameType":0,"manufacturerSpecific":false,"direction":1,"disableDefaultResponse":true,"reservedBits":0},"transactionSequenceNumber":17,"manufacturerCode":null,"commandIdentifier":22},"Payload":{"discComplete":1,"attrInfos":[{"attrId":53264,"dataType":48,"access":7},{"attrId":53280,"dataType":48,"access":7}]},"Command":{"ID":22,"name":"discoverExtRsp","parameters":[{"name":"attrId","type":33},{"name":"dataType","type":32},{"name":"access","type":32}]}},"address":41775,"endpoint":2,"linkquality":232,"groupID":0,"wasBroadcast":false,"destinationEndpoint":1}'

@@ -897,6 +897,33 @@ class Endpoint extends Entity {
}
}
}

public async generalCommand(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call this zclCommand and refactor the other zcl calls to use this method? E.g. readResponse and writeStructured can be easily refactored to this, probably also the others.

Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse,
options.manufacturerCode, transactionSequenceNumber, 'defaultRsp', clusterID, payload, options.reservedBits
);

const log = `DefaultResponse ${this.deviceIeeeAddress}/${this.ID} ` +
`${clusterID}(${commandID}, ${JSON.stringify(options)})`;
debug.info(log);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log statement should go into zclCommand() which should fix https://github.com/Koenkk/zigbee-herdsman/pull/978/files#r1530963264

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, but we lost some readability of the debug logs.
was:
Write 0x129/1 genOnOff({"onOff":1}, ...
became:
ZCL command 0x129/1 genOnOff.write([{"attrId":0,"attrData":1,"dataType":16}], ...
because at the zclCommand level the data has already been converted

Copy link
Owner

@Koenkk Koenkk Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, could we add the error log text as an optional argument to zclCommand?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, can. I try it later

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.
was:
Write 0x129/1 genOnOff({"onOff":1}, ...
became:
ZCL command 0x129/1 genOnOff.write({"onOff":1}, ...

try {
return await this.sendRequest(frame, options);
} catch (error) {
if (logError) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's always log the error here, then we can remove the try/catch + error logging from every function calling zclCommand()

@Koenkk Koenkk merged commit b688219 into Koenkk:master Mar 21, 2024
1 check passed
@Koenkk
Copy link
Owner

Koenkk commented Mar 21, 2024

Nice refactor, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants