DouweM / homebridge-unifi-occupancy

Homebridge plugin that adds HomeKit occupancy sensors for selected devices (and people) on your UniFi network to the iOS Home app: quickly see who's where and automate accordingly.
Apache License 2.0
42 stars 1 forks source link

Error : Unhandled rejection TypeError: Cannot read properties of undefined (reading 'updateCharacteristic') #16

Open nodecentral opened 1 year ago

nodecentral commented 1 year ago

Nothing visible that i can see, however I am still setting things up..

Unsure how to explain what it is, but have included the logs below..

It happens after a while, so it seems to be periodic,

Expected behavior:

No errors :-) ?

Logs:


[3/14/2023, 9:29:51 AM] [homebridge-unifi-occupancy] Updated accessory status: "Kitchen Guest: 26:42:xx:9b:ec:ii" active
[3/14/2023, 9:29:51 AM] [homebridge-unifi-occupancy] Updated accessory status: "Kitchen Joe" active
[3/14/2023, 10:22:37 AM] [homebridge-unifi-occupancy] Updated accessory status: "Kitchen Guest: 26:42:xx:9b:ec:ii" inactive
Unhandled rejection TypeError: Cannot read properties of undefined (reading 'updateCharacteristic')
    at ClientAccessoryHandler.update (/homebridge/node_modules/homebridge-unifi-occupancy/src/accessory_handler.ts:147:21)
    at UnifiOccupancyPlatform.updateAccessory (/homebridge/node_modules/homebridge-unifi-occupancy/src/platform.ts:323:29)
    at /homebridge/node_modules/homebridge-unifi-occupancy/src/platform.ts:301:16
    at Map.forEach (<anonymous>)
    at UnifiOccupancyPlatform.updateAccessories (/homebridge/node_modules/homebridge-unifi-occupancy/src/platform.ts:300:22)
    at /homebridge/node_modules/homebridge-unifi-occupancy/src/platform.ts:268:24
    at tryCatcher (/homebridge/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/homebridge/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/homebridge/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/homebridge/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/homebridge/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/promise.js:729:18)
    at _drainQueueStep (/homebridge/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/homebridge/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/homebridge/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/homebridge/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (node:internal/timers:471:21)

Plugin Config:

Screenshots:

Environment:

DouweM commented 1 year ago

Thanks for the report, I think this bug was introduced in my recent refactor. That's what I get for not having any tests 😅 I'll look into it later this week or this weekend!

DouweM commented 1 year ago

@nodecentral Can you turn on Debug logging in Homebridge (UI X) settings, and share the full logs the next time this happens again? I'd like to understand more clearly exactly what the properties are of the accessory that's being updated when this error occurs.

Z1mDMan commented 1 year ago

I'm seeing a similar issue. I will open a new issue report since the output is different. I have just enabled debug logging on my homebridge.

joecan00 commented 1 year ago

Was there ever a fix for this?

EnixCoda commented 1 year ago

The error seems caused due to lack of type definition in this function

https://github.com/DouweM/homebridge-unifi-occupancy/blob/cd96affa9e16b08a91e3d39bf95880fbaed1942f/src/platform.ts#L18-L29

Then in the constructor of a child class of AccessoryHandler arose.

I tried to add type definition

https://github.com/EnixCoda/homebridge-unifi-occupancy/blob/abe891065bf5c4bd247e0530e1caacbd4b9b0fa3/src/platform.ts#L18-L29

function ensure<K, V>(map: Map<K, V>, uuid: K, updater: (item: NonNullable<V>) => void, builder: () => V) {
  let item: V | null = map.get(uuid) || null;
  if (item) {
    updater(item);
  } else {
    item = builder();
    if (item) {
      map.set(uuid, item);
    }
  }
  return item;
}

but a type error arose from ensureAccessoryHandler method

image

I got stuck here because I'm not familiar with this repo. IMHO, I'd suggest the maintainer start from fixing the type errors

jondthompson commented 8 months ago

I'm still getting this error, or one like it..

Unhandled rejection TypeError: Cannot read properties of undefined (reading 'updateCharacteristic') at ClientAccessoryHandler.update (/usr/lib/node_modules/homebridge-unifi-occupancy/src/accessory_handler.ts:147:21) at UnifiOccupancyPlatform.updateAccessoryHandler (/usr/lib/node_modules/homebridge-unifi-occupancy/src/platform.ts:374:29) at /usr/lib/node_modules/homebridge-unifi-occupancy/src/platform.ts:362:12 at Map.forEach () at UnifiOccupancyPlatform.updateAccessories (/usr/lib/node_modules/homebridge-unifi-occupancy/src/platform.ts:360:22) at UnifiOccupancyPlatform.refreshAccessories (/usr/lib/node_modules/homebridge-unifi-occupancy/src/platform.ts:321:10) at /usr/lib/node_modules/homebridge-unifi-occupancy/src/platform.ts:284:24 at tryCatcher (/usr/lib/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/util.js:16:23) at Promise._settlePromiseFromHandler (/usr/lib/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/promise.js:547:31) at Promise._settlePromise (/usr/lib/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/promise.js:604:18) at Promise._settlePromise0 (/usr/lib/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/promise.js:649:10) at Promise._settlePromises (/usr/lib/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/promise.js:729:18) at _drainQueueStep (/usr/lib/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/async.js:93:12) at _drainQueue (/usr/lib/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/async.js:86:9) at Async._drainQueues (/usr/lib/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/async.js:102:5) at Immediate.Async.drainQueues [as _onImmediate] (/usr/lib/node_modules/homebridge-unifi-occupancy/node_modules/bluebird/js/release/async.js:15:14) at processImmediate (node:internal/timers:478:21)