flochtililoch / homebridge-pivot-power-genius

 Homebridge plugin for the Wink Pivot Power Genius (former Quirky).
4 stars 2 forks source link

homebridge crashes on certain outlets #2

Closed entmike closed 7 years ago

entmike commented 7 years ago

I have two Power Pivot Genius strips. One will reliably turn on and off, the other will change state once to on or off, and then crash. Below is example from config.json:

{
    "platform": "Wink Pivot Power Genius",
    "name": "Wink Pivot Power Genius",
    "client_id": "quirky_wink_android_app",
    "client_secret": "e749124ad386a5a35c0ab554a4f2c045",
    "username": "myuser@email.com",
    "password": "mypassword",
    "outlets": [
      {
        "uuid": "6c3266c1-5acd-45e0-865f-70e425674625_0",
        "hapService": "Outlet",
        "name": "VSphere ESXi"
      },
      {
        "uuid": "6c3266c1-5acd-45e0-865f-70e425674625_1",
        "hapService": "Outlet",
        "name": "Desk Lamp"
      },
      {
        "uuid": "eb24b286-0c87-4697-94d7-51cfd2e558c8_0",
        "hapService": "Lightbulb",
        "name": "Light"
      },
      {
        "uuid": "eb24b286-0c87-4697-94d7-51cfd2e558c8_1",
        "hapService": "Lightbulb",
        "name": "Outlet 2"
      }
    ]
  }

The error in the command window is as follows after toggling the outlet:

C:\Users\Administrator\AppData\Roaming\npm\node_modules\homebridge\bin>homebridge
C:\Users\Administrator\AppData\Roaming\npm\node_modules\homebridge-pivot-power-genius\lib\accessory.js:65
        return done(undefined, outlet.powered);
                                     ^

TypeError: Cannot read property 'powered' of undefined
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\homebridge-pivot-power-genius\lib\accessory.js:65:38
    at remoteOutlet.update (C:\Users\Administrator\AppData\Roaming\npm\node_modules\homebridge-pivot-power-genius\lib\accessory.js:58:7)
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\homebridge-pivot-power-genius\node_modules\wink-js\index.js:384:8
    at IncomingMessage.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules\homebridge-pivot-power-genius\node_modules\wink-js\index.js:75:7)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

C:\Users\Administrator\AppData\Roaming\npm\node_modules\homebridge\bin>

It's probably user error on my part, but I'm at a loss. Both strips work fine from Wink app, but the iOS Home app will crash out homebridge on certain outlets.

Thanks for any help, and for writing this plugin!

entmike commented 7 years ago

I kinda monkey-patched it on line 65 of accessory.js and changed it to this for now:

return done(undefined, (outlet)?outlet.powered:null);

flochtililoch commented 7 years ago

Interesting, I only have one Power Pivot Genius strip so I actually haven't verified if this would work well with multiple strips (should work theoretically). Could you try logging the content of error on line 65 to see what's the actual Wink API error? It sounds like the error is due to a configured outlet not found.

entmike commented 7 years ago

I logged error and it always just comes back undefined. It would seem that there is "no error", however the outlet argument sometimes is also being passed null/undefined. Thus, I just kinda put some error checking there to not throw an exception and everything works as intended.

Also, I've added some small additional code enhancements that adds proper(ish) homebridge logging for the powerstrips, as well as changes to the state of each outlet. Would you be interested in me committing the changes for your review?

flochtililoch commented 7 years ago

Ok interesting, I was planning on getting a second strip soon so I can further verify what's going on. Please do open a pull request with your improvements, much appreciated!

entmike commented 7 years ago

Hm, I am trying to, but do you have to add me as a collaborator? I cannot seem to open a pull request.

EDIT: I think I figured it out. Ignore my ignorance with all things Github :)