hobbyquaker / node-red-contrib-zigbee

Node-RED Nodes for ZigBee Devices 🐝
MIT License
86 stars 15 forks source link

Error when trying to set color_temp on Tradfri LED 1924G9 - Trying to contribute #154

Closed jokakilla closed 3 years ago

jokakilla commented 3 years ago

Hi, I've cloned the source in order to contribute an update on the zigbee-herdsman and zigbee-herdsman-converters dependencies and maybe add some smaller improvements.

Locally dependencies are now bumped to: "zigbee-herdsman": "^0.13.126", "zigbee-herdsman-converters": "^14.0.215"

Testing with an Aqara Door/Window contact ran fine but problems started when setting the color_temp on my Tradfri LED. The following log was always printed out by the converter node and the color_temp didn't change:

"Error: 0x LED Cannot read property 'log' of undefined" # #

I'm not even sure if this is caused by the changed dependency or if I just uncovered an already existing issue. Insights up to now: In converter.js the herdsman-convert convertSet method with a parameter meta is called. Meta contains logging methods for the different logging levels. The logger object is empty because the scope of "this" in meta object is different.

const meta = {
    options: {},
    message: payload,
    mapped: model,
    state: {},
    logger: {
        debug: this.debug,
        log: this.log,
        info: this.info,
        warn: this.warn,
        error: this.error
    }
};

A workaround that turned out to be working was like that but I've read that using the console logging methods is not good practice.

logger: {
    debug: console.debug,
    log: console.log,
    info: console.log,
    warn: console.warn,
    error: console.error
}

I'd like to solve that, run some more tests and create a pull request so you can integrate my changes if you think they are worth it ;)

jokakilla commented 3 years ago

Another issue I've found which is related to changes in zigbee-herdsman-coverters - after setting an value with the logger workaround this message appears:

(node:17) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'state' of undefined at Object.convert (/usr/src/node-red/node_modules/zigbee-herdsman-converters/converters/fromZigbee.js:564:79) at /usr/src/node-red/node-red-contrib-zigbee/nodes/converter.js:350:56 at Array.forEach () at HerdsmanProxy.messageHandler (/usr/src/node-red/node-red-contrib-zigbee/nodes/converter.js:349:28) at HerdsmanProxy.emit (events.js:375:28) at ZigbeeShepherd.messageHandler (/usr/src/node-red/node-red-contrib-zigbee/nodes/shepherd.js:1143:28) at Controller.message (/usr/src/node-red/node-red-contrib-zigbee/nodes/shepherd.js:517:26) at Controller.emit (events.js:375:28) at Controller.onZclOrRawData (/usr/src/node-red/node_modules/zigbee-herdsman/dist/controller/controller.js:555:18) at ZStackAdapter. (/usr/src/node-red/node_modules/zigbee-herdsman/dist/controller/controller.js:111:73)

This is because zigbee-herdsman-converters convert for color_colortemp is now using meta.state where for meta only {} is given by convert.js. return Object.assign(result, libColor.syncColorState(result, meta.state, options));

@hobbyquaker is there a way to contact you?

jokakilla commented 3 years ago

Found and solved the problem. https://github.com/hobbyquaker/node-red-contrib-zigbee/pull/157