homebridge-unifi-access 1.2.2 → 1.4.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/dist/access-controller.d.ts +4 -6
- package/dist/access-controller.js +28 -49
- package/dist/access-controller.js.map +1 -1
- package/dist/access-device.d.ts +1 -1
- package/dist/access-device.js +6 -7
- package/dist/access-device.js.map +1 -1
- package/dist/access-events.d.ts +0 -1
- package/dist/access-events.js +4 -4
- package/dist/access-events.js.map +1 -1
- package/dist/access-hub.js +16 -10
- package/dist/access-hub.js.map +1 -1
- package/dist/access-options.d.ts +6 -17
- package/dist/access-options.js +5 -133
- package/dist/access-options.js.map +1 -1
- package/dist/access-platform.d.ts +2 -3
- package/dist/access-platform.js +3 -28
- package/dist/access-platform.js.map +1 -1
- package/homebridge-ui/public/index.html +43 -38
- 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 +228 -123
- package/homebridge-ui/server.js +14 -56
- package/package.json +18 -19
- package/dist/access-mqtt.d.ts +0 -20
- package/dist/access-mqtt.js +0 -163
- package/dist/access-mqtt.js.map +0 -1
- package/homebridge-ui/public/access-featureoptions.mjs +0 -748
- package/homebridge-ui/public/lib/featureoptions.mjs +0 -201
|
@@ -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,287 @@
|
|
|
1
1
|
/* Copyright(C) 2017-2024, HJD (https://github.com/hjdhjd). All rights reserved.
|
|
2
2
|
*
|
|
3
|
-
* ui.mjs:
|
|
3
|
+
* ui.mjs: Homebridge UniFi Access webUI.
|
|
4
4
|
*/
|
|
5
5
|
"use strict";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
const featureOptions = new (await import("./access-featureoptions.mjs")).AccessFeatureOptions();
|
|
7
|
+
import { webUi } from "./lib/webUi.mjs";
|
|
9
8
|
|
|
10
|
-
//
|
|
11
|
-
|
|
9
|
+
// Execute our first run screen if we don't have valid Access login credentials and a controller.
|
|
10
|
+
const firstRunIsRequired = () => {
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
if(ui.featureOptions.currentConfig.length && ui.featureOptions.currentConfig[0].controllers?.length &&
|
|
13
|
+
ui.featureOptions.currentConfig[0].controllers[0]?.address?.length && ui.featureOptions.currentConfig[0].controllers[0]?.username?.length &&
|
|
14
|
+
ui.featureOptions.currentConfig[0].controllers[0]?.password?.length) {
|
|
15
|
+
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Initialize our first run screen with any information from our existing configuration.
|
|
23
|
+
const firstRunOnStart = () => {
|
|
24
|
+
|
|
25
|
+
// Pre-populate with anything we might already have in our configuration.
|
|
26
|
+
document.getElementById("address").value = ui.featureOptions.currentConfig[0].controllers?.[0]?.address ?? "";
|
|
27
|
+
document.getElementById("username").value = ui.featureOptions.currentConfig[0].controllers?.[0]?.username ?? "";
|
|
28
|
+
document.getElementById("password").value = ui.featureOptions.currentConfig[0].controllers?.[0]?.password ?? "";
|
|
29
|
+
|
|
30
|
+
return true;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Validate our Access credentials.
|
|
34
|
+
const firstRunOnSubmit = async () => {
|
|
35
|
+
|
|
36
|
+
const address = document.getElementById("address").value;
|
|
37
|
+
const username = document.getElementById("username").value;
|
|
38
|
+
const password = document.getElementById("password").value;
|
|
17
39
|
const tdLoginError = document.getElementById("loginError");
|
|
18
40
|
|
|
19
|
-
|
|
20
|
-
if(!featureOptions.currentConfig[0].controllers) {
|
|
41
|
+
tdLoginError.innerHTML = " ";
|
|
21
42
|
|
|
22
|
-
|
|
43
|
+
if(!address?.length || !username?.length || !password?.length) {
|
|
44
|
+
|
|
45
|
+
tdLoginError.innerHTML = "<code class=\"text-danger\">Please enter a valid UniFi Access controller address, username and password.</code>";
|
|
46
|
+
homebridge.hideSpinner();
|
|
47
|
+
|
|
48
|
+
return false;
|
|
23
49
|
}
|
|
24
50
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
51
|
+
const udaDevices = await homebridge.request("/getDevices", { address: address, username: username, password: password });
|
|
52
|
+
|
|
53
|
+
// Couldn't connect to the Access controller for some reason.
|
|
54
|
+
if(!udaDevices?.length) {
|
|
55
|
+
|
|
56
|
+
tdLoginError.innerHTML = "Unable to login to the UniFi Access controller.<br>Please check your controller address, username, and password.<br><code class=\"text-danger\">" + (await homebridge.request("/getErrorMessage")) + "</code>";
|
|
57
|
+
homebridge.hideSpinner();
|
|
58
|
+
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Save the login credentials to our configuration.
|
|
63
|
+
if(!ui.featureOptions.currentConfig[0].controllers?.length) {
|
|
64
|
+
|
|
65
|
+
ui.featureOptions.currentConfig[0].controllers = [{}];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
ui.featureOptions.currentConfig[0].controllers[0].address = address;
|
|
69
|
+
ui.featureOptions.currentConfig[0].controllers[0].username = username;
|
|
70
|
+
ui.featureOptions.currentConfig[0].controllers[0].password = password;
|
|
71
|
+
|
|
72
|
+
await homebridge.updatePluginConfig(ui.featureOptions.currentConfig);
|
|
73
|
+
|
|
74
|
+
return true;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Return the list of devices associated with a given Access controller.
|
|
78
|
+
const getDevices = async (controller) => {
|
|
79
|
+
|
|
80
|
+
// If we're in the global context, we have no devices.
|
|
81
|
+
if(!controller) {
|
|
29
82
|
|
|
30
|
-
|
|
31
|
-
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Retrieve the current list of devices from the Access controller.
|
|
87
|
+
let devices = await homebridge.request("/getDevices", { address: controller.address, username: controller.username, password: controller.password });
|
|
32
88
|
|
|
33
|
-
|
|
34
|
-
|
|
89
|
+
// Since the controller JSON doesn't have the same properties as the device JSON, let's make the controller JSON emulate the properties we care about.
|
|
90
|
+
if(devices?.length) {
|
|
91
|
+
|
|
92
|
+
devices[0].display_model = "controller";
|
|
93
|
+
devices[0].ip = devices[0].host.ip;
|
|
94
|
+
devices[0].is_online = true;
|
|
95
|
+
devices[0].mac = devices[0].host.mac;
|
|
96
|
+
devices[0].model = devices[0].host.device_type;
|
|
97
|
+
devices[0].unique_id = devices[0].host.mac;
|
|
98
|
+
}
|
|
35
99
|
|
|
36
|
-
|
|
100
|
+
// Add the fields that the webUI framework is looking for to render.
|
|
101
|
+
devices = devices.map(device => ({
|
|
37
102
|
|
|
38
|
-
|
|
39
|
-
|
|
103
|
+
...device,
|
|
104
|
+
serial: device.mac.replace(/:/g, "").toUpperCase()
|
|
105
|
+
}));
|
|
40
106
|
|
|
41
|
-
|
|
107
|
+
return devices;
|
|
108
|
+
};
|
|
42
109
|
|
|
43
|
-
|
|
44
|
-
|
|
110
|
+
// Return whether a given device is a controller.
|
|
111
|
+
const isController = (device) => device.modelKey === "controller";
|
|
45
112
|
|
|
46
|
-
|
|
47
|
-
|
|
113
|
+
// Show the list of Access devices associated with a controller, grouped by model.
|
|
114
|
+
const showSidebarDevices = (controller, devices) => {
|
|
48
115
|
|
|
49
|
-
|
|
50
|
-
|
|
116
|
+
// Workaround for the time being to reduce the number of models we see to just the currently supported ones.
|
|
117
|
+
const modelKeys = [...new Set(devices.filter(device => ["controller"].includes(device.display_model) || device.capabilities.includes("is_hub")).map(device => device.display_model))]
|
|
51
118
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const password = inputPassword.value;
|
|
119
|
+
// Start with a clean slate.
|
|
120
|
+
ui.featureOptions.devicesTable.innerHTML = "";
|
|
55
121
|
|
|
56
|
-
|
|
122
|
+
for(const key of modelKeys) {
|
|
57
123
|
|
|
58
|
-
|
|
124
|
+
// Get all the devices associated with this device category.
|
|
125
|
+
const modelDevices = devices.filter(x => x.display_model === key);
|
|
59
126
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
127
|
+
// Nothing in this category, let's keep going.
|
|
128
|
+
if(!modelDevices.length) {
|
|
129
|
+
|
|
130
|
+
continue;
|
|
63
131
|
}
|
|
64
132
|
|
|
65
|
-
|
|
133
|
+
// If it's a controller, we handle that case differently.
|
|
134
|
+
if(key === "controller") {
|
|
66
135
|
|
|
67
|
-
|
|
68
|
-
|
|
136
|
+
// Change the name of the controller that we show users once we've connected with the controller.
|
|
137
|
+
ui.featureOptions.webUiControllerList.map(x => (x.name === controller.address) ? x.childNodes[0].nodeValue = modelDevices[0].host.hostname : true);
|
|
69
138
|
|
|
70
|
-
|
|
71
|
-
homebridge.hideSpinner();
|
|
72
|
-
return;
|
|
139
|
+
continue;
|
|
73
140
|
}
|
|
74
141
|
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
featureOptions.currentConfig[0].controllers[0].username = username;
|
|
78
|
-
featureOptions.currentConfig[0].controllers[0].password = password;
|
|
142
|
+
// Create a row for this device category.
|
|
143
|
+
const trCategory = document.createElement("tr");
|
|
79
144
|
|
|
80
|
-
|
|
145
|
+
// Disable any pointer events and hover activity.
|
|
146
|
+
trCategory.style.pointerEvents = "none";
|
|
81
147
|
|
|
82
|
-
// Create our
|
|
83
|
-
document.
|
|
84
|
-
document.getElementById("menuWrapper").style.display = "inline-flex";
|
|
85
|
-
featureOptions.showUI();
|
|
86
|
-
});
|
|
148
|
+
// Create the cell for our device category row.
|
|
149
|
+
const tdCategory = document.createElement("td");
|
|
87
150
|
|
|
88
|
-
|
|
89
|
-
}
|
|
151
|
+
tdCategory.classList.add("m-0", "p-0", "pl-1", "w-100");
|
|
90
152
|
|
|
91
|
-
//
|
|
92
|
-
|
|
153
|
+
// Add the category name, with appropriate casing.
|
|
154
|
+
tdCategory.appendChild(document.createTextNode((key.charAt(0).toUpperCase() + key.slice(1) + "s")));
|
|
155
|
+
tdCategory.style.fontWeight = "bold";
|
|
93
156
|
|
|
94
|
-
|
|
95
|
-
|
|
157
|
+
// Add the cell to the table row.
|
|
158
|
+
trCategory.appendChild(tdCategory);
|
|
96
159
|
|
|
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");
|
|
160
|
+
// Add the table row to the table.
|
|
161
|
+
ui.featureOptions.devicesTable.appendChild(trCategory);
|
|
104
162
|
|
|
105
|
-
|
|
106
|
-
document.getElementById("pageFeatureOptions").style.display = "none";
|
|
163
|
+
for(const device of modelDevices) {
|
|
107
164
|
|
|
108
|
-
|
|
165
|
+
// Create a row for this device.
|
|
166
|
+
const trDevice = document.createElement("tr");
|
|
109
167
|
|
|
110
|
-
|
|
111
|
-
homebridge.hideSpinner();
|
|
112
|
-
}
|
|
168
|
+
trDevice.classList.add("m-0", "p-0");
|
|
113
169
|
|
|
114
|
-
//
|
|
115
|
-
|
|
170
|
+
// Create a cell for our device.
|
|
171
|
+
const tdDevice = document.createElement("td");
|
|
116
172
|
|
|
117
|
-
|
|
118
|
-
homebridge.showSpinner();
|
|
119
|
-
homebridge.hideSchemaForm();
|
|
173
|
+
tdDevice.classList.add("m-0", "p-0" , "w-100");
|
|
120
174
|
|
|
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");
|
|
175
|
+
const label = document.createElement("label");
|
|
128
176
|
|
|
129
|
-
|
|
130
|
-
|
|
177
|
+
label.name = device.serial;
|
|
178
|
+
label.appendChild(document.createTextNode(device.alias ?? device.display_model));
|
|
179
|
+
label.style.cursor = "pointer";
|
|
180
|
+
label.classList.add("mx-2", "my-0", "p-0", "w-100");
|
|
131
181
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
182
|
+
label.addEventListener("click", () => ui.featureOptions.showDeviceOptions(device.serial));
|
|
183
|
+
|
|
184
|
+
// Add the device label to our cell.
|
|
185
|
+
tdDevice.appendChild(label);
|
|
186
|
+
|
|
187
|
+
// Add the cell to the table row.
|
|
188
|
+
trDevice.appendChild(tdDevice);
|
|
135
189
|
|
|
136
|
-
//
|
|
137
|
-
|
|
190
|
+
// Add the table row to the table.
|
|
191
|
+
ui.featureOptions.devicesTable.appendChild(trDevice);
|
|
138
192
|
|
|
139
|
-
|
|
140
|
-
|
|
193
|
+
ui.featureOptions.webUiDeviceList.push(label);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
};
|
|
141
197
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
menuFeatureOptions.addEventListener("click", () => featureOptions.showUI());
|
|
145
|
-
menuSettings.addEventListener("click", () => showSettings());
|
|
198
|
+
// Only show feature options that are valid for the capabilities of this device.
|
|
199
|
+
const validOption = (device, option) => {
|
|
146
200
|
|
|
147
|
-
|
|
148
|
-
|
|
201
|
+
if(device && (device.display_model !== "controller") && (
|
|
202
|
+
(option.hasFeature && (!device.capabilities || !option.hasFeature.some(x => device.capabilities[x]))) ||
|
|
203
|
+
(option.hasProperty && !option.hasProperty.some(x => x in device)) ||
|
|
204
|
+
(option.modelKey && (option.modelKey !== "all") && !option.modelKey.includes(device.display_model)))) {
|
|
149
205
|
|
|
150
|
-
|
|
151
|
-
featureOptions.showUI();
|
|
152
|
-
return;
|
|
206
|
+
return false;
|
|
153
207
|
}
|
|
154
208
|
|
|
155
|
-
|
|
156
|
-
|
|
209
|
+
return true;
|
|
210
|
+
};
|
|
157
211
|
|
|
158
|
-
|
|
159
|
-
|
|
212
|
+
// Only show feature option categories that are valid for a particular device type.
|
|
213
|
+
const validOptionCategory = (device, category) => {
|
|
160
214
|
|
|
161
|
-
|
|
162
|
-
|
|
215
|
+
if(device && (device.display_model !== "controller") && !category.modelKey.some(model => ["all", device.display_model].includes(model))) {
|
|
216
|
+
|
|
217
|
+
return false;
|
|
163
218
|
}
|
|
164
219
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
showFirstRun();
|
|
168
|
-
}
|
|
220
|
+
return true;
|
|
221
|
+
};
|
|
169
222
|
|
|
170
|
-
//
|
|
171
|
-
|
|
223
|
+
// Show the details for this device.
|
|
224
|
+
const showAccessDetails = (device) => {
|
|
172
225
|
|
|
173
|
-
|
|
174
|
-
|
|
226
|
+
// No device specified, we must be in a global context.
|
|
227
|
+
if(!device) {
|
|
175
228
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
229
|
+
document.getElementById("device_model").classList.remove("text-center");
|
|
230
|
+
document.getElementById("device_model").colSpan = 1;
|
|
231
|
+
document.getElementById("device_model").style.fontWeight = "normal";
|
|
232
|
+
document.getElementById("device_model").innerHTML = "N/A"
|
|
233
|
+
document.getElementById("device_mac").innerHTML = "N/A";
|
|
234
|
+
document.getElementById("device_address").innerHTML = "N/A";
|
|
235
|
+
document.getElementById("device_online").innerHTML = "N/A";
|
|
179
236
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Populate the device details.
|
|
241
|
+
document.getElementById("device_model").classList.remove("text-center");
|
|
242
|
+
document.getElementById("device_model").colSpan = 1;
|
|
243
|
+
document.getElementById("device_model").style.fontWeight = "normal";
|
|
244
|
+
document.getElementById("device_model").innerHTML = device.model ?? device.display_model;
|
|
245
|
+
document.getElementById("device_mac").innerHTML = device.mac.replace(/:/g, "").toUpperCase();
|
|
246
|
+
document.getElementById("device_address").innerHTML = device.ip;
|
|
247
|
+
document.getElementById("device_online").innerHTML = device.is_online ? "Connected" : "Disconnected";
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// Parameters for our feature options webUI.
|
|
251
|
+
const featureOptionsParams = {
|
|
252
|
+
|
|
253
|
+
getDevices: getDevices,
|
|
254
|
+
hasControllers: true,
|
|
255
|
+
infoPanel: showAccessDetails,
|
|
256
|
+
sidebar: {
|
|
257
|
+
|
|
258
|
+
controllerLabel: "Access Controllers",
|
|
259
|
+
deviceLabel: "Access Devices",
|
|
260
|
+
showDevices: showSidebarDevices
|
|
261
|
+
},
|
|
262
|
+
ui: {
|
|
263
|
+
|
|
264
|
+
isController: isController,
|
|
265
|
+
validOption: validOption,
|
|
266
|
+
validOptionCategory: validOptionCategory
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
// Parameters for our plugin webUI.
|
|
271
|
+
const webUiParams = {
|
|
272
|
+
|
|
273
|
+
featureOptions: featureOptionsParams,
|
|
274
|
+
firstRun: {
|
|
275
|
+
|
|
276
|
+
isRequired: firstRunIsRequired,
|
|
277
|
+
onStart: firstRunOnStart,
|
|
278
|
+
onSubmit: firstRunOnSubmit
|
|
279
|
+
},
|
|
280
|
+
name: "UniFi Access"
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// Instantiate the webUI.
|
|
284
|
+
const ui = new webUi(webUiParams);
|
|
285
|
+
|
|
286
|
+
// Display the webUI.
|
|
287
|
+
ui.show();
|