sammy1881 / homebridge-sengled-bulbs

Homebridge plug-in for Sengled zigged bulbs
2 stars 4 forks source link

new version crashing homebridge v0.0.4 #8

Closed danhausman closed 2 years ago

danhausman commented 2 years ago

After upgrade, I have a crash on startup.

[12/3/2021, 7:09:25 AM] TypeError: Cannot read property 'colorTemperature' of undefined at Color.supportsColorTemperature (/usr/lib/node_modules/homebridge-sengled-bulbs/lib/color.js:95:48) at new Color (/usr/lib/node_modules/homebridge-sengled-bulbs/lib/color.js:78:12) at new SengledLightAccessory (/usr/lib/node_modules/homebridge-sengled-bulbs/index.js:213:16) at SengledHubPlatform.setService (/usr/lib/node_modules/homebridge-sengled-bulbs/index.js:196:9) at SengledHubPlatform.configureAccessory (/usr/lib/node_modules/homebridge-sengled-bulbs/index.js:52:31) at /usr/lib/node_modules/homebridge/src/bridgeService.ts:328:25 at Array.filter () at BridgeService.restoreCachedPlatformAccessories (/usr/lib/node_modules/homebridge/src/bridgeService.ts:288:69) at Server.start (/usr/lib/node_modules/homebridge/src/server.ts:171:24) [12/3/2021, 7:09:25 AM] Got SIGTERM, shutting down Homebridge...

More verbose logging:

[12/3/2021, 7:12:33 AM] [SengledHub] configureAccessory invoked [object Object] [12/3/2021, 7:12:33 AM] [SengledHub] configureAccessory: B0CE181400023E62 [12/3/2021, 7:12:33 AM] [SengledHub] setService invoked: [12/3/2021, 7:12:33 AM] [SengledHub] PlatformAccessory { _events: [Object: null prototype] {}, _eventsCount: 0, _maxListeners: undefined, services: [ AccessoryInformation { _events: [Object: null prototype], _eventsCount: 3, _maxListeners: undefined, iid: null, name: null, characteristics: [Array], optionalCharacteristics: [Array], isHiddenService: false, isPrimaryService: false, linkedServices: [], displayName: '', UUID: '0000003E-0000-1000-8000-0026BB765291', subtype: undefined,

},
Lightbulb {
  _events: [Object: null prototype],
  _eventsCount: 3,
  _maxListeners: undefined,
  iid: null,
  name: null,
  characteristics: [Array],
  optionalCharacteristics: [Array],
  isHiddenService: false,
  isPrimaryService: false,
  linkedServices: [],
  displayName: 'Hannah Bedroom Bulb 2',
  UUID: '00000043-0000-1000-8000-0026BB765291',
  subtype: undefined,
  [Symbol(kCapture)]: false
}

], reachable: true, context: { name: 'Hannah Bedroom Bulb 2', id: 'B0CE181400023E62', cb: null, status: '0', brightness: 20, colorTemperature: 20, manufacturer: 'Sengled', model: 'E11-N1EA' }, _associatedHAPAccessory: Accessory { _events: [Object: null prototype] { identify: [Function (anonymous)], 'characteristic-warning': [Function: bound printCharacteristicWriteWarning] }, _eventsCount: 2, _maxListeners: undefined, displayName: 'Hannah Bedroom Bulb 2', UUID: 'd03c93d5-b394-40fc-b5e6-dc7b71feb90c', aid: null, _isBridge: false, bridged: false, bridgedAccessories: [], reachable: true, category: 5, services: [ [AccessoryInformation], [Lightbulb] ], shouldPurgeUnusedIDs: true, initialized: false, controllers: {}, _setupID: null, controllerStorage: ControllerStorage { initialized: false, fileCreated: false, purgeUnidentifiedAccessoryData: true, trackedControllers: [], controllerData: {}, accessoryUUID: 'd03c93d5-b394-40fc-b5e6-dc7b71feb90c' }, lastAccessoriesRequest: 0, getPrimaryAccessory: [Function (anonymous)], disableUnusedIDPurge: [Function (anonymous)], enableUnusedIDPurge: [Function (anonymous)], purgeUnusedIDs: [Function (anonymous)], configurationChangeDebounceTimeout: Timeout { _idleTimeout: 1000, _idlePrev: [Timeout], _idleNext: [Timeout], _idleStart: 1766, _onTimeout: [Function (anonymous)], _timerArgs: undefined, _repeat: null, _destroyed: false,

  [Symbol(kHasPrimitive)]: false,
  [Symbol(asyncId)]: 21,
  [Symbol(triggerId)]: 0
},
lastKnownUsername: undefined,
[Symbol(kCapture)]: false

}, displayName: 'Hannah Bedroom Bulb 2', UUID: 'd03c93d5-b394-40fc-b5e6-dc7b71feb90c', category: 5, _associatedPlugin: 'homebridge-sengled-bulbs', _associatedPlatform: 'SengledHub',

} [12/3/2021, 7:12:34 AM] TypeError: Cannot read property 'colorTemperature' of undefined at Color.supportsColorTemperature (/usr/lib/node_modules/homebridge-sengled-bulbs/lib/color.js:95:48) at new Color (/usr/lib/node_modules/homebridge-sengled-bulbs/lib/color.js:78:12) at new SengledLightAccessory (/usr/lib/node_modules/homebridge-sengled-bulbs/index.js:213:16) at SengledHubPlatform.setService (/usr/lib/node_modules/homebridge-sengled-bulbs/index.js:196:9) at SengledHubPlatform.configureAccessory (/usr/lib/node_modules/homebridge-sengled-bulbs/index.js:52:31) at /usr/lib/node_modules/homebridge/src/bridgeService.ts:328:25 at Array.filter () at BridgeService.restoreCachedPlatformAccessories (/usr/lib/node_modules/homebridge/src/bridgeService.ts:288:69) at Server.start (/usr/lib/node_modules/homebridge/src/server.ts:171:24) [12/3/2021, 7:12:34 AM] Got SIGTERM, shutting down Homebridge...

sammy1881 commented 2 years ago

What version of homebridge are you running? Have you tried upgrading node and homebridge to the latest version?

danhausman commented 2 years ago

Node v14.18.2 Homebridge 1.3.8

Should I be on Node 16?

danhausman commented 2 years ago

Upgraded to Node v16.13.1 same issue.

RandyTidd commented 2 years ago

I'm new to homebridge, but my guess at the issue is that I changed the data stored in the .context to add members for color etc. The crashing stack provided is the path taken when restoring accessories from the homebridge cache. I think it makes sense that homebridge wouldn't clear this out on an upgrade, but I'm depending on the changes being there when I load from the cache. I think this wasn't an issue for me because I was constantly clearing this out to test the other parts of the code.

Do you have a lot of automations tied to the light through homekit? If I'm right, you should be able to go into homebridge settings on the homebridge UI, and click "Remove Single Cached Accessory" and clear out all your Sengled bulbs and restart homebridge. I think this will break any automations (like scenes or siri shortcuts) you have tied to the light though and also move them to your default room so you'd have to fix that up again, so let me know if this is an option for you.

I'll look at what a fix would take, but may be a few days. Sorry for the trouble.

danhausman commented 2 years ago

I cleared out the cache for all of my bulbs. Still crashing. I rolled back to 0.0.3 and that is failing now too. You think going from node 14 to node 16 is causing a problem?

[12/4/2021, 8:43:32 AM] Error: timeout of 2000ms exceeded at createError (/usr/lib/node_modules/homebridge-sengled-bulbs/node_modules/axios/lib/core/createError.js:16:15) at ClientRequest.handleRequestTimeout (/usr/lib/node_modules/homebridge-sengled-bulbs/node_modules/axios/lib/adapters/http.js:303:16) at Object.onceWrapper (node:events:509:28) at ClientRequest.emit (node:events:390:28) at TLSSocket.emitRequestTimeout (node:_http_client:763:9) at Object.onceWrapper (node:events:509:28) at TLSSocket.emit (node:events:402:35) at TLSSocket.Socket._onTimeout (node:net:501:8) at listOnTimeout (node:internal/timers:557:17) at processTimers (node:internal/timers:500:7) [12/4/2021, 8:43:32 AM] Got SIGTERM, shutting down Homebridge...

sammy1881 commented 2 years ago

So I’ve found in my testing that the downgrading to node14 and clearing the cache works!

danhausman commented 2 years ago

I rolled back to node 14.

Now I am seeing this error: (node:958) UnhandledPromiseRejectionWarning: Error: timeout of 2000ms exceeded at createError (/usr/lib/node_modules/homebridge-sengled-bulbs/node_modules/axios/lib/core/createError.js:16:15) at ClientRequest.handleRequestTimeout (/usr/lib/node_modules/homebridge-sengled-bulbs/node_modules/axios/lib/adapters/http.js:303:16) at Object.onceWrapper (events.js:519:28) at ClientRequest.emit (events.js:400:28) at TLSSocket.emitRequestTimeout (_http_client.js:790:9) at Object.onceWrapper (events.js:519:28) at TLSSocket.emit (events.js:412:35) at TLSSocket.Socket._onTimeout (net.js:495:8) at listOnTimeout (internal/timers.js:557:17) at processTimers (internal/timers.js:500:7) (Use node --trace-warnings ... to show where the warning was created) (node:958) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:958) [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.

RandyTidd commented 2 years ago

FWIW, I'm getting the same timeout error now. I added the missing .catch statement, and it's coming from the login request apparently:

[12/4/2021, 9:37:39 AM] [SengledHub] Error: timeout of 2000ms exceeded at createError (/home/randy/github/randy/homebridge-sengled-bulbs/node_modules/axios/lib/core/createError.js:16:15) at ClientRequest.handleRequestTimeout (/home/randy/github/randy/homebridge-sengled-bulbs/node_modules/axios/lib/adapters/http.js:303:16) at Object.onceWrapper (events.js:481:28) at ClientRequest.emit (events.js:375:28) at TLSSocket.emitRequestTimeout (_http_client.js:790:9) at Object.onceWrapper (events.js:481:28) at TLSSocket.emit (events.js:387:35) at TLSSocket.Socket._onTimeout (net.js:484:8) at listOnTimeout (internal/timers.js:557:17) at processTimers (internal/timers.js:500:7) { config: { url: 'https://us-elements.cloud.sengled.com/zigbee/customer/login.json', method: 'post', ...

RandyTidd commented 2 years ago

I think the login timeout issue is on the segnled side. I changed the login url to https://ucenter.cloud.sengled.com/user/app/customer/v2/AuthenCross.json, made the fixups to the data format, and upped the timeout from 2000 to 4000 and now I can get the plugin working again.

danhausman commented 2 years ago

Where did you make that change?

RandyTidd commented 2 years ago

@danhausman I pushed the branch with what I have, you can see the compare here:

https://github.com/sammy1881/homebridge-sengled-bulbs/compare/main...RandyTidd:FixContextState

Branch here:

https://github.com/RandyTidd/homebridge-sengled-bulbs/tree/FixContextState

I don't know if this is just a temporary problem with the current login or not. I've also commented out some state polling in GetPowerState as this was giving me frequent timeouts as well.

danhausman commented 2 years ago

@RandyTidd newbie question (sorry) how do I install your fork?

danhausman commented 2 years ago

@RandyTidd Nextime I will wait 10 seconds before I comment. I answered my own question with google. sudo npm install -g git+https://github.com/RandyTidd/homebridge-sengled-bulbs/tree/FixContextState

:) Confirmed working on my end now.

Does this get rolled back into sammy1881's project.

Also thank you both so much for doing this. This really solves some integration issues for me.

sammy1881 commented 2 years ago

It's weird because I'm not seeing any issue with the current endpoint, however do notice that it is way slower to respond. But if you guys are having better performance after moving to the other login URL, we can consider merging FixContextState PR to main.

sammy1881 commented 2 years ago

https://github.com/RandyTidd/homebridge-sengled-bulbs/tree/FixContextState doesn't work for me at all. I'm getting the following error: [05/12/2021, 09:47:44] ReferenceError: accessory is not defined at SengledLightAccessory.getInitState (/home/pi/Development/homebridge-sengled-bulbs/index.js:276:50) at new SengledLightAccessory (/home/pi/Development/homebridge-sengled-bulbs/index.js:267:8) at SengledHubPlatform.setService (/home/pi/Development/homebridge-sengled-bulbs/index.js:199:9) at SengledHubPlatform.configureAccessory (/home/pi/Development/homebridge-sengled-bulbs/index.js:52:31) at /usr/local/lib/node_modules/homebridge/src/bridgeService.ts:328:25 at Array.filter (<anonymous>) at BridgeService.restoreCachedPlatformAccessories (/usr/local/lib/node_modules/homebridge/src/bridgeService.ts:288:69) at Server.start (/usr/local/lib/node_modules/homebridge/src/server.ts:171:24)

However, just increasing the timeout to 4000 in my main branch works great. Can you give this branch a try? https://github.com/sammy1881/homebridge-sengled-bulbs/tree/feature/timeout

danhausman commented 2 years ago

just tried https://github.com/sammy1881/homebridge-sengled-bulbs/tree/feature/timeout and I can confirm it was working for me too.

RandyTidd commented 2 years ago

@danhausman I really didn't know. :) I know what I do to work on the plugin, which doesn't seem convenient for testing. This looks like a better way to go.

@sammy1881 This latest crash looks like a problem from my change in the debug logging which I'm guessing you have enabled. I'll update the branch for that.

I still get timeouts unfortunately with feature/timeout. I tried as high as 20,000 earlier and same issue. I think it's fine to go with that fix for now if it works for @danhausman. I can keep using the method in my branch to work on the context state issues.

[12/5/2021, 9:17:21 AM] [SengledHub] Failed to get power state [12/5/2021, 9:17:21 AM] [SengledHub] timeout of 4000ms exceeded

RandyTidd commented 2 years ago

@sammy1881 I've submitted a PR just to fix the logging issue. That seemed important to fix sooner since we may need the debug output for other things.

I've also updated the FixContextState branch to make using the alternate login URL and timeout values a config option. Let me know what you think.

RandyTidd commented 2 years ago

FixContextState latest commit prototype of the fix for the state issue reported in this issue. It defers the creation of the SengledLightAccessory until after the context data is up to date. Need to do some testing though.

sammy1881 commented 2 years ago

Hi @RandyTidd, sorry I was out for the holidays. Happy new year! I've just tested it and it looks good. I'll merge it! Thanks for all the awesome work and reviving the project.