homebridge-unifi-protect 6.22.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -29
- package/config.schema.json +5 -15
- package/dist/devices/protect-camera-package.d.ts +0 -2
- package/dist/devices/protect-camera-package.js +4 -12
- package/dist/devices/protect-camera-package.js.map +1 -1
- package/dist/devices/protect-camera.d.ts +0 -3
- package/dist/devices/protect-camera.js +21 -119
- package/dist/devices/protect-camera.js.map +1 -1
- package/dist/devices/protect-chime.js +2 -6
- package/dist/devices/protect-chime.js.map +1 -1
- package/dist/devices/protect-device.d.ts +9 -5
- package/dist/devices/protect-device.js +17 -20
- package/dist/devices/protect-device.js.map +1 -1
- package/dist/devices/protect-doorbell.d.ts +0 -2
- package/dist/devices/protect-doorbell.js +39 -58
- package/dist/devices/protect-doorbell.js.map +1 -1
- package/dist/devices/protect-light.js +1 -3
- package/dist/devices/protect-light.js.map +1 -1
- package/dist/devices/protect-liveviews.js +2 -1
- package/dist/devices/protect-liveviews.js.map +1 -1
- package/dist/devices/protect-nvr-systeminfo.js +1 -1
- package/dist/devices/protect-nvr-systeminfo.js.map +1 -1
- package/dist/devices/protect-securitysystem.js +4 -4
- package/dist/devices/protect-securitysystem.js.map +1 -1
- package/dist/devices/protect-sensor.js +2 -6
- package/dist/devices/protect-sensor.js.map +1 -1
- package/dist/ffmpeg/protect-ffmpeg-codecs.js.map +1 -1
- package/dist/ffmpeg/protect-ffmpeg-exec.js.map +1 -1
- package/dist/ffmpeg/protect-ffmpeg-options.js +2 -20
- package/dist/ffmpeg/protect-ffmpeg-options.js.map +1 -1
- package/dist/ffmpeg/protect-ffmpeg-record.js +2 -1
- package/dist/ffmpeg/protect-ffmpeg-record.js.map +1 -1
- package/dist/ffmpeg/protect-ffmpeg-stream.js +14 -8
- package/dist/ffmpeg/protect-ffmpeg-stream.js.map +1 -1
- package/dist/ffmpeg/protect-ffmpeg.d.ts +2 -2
- package/dist/ffmpeg/protect-ffmpeg.js.map +1 -1
- package/dist/protect-events.d.ts +1 -1
- package/dist/protect-events.js +36 -33
- package/dist/protect-events.js.map +1 -1
- package/dist/protect-nvr.d.ts +7 -11
- package/dist/protect-nvr.js +14 -60
- package/dist/protect-nvr.js.map +1 -1
- package/dist/protect-options.d.ts +8 -23
- package/dist/protect-options.js +4 -128
- package/dist/protect-options.js.map +1 -1
- package/dist/protect-platform.d.ts +2 -4
- package/dist/protect-platform.js +3 -28
- package/dist/protect-platform.js.map +1 -1
- package/dist/protect-record.d.ts +2 -1
- package/dist/protect-record.js +21 -27
- package/dist/protect-record.js.map +1 -1
- package/dist/protect-snapshot.d.ts +2 -2
- package/dist/protect-snapshot.js +7 -3
- package/dist/protect-snapshot.js.map +1 -1
- package/dist/protect-stream.d.ts +3 -3
- package/dist/protect-stream.js +87 -90
- package/dist/protect-stream.js.map +1 -1
- package/dist/protect-timeshift.d.ts +9 -3
- package/dist/protect-timeshift.js +76 -24
- package/dist/protect-timeshift.js.map +1 -1
- package/dist/protect-types.d.ts +0 -7
- package/dist/protect-types.js +0 -1
- package/dist/protect-types.js.map +1 -1
- package/dist/settings.d.ts +2 -1
- package/dist/settings.js +4 -2
- package/dist/settings.js.map +1 -1
- package/homebridge-ui/public/index.html +42 -21
- package/homebridge-ui/public/lib/featureoptions.js +376 -0
- package/homebridge-ui/public/lib/featureoptions.js.map +1 -0
- package/homebridge-ui/public/lib/webUi-featureoptions.mjs +836 -0
- package/homebridge-ui/public/lib/webUi.mjs +184 -0
- package/homebridge-ui/public/ui.mjs +208 -124
- package/homebridge-ui/server.js +13 -39
- package/package.json +22 -21
- package/dist/protect-mqtt.d.ts +0 -20
- package/dist/protect-mqtt.js +0 -177
- package/dist/protect-mqtt.js.map +0 -1
- package/dist/protect-rtp.d.ts +0 -26
- package/dist/protect-rtp.js +0 -180
- package/dist/protect-rtp.js.map +0 -1
- package/homebridge-ui/public/lib/featureoptions.mjs +0 -201
- package/homebridge-ui/public/protect-featureoptions.mjs +0 -736
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/* Copyright(C) 2017-2024, HJD (https://github.com/hjdhjd). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* webUi.mjs: Plugin webUI.
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
import { webUiFeatureOptions } from "./webUi-featureoptions.mjs";
|
|
8
|
+
|
|
9
|
+
export class webUi {
|
|
10
|
+
|
|
11
|
+
// Feature options class instance.
|
|
12
|
+
featureOptions;
|
|
13
|
+
|
|
14
|
+
// First run webUI callback endpoints for customization.
|
|
15
|
+
#firstRun;
|
|
16
|
+
|
|
17
|
+
// Plugin name.
|
|
18
|
+
#name;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* featureOptions - parameters to webUiFeatureOptions.
|
|
22
|
+
* firstRun - first run handlers:
|
|
23
|
+
* isRequired - do we need to run the first run UI workflow?
|
|
24
|
+
* onStart - initialization for the first run webUI to populate forms and other startup tasks.
|
|
25
|
+
* onSubmit - execute the first run workflow, typically a login or configuration validation of some sort.
|
|
26
|
+
* name - plugin name.
|
|
27
|
+
*/
|
|
28
|
+
constructor({ featureOptions, firstRun = {}, name } = {}) {
|
|
29
|
+
|
|
30
|
+
// Defaults for our first run handlers.
|
|
31
|
+
this.firstRun = { isRequired: () => false, onStart: () => true, onSubmit: () => true };
|
|
32
|
+
|
|
33
|
+
// Figure out the options passed in to us.
|
|
34
|
+
this.featureOptions = new webUiFeatureOptions(featureOptions);
|
|
35
|
+
this.firstRun = Object.assign({}, this.firstRun, firstRun);
|
|
36
|
+
this.name = name;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Render the webUI.
|
|
41
|
+
*/
|
|
42
|
+
// Render the UI.
|
|
43
|
+
show() {
|
|
44
|
+
|
|
45
|
+
// Fire off our UI, catching errors along the way.
|
|
46
|
+
try {
|
|
47
|
+
|
|
48
|
+
this.#launchWebUI();
|
|
49
|
+
} catch(err) {
|
|
50
|
+
|
|
51
|
+
// If we had an error instantiating or updating the UI, notify the user.
|
|
52
|
+
homebridge.toast.error(err.message, "Error");
|
|
53
|
+
} finally {
|
|
54
|
+
|
|
55
|
+
// Always leave the UI in a usable place for the end user.
|
|
56
|
+
homebridge.hideSpinner();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Show the first run user experience if we don't have valid login credentials.
|
|
61
|
+
async #showFirstRun() {
|
|
62
|
+
|
|
63
|
+
const buttonFirstRun = document.getElementById("firstRun");
|
|
64
|
+
|
|
65
|
+
// Run a custom initialization handler the user may have provided.
|
|
66
|
+
if(!(await this.#processHandler(this.firstRun.onStart))) {
|
|
67
|
+
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// First run user experience.
|
|
72
|
+
buttonFirstRun.addEventListener("click", async () => {
|
|
73
|
+
|
|
74
|
+
// Show the beachball while we setup.
|
|
75
|
+
homebridge.showSpinner();
|
|
76
|
+
|
|
77
|
+
// Run a custom submit handler the user may have provided.
|
|
78
|
+
if(!(await this.#processHandler(this.firstRun.onSubmit))) {
|
|
79
|
+
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Create our UI.
|
|
84
|
+
document.getElementById("pageFirstRun").style.display = "none";
|
|
85
|
+
document.getElementById("menuWrapper").style.display = "inline-flex";
|
|
86
|
+
this.featureOptions.show();
|
|
87
|
+
|
|
88
|
+
// All done. Let the user interact with us, although in practice, we shouldn't get here.
|
|
89
|
+
// homebridge.hideSpinner();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
document.getElementById("pageFirstRun").style.display = "block";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Show the main plugin configuration tab.
|
|
96
|
+
#showSettings() {
|
|
97
|
+
|
|
98
|
+
// Show the beachball while we setup.
|
|
99
|
+
homebridge.showSpinner();
|
|
100
|
+
|
|
101
|
+
// Highlight the tab in our UI.
|
|
102
|
+
this.#toggleClasses("menuHome", "btn-elegant", "btn-primary");
|
|
103
|
+
this.#toggleClasses("menuFeatureOptions", "btn-elegant", "btn-primary");
|
|
104
|
+
this.#toggleClasses("menuSettings", "btn-primary", "btn-elegant");
|
|
105
|
+
|
|
106
|
+
document.getElementById("pageSupport").style.display = "none";
|
|
107
|
+
document.getElementById("pageFeatureOptions").style.display = "none";
|
|
108
|
+
|
|
109
|
+
homebridge.showSchemaForm();
|
|
110
|
+
|
|
111
|
+
// All done. Let the user interact with us.
|
|
112
|
+
homebridge.hideSpinner();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Show the support tab.
|
|
116
|
+
#showSupport() {
|
|
117
|
+
|
|
118
|
+
// Show the beachball while we setup.
|
|
119
|
+
homebridge.showSpinner();
|
|
120
|
+
homebridge.hideSchemaForm();
|
|
121
|
+
|
|
122
|
+
// Highlight the tab in our UI.
|
|
123
|
+
this.#toggleClasses("menuHome", "btn-primary", "btn-elegant");
|
|
124
|
+
this.#toggleClasses("menuFeatureOptions", "btn-elegant", "btn-primary");
|
|
125
|
+
this.#toggleClasses("menuSettings", "btn-elegant", "btn-primary");
|
|
126
|
+
|
|
127
|
+
document.getElementById("pageSupport").style.display = "block";
|
|
128
|
+
document.getElementById("pageFeatureOptions").style.display = "none";
|
|
129
|
+
|
|
130
|
+
// All done. Let the user interact with us.
|
|
131
|
+
homebridge.hideSpinner();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Launch our webUI.
|
|
135
|
+
async #launchWebUI() {
|
|
136
|
+
|
|
137
|
+
// Retrieve the current plugin configuration.
|
|
138
|
+
this.featureOptions.currentConfig = await homebridge.getPluginConfig();
|
|
139
|
+
|
|
140
|
+
// Add our event listeners to animate the UI.
|
|
141
|
+
document.getElementById("menuHome").addEventListener("click", () => this.#showSupport());
|
|
142
|
+
document.getElementById("menuFeatureOptions").addEventListener("click", () => this.featureOptions.show());
|
|
143
|
+
document.getElementById("menuSettings").addEventListener("click", () => this.#showSettings());
|
|
144
|
+
|
|
145
|
+
// Get the list of devices the plugin knows about.
|
|
146
|
+
const devices = await homebridge.getCachedAccessories();
|
|
147
|
+
|
|
148
|
+
// If we've got devices detected, we launch our feature option UI. Otherwise, we launch our first run UI.
|
|
149
|
+
if(this.featureOptions.currentConfig.length && devices?.length && !(await this.#processHandler(this.firstRun.isRequired))) {
|
|
150
|
+
|
|
151
|
+
document.getElementById("menuWrapper").style.display = "inline-flex";
|
|
152
|
+
this.featureOptions.show();
|
|
153
|
+
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// If we have the name property set for the plugin configuration yet, let's do so now. If we don't have a configuration, let's initialize it as well.
|
|
158
|
+
(this.featureOptions.currentConfig[0] ??= { name: this.name }).name ??= this.name;
|
|
159
|
+
|
|
160
|
+
// Update the plugin configuration and launch the first run UI.
|
|
161
|
+
await homebridge.updatePluginConfig(this.featureOptions.currentConfig);
|
|
162
|
+
this.#showFirstRun();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Utility to process user-provided custom handlers that can handle both synchronous and asynchronous handlers.
|
|
166
|
+
async #processHandler(handler) {
|
|
167
|
+
|
|
168
|
+
if(((typeof handler === "function") && !(await handler())) || ((typeof handler !== "function") && !handler)) {
|
|
169
|
+
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Utility to toggle our classes.
|
|
177
|
+
#toggleClasses(id, removeClass, addClass) {
|
|
178
|
+
|
|
179
|
+
const element = document.getElementById(id);
|
|
180
|
+
|
|
181
|
+
element.classList.remove(removeClass);
|
|
182
|
+
element.classList.add(addClass);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -1,182 +1,266 @@
|
|
|
1
1
|
/* Copyright(C) 2017-2024, HJD (https://github.com/hjdhjd). All rights reserved.
|
|
2
2
|
*
|
|
3
|
-
* ui.mjs:
|
|
3
|
+
* ui.mjs: Homebridge UniFi Protect webUI.
|
|
4
4
|
*/
|
|
5
|
+
|
|
5
6
|
"use strict";
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
import { webUi } from "./lib/webUi.mjs";
|
|
9
|
+
|
|
10
|
+
// Execute our first run screen if we don't have valid Protect login credentials and a controller.
|
|
11
|
+
const firstRunIsRequired = () => {
|
|
12
|
+
|
|
13
|
+
if(ui.featureOptions.currentConfig.length && ui.featureOptions.currentConfig[0].controllers?.length &&
|
|
14
|
+
ui.featureOptions.currentConfig[0].controllers[0]?.address?.length && ui.featureOptions.currentConfig[0].controllers[0]?.username?.length &&
|
|
15
|
+
ui.featureOptions.currentConfig[0].controllers[0]?.password?.length) {
|
|
16
|
+
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Initialize our first run screen with any information from our existing configuration.
|
|
24
|
+
const firstRunOnStart = () => {
|
|
25
|
+
|
|
26
|
+
// Pre-populate with anything we might already have in our configuration.
|
|
27
|
+
document.getElementById("address").value = ui.featureOptions.currentConfig[0].controllers[0].address ?? "";
|
|
28
|
+
document.getElementById("username").value = ui.featureOptions.currentConfig[0].controllers[0].username ?? "";
|
|
29
|
+
document.getElementById("password").value = ui.featureOptions.currentConfig[0].controllers[0].password ?? "";
|
|
30
|
+
|
|
31
|
+
return true;
|
|
32
|
+
};
|
|
9
33
|
|
|
10
|
-
//
|
|
11
|
-
|
|
34
|
+
// Validate our Protect credentials.
|
|
35
|
+
const firstRunOnSubmit = async () => {
|
|
12
36
|
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const inputPassword = document.getElementById("password");
|
|
37
|
+
const address = document.getElementById("address").value;
|
|
38
|
+
const username = document.getElementById("username").value;
|
|
39
|
+
const password = document.getElementById("password").value;
|
|
17
40
|
const tdLoginError = document.getElementById("loginError");
|
|
18
41
|
|
|
19
|
-
|
|
20
|
-
if(!featureOptions.currentConfig[0].controllers) {
|
|
42
|
+
tdLoginError.innerHTML = " ";
|
|
21
43
|
|
|
22
|
-
|
|
44
|
+
if(!address?.length || !username?.length || !password?.length) {
|
|
45
|
+
|
|
46
|
+
tdLoginError.innerHTML = "<code class=\"text-danger\">Please enter a valid UniFi Protect controller address, username and password.</code>";
|
|
47
|
+
homebridge.hideSpinner();
|
|
48
|
+
|
|
49
|
+
return false;
|
|
23
50
|
}
|
|
24
51
|
|
|
25
|
-
|
|
26
|
-
inputAddress.value = featureOptions.currentConfig[0].controllers[0].address ?? "";
|
|
27
|
-
inputUsername.value = featureOptions.currentConfig[0].controllers[0].username ?? "";
|
|
28
|
-
inputPassword.value = featureOptions.currentConfig[0].controllers[0].password ?? "";
|
|
52
|
+
const ufpDevices = await homebridge.request("/getDevices", { address: address, username: username, password: password });
|
|
29
53
|
|
|
30
|
-
//
|
|
31
|
-
|
|
54
|
+
// Couldn't connect to the Protect controller for some reason.
|
|
55
|
+
if(!ufpDevices?.length) {
|
|
32
56
|
|
|
33
|
-
tdLoginError.innerHTML = "
|
|
34
|
-
|
|
57
|
+
tdLoginError.innerHTML = "Unable to login to the UniFi Protect controller.<br>Please check your controller address, username, and password.<br><code class=\"text-danger\">" + (await homebridge.request("/getErrorMessage")) + "</code>";
|
|
58
|
+
homebridge.hideSpinner();
|
|
35
59
|
|
|
36
|
-
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
37
62
|
|
|
38
|
-
|
|
39
|
-
|
|
63
|
+
// Save the login credentials to our configuration.
|
|
64
|
+
ui.featureOptions.currentConfig[0].controllers[0].address = address;
|
|
65
|
+
ui.featureOptions.currentConfig[0].controllers[0].username = username;
|
|
66
|
+
ui.featureOptions.currentConfig[0].controllers[0].password = password;
|
|
40
67
|
|
|
41
|
-
|
|
68
|
+
await homebridge.updatePluginConfig(ui.featureOptions.currentConfig);
|
|
42
69
|
|
|
43
|
-
|
|
44
|
-
|
|
70
|
+
return true;
|
|
71
|
+
};
|
|
45
72
|
|
|
46
|
-
|
|
47
|
-
|
|
73
|
+
// Return the list of devices associated with a given Protect controller.
|
|
74
|
+
const getDevices = async (controller) => {
|
|
48
75
|
|
|
49
|
-
|
|
50
|
-
|
|
76
|
+
// If we're in the global context, we have no devices.
|
|
77
|
+
if(!controller) {
|
|
51
78
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const password = inputPassword.value;
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
55
81
|
|
|
56
|
-
|
|
82
|
+
// Retrieve the current list of devices from the Protect controller.
|
|
83
|
+
let devices = await homebridge.request("/getDevices", { address: controller.address, username: controller.username, password: controller.password });
|
|
57
84
|
|
|
58
|
-
|
|
85
|
+
// Add the fields that the webUI framework is looking for to render.
|
|
86
|
+
devices = devices.map(device => ({
|
|
59
87
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
88
|
+
...device,
|
|
89
|
+
serial: device.mac
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
return devices;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Return whether a given device is a controller.
|
|
96
|
+
const isController = (device) => device.modelKey === "nvr";
|
|
97
|
+
|
|
98
|
+
// Show the list of Protect devices associated with a controller, grouped by model.
|
|
99
|
+
const showSidebarDevices = (controller, devices) => {
|
|
100
|
+
|
|
101
|
+
const modelKeys = [...new Set(devices.map(x => x.modelKey))];
|
|
102
|
+
|
|
103
|
+
// Start with a clean slate.
|
|
104
|
+
ui.featureOptions.devicesTable.innerHTML = "";
|
|
64
105
|
|
|
65
|
-
|
|
106
|
+
for(const key of modelKeys) {
|
|
66
107
|
|
|
67
|
-
//
|
|
68
|
-
|
|
108
|
+
// Get all the devices associated with this device category.
|
|
109
|
+
const modelDevices = devices.filter(x => x.modelKey === key);
|
|
69
110
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
111
|
+
// If it's a controller, we handle that case differently.
|
|
112
|
+
if((key === "nvr") && modelDevices.length) {
|
|
113
|
+
|
|
114
|
+
// Change the name of the controller that we show users once we've connected with the controller.
|
|
115
|
+
ui.featureOptions.webUiControllerList.map(x => (x.name === controller.address) ? x.childNodes[0].nodeValue = modelDevices[0].name : true);
|
|
116
|
+
|
|
117
|
+
continue;
|
|
73
118
|
}
|
|
74
119
|
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
featureOptions.currentConfig[0].controllers[0].username = username;
|
|
78
|
-
featureOptions.currentConfig[0].controllers[0].password = password;
|
|
120
|
+
// Create a row for this device category.
|
|
121
|
+
const trCategory = document.createElement("tr");
|
|
79
122
|
|
|
80
|
-
|
|
123
|
+
// Disable any pointer events and hover activity.
|
|
124
|
+
trCategory.style.pointerEvents = "none";
|
|
81
125
|
|
|
82
|
-
// Create our
|
|
83
|
-
document.
|
|
84
|
-
document.getElementById("menuWrapper").style.display = "inline-flex";
|
|
85
|
-
featureOptions.showUI();
|
|
86
|
-
});
|
|
126
|
+
// Create the cell for our device category row.
|
|
127
|
+
const tdCategory = document.createElement("td");
|
|
87
128
|
|
|
88
|
-
|
|
89
|
-
}
|
|
129
|
+
tdCategory.classList.add("m-0", "p-0", "pl-1", "w-100");
|
|
90
130
|
|
|
91
|
-
//
|
|
92
|
-
|
|
131
|
+
// Add the category name, with appropriate casing.
|
|
132
|
+
tdCategory.appendChild(document.createTextNode((key.charAt(0).toUpperCase() + key.slice(1) + "s")));
|
|
133
|
+
tdCategory.style.fontWeight = "bold";
|
|
93
134
|
|
|
94
|
-
|
|
95
|
-
|
|
135
|
+
// Add the cell to the table row.
|
|
136
|
+
trCategory.appendChild(tdCategory);
|
|
96
137
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
document.getElementById("menuHome").classList.add("btn-primary");
|
|
100
|
-
document.getElementById("menuFeatureOptions").classList.remove("btn-elegant");
|
|
101
|
-
document.getElementById("menuFeatureOptions").classList.add("btn-primary");
|
|
102
|
-
document.getElementById("menuSettings").classList.add("btn-elegant");
|
|
103
|
-
document.getElementById("menuSettings").classList.remove("btn-primary");
|
|
138
|
+
// Add the table row to the table.
|
|
139
|
+
ui.featureOptions.devicesTable.appendChild(trCategory);
|
|
104
140
|
|
|
105
|
-
|
|
106
|
-
document.getElementById("pageFeatureOptions").style.display = "none";
|
|
141
|
+
for(const device of modelDevices) {
|
|
107
142
|
|
|
108
|
-
|
|
143
|
+
// Create a row for this device.
|
|
144
|
+
const trDevice = document.createElement("tr");
|
|
109
145
|
|
|
110
|
-
|
|
111
|
-
homebridge.hideSpinner();
|
|
112
|
-
}
|
|
146
|
+
trDevice.classList.add("m-0", "p-0");
|
|
113
147
|
|
|
114
|
-
//
|
|
115
|
-
|
|
148
|
+
// Create a cell for our device.
|
|
149
|
+
const tdDevice = document.createElement("td");
|
|
116
150
|
|
|
117
|
-
|
|
118
|
-
homebridge.showSpinner();
|
|
119
|
-
homebridge.hideSchemaForm();
|
|
151
|
+
tdDevice.classList.add("m-0", "p-0" , "w-100");
|
|
120
152
|
|
|
121
|
-
|
|
122
|
-
document.getElementById("menuHome").classList.add("btn-elegant");
|
|
123
|
-
document.getElementById("menuHome").classList.remove("btn-primary");
|
|
124
|
-
document.getElementById("menuFeatureOptions").classList.remove("btn-elegant");
|
|
125
|
-
document.getElementById("menuFeatureOptions").classList.add("btn-primary");
|
|
126
|
-
document.getElementById("menuSettings").classList.remove("btn-elegant");
|
|
127
|
-
document.getElementById("menuSettings").classList.add("btn-primary");
|
|
153
|
+
const label = document.createElement("label");
|
|
128
154
|
|
|
129
|
-
|
|
130
|
-
|
|
155
|
+
label.name = device.serial;
|
|
156
|
+
label.appendChild(document.createTextNode(device.name ?? device.marketName));
|
|
157
|
+
label.style.cursor = "pointer";
|
|
158
|
+
label.classList.add("mx-2", "my-0", "p-0", "w-100");
|
|
131
159
|
|
|
132
|
-
|
|
133
|
-
homebridge.hideSpinner();
|
|
134
|
-
}
|
|
160
|
+
label.addEventListener("click", () => ui.featureOptions.showDeviceOptions(device.serial));
|
|
135
161
|
|
|
136
|
-
//
|
|
137
|
-
|
|
162
|
+
// Add the device label to our cell.
|
|
163
|
+
tdDevice.appendChild(label);
|
|
138
164
|
|
|
139
|
-
|
|
140
|
-
|
|
165
|
+
// Add the cell to the table row.
|
|
166
|
+
trDevice.appendChild(tdDevice);
|
|
141
167
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
menuFeatureOptions.addEventListener("click", () => featureOptions.showUI());
|
|
145
|
-
menuSettings.addEventListener("click", () => showSettings());
|
|
168
|
+
// Add the table row to the table.
|
|
169
|
+
ui.featureOptions.devicesTable.appendChild(trDevice);
|
|
146
170
|
|
|
147
|
-
|
|
148
|
-
|
|
171
|
+
ui.featureOptions.webUiDeviceList.push(label);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
149
175
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
176
|
+
// Only show feature options that are valid for the capabilities of this device.
|
|
177
|
+
const validOption = (device, option) => {
|
|
178
|
+
|
|
179
|
+
if(device && (device.modelKey !== "nvr") && (
|
|
180
|
+
(option.hasFeature && (!device.featureFlags || !option.hasFeature.some(x => device.featureFlags[x]))) ||
|
|
181
|
+
(option.hasProperty && !option.hasProperty.some(x => x in device)) ||
|
|
182
|
+
(option.modelKey && (option.modelKey !== "all") && !option.modelKey.includes(device.modelKey)) ||
|
|
183
|
+
(option.hasSmartObjectType && device.featureFlags?.smartDetectTypes && !option.hasSmartObjectType.some(x => device.featureFlags.smartDetectTypes.includes(x))))) {
|
|
184
|
+
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return true;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// Only show feature option categories that are valid for a particular device type.
|
|
192
|
+
const validOptionCategory = (device, category) => {
|
|
193
|
+
|
|
194
|
+
if(device && (device.modelKey !== "nvr") && !category.modelKey.some(model => ["all", device.modelKey].includes(model))) {
|
|
195
|
+
|
|
196
|
+
return false;
|
|
153
197
|
}
|
|
154
198
|
|
|
155
|
-
|
|
156
|
-
|
|
199
|
+
return true;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// Show the details for this device.
|
|
203
|
+
const showProtectDetails = (device) => {
|
|
204
|
+
|
|
205
|
+
// No device specified, we must be in a global context.
|
|
206
|
+
if(!device) {
|
|
157
207
|
|
|
158
|
-
|
|
159
|
-
|
|
208
|
+
document.getElementById("device_model").classList.remove("text-center");
|
|
209
|
+
document.getElementById("device_model").colSpan = 1;
|
|
210
|
+
document.getElementById("device_model").style.fontWeight = "normal";
|
|
211
|
+
document.getElementById("device_model").innerHTML = "N/A"
|
|
212
|
+
document.getElementById("device_mac").innerHTML = "N/A";
|
|
213
|
+
document.getElementById("device_address").innerHTML = "N/A";
|
|
214
|
+
document.getElementById("device_online").innerHTML = "N/A";
|
|
160
215
|
|
|
161
|
-
|
|
162
|
-
featureOptions.currentConfig[0].name = "UniFi Protect";
|
|
216
|
+
return;
|
|
163
217
|
}
|
|
164
218
|
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
219
|
+
// Populate the device details.
|
|
220
|
+
document.getElementById("device_model").classList.remove("text-center");
|
|
221
|
+
document.getElementById("device_model").colSpan = 1;
|
|
222
|
+
document.getElementById("device_model").style.fontWeight = "normal";
|
|
223
|
+
document.getElementById("device_model").innerHTML = device.marketName ?? device.type;
|
|
224
|
+
document.getElementById("device_mac").innerHTML = device.mac;
|
|
225
|
+
document.getElementById("device_address").innerHTML = device.host ?? (device.modelKey === "sensor" ? "Bluetooth Device" : "None");
|
|
226
|
+
document.getElementById("device_online").innerHTML = ("state" in device) ? (device.state.charAt(0).toUpperCase() + device.state.slice(1).toLowerCase()) : "Connected";
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
// Parameters for our feature options webUI.
|
|
230
|
+
const featureOptionsParams = {
|
|
231
|
+
|
|
232
|
+
getDevices: getDevices,
|
|
233
|
+
hasControllers: true,
|
|
234
|
+
infoPanel: showProtectDetails,
|
|
235
|
+
sidebar: {
|
|
236
|
+
|
|
237
|
+
controllerLabel: "Protect Controllers",
|
|
238
|
+
deviceLabel: "Protect Devices",
|
|
239
|
+
showDevices: showSidebarDevices
|
|
240
|
+
},
|
|
241
|
+
ui: {
|
|
242
|
+
|
|
243
|
+
isController: isController,
|
|
244
|
+
validOption: validOption,
|
|
245
|
+
validOptionCategory: validOptionCategory
|
|
246
|
+
}
|
|
247
|
+
};
|
|
169
248
|
|
|
170
|
-
//
|
|
171
|
-
|
|
249
|
+
// Parameters for our plugin webUI.
|
|
250
|
+
const webUiParams = {
|
|
172
251
|
|
|
173
|
-
|
|
174
|
-
|
|
252
|
+
featureOptions: featureOptionsParams,
|
|
253
|
+
firstRun: {
|
|
175
254
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
255
|
+
isRequired: firstRunIsRequired,
|
|
256
|
+
onStart: firstRunOnStart,
|
|
257
|
+
onSubmit: firstRunOnSubmit
|
|
258
|
+
},
|
|
259
|
+
name: "UniFi Protect"
|
|
260
|
+
};
|
|
179
261
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
262
|
+
// Instantiate the webUI.
|
|
263
|
+
const ui = new webUi(webUiParams);
|
|
264
|
+
|
|
265
|
+
// Display the webUI.
|
|
266
|
+
ui.show();
|