homebridge-unifi-protect 5.5.2 → 6.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 +3 -3
- package/config.schema.json +17 -16
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/protect-camera.d.ts +58 -0
- package/dist/protect-camera.js +367 -246
- package/dist/protect-camera.js.map +1 -1
- package/dist/protect-device.d.ts +48 -0
- package/dist/protect-device.js +189 -0
- package/dist/protect-device.js.map +1 -0
- package/dist/protect-doorbell.d.ts +22 -0
- package/dist/protect-doorbell.js +75 -64
- package/dist/protect-doorbell.js.map +1 -1
- package/dist/protect-ffmpeg-record.d.ts +15 -0
- package/dist/protect-ffmpeg-record.js +48 -34
- package/dist/protect-ffmpeg-record.js.map +1 -1
- package/dist/protect-ffmpeg-stream.d.ts +15 -0
- package/dist/protect-ffmpeg-stream.js +22 -12
- package/dist/protect-ffmpeg-stream.js.map +1 -1
- package/dist/protect-ffmpeg.d.ts +42 -0
- package/dist/protect-ffmpeg.js +49 -58
- package/dist/protect-ffmpeg.js.map +1 -1
- package/dist/protect-light.d.ts +13 -0
- package/dist/protect-light.js +63 -40
- package/dist/protect-light.js.map +1 -1
- package/dist/protect-liveviews.d.ts +17 -0
- package/dist/protect-liveviews.js +117 -101
- package/dist/protect-liveviews.js.map +1 -1
- package/dist/protect-mqtt.d.ts +19 -0
- package/dist/protect-mqtt.js +26 -35
- package/dist/protect-mqtt.js.map +1 -1
- package/dist/protect-nvr-events.d.ts +30 -0
- package/dist/protect-nvr-events.js +168 -431
- package/dist/protect-nvr-events.js.map +1 -1
- package/dist/protect-nvr-systeminfo.d.ts +15 -0
- package/dist/protect-nvr-systeminfo.js +43 -49
- package/dist/protect-nvr-systeminfo.js.map +1 -1
- package/dist/protect-nvr.d.ts +48 -0
- package/dist/protect-nvr.js +327 -359
- package/dist/protect-nvr.js.map +1 -1
- package/dist/protect-options.d.ts +39 -0
- package/dist/protect-options.js +172 -6
- package/dist/protect-options.js.map +1 -1
- package/dist/protect-platform.d.ts +17 -0
- package/dist/protect-platform.js +17 -30
- package/dist/protect-platform.js.map +1 -1
- package/dist/protect-record.d.ts +33 -0
- package/dist/protect-record.js +130 -126
- package/dist/protect-record.js.map +1 -1
- package/dist/protect-rtp.d.ts +29 -0
- package/dist/protect-rtp.js +133 -16
- package/dist/protect-rtp.js.map +1 -1
- package/dist/protect-securitysystem.d.ts +18 -0
- package/dist/protect-securitysystem.js +105 -109
- package/dist/protect-securitysystem.js.map +1 -1
- package/dist/protect-sensor.d.ts +28 -0
- package/dist/protect-sensor.js +79 -97
- package/dist/protect-sensor.js.map +1 -1
- package/dist/protect-stream.d.ts +41 -0
- package/dist/protect-stream.js +298 -156
- package/dist/protect-stream.js.map +1 -1
- package/dist/protect-timeshift.d.ts +30 -0
- package/dist/protect-timeshift.js +65 -48
- package/dist/protect-timeshift.js.map +1 -1
- package/dist/protect-types.d.ts +50 -0
- package/dist/protect-types.js +22 -0
- package/dist/protect-types.js.map +1 -0
- package/dist/protect-viewer.d.ts +17 -0
- package/dist/protect-viewer.js +41 -47
- package/dist/protect-viewer.js.map +1 -1
- package/dist/settings.d.ts +22 -0
- package/dist/settings.js +30 -35
- package/dist/settings.js.map +1 -1
- package/homebridge-ui/public/index.html +715 -0
- package/homebridge-ui/server.js +156 -0
- package/package.json +15 -16
- package/dist/protect-accessory.js +0 -184
- package/dist/protect-accessory.js.map +0 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/* Copyright(C) 2017-2023, HJD (https://github.com/hjdhjd). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* server.js: Homebridge camera streaming delegate implementation for Protect.
|
|
4
|
+
*
|
|
5
|
+
* This module is heavily inspired by the homebridge-config-ui-x source code and borrows from both.
|
|
6
|
+
* Thank you oznu for your contributions to the HomeKit world.
|
|
7
|
+
*/
|
|
8
|
+
/* eslint-disable no-undef */
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
10
|
+
/* jshint node: true,esversion: 9, -W014, -W033 */
|
|
11
|
+
/* eslint-disable new-cap */
|
|
12
|
+
"use strict";
|
|
13
|
+
|
|
14
|
+
import { featureOptionCategories, featureOptions, optionEnabled } from "../dist/protect-options.js";
|
|
15
|
+
import { HomebridgePluginUiServer } from "@homebridge/plugin-ui-utils";
|
|
16
|
+
import { ProtectApi } from "unifi-protect";
|
|
17
|
+
import * as fs from "node:fs";
|
|
18
|
+
|
|
19
|
+
class PluginUiServer extends HomebridgePluginUiServer {
|
|
20
|
+
|
|
21
|
+
constructor () {
|
|
22
|
+
super();
|
|
23
|
+
|
|
24
|
+
// Return the list of Protect devices.
|
|
25
|
+
this.onRequest("/getDevices", async (controller) => {
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
|
|
29
|
+
// Connect to the Protect controller.
|
|
30
|
+
const ufpApi = new ProtectApi();
|
|
31
|
+
|
|
32
|
+
if(!(await ufpApi.login(controller.address, controller.username, controller.password))) {
|
|
33
|
+
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Bootstrap the controller. It will emit a message once it's received the bootstrap JSON, or you can alternatively wait for the Promise to resolve.
|
|
38
|
+
if(!(await ufpApi.getBootstrap())) {
|
|
39
|
+
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const bootstrap = ufpApi.bootstrap;
|
|
44
|
+
|
|
45
|
+
bootstrap.cameras = bootstrap.cameras.filter(x => !x.isAdoptedByOther && x.isAdopted);
|
|
46
|
+
bootstrap.lights = bootstrap.lights.filter(x => !x.isAdoptedByOther && x.isAdopted);
|
|
47
|
+
bootstrap.sensors = bootstrap.sensors.filter(x => !x.isAdoptedByOther && x.isAdopted);
|
|
48
|
+
bootstrap.viewers = bootstrap.viewers.filter(x => !x.isAdoptedByOther && x.isAdopted);
|
|
49
|
+
|
|
50
|
+
bootstrap.cameras.sort((a, b) => {
|
|
51
|
+
|
|
52
|
+
const aCase = a.name.toLowerCase();
|
|
53
|
+
const bCase = b.name.toLowerCase();
|
|
54
|
+
|
|
55
|
+
return aCase > bCase ? 1 : (bCase > aCase ? -1 : 0);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
bootstrap.lights.sort((a, b) => {
|
|
59
|
+
|
|
60
|
+
const aCase = a.name.toLowerCase();
|
|
61
|
+
const bCase = b.name.toLowerCase();
|
|
62
|
+
|
|
63
|
+
return aCase > bCase ? 1 : (bCase > aCase ? -1 : 0);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
bootstrap.sensors.sort((a, b) => {
|
|
67
|
+
|
|
68
|
+
const aCase = a.name.toLowerCase();
|
|
69
|
+
const bCase = b.name.toLowerCase();
|
|
70
|
+
|
|
71
|
+
return aCase > bCase ? 1 : (bCase > aCase ? -1 : 0);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
bootstrap.viewers.sort((a, b) => {
|
|
75
|
+
|
|
76
|
+
const aCase = a.name.toLowerCase();
|
|
77
|
+
const bCase = b.name.toLowerCase();
|
|
78
|
+
|
|
79
|
+
return aCase > bCase ? 1 : (bCase > aCase ? -1 : 0);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return [ ufpApi.bootstrap.nvr, ...ufpApi.bootstrap.cameras, ...ufpApi.bootstrap.lights, ...ufpApi.bootstrap.sensors, ...ufpApi.bootstrap.viewers ];
|
|
83
|
+
} catch(err) {
|
|
84
|
+
|
|
85
|
+
console.log("ERRORING OUT FOR " + controller.address);
|
|
86
|
+
console.log(err);
|
|
87
|
+
|
|
88
|
+
// Return nothing if we error out for some reason.
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Return the list of options configured for a given Protect device.
|
|
94
|
+
this.onRequest("/getOptions", async(request) => {
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
|
|
98
|
+
const optionSet = {};
|
|
99
|
+
|
|
100
|
+
// Loop through all the feature option categories.
|
|
101
|
+
for(const category of featureOptionCategories) {
|
|
102
|
+
|
|
103
|
+
optionSet[category.name] = [];
|
|
104
|
+
|
|
105
|
+
for(const options of featureOptions[category.name]) {
|
|
106
|
+
|
|
107
|
+
options.value = optionEnabled(request.configOptions, request.nvrUfp, request.deviceUfp, category.name + "." + options.name, options.default);
|
|
108
|
+
optionSet[category.name].push(options);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return { categories: featureOptionCategories, options: optionSet };
|
|
113
|
+
|
|
114
|
+
} catch(err) {
|
|
115
|
+
|
|
116
|
+
// Return nothing if we error out for some reason.
|
|
117
|
+
return {};
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Compatibility for older versions of the Homebridge UI.
|
|
122
|
+
this.onRequest("/getCachedAccessories", async () => {
|
|
123
|
+
try {
|
|
124
|
+
|
|
125
|
+
// Define the plugin and create the array to return
|
|
126
|
+
const plugin = "homebridge-unifi-protect";
|
|
127
|
+
const devicesToReturn = [];
|
|
128
|
+
|
|
129
|
+
// The path and file of the cached accessories
|
|
130
|
+
const accFile = this.homebridgeStoragePath + "/accessories/cachedAccessories";
|
|
131
|
+
|
|
132
|
+
// Check the file exists
|
|
133
|
+
if (fs.existsSync(accFile)) {
|
|
134
|
+
|
|
135
|
+
// Read the cached accessories file
|
|
136
|
+
let cachedAccessories = await fs.promises.readFile(accFile);
|
|
137
|
+
|
|
138
|
+
// Parse the JSON
|
|
139
|
+
cachedAccessories = JSON.parse(cachedAccessories);
|
|
140
|
+
|
|
141
|
+
// We only want the accessories for this plugin
|
|
142
|
+
cachedAccessories.filter(accessory => accessory.plugin === plugin).map(accessory => devicesToReturn.push(accessory));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Return the array
|
|
146
|
+
return devicesToReturn;
|
|
147
|
+
} catch (err) {
|
|
148
|
+
// Just return an empty accessory list in case of any errors
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
this.ready();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
(() => new PluginUiServer())();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-unifi-protect",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"displayName": "Homebridge UniFi Protect",
|
|
5
5
|
"description": "Homebridge UniFi Protect plugin providing complete HomeKit integration for the UniFi Protect ecosystem with full support for most features including autoconfiguration, motion detection, multiple controllers, and realtime updates.",
|
|
6
6
|
"author": {
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "http://github.com/hjdhjd/homebridge-unifi-protect/issues"
|
|
18
18
|
},
|
|
19
|
+
"type": "module",
|
|
19
20
|
"engines": {
|
|
20
|
-
"homebridge": ">=1.
|
|
21
|
+
"homebridge": ">=1.4.0",
|
|
21
22
|
"node": ">=12.22.10"
|
|
22
23
|
},
|
|
23
24
|
"keywords": [
|
|
@@ -64,23 +65,21 @@
|
|
|
64
65
|
},
|
|
65
66
|
"main": "dist/index.js",
|
|
66
67
|
"dependencies": {
|
|
67
|
-
"
|
|
68
|
-
"ffmpeg-for-homebridge": "=0.0.10",
|
|
68
|
+
"ffmpeg-for-homebridge": "^0.1.4",
|
|
69
69
|
"mqtt": "4.3.7",
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"ws": "^8.6.0"
|
|
70
|
+
"unifi-protect": "^4.0.0",
|
|
71
|
+
"ws": "^8.13.0"
|
|
73
72
|
},
|
|
74
73
|
"devDependencies": {
|
|
75
74
|
"@types/ip": "^1.1.0",
|
|
76
|
-
"@types/node": "^
|
|
77
|
-
"@types/ws": "^8.5.
|
|
78
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
79
|
-
"@typescript-eslint/parser": "^5.
|
|
80
|
-
"eslint": "^8.
|
|
81
|
-
"homebridge": "
|
|
82
|
-
"nodemon": "^2.0.
|
|
83
|
-
"rimraf": "^
|
|
84
|
-
"typescript": "^
|
|
75
|
+
"@types/node": "^18.15.10",
|
|
76
|
+
"@types/ws": "^8.5.4",
|
|
77
|
+
"@typescript-eslint/eslint-plugin": "^5.56.0",
|
|
78
|
+
"@typescript-eslint/parser": "^5.56.0",
|
|
79
|
+
"eslint": "^8.36.0",
|
|
80
|
+
"homebridge": "=1.5.1",
|
|
81
|
+
"nodemon": "^2.0.22",
|
|
82
|
+
"rimraf": "^4.4.1",
|
|
83
|
+
"typescript": "^5.0.2"
|
|
85
84
|
}
|
|
86
85
|
}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProtectAccessory = exports.ProtectBase = exports.ProtectReservedNames = void 0;
|
|
4
|
-
var ProtectReservedNames;
|
|
5
|
-
(function (ProtectReservedNames) {
|
|
6
|
-
// Manage our contact sensor types.
|
|
7
|
-
ProtectReservedNames["CONTACT_MOTION_SMARTDETECT"] = "ContactMotionSmartDetect";
|
|
8
|
-
ProtectReservedNames["CONTACT_SENSOR"] = "ContactSensor";
|
|
9
|
-
ProtectReservedNames["CONTACT_SENSOR_ALARM_SOUND"] = "ContactAlarmSound";
|
|
10
|
-
// Manage our switch types.
|
|
11
|
-
ProtectReservedNames["SWITCH_DOORBELL_TRIGGER"] = "DoorbellTrigger";
|
|
12
|
-
ProtectReservedNames["SWITCH_DYNAMIC_BITRATE"] = "DynamicBitrate";
|
|
13
|
-
ProtectReservedNames["SWITCH_HKSV_RECORDING"] = "HKSVRecordingSwitch";
|
|
14
|
-
ProtectReservedNames["SWITCH_MOTION_SENSOR"] = "MotionSensorSwitch";
|
|
15
|
-
ProtectReservedNames["SWITCH_MOTION_TRIGGER"] = "MotionSensorTrigger";
|
|
16
|
-
ProtectReservedNames["SWITCH_UFP_RECORDING_ALWAYS"] = "UFPRecordingSwitch.always";
|
|
17
|
-
ProtectReservedNames["SWITCH_UFP_RECORDING_DETECTIONS"] = "UFPRecordingSwitch.detections";
|
|
18
|
-
ProtectReservedNames["SWITCH_UFP_RECORDING_NEVER"] = "UFPRecordingSwitch.never";
|
|
19
|
-
})(ProtectReservedNames = exports.ProtectReservedNames || (exports.ProtectReservedNames = {}));
|
|
20
|
-
class ProtectBase {
|
|
21
|
-
// The constructor initializes key variables and calls configureDevice().
|
|
22
|
-
constructor(nvr) {
|
|
23
|
-
this.api = nvr.platform.api;
|
|
24
|
-
this.debug = nvr.platform.debug.bind(this);
|
|
25
|
-
this.hap = this.api.hap;
|
|
26
|
-
this.log = nvr.platform.log;
|
|
27
|
-
this.nvr = nvr;
|
|
28
|
-
this.nvrApi = nvr.nvrApi;
|
|
29
|
-
this.platform = nvr.platform;
|
|
30
|
-
}
|
|
31
|
-
// Configure the device device information for HomeKit.
|
|
32
|
-
setInfo(accessory, device) {
|
|
33
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
34
|
-
// If we don't have a device, we're done.
|
|
35
|
-
if (!device) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
// Update the manufacturer information for this device.
|
|
39
|
-
(_a = accessory
|
|
40
|
-
.getService(this.hap.Service.AccessoryInformation)) === null || _a === void 0 ? void 0 : _a.updateCharacteristic(this.hap.Characteristic.Manufacturer, "Ubiquiti Networks");
|
|
41
|
-
// Update the model information for this device.
|
|
42
|
-
if ((_b = device.type) === null || _b === void 0 ? void 0 : _b.length) {
|
|
43
|
-
(_c = accessory
|
|
44
|
-
.getService(this.hap.Service.AccessoryInformation)) === null || _c === void 0 ? void 0 : _c.updateCharacteristic(this.hap.Characteristic.Model, device.type);
|
|
45
|
-
}
|
|
46
|
-
// Update the serial number for this device.
|
|
47
|
-
if ((_d = device.mac) === null || _d === void 0 ? void 0 : _d.length) {
|
|
48
|
-
(_e = accessory
|
|
49
|
-
.getService(this.hap.Service.AccessoryInformation)) === null || _e === void 0 ? void 0 : _e.updateCharacteristic(this.hap.Characteristic.SerialNumber, device.mac);
|
|
50
|
-
}
|
|
51
|
-
// Update the hardware revision for this device, if available.
|
|
52
|
-
if ((_f = device.hardwareRevision) === null || _f === void 0 ? void 0 : _f.length) {
|
|
53
|
-
(_g = accessory
|
|
54
|
-
.getService(this.hap.Service.AccessoryInformation)) === null || _g === void 0 ? void 0 : _g.updateCharacteristic(this.hap.Characteristic.HardwareRevision, device.hardwareRevision);
|
|
55
|
-
}
|
|
56
|
-
// Update the firmware revision for this device.
|
|
57
|
-
if ((_h = device.firmwareVersion) === null || _h === void 0 ? void 0 : _h.length) {
|
|
58
|
-
(_j = accessory
|
|
59
|
-
.getService(this.hap.Service.AccessoryInformation)) === null || _j === void 0 ? void 0 : _j.updateCharacteristic(this.hap.Characteristic.FirmwareRevision, device.firmwareVersion);
|
|
60
|
-
}
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
// Utility function to return the fully enumerated name of this camera.
|
|
64
|
-
name() {
|
|
65
|
-
return this.nvr.nvrApi.getNvrName();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.ProtectBase = ProtectBase;
|
|
69
|
-
class ProtectAccessory extends ProtectBase {
|
|
70
|
-
// The constructor initializes key variables and calls configureDevice().
|
|
71
|
-
constructor(nvr, accessory) {
|
|
72
|
-
// Call the constructor of our base class.
|
|
73
|
-
super(nvr);
|
|
74
|
-
// Set the accessory.
|
|
75
|
-
this.accessory = accessory;
|
|
76
|
-
// Configure the device.
|
|
77
|
-
void this.configureDevice();
|
|
78
|
-
}
|
|
79
|
-
// Configure the device device information for HomeKit.
|
|
80
|
-
configureInfo() {
|
|
81
|
-
return this.setInfo(this.accessory, this.accessory.context.device);
|
|
82
|
-
}
|
|
83
|
-
// Configure the Protect motion sensor for HomeKit.
|
|
84
|
-
configureMotionSensor(isEnabled = true) {
|
|
85
|
-
var _a, _b;
|
|
86
|
-
const device = this.accessory.context.device;
|
|
87
|
-
// Find the motion sensor service, if it exists.
|
|
88
|
-
let motionService = this.accessory.getService(this.hap.Service.MotionSensor);
|
|
89
|
-
// Have we disabled motion sensors?
|
|
90
|
-
if (!isEnabled || !((_a = this.nvr) === null || _a === void 0 ? void 0 : _a.optionEnabled(device, "Motion.Sensor"))) {
|
|
91
|
-
if (motionService) {
|
|
92
|
-
this.accessory.removeService(motionService);
|
|
93
|
-
(_b = this.nvr.mqtt) === null || _b === void 0 ? void 0 : _b.unsubscribe(this.accessory, "motion/trigger");
|
|
94
|
-
this.log.info("%s: Disabling motion sensor.", this.name());
|
|
95
|
-
}
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
// We don't have a motion sensor, let's add it to the camera.
|
|
99
|
-
if (!motionService) {
|
|
100
|
-
// We don't have it, add the motion sensor to the camera.
|
|
101
|
-
motionService = new this.hap.Service.MotionSensor(this.accessory.displayName);
|
|
102
|
-
if (!motionService) {
|
|
103
|
-
this.log.error("%s: Unable to add motion sensor.", this.name());
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
this.accessory.addService(motionService);
|
|
107
|
-
this.log.info("%s: Enabling motion sensor.", this.name());
|
|
108
|
-
}
|
|
109
|
-
// Initialize the state of the motion sensor.
|
|
110
|
-
motionService.updateCharacteristic(this.hap.Characteristic.MotionDetected, false);
|
|
111
|
-
motionService.updateCharacteristic(this.hap.Characteristic.StatusActive, device.state === "CONNECTED");
|
|
112
|
-
motionService.getCharacteristic(this.hap.Characteristic.StatusActive).onGet(() => {
|
|
113
|
-
return this.accessory.context.device.state === "CONNECTED";
|
|
114
|
-
});
|
|
115
|
-
this.configureMqttMotionTrigger();
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
// Configure a switch to easily activate or deactivate motion sensor detection for HomeKit.
|
|
119
|
-
configureMotionSwitch() {
|
|
120
|
-
var _a, _b, _c;
|
|
121
|
-
// Find the switch service, if it exists.
|
|
122
|
-
let switchService = this.accessory.getServiceById(this.hap.Service.Switch, ProtectReservedNames.SWITCH_MOTION_SENSOR);
|
|
123
|
-
// Have we disabled motion sensors or the motion switch? Motion switches are disabled by default.
|
|
124
|
-
if (!((_a = this.nvr) === null || _a === void 0 ? void 0 : _a.optionEnabled(this.accessory.context.device, "Motion.Sensor")) ||
|
|
125
|
-
!((_b = this.nvr) === null || _b === void 0 ? void 0 : _b.optionEnabled(this.accessory.context.device, "Motion.Switch", false))) {
|
|
126
|
-
if (switchService) {
|
|
127
|
-
this.accessory.removeService(switchService);
|
|
128
|
-
}
|
|
129
|
-
// If we disable the switch, make sure we fully reset it's state.
|
|
130
|
-
this.accessory.context.detectMotion = true;
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
this.log.info("%s: Enabling motion sensor switch.", this.name());
|
|
134
|
-
// Add the switch to the camera, if needed.
|
|
135
|
-
if (!switchService) {
|
|
136
|
-
switchService = new this.hap.Service.Switch(this.accessory.displayName + " Motion Events", ProtectReservedNames.SWITCH_MOTION_SENSOR);
|
|
137
|
-
if (!switchService) {
|
|
138
|
-
this.log.error("%s: Unable to add motion sensor switch.", this.name());
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
this.accessory.addService(switchService);
|
|
142
|
-
}
|
|
143
|
-
// Activate or deactivate motion detection.
|
|
144
|
-
(_c = switchService
|
|
145
|
-
.getCharacteristic(this.hap.Characteristic.On)) === null || _c === void 0 ? void 0 : _c.onGet(() => {
|
|
146
|
-
return this.accessory.context.detectMotion === true;
|
|
147
|
-
}).onSet((value) => {
|
|
148
|
-
if (this.accessory.context.detectMotion !== value) {
|
|
149
|
-
this.log.info("%s: Motion detection %s.", this.name(), (value === true) ? "enabled" : "disabled");
|
|
150
|
-
}
|
|
151
|
-
this.accessory.context.detectMotion = value === true;
|
|
152
|
-
});
|
|
153
|
-
// Initialize the switch.
|
|
154
|
-
switchService.updateCharacteristic(this.hap.Characteristic.On, this.accessory.context.detectMotion);
|
|
155
|
-
return true;
|
|
156
|
-
}
|
|
157
|
-
// Configure MQTT motion triggers.
|
|
158
|
-
configureMqttMotionTrigger() {
|
|
159
|
-
var _a;
|
|
160
|
-
// Trigger a motion event in MQTT, if requested to do so.
|
|
161
|
-
(_a = this.nvr.mqtt) === null || _a === void 0 ? void 0 : _a.subscribe(this.accessory, "motion/trigger", (message) => {
|
|
162
|
-
const value = message.toString();
|
|
163
|
-
// When we get the right message, we trigger the motion event.
|
|
164
|
-
if ((value === null || value === void 0 ? void 0 : value.toLowerCase()) !== "true") {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
// Trigger the motion event.
|
|
168
|
-
this.nvr.events.motionEventHandler(this.accessory, Date.now());
|
|
169
|
-
this.log.info("%s: Motion event triggered via MQTT.", this.name());
|
|
170
|
-
});
|
|
171
|
-
return true;
|
|
172
|
-
}
|
|
173
|
-
// Utility function for reserved identifiers for switches.
|
|
174
|
-
isReservedName(name) {
|
|
175
|
-
return name === undefined ? false : Object.values(ProtectReservedNames).map(x => x.toUpperCase()).includes(name.toUpperCase());
|
|
176
|
-
}
|
|
177
|
-
// Utility function to return the fully enumerated name of this camera.
|
|
178
|
-
name() {
|
|
179
|
-
var _a;
|
|
180
|
-
return this.nvr.nvrApi.getFullName((_a = this.accessory.context.device) !== null && _a !== void 0 ? _a : null);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
exports.ProtectAccessory = ProtectAccessory;
|
|
184
|
-
//# sourceMappingURL=protect-accessory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protect-accessory.js","sourceRoot":"","sources":["../src/protect-accessory.ts"],"names":[],"mappings":";;;AAgBA,IAAY,oBAgBX;AAhBD,WAAY,oBAAoB;IAE9B,mCAAmC;IACnC,+EAAuD,CAAA;IACvD,wDAAgC,CAAA;IAChC,wEAAgD,CAAA;IAEhD,2BAA2B;IAC3B,mEAA2C,CAAA;IAC3C,iEAAyC,CAAA;IACzC,qEAA6C,CAAA;IAC7C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