Skip to content

Commit b28eef9

Browse files
committed
unifi-protect: squelch logging
1 parent f66d39f commit b28eef9

File tree

3 files changed

+43
-35
lines changed

3 files changed

+43
-35
lines changed

Diff for: plugins/unifi-protect/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: plugins/unifi-protect/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@scrypted/unifi-protect",
3-
"version": "0.0.141",
3+
"version": "0.0.142",
44
"description": "Unifi Protect Plugin for Scrypted",
55
"author": "Scrypted",
66
"license": "Apache",

Diff for: plugins/unifi-protect/src/main.ts

+40-32
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { UnifiLight } from "./light";
88
import { UnifiLock } from "./lock";
99
import { sleep } from "@scrypted/common/src/sleep";
1010
import axios from "axios";
11+
import { StorageSettings } from "@scrypted/sdk/storage-settings";
1112

1213
const { deviceManager } = sdk;
1314

@@ -72,7 +73,7 @@ export class UnifiProtect extends ScryptedDeviceBase implements Settings, Device
7273
for (const k of filter) {
7374
keys.delete(k);
7475
}
75-
if (keys.size > 0)
76+
if (keys.size > 0 && this.storageSettings.values.debugLog)
7677
ret?.console.log('update packet', packet.payload);
7778
return ret;
7879
}
@@ -228,7 +229,7 @@ export class UnifiProtect extends ScryptedDeviceBase implements Settings, Device
228229
};
229230

230231
debugLog(message: string, ...parameters: any[]) {
231-
if (this.storage.getItem('debug'))
232+
if (this.storageSettings.values.debugLog)
232233
this.console.log(message, ...parameters);
233234
}
234235

@@ -543,33 +544,42 @@ export class UnifiProtect extends ScryptedDeviceBase implements Settings, Device
543544
return this.storage.getItem(key);
544545
}
545546

547+
rediscover() {
548+
this.discoverDevices(0);
549+
this.updateManagementUrl();
550+
}
551+
552+
storageSettings = new StorageSettings(this, {
553+
username: {
554+
title: 'Username',
555+
onPut: () => this.rediscover(),
556+
},
557+
password: {
558+
title: 'Password',
559+
type: 'password',
560+
onPut: () => this.rediscover(),
561+
},
562+
ip: {
563+
title: 'Unifi Protect IP',
564+
placeholder: '192.168.1.100',
565+
onPut: () => this.rediscover(),
566+
},
567+
useConnectionHost: {
568+
title: 'Use Connection Host',
569+
group: 'Advanced',
570+
description: 'Uses the connection host to connect to the RTSP Stream. This is required in stacked UNVR configurations. Disabling this setting will always use the configured Unifi Protect IP as the RTSP stream IP.',
571+
type: 'boolean',
572+
},
573+
debugLog: {
574+
title: 'Debug Log',
575+
description: 'Enable debug log to see additional logging.',
576+
group: 'Advanced',
577+
type: 'boolean',
578+
},
579+
});
580+
546581
async getSettings(): Promise<Setting[]> {
547-
const ret: Setting[] = [
548-
{
549-
key: 'username',
550-
title: 'Username',
551-
value: this.getSetting('username') || '',
552-
},
553-
{
554-
key: 'password',
555-
title: 'Password',
556-
type: 'password',
557-
value: this.getSetting('password') || '',
558-
},
559-
{
560-
key: 'ip',
561-
title: 'Unifi Protect IP',
562-
placeholder: '192.168.1.100',
563-
value: this.getSetting('ip') || '',
564-
},
565-
{
566-
key: 'useConnectionHost',
567-
title: 'Use Connection Host',
568-
description: 'Uses the connection host to connect to the RTSP Stream. This is required in stacked UNVR configurations. Disabling this setting will always use the configured Unifi Protect IP as the RTSP stream IP.',
569-
type: 'boolean',
570-
value: this.getSetting('useConnectionHost') !== 'false',
571-
}
572-
];
582+
const ret = await this.storageSettings.getSettings();
573583

574584
if (!isInstanceableProviderModeEnabled()) {
575585
ret.push({
@@ -578,6 +588,7 @@ export class UnifiProtect extends ScryptedDeviceBase implements Settings, Device
578588
value: '',
579589
description: 'To add more than one Unifi Protect application, you will need to migrate the plugin to multi-application mode. Type "MIGRATE" in the textbox to confirm.',
580590
placeholder: 'MIGRATE',
591+
group: 'Advanced',
581592
});
582593
}
583594
return ret;
@@ -603,10 +614,7 @@ export class UnifiProtect extends ScryptedDeviceBase implements Settings, Device
603614
return;
604615
}
605616

606-
this.storage.setItem(key, value.toString());
607-
this.discoverDevices(0);
608-
609-
this.updateManagementUrl();
617+
return this.storageSettings.putSetting(key, value);
610618
}
611619
}
612620

0 commit comments

Comments
 (0)