ilcato / homebridge-Fibaro-HC2

Homebridge plugin for Fibaro Home Center 2 (and Home Center Lite ...)
Apache License 2.0
65 stars 27 forks source link

Bugfix: TypeError: Cannot read property 'zwaveCompany' of undefined #155

Closed 0ff closed 5 years ago

0ff commented 5 years ago

When defining virtual devices (such as global variables) in HC2 and exposing them via this plugin, the newest version would throw the following error:

[5/26/2019, 11:14:16 AM] [FibaroHC2] Error getting data from Home Center:  TypeError: Cannot read property 'zwaveCompany' of undefined
    at ShadowAccessory.initAccessory (/homebridge/node_modules/homebridge-fibaro-hc2/dist/shadows.js:44:52)
    at FibaroHC2.addAccessory (/homebridge/node_modules/homebridge-fibaro-hc2/dist/index.js:190:25)
    at FibaroHC2.LoadAccessories (/homebridge/node_modules/homebridge-fibaro-hc2/dist/index.js:157:22)
    at fibaroClient.getScenes.then.then (/homebridge/node_modules/homebridge-fibaro-hc2/dist/index.js:103:18)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:583) UnhandledPromiseRejectionWarning: Error: Startup error: get scenes or devices
    at fibaroClient.getScenes.then.then.catch (/homebridge/node_modules/homebridge-fibaro-hc2/dist/index.js:107:19)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:583) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:583) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

My proposed solution is to have an empty fallback-object that would make sure the defaults are used instead of throwing an error.

hovorkap commented 5 years ago

@0ff I am just curious, which type of fibaro device does not have properties?

0ff commented 5 years ago

Hi @hovorkap, I have defined several Globals in HC2 (Panels > Variables Panel) and then I've set the switchglobalvariables value of homebridge-Fibaro-HC2 to include some of them. These global "switches", it seems, don't have any properties. Makes sense, if you ask me :)

EDIT: Seems to be these here: https://github.com/ilcato/homebridge-Fibaro-HC2/blob/2ad4eb173d9d9faeb8f0e99f746fe9dfcf58f082/src/index.ts#L208

hovorkap commented 5 years ago

Cool, maybe the variable switch deserves some polishing rather than NPE fix in shadows. Thanks for help