homebridge-unifi-access 1.3.0 → 1.5.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.
@@ -1,201 +0,0 @@
1
- /* Copyright(C) 2017-2024, HJD (https://github.com/hjdhjd). All rights reserved.
2
- *
3
- * featureoptions.mjs: Feature option webUI base class.
4
- */
5
- "use strict";
6
-
7
- export class FeatureOptions {
8
-
9
- controller;
10
-
11
- featureOptionGroups;
12
- featureOptionList;
13
- optionsList;
14
-
15
- constructor() {
16
-
17
- this.featureOptionGroups = {};
18
- this.featureOptionList = {};
19
- this.controller = null;
20
- this.optionsList = [];
21
- }
22
-
23
- // Abstract method to be implemented by subclasses to render the feature option webUI.
24
- async showUI() {
25
- }
26
-
27
- // Is this feature option set explicitly?
28
- isOptionSet(featureOption, deviceMac) {
29
-
30
- const optionRegex = new RegExp("^(?:Enable|Disable)\\." + featureOption + (!deviceMac ? "" : "\\." + deviceMac) + "$", "gi");
31
- return this.optionsList.filter(x => optionRegex.test(x)).length ? true : false;
32
- }
33
-
34
- // Is a feature option globally enabled?
35
- isGlobalOptionEnabled(featureOption, defaultState) {
36
-
37
- featureOption = featureOption.toUpperCase();
38
-
39
- // Test device-specific options.
40
- return this.optionsList.some(x => x === ("ENABLE." + featureOption)) ? true :
41
- (this.optionsList.some(x => x === ("DISABLE." + featureOption)) ? false : defaultState
42
- );
43
- }
44
-
45
- // Is a feature option enabled at the device or global level. This function does not traverse the scoping hierarchy.
46
- isDeviceOptionEnabled(featureOption, mac, defaultState) {
47
-
48
- if(!mac) {
49
-
50
- return this.isGlobalOptionEnabled(featureOption, defaultState);
51
- }
52
-
53
- featureOption = featureOption.toUpperCase();
54
- mac = mac.toUpperCase();
55
-
56
- // Test device-specific options.
57
- return this.optionsList.some(x => x === ("ENABLE." + featureOption + "." + mac)) ? true :
58
- (this.optionsList.some(x => x === ("DISABLE." + featureOption + "." + mac)) ? false : defaultState
59
- );
60
- }
61
-
62
- // Is a value-centric feature option enabled at the device or global level. This function does not traverse the scoping hierarchy.
63
- isOptionValueSet(featureOption, deviceMac) {
64
-
65
- const optionRegex = new RegExp("^Enable\\." + featureOption + (!deviceMac ? "" : "\\." + deviceMac) + "\\.([^\\.]+)$", "gi");
66
-
67
-
68
- return this.optionsList.some(x => optionRegex.test(x));
69
- }
70
-
71
- // Get the value of a value-centric feature option.
72
- getOptionValue(featureOption, deviceMac) {
73
-
74
- const optionRegex = new RegExp("^Enable\\." + featureOption + (!deviceMac ? "" : "\\." + deviceMac) + "\\.([^\\.]+)$", "gi");
75
-
76
- // Get the option value, if we have one.
77
- for(const option of this.optionsList) {
78
-
79
- const regexMatch = optionRegex.exec(option);
80
-
81
- if(regexMatch) {
82
-
83
- return regexMatch[1];
84
- }
85
- }
86
-
87
- return undefined;
88
- }
89
-
90
- // Is a feature option enabled at the device or global level. It does traverse the scoping hierarchy.
91
- isOptionEnabled(featureOption, deviceMac) {
92
-
93
- const defaultState = this.featureOptionList[featureOption]?.default ?? true;
94
-
95
- if(deviceMac) {
96
-
97
- // Device level check.
98
- if(this.isDeviceOptionEnabled(featureOption, deviceMac, defaultState) !== defaultState) {
99
-
100
- return !defaultState;
101
- }
102
-
103
- // Controller level check.
104
- if(this.isDeviceOptionEnabled(featureOption, this.controller, defaultState) !== defaultState) {
105
-
106
- return !defaultState;
107
- }
108
- }
109
-
110
- // Global check.
111
- if(this.isGlobalOptionEnabled(featureOption, defaultState) !== defaultState) {
112
-
113
- return !defaultState;
114
- }
115
-
116
- // Return the default.
117
- return defaultState;
118
- };
119
-
120
- // Return the scope level of a feature option.
121
- optionScope(featureOption, deviceMac, defaultState, isOptionValue = false) {
122
-
123
- // Scope priority is always: device, controller, global.
124
-
125
- // If we have a value-centric feature option, our lookups are a bit different.
126
- if(isOptionValue) {
127
-
128
- if(deviceMac) {
129
-
130
- if(this.isOptionValueSet(featureOption, deviceMac)) {
131
-
132
- return "device";
133
- }
134
-
135
- if(this.isOptionValueSet(featureOption, this.controller)) {
136
-
137
- return "controller";
138
- }
139
- }
140
-
141
- if(this.isOptionValueSet(featureOption)) {
142
-
143
- return "global";
144
- }
145
-
146
- return "none";
147
- }
148
-
149
- if(deviceMac) {
150
-
151
- // Let's see if we've set it at the device-level.
152
- if((this.isDeviceOptionEnabled(featureOption, deviceMac, defaultState) !== defaultState) || this.isOptionSet(featureOption, deviceMac)) {
153
-
154
- return "device";
155
- }
156
-
157
- // Now let's test the controller level.
158
- if((this.isDeviceOptionEnabled(featureOption, this.controller, defaultState) !== defaultState) || this.isOptionSet(featureOption, this.controller)) {
159
-
160
- return "controller";
161
- }
162
- }
163
-
164
- // Finally, let's test the global level.
165
- if((this.isGlobalOptionEnabled(featureOption, defaultState) !== defaultState) || this.isOptionSet(featureOption)) {
166
-
167
- return "global";
168
- }
169
-
170
- // Option isn't set to a non-default value.
171
- return "none";
172
- };
173
-
174
- // Return the color hinting for a given option's scope.
175
- optionScopeColor(featureOption, deviceMac, defaultState, isOptionValue) {
176
-
177
- switch(this.optionScope(featureOption, deviceMac, defaultState, isOptionValue)) {
178
-
179
- case "device":
180
-
181
- return "text-info";
182
- break;
183
-
184
- case "controller":
185
-
186
- return "text-success";
187
- break;
188
-
189
- case "global":
190
-
191
- return deviceMac ? "text-warning" : "text-info";
192
- break;
193
-
194
- default:
195
-
196
- break;
197
- }
198
-
199
- return null;
200
- };
201
- }