athombv / homey-web-api-issues

This issue tracker is for Homey Developers using the Web API.
4 stars 1 forks source link

TypeError: this.__listener is not a function #18

Closed lvanderree closed 1 year ago

lvanderree commented 1 year ago

My application always used AthomAPI till I've upgraded to SDKv3 and updated to HomeyAPI as well.

However it now crashes with a stacktrace without my source-code in it in a situation of a user which I cannot reproduce:

Stack trace
/node_modules/homey-api/lib/HomeyAPI/HomeyAPIV2/DeviceCapability.js:107
    this.__listener(value);
         ^

TypeError: this.__listener is not a function
    at DeviceCapability.__onCapabilityValue (/node_modules/homey-api/lib/HomeyAPI/HomeyAPIV2/DeviceCapability.js:107:10)
    at /node_modules/homey-api/lib/EventEmitter.js:26:9
    at Array.forEach (<anonymous>)
    at Device.emit (/node_modules/homey-api/lib/EventEmitter.js:25:17)
    at onEvent (/node_modules/homey-api/lib/HomeyAPI/HomeyAPIV2/Item.js:103:18)
    at Socket.__onEvent (/node_modules/homey-api/lib/HomeyAPI/HomeyAPIV2.js:528:7)
    at Socket.Emitter.emit (/node_modules/homey-api/node_modules/component-emitter/index.js:133:20)
    at Socket.onevent (/node_modules/homey-api/node_modules/socket.io-client/lib/socket.js:270:10)
    at Socket.onpacket (/node_modules/homey-api/node_modules/socket.io-client/lib/socket.js:228:12)
    at Manager.<anonymous> (/node_modules/component-bind/index.js:21:15)

https://tools.developer.homey.app/apps/app/com.synplyworks.thenmore/build/2/crashes https://community.homey.app/t/timer-0-8-0-test-homey-v3-0-7-3-beta-homey-v2-v0-4-3-stable-homey-v1-5-fka-then-more-add-timers-to-temporarily-turn-on-devices/3722/72?u=lvanderree

Am I using the API wrong, or is it an issue in the HomeyAPI? And why is SDKV2 being shown in the stack? While my manifest states SDKv3. (are the SDKV2 sources being reused for v3?)

lvanderree commented 1 year ago

Robert Klep found the cause in my code

https://community.homey.app/t/timer-0-8-0-test-homey-v3-0-7-3-beta-homey-v2-v0-4-3-stable-homey-v1-5-fka-then-more-add-timers-to-temporarily-turn-on-devices/3722/74?u=lvanderree

The problem was that I had called makeCapabilityInstance without providing a second argument for the event-handler. I could easily fix it by replacing the call by retrieving the capabilitiesObj instance. I wonder if that was already there in the athom-api library. In this case it might be nicer to have a better error, mentioning that the event-listener should be provided, since the stack-trace has no reference to the faulty source.