bassrock / homebridge-flair

Homebridge Plugin for Flair Smart Vents
18 stars 6 forks source link

"Cannot read properties of null" resulting in accessories not responding #364

Open DanielSchaffer opened 1 year ago

DanielSchaffer commented 1 year ago

I just started running into this recently - I'd had the plugin running without problems for several weeks, and then the accessories would randomly start showing as "not responding" in the Home app. This would coincide with seeing this error in the Homebridge log:

/homebridge/node_modules/homebridge-flair/node_modules/follow-redirects/index.js:592
  const dot = subdomain.length - domain.length - 1;
                                        ^
TypeError: Cannot read properties of null (reading 'length')
    at isSubdomain (/homebridge/node_modules/homebridge-flair/node_modules/follow-redirects/index.js:592:41)
    at RedirectableRequest._processResponse (/homebridge/node_modules/homebridge-flair/node_modules/follow-redirects/index.js:427:7)
    at ClientRequest.RedirectableRequest._onNativeResponse (/homebridge/node_modules/homebridge-flair/node_modules/follow-redirects/index.js:57:10)
    at Object.onceWrapper (node:events:628:26)
    at ClientRequest.emit (node:events:513:28)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:693:27)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:117:17)
    at Socket.socketOnData (node:_http_client:534:22)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
[11/28/2022, 9:04:58 AM] [homebridge-flair] Child bridge process ended
[11/28/2022, 9:04:58 AM] [homebridge-flair] Process Ended. Code: 1, Signal: null
[11/28/2022, 9:05:05 AM] [homebridge-flair] Restarting Process...
[11/28/2022, 9:05:06 AM] [homebridge-flair] Launched child bridge with PID 37421
[11/28/2022, 9:05:06 AM] Registering platform 'homebridge-flair.Flair'
[11/28/2022, 9:05:06 AM] [homebridge-flair] Loaded homebridge-flair v1.3.5 child bridge successfully
[11/28/2022, 9:05:06 AM] Loaded 8 cached accessories from cachedAccessories.0ED7C5442EB6.
[11/28/2022, 9:05:06 AM] Homebridge v1.6.0 (HAP v0.11.0) (homebridge-flair) is running on port 31970.

The only thing that I've been able to figure out that allows the accessories to work again once this happens is to completely remove the them from Homekit and re-add them, which is not ideal since it seems to be a fairly regular thing now - re-adding only seems to work for around 24 hours.

Other things I've tried that do not work:

This "smells" like an authentication issue - perhaps the plugin is caching an access token that's recently started expiring after 24h? That's why I'd tried switching the credentials around, but maybe what I did wasn't enough to remove whatever is cached.

DanielSchaffer commented 1 year ago

This seems to be directly related to my Homebridge Docker container being re-created (e.g. docker compose down; docker compose up -d), though I can't tell if it's something about the Flair credentials not persisting, or something getting lost related to the child bridge pairing. When this happens, I have to remove the child bridge from Homekit, then re-add it, and it works fine until the next time I have to recreate the container.