homebridge-unifi-access 0.0.1 → 1.1.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/LICENSE.md +3 -3
- package/README.md +88 -3
- package/config.schema.json +202 -0
- package/dist/access-controller.d.ts +45 -0
- package/dist/access-controller.js +387 -0
- package/dist/access-controller.js.map +1 -0
- package/dist/access-device.d.ts +53 -0
- package/dist/access-device.js +362 -0
- package/dist/access-device.js.map +1 -0
- package/dist/access-events.d.ts +24 -0
- package/dist/access-events.js +151 -0
- package/dist/access-events.js.map +1 -0
- package/dist/access-hub.d.ts +21 -0
- package/dist/access-hub.js +277 -0
- package/dist/access-hub.js.map +1 -0
- package/dist/access-mqtt.d.ts +20 -0
- package/dist/access-mqtt.js +163 -0
- package/dist/access-mqtt.js.map +1 -0
- package/dist/access-options.d.ts +38 -0
- package/dist/access-options.js +167 -0
- package/dist/access-options.js.map +1 -0
- package/dist/access-platform.d.ts +16 -0
- package/dist/access-platform.js +103 -0
- package/dist/access-platform.js.map +1 -0
- package/dist/access-types.d.ts +11 -0
- package/dist/access-types.js +13 -0
- package/dist/access-types.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/settings.d.ts +10 -0
- package/dist/settings.js +23 -10
- package/dist/settings.js.map +1 -1
- package/homebridge-ui/public/access-featureoptions.mjs +748 -0
- package/homebridge-ui/public/index.html +151 -0
- package/homebridge-ui/public/lib/featureoptions.mjs +201 -0
- package/homebridge-ui/public/ui.mjs +182 -0
- package/homebridge-ui/server.js +153 -0
- package/package.json +55 -23
- package/.eslintrc.json +0 -45
- package/dist/platform.js +0 -98
- package/dist/platform.js.map +0 -1
- package/dist/platformAccessory.js +0 -104
- package/dist/platformAccessory.js.map +0 -1
- package/src/index.ts +0 -11
- package/src/platform.ts +0 -116
- package/src/platformAccessory.ts +0 -130
- package/src/settings.ts +0 -9
- package/tsconfig.json +0 -20
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
/* Copyright(C) 2017-2024, HJD (https://github.com/hjdhjd). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* access-controller.ts: Access controller device class for UniFi Access.
|
|
4
|
+
*/
|
|
5
|
+
import { ACCESS_CONTROLLER_REFRESH_INTERVAL, ACCESS_CONTROLLER_RETRY_INTERVAL, PLATFORM_NAME, PLUGIN_NAME } from "./settings.js";
|
|
6
|
+
import { AccessApi } from "unifi-access";
|
|
7
|
+
import { getOptionFloat, getOptionNumber, getOptionValue, isOptionEnabled } from "./access-options.js";
|
|
8
|
+
import { AccessEvents } from "./access-events.js";
|
|
9
|
+
import { AccessHub } from "./access-hub.js";
|
|
10
|
+
import { AccessMqtt } from "./access-mqtt.js";
|
|
11
|
+
import util from "node:util";
|
|
12
|
+
export class AccessController {
|
|
13
|
+
api;
|
|
14
|
+
config;
|
|
15
|
+
deviceRemovalQueue;
|
|
16
|
+
configuredDevices;
|
|
17
|
+
events;
|
|
18
|
+
isEnabled;
|
|
19
|
+
hap;
|
|
20
|
+
logApiErrors;
|
|
21
|
+
log;
|
|
22
|
+
mqtt;
|
|
23
|
+
name;
|
|
24
|
+
platform;
|
|
25
|
+
uda;
|
|
26
|
+
udaApi;
|
|
27
|
+
unsupportedDevices;
|
|
28
|
+
constructor(platform, accessOptions) {
|
|
29
|
+
this.api = platform.api;
|
|
30
|
+
this.config = accessOptions;
|
|
31
|
+
this.configuredDevices = {};
|
|
32
|
+
this.deviceRemovalQueue = {};
|
|
33
|
+
this.isEnabled = false;
|
|
34
|
+
this.hap = this.api.hap;
|
|
35
|
+
this.logApiErrors = true;
|
|
36
|
+
this.mqtt = null;
|
|
37
|
+
this.name = accessOptions.name ?? accessOptions.address;
|
|
38
|
+
this.platform = platform;
|
|
39
|
+
this.uda = {};
|
|
40
|
+
this.unsupportedDevices = {};
|
|
41
|
+
// Configure our logging.
|
|
42
|
+
this.log = {
|
|
43
|
+
debug: (message, ...parameters) => this.platform.debug(util.format((this.udaApi?.name ?? this.name) + ": " + message, ...parameters)),
|
|
44
|
+
error: (message, ...parameters) => this.platform.log.error(util.format((this.udaApi?.name ?? this.name) + ": " + message, ...parameters)),
|
|
45
|
+
info: (message, ...parameters) => this.platform.log.info(util.format((this.udaApi?.name ?? this.name) + ": " + message, ...parameters)),
|
|
46
|
+
warn: (message, ...parameters) => this.platform.log.warn(util.format((this.udaApi?.name ?? this.name) + ": " + message, ...parameters))
|
|
47
|
+
};
|
|
48
|
+
// Validate our controller address and login information.
|
|
49
|
+
if (!accessOptions.address || !accessOptions.username || !accessOptions.password) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Retrieve the bootstrap configuration from the Access controller.
|
|
54
|
+
async bootstrapController() {
|
|
55
|
+
// Attempt to bootstrap the controller until we're successful.
|
|
56
|
+
await this.retry(() => this.udaApi.getBootstrap(), ACCESS_CONTROLLER_RETRY_INTERVAL * 1000);
|
|
57
|
+
}
|
|
58
|
+
// Initialize our connection to the UniFi Access controller.
|
|
59
|
+
async login() {
|
|
60
|
+
// The plugin has been disabled globally. Let the user know that we're done here.
|
|
61
|
+
if (!this.hasFeature("Device")) {
|
|
62
|
+
this.log.info("Disabling this UniFi Access controller.");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
// Initialize our connection to the UniFi Access API.
|
|
66
|
+
const udaLog = {
|
|
67
|
+
debug: (message, ...parameters) => this.platform.debug(util.format(message, ...parameters)),
|
|
68
|
+
error: (message, ...parameters) => {
|
|
69
|
+
if (this.logApiErrors) {
|
|
70
|
+
this.platform.log.error(util.format(message, ...parameters));
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
info: (message, ...parameters) => this.platform.log.info(util.format(message, ...parameters)),
|
|
74
|
+
warn: (message, ...parameters) => this.platform.log.warn(util.format(message, ...parameters))
|
|
75
|
+
};
|
|
76
|
+
// Create our connection to the Access API.
|
|
77
|
+
this.udaApi = new AccessApi(udaLog);
|
|
78
|
+
// Attempt to login to the Access controller, retrying at reasonable intervals. This accounts for cases where the Access controller or the network connection
|
|
79
|
+
// may not be fully available when we startup.
|
|
80
|
+
await this.retry(() => this.udaApi.login(this.config.address, this.config.username, this.config.password), ACCESS_CONTROLLER_RETRY_INTERVAL * 1000);
|
|
81
|
+
// Now, let's get the bootstrap configuration from the Access controller.
|
|
82
|
+
await this.bootstrapController();
|
|
83
|
+
// Set our Access configuration from the controller.
|
|
84
|
+
this.uda = this.udaApi.controller;
|
|
85
|
+
// Assign our name if the user hasn't explicitly specified a preference.
|
|
86
|
+
this.name = this.config.name ?? (this.uda.host.hostname ?? this.uda.host.device_type);
|
|
87
|
+
// We successfully logged in.
|
|
88
|
+
this.log.info("Connected to %s (UniFi Access %s running on UniFi OS %s).", this.config.address, this.uda.version, this.uda.host.firmware_version);
|
|
89
|
+
// Mark this NVR as enabled or disabled.
|
|
90
|
+
this.isEnabled = this.hasFeature("Device");
|
|
91
|
+
// If the Access controller is disabled, we're done.
|
|
92
|
+
if (!this.isEnabled) {
|
|
93
|
+
this.udaApi.logout();
|
|
94
|
+
this.log.info("Disabling this UniFi Access controller in HomeKit.");
|
|
95
|
+
// Let's sleep for thirty seconds to give all the accessories a chance to load before disabling everything. Homebridge doesn't have a good mechanism to notify us
|
|
96
|
+
// when all the cached accessories are loaded at startup.
|
|
97
|
+
await this.sleep(30);
|
|
98
|
+
// Unregister all the accessories for this controller from Homebridge that may have been restored already. Any additional ones will be automatically caught when
|
|
99
|
+
// they are restored.
|
|
100
|
+
this.removeHomeKitAccessories(this.platform.accessories.filter(x => x.context.controller === this.uda.host.mac));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// Initialize our UniFi Access events handler.
|
|
104
|
+
this.events = new AccessEvents(this);
|
|
105
|
+
// Configure any controller-specific settings.
|
|
106
|
+
this.configureController();
|
|
107
|
+
// Initialize MQTT, if needed.
|
|
108
|
+
if (!this.mqtt && this.config.mqttUrl) {
|
|
109
|
+
this.mqtt = new AccessMqtt(this);
|
|
110
|
+
}
|
|
111
|
+
// Inform the user about the devices we see.
|
|
112
|
+
if (this.udaApi.devices) {
|
|
113
|
+
for (const device of this.udaApi.devices) {
|
|
114
|
+
// Filter out any devices that aren't adopted by this Access controller.
|
|
115
|
+
if (!device.is_adopted || !device.is_managed) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
this.log.info("Discovered %s: %s.", device.model ?? device.display_model, this.udaApi.getDeviceName(device, device.name ?? device.model, true));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Sync the Access controller's devices with HomeKit.
|
|
122
|
+
const syncUdaHomeKit = () => {
|
|
123
|
+
// Sync status and check for any new or removed accessories.
|
|
124
|
+
this.discoverAndSyncAccessories();
|
|
125
|
+
// Refresh the accessory cache.
|
|
126
|
+
this.api.updatePlatformAccessories(this.platform.accessories);
|
|
127
|
+
};
|
|
128
|
+
// Initialize our Access controller device sync.
|
|
129
|
+
syncUdaHomeKit();
|
|
130
|
+
// Bootstrap refresh loop.
|
|
131
|
+
const bootstrapRefresh = () => {
|
|
132
|
+
// Sleep until it's time to bootstrap again.
|
|
133
|
+
setTimeout(() => void this.bootstrapController(), ACCESS_CONTROLLER_REFRESH_INTERVAL * 1000);
|
|
134
|
+
};
|
|
135
|
+
// Let's set a listener to wait for bootstrap events to occur so we can keep ourselves in sync with the Access controller.
|
|
136
|
+
this.udaApi.on("bootstrap", () => {
|
|
137
|
+
// Sync our device view.
|
|
138
|
+
syncUdaHomeKit();
|
|
139
|
+
// Refresh our bootstrap.
|
|
140
|
+
bootstrapRefresh();
|
|
141
|
+
});
|
|
142
|
+
// Kickoff our first round of bootstrap refreshes to ensure we stay in sync.
|
|
143
|
+
bootstrapRefresh();
|
|
144
|
+
}
|
|
145
|
+
// Configure controller-specific settings.
|
|
146
|
+
configureController() {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
// Create instances of Access device types in our plugin.
|
|
150
|
+
addAccessDevice(accessory, device) {
|
|
151
|
+
if (!accessory || !device) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
switch (device.device_type) {
|
|
155
|
+
case "UAH":
|
|
156
|
+
// We have a UniFi Access hub.
|
|
157
|
+
this.configuredDevices[accessory.UUID] = new AccessHub(this, device, accessory);
|
|
158
|
+
return true;
|
|
159
|
+
break;
|
|
160
|
+
default:
|
|
161
|
+
this.log.error("Unknown device class %s detected for %s.", device.device_type, device.name ?? device.model);
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// Discover UniFi Access devices that may have been added to the controller since we last checked.
|
|
166
|
+
discoverDevices(devices) {
|
|
167
|
+
// Iterate through the list of devices that Access has returned and sync them with what we show HomeKit.
|
|
168
|
+
for (const device of devices) {
|
|
169
|
+
this.addHomeKitDevice(device);
|
|
170
|
+
}
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
// Add a newly detected Access device to HomeKit.
|
|
174
|
+
addHomeKitDevice(device) {
|
|
175
|
+
// If we have no MAC address, name, or this device isn't being managed by this Access controller, we're done.
|
|
176
|
+
if (!this.uda?.host.mac || !device || !device.mac || !device.is_adopted || !device.is_managed) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
// We only support certain devices.
|
|
180
|
+
switch (device.device_type) {
|
|
181
|
+
case "UAH":
|
|
182
|
+
break;
|
|
183
|
+
default:
|
|
184
|
+
// If we've already informed the user about this one, we're done.
|
|
185
|
+
if (this.unsupportedDevices[device.mac]) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
// Notify the user we see this device, but we aren't adding it to HomeKit.
|
|
189
|
+
this.unsupportedDevices[device.mac] = true;
|
|
190
|
+
this.log.info("UniFi Access device type '%s' is not currently supported, ignoring: %s.", device.device_type, this.udaApi.getDeviceName(device));
|
|
191
|
+
return null;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
// Exclude or include certain devices based on configuration parameters.
|
|
195
|
+
if (!this.hasFeature("Device", true, device)) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
// Generate this device's unique identifier.
|
|
199
|
+
const uuid = this.hap.uuid.generate(device.mac);
|
|
200
|
+
let accessory;
|
|
201
|
+
// See if we already know about this accessory or if it's truly new. If it is new, add it to HomeKit.
|
|
202
|
+
if ((accessory = this.platform.accessories.find(x => x.UUID === uuid)) === undefined) {
|
|
203
|
+
accessory = new this.api.platformAccessory(device.name ?? device.model, uuid);
|
|
204
|
+
this.log.info("%s: Adding %s to HomeKit.", this.udaApi.getFullName(device), device.model);
|
|
205
|
+
// Register this accessory with homebridge and add it to the accessory array so we can track it.
|
|
206
|
+
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
207
|
+
this.platform.accessories.push(accessory);
|
|
208
|
+
this.api.updatePlatformAccessories(this.platform.accessories);
|
|
209
|
+
}
|
|
210
|
+
// Link the accessory to it's device object and it's hosting NVR.
|
|
211
|
+
accessory.context.controller = this.uda.host.mac;
|
|
212
|
+
// Locate our existing Access device instance, if we have one.
|
|
213
|
+
const accessDevice = this.configuredDevices[accessory.UUID];
|
|
214
|
+
// Setup the Access device if it hasn't been configured yet.
|
|
215
|
+
if (!accessDevice) {
|
|
216
|
+
this.addAccessDevice(accessory, device);
|
|
217
|
+
}
|
|
218
|
+
return accessDevice;
|
|
219
|
+
}
|
|
220
|
+
// Discover and sync UniFi Access devices between HomeKit and the Access controller.
|
|
221
|
+
discoverAndSyncAccessories() {
|
|
222
|
+
if (!this.udaApi.bootstrap) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
if (this.udaApi.devices && !this.discoverDevices(this.udaApi.devices)) {
|
|
226
|
+
this.log.error("Error discovering devices.");
|
|
227
|
+
}
|
|
228
|
+
// Remove Access devices that are no longer found on this Access controller, but we still have in HomeKit.
|
|
229
|
+
this.cleanupDevices();
|
|
230
|
+
// Sync our names.
|
|
231
|
+
Object.keys(this.configuredDevices).filter(x => ("hints" in this.configuredDevices[x]) && this.configuredDevices[x].hints.syncName)
|
|
232
|
+
.map(x => (this.configuredDevices[x].accessoryName = this.configuredDevices[x].uda.name));
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
// Cleanup removed Access devices from HomeKit.
|
|
236
|
+
cleanupDevices() {
|
|
237
|
+
for (const accessory of this.platform.accessories) {
|
|
238
|
+
const accessDevice = this.configuredDevices[accessory.UUID];
|
|
239
|
+
// Check to see if we have an orphan - where we haven't configured this in the plugin, but the accessory still exists in HomeKit. One example of when this might
|
|
240
|
+
// happen is when Homebridge might be shutdown and a device is then removed. When we start back up, the device still exists in HomeKit but not in Access. We
|
|
241
|
+
// catch those orphan devices here.
|
|
242
|
+
if (!accessDevice) {
|
|
243
|
+
// We only remove devices if they're on the Access controller we're interested in.
|
|
244
|
+
if (("controller" in accessory.context) && (accessory.context.controller !== this.uda.host.mac)) {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
// We only store MAC addresses on devices that exist on the Access controller. Any other accessories created are ones we created ourselves and are managed
|
|
248
|
+
// elsewhere.
|
|
249
|
+
if (!("mac" in accessory.context)) {
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
// For certain use cases, we may want to defer removal of an Access device for a brief period of time.
|
|
253
|
+
const delayInterval = this.getFeatureNumber("Controller.DelayDeviceRemoval");
|
|
254
|
+
if ((delayInterval !== undefined) && (delayInterval > 0)) {
|
|
255
|
+
// Have we seen this device queued for removal previously? If not, let's add it to the queue and come back after our specified delay.
|
|
256
|
+
if (!this.deviceRemovalQueue[accessory.UUID]) {
|
|
257
|
+
this.deviceRemovalQueue[accessory.UUID] = Date.now();
|
|
258
|
+
this.log.info("%s: Delaying device removal for at least %s second%s.", accessory.displayName, delayInterval, delayInterval > 1 ? "s" : "");
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
// Is it time to process this device removal?
|
|
262
|
+
if ((delayInterval * 1000) > (Date.now() - this.deviceRemovalQueue[accessory.UUID])) {
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
// Cleanup after ourselves.
|
|
266
|
+
delete this.deviceRemovalQueue[accessory.UUID];
|
|
267
|
+
}
|
|
268
|
+
this.log.info("%s: Removing device from HomeKit.", accessory.displayName);
|
|
269
|
+
// Unregister the accessory and delete it's remnants from HomeKit.
|
|
270
|
+
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
271
|
+
this.platform.accessories.splice(this.platform.accessories.indexOf(accessory), 1);
|
|
272
|
+
this.api.updatePlatformAccessories(this.platform.accessories);
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
// If we don't have the Access bootstrap JSON available, we're done. We need to know what's on the Access controller in order to determine what to do with
|
|
276
|
+
// the accessories we know about.
|
|
277
|
+
if (!this.udaApi.bootstrap) {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
// Check to see if the device still exists on the Access controller and the user has not chosen to hide it.
|
|
281
|
+
switch (accessDevice.uda.device_type) {
|
|
282
|
+
case "UAH":
|
|
283
|
+
if (this.udaApi.devices?.some((x) => x.mac === accessDevice.uda.mac) && accessDevice.hasFeature("Device")) {
|
|
284
|
+
// In case we have previously queued a device for deletion, let's remove it from the queue since it's reappeared.
|
|
285
|
+
delete this.deviceRemovalQueue[accessDevice.accessory.UUID];
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
break;
|
|
289
|
+
default:
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
// Process the device removal.
|
|
293
|
+
this.removeHomeKitDevice(this.configuredDevices[accessory.UUID]);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// Remove an individual Access device from HomeKit.
|
|
297
|
+
removeHomeKitDevice(accessDevice) {
|
|
298
|
+
// Sanity check.
|
|
299
|
+
if (!accessDevice) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
// We only remove devices if they're on the Access controller we're interested in.
|
|
303
|
+
if (accessDevice.accessory.context.controller !== this.uda.host.mac) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
// For certain use cases, we may want to defer removal of an Access device.
|
|
307
|
+
const delayInterval = this.getFeatureNumber("Controller.DelayDeviceRemoval");
|
|
308
|
+
if ((delayInterval !== undefined) && (delayInterval > 0)) {
|
|
309
|
+
// Have we seen this device queued for removal previously? If not, let's add it to the queue and come back after our specified delay.
|
|
310
|
+
if (!this.deviceRemovalQueue[accessDevice.accessory.UUID]) {
|
|
311
|
+
this.deviceRemovalQueue[accessDevice.accessory.UUID] = Date.now();
|
|
312
|
+
this.log.info("%s: Delaying device removal for %s second%s.", accessDevice.uda.name ? this.udaApi.getDeviceName(accessDevice.uda) : accessDevice.accessoryName, delayInterval, delayInterval > 1 ? "s" : "");
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
// Is it time to process this device removal?
|
|
316
|
+
if ((delayInterval * 1000) > (Date.now() - this.deviceRemovalQueue[accessDevice.accessory.UUID])) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
// Cleanup after ourselves.
|
|
320
|
+
delete this.deviceRemovalQueue[accessDevice.accessory.UUID];
|
|
321
|
+
}
|
|
322
|
+
// Remove this device.
|
|
323
|
+
this.log.info("%s: Removing %s from HomeKit.", accessDevice.uda.name ? this.udaApi.getDeviceName(accessDevice.uda) : accessDevice.accessoryName, accessDevice.uda.model ? accessDevice.uda.model : "device");
|
|
324
|
+
const deletingAccessories = [accessDevice.accessory];
|
|
325
|
+
// Cleanup our event handlers.
|
|
326
|
+
accessDevice.cleanup();
|
|
327
|
+
// Unregister the accessory and delete it's remnants from HomeKit and the plugin.
|
|
328
|
+
delete this.configuredDevices[accessDevice.accessory.UUID];
|
|
329
|
+
this.removeHomeKitAccessories(deletingAccessories);
|
|
330
|
+
}
|
|
331
|
+
// Remove accessories from HomeKit and Homebridge.
|
|
332
|
+
removeHomeKitAccessories(deletingAccessories) {
|
|
333
|
+
// Sanity check.
|
|
334
|
+
if (!deletingAccessories || (deletingAccessories.length <= 0)) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
// Unregister the accessories from Homebridge and HomeKit.
|
|
338
|
+
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, deletingAccessories);
|
|
339
|
+
// Update our internal list of all the accessories we know about.
|
|
340
|
+
for (const accessory of deletingAccessories) {
|
|
341
|
+
this.platform.accessories.splice(this.platform.accessories.indexOf(accessory), 1);
|
|
342
|
+
}
|
|
343
|
+
// Tell Homebridge to save the updated list of accessories.
|
|
344
|
+
this.api.updatePlatformAccessories(this.platform.accessories);
|
|
345
|
+
}
|
|
346
|
+
// Reauthenticate with the controller.
|
|
347
|
+
async resetControllerConnection() {
|
|
348
|
+
// Clear our login credentials and statistics.
|
|
349
|
+
this.udaApi.reset();
|
|
350
|
+
// Bootstrap the Access controller.
|
|
351
|
+
await this.bootstrapController();
|
|
352
|
+
}
|
|
353
|
+
// Lookup a device by it's identifier and return it if it exists.
|
|
354
|
+
deviceLookup(deviceId) {
|
|
355
|
+
// Find the device.
|
|
356
|
+
const foundDevice = Object.keys(this.configuredDevices).find(x => this.configuredDevices[x].uda.unique_id === deviceId);
|
|
357
|
+
return foundDevice ? this.configuredDevices[foundDevice] : null;
|
|
358
|
+
}
|
|
359
|
+
// Utility function to return a floating point configuration parameter on a device.
|
|
360
|
+
getFeatureFloat(option) {
|
|
361
|
+
return getOptionFloat(getOptionValue(this.platform.featureOptions, this.uda, null, option));
|
|
362
|
+
}
|
|
363
|
+
// Utility function to return an integer configuration parameter on a device.
|
|
364
|
+
getFeatureNumber(option) {
|
|
365
|
+
return getOptionNumber(getOptionValue(this.platform.featureOptions, this.uda, null, option));
|
|
366
|
+
}
|
|
367
|
+
// Utility for checking feature options on the NVR.
|
|
368
|
+
hasFeature(option, defaultReturnValue, device = null) {
|
|
369
|
+
return isOptionEnabled(this.platform.featureOptions, this.uda, device, option, defaultReturnValue ?? this.platform.featureOptionDefault(option));
|
|
370
|
+
}
|
|
371
|
+
// Emulate a sleep function.
|
|
372
|
+
sleep(sleepTimer) {
|
|
373
|
+
return new Promise(resolve => setTimeout(resolve, sleepTimer));
|
|
374
|
+
}
|
|
375
|
+
// Retry an operation until we're successful.
|
|
376
|
+
async retry(operation, retryInterval) {
|
|
377
|
+
// Try the operation that was requested.
|
|
378
|
+
if (!(await operation())) {
|
|
379
|
+
// If the operation wasn't successful, let's sleep for the requested interval and try again.
|
|
380
|
+
await this.sleep(retryInterval);
|
|
381
|
+
return this.retry(operation, retryInterval);
|
|
382
|
+
}
|
|
383
|
+
// We were successful - we're done.
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
//# sourceMappingURL=access-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-controller.js","sourceRoot":"","sources":["../src/access-controller.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,kCAAkC,EAAE,gCAAgC,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjI,OAAO,EAAE,SAAS,EAA8C,MAAM,cAAc,CAAC;AACrF,OAAO,EAA2B,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEhI,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,OAAO,gBAAgB;IAEnB,GAAG,CAAM;IACV,MAAM,CAA0B;IAC/B,kBAAkB,CAA8B;IACxC,iBAAiB,CAAoC;IAC9D,MAAM,CAAgB;IACrB,SAAS,CAAU;IACnB,GAAG,CAAM;IACV,YAAY,CAAU;IACb,GAAG,CA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9F,CAAC;IAED,6EAA6E;IACtE,gBAAgB,CAAC,MAAc;QAEpC,OAAO,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAC/F,CAAC;IAED,mDAAmD;IAC5C,UAAU,CAAC,MAAc,EAAE,kBAA4B,EAAE,SAA8D,IAAI;QAEhI,OAAO,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,IAAI,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;IACnJ,CAAC;IAED,4BAA4B;IACrB,KAAK,CAAC,UAAkB;QAE7B,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,6CAA6C;IACrC,KAAK,CAAC,KAAK,CAAC,SAAiC,EAAE,aAAqB;QAE1E,wCAAwC;QACxC,IAAG,CAAC,CAAC,MAAM,SAAS,EAAE,CAAC,EAAE,CAAC;YAExB,4FAA4F;YAC5F,MAAM,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YAChC,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QAC9C,CAAC;QAED,mCAAmC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { API, HAP, PlatformAccessory } from "homebridge";
|
|
2
|
+
import { AccessApi, AccessDeviceConfig, AccessEventPacket } from "unifi-access";
|
|
3
|
+
import { AccessLogging } from "./access-types.js";
|
|
4
|
+
import { AccessController } from "./access-controller.js";
|
|
5
|
+
import { AccessPlatform } from "./access-platform.js";
|
|
6
|
+
export interface AccessHints {
|
|
7
|
+
ledStatus: boolean;
|
|
8
|
+
logDoorbell: boolean;
|
|
9
|
+
logLock: boolean;
|
|
10
|
+
logMotion: boolean;
|
|
11
|
+
motionDuration: number;
|
|
12
|
+
occupancyDuration: number;
|
|
13
|
+
syncName: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare abstract class AccessBase {
|
|
16
|
+
readonly api: API;
|
|
17
|
+
private debug;
|
|
18
|
+
protected readonly hap: HAP;
|
|
19
|
+
readonly log: AccessLogging;
|
|
20
|
+
readonly controller: AccessController;
|
|
21
|
+
udaApi: AccessApi;
|
|
22
|
+
readonly platform: AccessPlatform;
|
|
23
|
+
constructor(controller: AccessController);
|
|
24
|
+
protected setInfo(accessory: PlatformAccessory, device: AccessDeviceConfig): boolean;
|
|
25
|
+
get name(): string;
|
|
26
|
+
}
|
|
27
|
+
export declare abstract class AccessDevice extends AccessBase {
|
|
28
|
+
accessory: PlatformAccessory;
|
|
29
|
+
hints: AccessHints;
|
|
30
|
+
protected listeners: {
|
|
31
|
+
[index: string]: (packet: AccessEventPacket) => void;
|
|
32
|
+
};
|
|
33
|
+
abstract uda: AccessDeviceConfig;
|
|
34
|
+
constructor(controller: AccessController, accessory: PlatformAccessory);
|
|
35
|
+
protected configureHints(): boolean;
|
|
36
|
+
configureInfo(): boolean;
|
|
37
|
+
cleanup(): void;
|
|
38
|
+
protected configureMotionSensor(isEnabled?: boolean, isInitialized?: boolean): boolean;
|
|
39
|
+
private configureMotionSwitch;
|
|
40
|
+
private configureMotionTrigger;
|
|
41
|
+
private configureMqttMotionTrigger;
|
|
42
|
+
protected configureOccupancySensor(isEnabled?: boolean, isInitialized?: boolean): boolean;
|
|
43
|
+
getFeatureFloat(option: string): number | undefined;
|
|
44
|
+
getFeatureNumber(option: string): number | undefined;
|
|
45
|
+
getFeatureValue(option: string): string | undefined;
|
|
46
|
+
hasFeature(option: string, defaultReturnValue?: boolean): boolean;
|
|
47
|
+
isReservedName(name: string | undefined): boolean;
|
|
48
|
+
get isOnline(): boolean;
|
|
49
|
+
get id(): string;
|
|
50
|
+
get name(): string;
|
|
51
|
+
get accessoryName(): string;
|
|
52
|
+
set accessoryName(name: string);
|
|
53
|
+
}
|