unifi-protect: consider host when trying to find stable ids

This commit is contained in:
Koushik Dutta
2024-10-04 17:23:59 -07:00
parent d38abcd563
commit f26b6c3bca
3 changed files with 12 additions and 6 deletions

View File

@@ -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",

View File

@@ -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",

View File

@@ -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 ||= {};