jeffschubert / homebridge-daikin-oneplus

Homebridge plugin to control a Daikin One+ thermostat
Apache License 2.0
18 stars 7 forks source link

Exception during initialization if locations not retrieved #6

Closed jeffschubert closed 2 years ago

jeffschubert commented 2 years ago

Describe The Bug: If locations can't be retrieved from the api when initializing, an error is thrown later.

To Reproduce: Enter invalid credentials and the plug-in will fail to retrieve a token. Locations won't be retrieved and the error will be seen.

Expected behavior: The failure to get locations logged and initialization stopped appropriately.

Logs:

02/08/2021, 21:44:08] [Daikin One+] Error with token response: []
[02/08/2021, 21:44:08] [Daikin One+] { message: 'NotAuthorizedException' } []
[02/08/2021, 21:44:08] [Daikin One+] 400 []
[02/08/2021, 21:44:08] [Daikin One+] {
  'content-type': 'application/json',
  'content-length': '36',
  connection: 'close',
  date: 'Tue, 03 Aug 2021 04:44:08 GMT',
  'x-amzn-requestid': '<redacted>',
  'access-control-allow-origin': '*',
  'access-control-allow-headers': 'Content-Type,Authorization,X-Api-Key',
  'x-amz-apigw-id': '<redacted>',
  'access-control-allow-methods': 'DELETE,GET,OPTIONS,POST,PUT',
  'x-amzn-trace-id': 'Root=1-<redacted>;Sampled=0',
  'x-cache': 'Error from cloudfront',
  via: '1.1 a2f3f72865ff056225454005e6fdaae6.cloudfront.net (CloudFront)',
  'x-amz-cf-pop': 'LAX50-C3',
  'x-amz-cf-id': '<redacted>'
} []
[02/08/2021, 21:44:08] [Daikin One+] No token for request: https://api.daikinskyport.com/locations []
[02/08/2021, 21:44:08] [Daikin One+] No token for request: https://api.daikinskyport.com/devices []
[02/08/2021, 21:44:08] [Daikin One+] Unable to retrieve token. []
(node:4835) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
    at DaikinApi.Initialize (/usr/local/lib/node_modules/homebridge-daikin-oneplus/src/daikinapi.ts:47:59)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at DaikinOnePlusPlatform.discoverDevices (/usr/local/lib/node_modules/homebridge-daikin-oneplus/src/platform.ts:100:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:4835) 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:4835) [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.
jeffschubert commented 2 years ago

I think I've got this fixed locally. Testing some more before committing and closing.

jeffschubert commented 2 years ago

v1.0.4 just published detects and handles the case when the plugin can't connect to the Daikin API on start. It will now retry to connect to the api repeatedly (per the configured refresh interval) until it is successful.