rnilssoncx / homebridge-pico

Expose Lutron Pico Remotes in Homebridge: https://github.com/nfarina/homebridge
MIT License
63 stars 6 forks source link

index.js TypeError trying to iterate non-iterable object crashes homebridge while initializing on startup #13

Closed munskey closed 3 years ago

munskey commented 3 years ago

Pico plugin fails to initialize, generates SIGTERM error and crashes Homebridge.

How to Recreate: Install Pico plugin. Restart homebridge. Plugins initialize

Unexpected: Pico plugin initializing fails and generates homebridge crash with log "TypeError: config.servers is not iterable...PMcGot SIGTERM, shutting down Bridge..."

Expected Pico plugin initializes successfully

Log capture:

1/5/2021, 12:40:09 PM Loaded plugin '@balansse/homebridge-vivint'
1/5/2021, 12:40:09 PM [1/5/2021, 12:40:09 PM] Registering platform 'balansse/homebridge-vivint.Vivint'
1/5/2021, 12:40:09 PM [1/5/2021, 12:40:09 PM] The plugin "homebridge-myq" requires Node version of >=12.20.0 which does not satisfy the current Node version of v12.16.3. You may need to upgrade your installation of Node.
1/5/2021, 12:40:09 PM Loaded plugin 'homebridge-myq'
1/5/2021, 12:40:09 PM [1/5/2021, 12:40:09 PM] Registering platform 'homebridge-myq.myQ'
1/5/2021, 12:40:10 PM Loaded plugin 'homebridge-nest'
1/5/2021, 12:40:10 PM [1/5/2021, 12:40:10 PM] Registering platform 'homebridge-nest.Nest'
1/5/2021, 12:40:10 PM Loaded plugin 'homebridge-pico'
1/5/2021, 12:40:10 PM [1/5/2021, 12:40:10 PM] Registering platform 'homebridge-pico.Pico'
1/5/2021, 12:40:10 PM Loading 4 platforms...
1/5/2021, 12:40:10 PM [Vivint] Initializing Vivint platform...
1/5/2021, 12:40:10 PM [Nest] Initializing Nest platform...
1/5/2021, 12:40:10 PM [myQ] Initializing myQ platform...
1/5/2021, 12:40:10 PM [Pico] Initializing Pico platform...
1/5/2021, 12:40:10 PM [Pico] Pico Plugin Loaded - Version 1.0.2
1/5/2021, 12:40:10 PM [Pico] Bus Logging set to monitor
1/5/2021, 12:40:10 PM TypeError: config.servers is not iterable
    at new Pico (/home/hoobs/.hoobs/node_modules/homebridge-pico/index.js:39:31)
    at /usr/local/lib/node_modules/@hoobs/hoobs/bridge/server.js:346:30
    at Array.forEach (<anonymous>)
    at Server.loadPlatforms (/usr/local/lib/node_modules/@hoobs/hoobs/bridge/server.js:320:31)
    at Server.start (/usr/local/lib/node_modules/@hoobs/hoobs/bridge/server.js:152:35)
    at /usr/local/lib/node_modules/@hoobs/hoobs/bridge/cli.js:94:16
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
1/5/2021, 12:40:10 PMcGot SIGTERM, shutting down Bridge...

Environment__ Server: Raspberry Pi 4, 8GB

Homebridge: HOOBS v3.3.1 Node v12.16.3

Installed Plugins: Vivint 1.3.1 published 10/14/2020 myQ 2.4.1 published 1/1/2021 Nest 4.5.1 published 11/20/2020 Pico 1.0.2 published 12/22/2020

Thanks for the help and creating the plugin; excited to get my Lutron Pico keypads implemented!

rnilssoncx commented 3 years ago

Can you share your homebridge configuration? This is happening as the plugin is reading in your settings.

munskey commented 3 years ago

To help isolate the issue, I reset to factory defaults my Hoob install. No plugins, brand new installation. Then tried the below methods.

1) Installed Pico plugin, automatic homebridge reboot, SIGTERM, homebridge crash, log below.

1/10/2021, 7:42:57 PM Plugin "homebridge-pico" installed. 1/10/2021, 7:42:58 PM Got SIGINT, shutting down Bridge... 1/10/2021, 7:43:02 PM Loaded plugin 'homebridge-pico' 1/10/2021, 7:43:02 PM [1/10/2021, 7:43:02 PM] Registering platform 'homebridge-pico.Pico' 1/10/2021, 7:43:02 PM Loading 1 platforms... 1/10/2021, 7:43:02 PM [Pico] Initializing Pico platform... 1/10/2021, 7:43:02 PM [Pico] Pico Plugin Loaded - Version 1.0.2 1/10/2021, 7:43:02 PM [Pico] Bus Logging set to off 1/10/2021, 7:43:02 PM TypeError: config.servers is not iterable at new Pico (/home/hoobs/.hoobs/node_modules/homebridge-pico/index.js:39:31) at /usr/local/lib/node_modules/@hoobs/hoobs/bridge/server.js:346:30 at Array.forEach (<anonymous>) at Server.loadPlatforms (/usr/local/lib/node_modules/@hoobs/hoobs/bridge/server.js:320:31) at Server.start (/usr/local/lib/node_modules/@hoobs/hoobs/bridge/server.js:152:35) at /usr/local/lib/node_modules/@hoobs/hoobs/bridge/cli.js:94:16 at processTicksAndRejections (internal/process/task_queues.js:97:5)

*Note above is freshly installed, non-configured plugin (no host, port, switches).

2) Next, configured the plugin with server "host" and "port" settings, per the guide, reboot, SIGTERM, homebridge crash. "not iterable error..." [ { "host": "192.168.86.13", "port": 23, "switches": [] } ]

3) Final step, configured plugin with complete "switches" details, reboot, Pico plugin WORKS. [ { "host": "192.168.86.13", "port": 23, "switches": [ { "name": "Master Bedroom", "pico": 15, "type": "PJ2-2B" }, { "name": "Front Foyer", "pico": 16, "type": "PJ2-2B" }, { "name": "Living Room", "pico": 21, "type": "PJ2-4B-XXX-L31" } ] } ]

Other plugins I've installed don't crash homebridge when not fully configured. This led me down the path of incorrectly assuming that an incompatibility existed as the plugin crashed homebridge on initial install and crashed homebridge after configuring my host and port, so I did not pursue it further; "why setup a plugin that crashes on initial install?".

An improvement to the plugin design could be handling those exceptions gracefully (don't crash when they don't exist) or populating host, port and switches with filler/template data to mitigate the "not iterable error" and aid in the user populating/replacing the data in the config file.

Thank you for creating/enhancing such an immensely useful and underutilized plugin, been enjoying it since yesterday and your willingness to chase down my ticket is appreciated!

rnilssoncx commented 3 years ago

I'm glad this is now working for you!

When I do my next updates I'll look at making it more graceful when it isn't configured, or is partially configured.

munskey commented 3 years ago

Sounds good, thanks again for the immensely useful plugin. Closing the ticket.