ilcato / homebridge-Fibaro-HC2

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

"Cannot read property 'pollerperiod' of null" when plugin is not in use #165

Closed Krillle closed 4 years ago

Krillle commented 5 years ago

When starting Homebridge where Fibaro-HC2 plugin is installed but not in use (e.g. in a second instance on the same device, to not exceed the number of devices) Homebridge crashes with the exception "Cannot read property 'pollerperiod' of null":

Aug 10 01:37:12 Homebridge homebridge[21793]: Load homebridge-fibaro-hc2.FibaroHC2
Aug 10 01:37:12 Homebridge homebridge[21793]: /usr/lib/node_modules/homebridge-fibaro-hc2/dist/index.js:67
Aug 10 01:37:12 Homebridge homebridge[21793]:         let pollerPeriod = this.config.pollerperiod ? parseInt(this.config.pollerperiod) : defaultPollerPeriod;
Aug 10 01:37:12 Homebridge homebridge[21793]:                                        ^
Aug 10 01:37:12 Homebridge homebridge[21793]: TypeError: Cannot read property 'pollerperiod' of null
Aug 10 01:37:12 Homebridge homebridge[21793]:     at new FibaroHC2 (/usr/lib/node_modules/homebridge-fibaro-hc2/dist/index.js:67:40)
Aug 10 01:37:12 Homebridge homebridge[21793]:     at Server._loadDynamicPlatforms (/usr/lib/node_modules/homebridge/lib/server.js:346:30)
Aug 10 01:37:12 Homebridge homebridge[21793]:     at Server.run (/usr/lib/node_modules/homebridge/lib/server.js:87:8)
Aug 10 01:37:12 Homebridge homebridge[21793]:     at module.exports (/usr/lib/node_modules/homebridge/lib/cli.js:43:10)
Aug 10 01:37:12 Homebridge homebridge[21793]:     at Object.<anonymous> (/usr/lib/node_modules/homebridge/bin/homebridge:17:22)
Aug 10 01:37:12 Homebridge homebridge[21793]:     at Module._compile (module.js:652:30)
Aug 10 01:37:12 Homebridge homebridge[21793]:     at Object.Module._extensions..js (module.js:663:10)
Aug 10 01:37:12 Homebridge homebridge[21793]:     at Module.load (module.js:565:32)
Aug 10 01:37:12 Homebridge homebridge[21793]:     at tryModuleLoad (module.js:505:12)
Aug 10 01:37:12 Homebridge homebridge[21793]:     at Function.Module._load (module.js:497:3)
Aug 10 01:37:12 Homebridge homebridge[21793]:     at Function.Module.runMain (module.js:693:10)
Aug 10 01:37:12 Homebridge homebridge[21793]:     at startup (bootstrap_node.js:191:16)
Aug 10 01:37:12 Homebridge homebridge[21793]:     at bootstrap_node.js:612:3
Aug 10 01:37:12 Homebridge systemd[1]: homebridge-tesla.service: Main process exited, code=exited, status=1/FAILURE
Aug 

Plugin should abort when no parameters are found.

ilcato commented 5 years ago

@Krillle, this is normally a case in whiuch homebridge is not able to read the config.json file. Please be sure to have the file in the .homebridge directory of the user that launch the homebridge program or to specify the config.json location in the command line. Will add a control in the startup of the plugin in order to signal this misconfiguration.

Krillle commented 5 years ago

Yes, I know. And also in case there is no section for Fibaro defined. Means the plugin is installed, but no in use. This occurs for example if you have two instances of homebridge running on same raspberry pi. One fore Fibaro, in my case second instance for my Tesla.

Problem is here: let pollerPeriod = this.config.pollerperiod ? parseInt(this.config.pollerperiod) : defaultPollerPeriod; This crashes if no pollerPeriod is found in config file. https://github.com/ilcato/homebridge-Fibaro-HC2/blob/dd926384229b97a3518e421ec4407683e084d7ba/src/index.ts#L117

If no configuration section for Fibaro is found, the plugin should abort:

if (!(config)) { log ("No Fibaro configuration found"); return; }

ilcato commented 5 years ago

No @Krillle the error says that this.config is null, so homebridge was not able to instantiate a config object for the plugin. I will check this case and exit the constructor without crashing. Give me 15 minutes and try with the new version.

Krillle commented 5 years ago

I send a pull request with my proposal.

Krillle commented 5 years ago

this.config is null in a valid context, in case home bridge is started with the fibaro-hc2 plugin installed, while it is not in use. Means no section for fibaro plugin in config.json.

This is a valid scenario. The plugin should not crash homebridge then.

ilcato commented 5 years ago

please do

Krillle commented 5 years ago

You changed already. I would have done same way.

ilcato commented 5 years ago

Yes, but this create a TS compilation problem. Will fix it.

ilcato commented 5 years ago

@Krillle, can you try?

ilcato commented 5 years ago

@Krillle, were you able to test it?

Krillle commented 5 years ago

Thanks for coming back to it. Unfortuately i didn't find the time yet.

ilcato commented 4 years ago

@Krillle, any news?

ilcato commented 4 years ago

@Krillle, any chance to have this tested by you? It works for me. I will close the issue the next week.

Krillle commented 4 years ago

Yes it works for me now. Thank you for fixing. Btw I learned that the new parameter -x is doing the same thing.

ilcato commented 4 years ago

ok