Koenkk / zigbee-herdsman

A Node.js Zigbee library
MIT License
483 stars 300 forks source link

Changes to payload when sending zclData to a device breaks iobroker.zigbee function #998

Closed asgothian closed 1 month ago

asgothian commented 8 months ago

With the latest version of the iobroker zigbee adapter I found that code which used to work now raises an error:

as it is a rarely used function, I do not know for how long this has been the case. It can be up to 9 months.

the code is:

        this.debug(`Zigbee publish to '${deviceID}', ${cid} - cmd ${cmd} - payload ${JSON.stringify(zclData)} - cfg ${JSON.stringify(cfg)} - endpoint ${ep}`);

        if (cfg == null) {
            cfg = {};
        }

        if (type === 'foundation') {
            cfg.disableDefaultResponse = true;
            if (cmd === 'read' && !Array.isArray(zclData)) {
                // needs to be iterable (string[] | number [])
                zclData[Symbol.iterator] = function* () {
                    let k;
                    for (k in this) {
                        yield k;
                    }
                };
            }
            let result;
            if (cmd === 'configReport') {
                result = await endpoint.configureReporting(cid, zclData, cfg);
            } else {
                result = await endpoint[cmd](cid, zclData, cfg);
            }
            callback && callback(undefined, result);

The object endpoint is queried from the herdsman with endpoint ID and DeviceID. The log shows the following result. The error is caught via a try/catch construct which encapsulates this function.

2024-03-31 19:45:58.737 - debug: zigbee.0 (4066) Ready to send (ep: 1, cid: genBasic, cmd read, zcl: {"manufacturerName":{}})
--
2024-03-31 19:45:58.739 - debug: zigbee.0 (4066) Zigbee publish to '0x00158d0006371a7b', genBasic - cmd read - payload {"manufacturerName":{}} - cfg null - endpoint 1
2024-03-31 19:45:58.740 - error: zigbee.0 (4066) SendToZigbee failed! (TypeError: attributes.map is not a function)

the code on the zigbee adapter side (iobroker) for this section has not been changed significantly since 2020. The last change is from October 2023, but only contains code reformatting.

I am aware that this is no bug in the herdsman, but I need help to construct a valid payload as this function is used for checking device capabilities on new devices.

A.

github-actions[bot] commented 1 month ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days