From f26b6c3bcaedd1ee779486dd577f4aaf0d70a494 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Fri, 4 Oct 2024 17:23:59 -0700 Subject: [PATCH] unifi-protect: consider host when trying to find stable ids --- plugins/unifi-protect/package-lock.json | 4 ++-- plugins/unifi-protect/package.json | 2 +- plugins/unifi-protect/src/main.ts | 12 +++++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/plugins/unifi-protect/package-lock.json b/plugins/unifi-protect/package-lock.json index 424c704d7..dada894f9 100644 --- a/plugins/unifi-protect/package-lock.json +++ b/plugins/unifi-protect/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/unifi-protect", - "version": "0.0.155", + "version": "0.0.156", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/unifi-protect", - "version": "0.0.155", + "version": "0.0.156", "license": "Apache", "dependencies": { "@koush/unifi-protect": "file:../../external/unifi-protect", diff --git a/plugins/unifi-protect/package.json b/plugins/unifi-protect/package.json index 0ed2eb738..2ef5cd58a 100644 --- a/plugins/unifi-protect/package.json +++ b/plugins/unifi-protect/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/unifi-protect", - "version": "0.0.155", + "version": "0.0.156", "description": "Unifi Protect Plugin for Scrypted", "author": "Scrypted", "license": "Apache", diff --git a/plugins/unifi-protect/src/main.ts b/plugins/unifi-protect/src/main.ts index 25ed0ee42..cc8bae1b0 100644 --- a/plugins/unifi-protect/src/main.ts +++ b/plugins/unifi-protect/src/main.ts @@ -602,6 +602,7 @@ export class UnifiProtect extends ScryptedDeviceBase implements Settings, Device anonymousDeviceId: {}, id: {}, nativeId: {}, + host: {}, }, } }); @@ -611,14 +612,15 @@ export class UnifiProtect extends ScryptedDeviceBase implements Settings, Device return this.storageSettings.values.idMaps.nativeId?.[nativeId] || nativeId; } - getNativeId(device: { id?: string, mac?: string; anonymousDeviceId?: string }, update: boolean) { - const { id, mac, anonymousDeviceId } = device; + getNativeId(device: { id?: string, mac?: string; anonymousDeviceId?: string, host?: string }, update: boolean) { + const { id, mac, anonymousDeviceId,host } = device; const idMaps = this.storageSettings.values.idMaps; // try to find an existing nativeId given the mac and anonymous device id const found = (mac && idMaps.mac[mac]) || (anonymousDeviceId && idMaps.anonymousDeviceId[anonymousDeviceId]) || (id && idMaps.id[id]) + || (host && idMaps.host[host]) ; // use the found id if one exists (device got provisioned a new id), otherwise use the id provided by the device. @@ -627,7 +629,7 @@ export class UnifiProtect extends ScryptedDeviceBase implements Settings, Device if (!update) return nativeId; - // map the mac and anonymous device id to the native id. + // map the mac, host, and anonymous device id to the native id. if (mac) { idMaps.mac ||= {}; idMaps.mac[mac] = nativeId; @@ -636,6 +638,10 @@ export class UnifiProtect extends ScryptedDeviceBase implements Settings, Device idMaps.anonymousDeviceId ||= {}; idMaps.anonymousDeviceId[anonymousDeviceId] = nativeId; } + if (host) { + idMaps.host ||= {}; + idMaps.host[host] = nativeId; + } // map the id and native id to each other. idMaps.id ||= {};