derek-miller / homebridge-unifi-smartpower

Homebridge UniFi SmartPower Plugin
Apache License 2.0
7 stars 1 forks source link

Segfault when plugin loads #23

Closed jgstroud closed 1 year ago

jgstroud commented 1 year ago

Homebridge crashes whenever this plugin is enabled. I think its having issues with my USP-Plug.

Logs:

[1/25/2023, 10:36:51 PM] [UniFi SmartPower] Initializing UniFiSmartPower platform...
[1/25/2023, 10:36:51 PM] [UniFi SmartPower] Loading accessory from cache: US8P60
[1/25/2023, 10:36:56 PM] [UniFi SmartPower] Site [default]: Default
[1/25/2023, 10:36:57 PM] [UniFi SmartPower] Restoring existing accessory from cache: US8P60
[1/25/2023, 10:36:57 PM] [UniFi SmartPower] Device [7483C27C9EBB]: US8P60
[1/25/2023, 10:36:57 PM] [UniFi SmartPower] Port [7483C27C9EBB.5]: US8P60 > Port 5
[1/25/2023, 10:36:57 PM] [UniFi SmartPower] Port [7483C27C9EBB.6]: US8P60 > Port 6
[1/25/2023, 10:36:57 PM] [UniFi SmartPower] Port [7483C27C9EBB.7]: US8P60 > Port 7
[1/25/2023, 10:36:57 PM] [UniFi SmartPower] Port [7483C27C9EBB.8]: US8P60 > Port 8
[1/25/2023, 10:36:57 PM] AssertionError [ERR_ASSERTION]: Accessories must be created with a non-empty displayName.
    at new Accessory (/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:491:11)
    at new PlatformAccessory (/homebridge/node_modules/homebridge/src/platformAccessory.ts:71:9)
    at UniFiSmartPowerHomebridgePlatform.discoverDevices (/homebridge/node_modules/homebridge-unifi-smartpower/src/platform.ts:129:32)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at HomebridgeAPI.refreshDevices (/homebridge/node_modules/homebridge-unifi-smartpower/src/platform.ts:60:7)
[1/25/2023, 10:36:57 PM] Got SIGTERM, shutting down Homebridge...

Plugin Config:

       {
            "name": "UniFi SmartPower",
            "host": "192.168.10.1",
            "port": 443,
            "username": "x",
            "password": "x",
            "includeInactivePorts": true,
            "refreshDevicesPollInterval": 600,
            "outletStatusCacheTtl": 15,
            "outletStatusPollInterval": 15,
            "logApiResponses": false,
            "platform": "UniFiSmartPower"
        }

Screenshots:

Environment:

derek-miller commented 1 year ago

This should be resolved in v1.0.6. Please reopen if you still see the issue.

jgstroud commented 1 year ago

The patch works. I'm no typescript expert by any means. I looked at the code and thought the original code looked correct. I'm guessing that before it was seeing the name value was defined and using that even though it was just an empty string.

derek-miller commented 1 year ago

Yeah thats exactly correct. ?? will only take the right side if the left side is null or undefined. In your case I believe it was an empty string. || will take the right side if the left is "falsey" which an empty string is.