zyonse / homebridge-dreo

Apple HomeKit integration for Dreo Smart Devices
https://www.npmjs.com/package/homebridge-dreo
Apache License 2.0
38 stars 19 forks source link

Fix HomeBridge crash for fans with no shakehorizon state #20

Closed mganjoo closed 11 months ago

mganjoo commented 11 months ago

On a fan like DR-HAF003S, the plugin (git head) crashes HomeBridge on startup:

[10/10/2023, 7:33:04 PM] TypeError: Cannot read properties of undefined (reading 'state')
    at new FanAccessory (/homebridge/node_modules/homebridge-dreo/src/FanAccessory.ts:76:48)
    at DreoPlatform.discoverDevices (/homebridge/node_modules/homebridge-dreo/src/platform.ts:131:9)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

This is because the plugin tries to read the shakehorizon key, even when only hoscon exists.

This fix ensures we only read one or the other.

mganjoo commented 11 months ago

Hi @zyonse - does this look good to merge? I think this will also fix #16, oscillation then definitely works on DR-HAF003S.

zyonse commented 11 months ago

Good catch. This is definitely why my initial fix was causing issues.