jfarmer08 / homebridge-wyze-smart-home

Wyze Smart Home plugin for Homebridge.
MIT License
93 stars 14 forks source link

Unsupported Device in Cache Breaks Startup #202

Closed HewittJC closed 4 months ago

HewittJC commented 6 months ago

Describe The Bug: When the configureAccessory is called to check if accessories are setup already it can fail to do the unregisterPlatformAccessories call. This failure is typically handled gracefully by the try..catch but there is a typo in the catch block.

To Reproduce: I believe the issue stemmed from having a Wyze Lock Bolt on my account, it doesn't know how to handle this device for multiple reasons, but I mainly think because it has no MAC address.

Expected behavior:

Logs:

[12/23/2023, 3:39:25 PM] [Wyze] Launched child bridge with PID 1081
[12/23/2023, 3:39:25 PM] Registering platform 'homebridge-wyze-smart-home.WyzeSmartHome'
[12/23/2023, 3:39:25 PM] [Wyze] Loaded homebridge-wyze-smart-home v0.5.37-alpha.7 child bridge successfully
[12/23/2023, 3:39:25 PM] Loaded 77 cached accessories from cachedAccessories.0ED793A0892D.

/homebridge/node_modules/homebridge-wyze-smart-home/src/WyzeSmartHome.js:227
        this.log.error(`[${device.product_type}] Error removing accessory ${homeKitAccessory.context.nickname} (MAC: ${homeKitAccessory.context.mac}) : ${error}`)
                           ^
ReferenceError: device is not defined
    at WyzeSmartHome.configureAccessory (/homebridge/node_modules/homebridge-wyze-smart-home/src/WyzeSmartHome.js:227:28)
    at /homebridge/node_modules/homebridge/src/bridgeService.ts:328:25
    at Array.filter (<anonymous>)
    at BridgeService.restoreCachedPlatformAccessories (/homebridge/node_modules/homebridge/src/bridgeService.ts:288:69)
    at ChildBridgeFork.startBridge (/homebridge/node_modules/homebridge/src/childBridgeFork.ts:186:24)
[12/23/2023, 3:39:25 PM] [Wyze] Child bridge process ended
[12/23/2023, 3:39:25 PM] [Wyze] Process Ended. Code: 1, Signal: null

Plugin Config:

{
    "apiKey": "XXX",
    "password": "XXX",
    "username": "XXX@gmail.com",
    "excludeMacAddress": false,
    "refreshInterval": 60000,
    "keyId": "XXX",
    "name": "Wyze",
    "showAdvancedOptions": false,
    "mfaCode": "889141",
    "entryExitDelay": 30,
    "platform": "WyzeSmartHome",
    "_bridge": {
        "username": "XXX",
        "port": 55280
    }
}

Environment:


Fix:

This can be fixed by replacing the following line:

this.log.error(`[${device.product_type}] Error removing accessory ${homeKitAccessory.context.nickname} (MAC: ${homeKitAccessory.context.mac}) : ${error}`)

To:

this.log.error(`[${homeKitAccessory.product_type}] Error removing accessory ${homeKitAccessory.context.nickname} (MAC: ${homeKitAccessory.context.mac}) : ${error}`)

Notice the device --> homeKitAccessory change at the start of the .error()

github-actions[bot] commented 6 months ago

Message that will be displayed on users' first issue

carTloyal123 commented 4 months ago

@HewittJC feel free to submit this in a pull request if you have not already, would love the contribution!

carTloyal123 commented 4 months ago

Actually it looks like this is already fixed: https://github.com/jfarmer08/homebridge-wyze-smart-home/blob/6af83083f6ffbca90d6d008a65f957ae9c21df64/src/WyzeSmartHome.js#L228 #