hoffmation-base 3.2.3-alpha.8 → 3.2.4
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/lib/devices/CameraDevice.js +1 -1
- package/lib/devices/unifi/own-unifi-camera.d.ts +2 -2
- package/lib/devices/unifi/own-unifi-camera.js +15 -10
- package/lib/devices/unifi/unifi-protect.d.ts +2 -0
- package/lib/devices/unifi/unifi-protect.js +21 -4
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -140,7 +140,7 @@ class CameraDevice extends RoomBaseDevice_1.RoomBaseDevice {
|
|
|
140
140
|
onNewPersonDetectedValue(newValue, source = enums_1.CommandSource.Automatic) {
|
|
141
141
|
this.log(enums_1.LogLevel.Debug, `Update for PersonDetected to value: ${newValue}`);
|
|
142
142
|
if (newValue) {
|
|
143
|
-
this.log(enums_1.LogLevel.Info,
|
|
143
|
+
this.log(enums_1.LogLevel.Info, `Person Detected (${enums_1.CommandSource[source]})`);
|
|
144
144
|
this.resetPersonDetectFallbackTimer();
|
|
145
145
|
}
|
|
146
146
|
this._personDetected = newValue;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CameraDevice } from '../index';
|
|
2
|
-
import { ProtectCameraConfig, ProtectEventPacket } from 'unifi-protect';
|
|
2
|
+
import { ProtectCameraConfig, ProtectEventAdd, ProtectEventPacket } from 'unifi-protect';
|
|
3
3
|
export declare class OwnUnifiCamera extends CameraDevice {
|
|
4
4
|
/**
|
|
5
5
|
* The name of the camera in Unifi
|
|
@@ -18,7 +18,7 @@ export declare class OwnUnifiCamera extends CameraDevice {
|
|
|
18
18
|
/**
|
|
19
19
|
* @inheritDoc
|
|
20
20
|
*/
|
|
21
|
-
update(packet: ProtectEventPacket): void;
|
|
21
|
+
update(packet: ProtectEventPacket, baseEvent?: ProtectEventAdd): void;
|
|
22
22
|
private checkForMotionUpdate;
|
|
23
23
|
initialize(data: ProtectCameraConfig): void;
|
|
24
24
|
protected resetPersonDetectedState(): void;
|
|
@@ -21,29 +21,34 @@ class OwnUnifiCamera extends index_1.CameraDevice {
|
|
|
21
21
|
/**
|
|
22
22
|
* @inheritDoc
|
|
23
23
|
*/
|
|
24
|
-
update(packet) {
|
|
25
|
-
this.checkForMotionUpdate(packet);
|
|
24
|
+
update(packet, baseEvent) {
|
|
25
|
+
this.checkForMotionUpdate(packet, baseEvent);
|
|
26
26
|
this._lastUpdate = new Date();
|
|
27
27
|
}
|
|
28
|
-
checkForMotionUpdate(packet) {
|
|
29
|
-
var _a;
|
|
28
|
+
checkForMotionUpdate(packet, baseEvent) {
|
|
29
|
+
var _a, _b;
|
|
30
30
|
const payload = packet.payload;
|
|
31
|
-
const
|
|
31
|
+
const eventAddInfo = baseEvent !== null && baseEvent !== void 0 ? baseEvent : payload;
|
|
32
|
+
const payloadAsEventAdd = payload;
|
|
32
33
|
if (packet.header.modelKey !== 'smartDetectObject' &&
|
|
33
34
|
(packet.header.modelKey !== 'event' ||
|
|
34
|
-
!['smartDetectLine', 'smartDetectZone'].includes(
|
|
35
|
-
!
|
|
35
|
+
!['smartDetectLine', 'smartDetectZone'].includes(eventAddInfo.type) ||
|
|
36
|
+
!((_a = payloadAsEventAdd.smartDetectTypes) !== null && _a !== void 0 ? _a : []).length)) {
|
|
37
|
+
// this.log(LogLevel.Debug, `Ignored event: ${JSON.stringify(packet)}`);
|
|
38
|
+
// this.log(LogLevel.Debug, `Ignored event initial Info: ${JSON.stringify(baseEvent)}`);
|
|
36
39
|
return;
|
|
37
40
|
}
|
|
38
41
|
this.log(enums_1.LogLevel.Debug, `Update for "${packet.header.modelKey}" to value: ${JSON.stringify(payload)}`);
|
|
39
|
-
const detectedTypes = packet.header.modelKey === 'smartDetectObject'
|
|
42
|
+
const detectedTypes = packet.header.modelKey === 'smartDetectObject'
|
|
43
|
+
? [payloadAsEventAdd.type]
|
|
44
|
+
: ((_b = payloadAsEventAdd === null || payloadAsEventAdd === void 0 ? void 0 : payloadAsEventAdd.smartDetectTypes) !== null && _b !== void 0 ? _b : []);
|
|
40
45
|
for (const smartDetectType of detectedTypes) {
|
|
41
46
|
switch (smartDetectType) {
|
|
42
47
|
case 'licensePlate':
|
|
43
|
-
this.log(enums_1.LogLevel.Debug, `Detected "licensePlate": ${JSON.stringify(
|
|
48
|
+
this.log(enums_1.LogLevel.Debug, `Detected "licensePlate": ${JSON.stringify(payloadAsEventAdd.metadata.licensePlate)}`);
|
|
44
49
|
break;
|
|
45
50
|
case 'person':
|
|
46
|
-
this.onNewPersonDetectedValue(true);
|
|
51
|
+
this.onNewPersonDetectedValue(true, enums_1.CommandSource.Automatic);
|
|
47
52
|
break;
|
|
48
53
|
}
|
|
49
54
|
}
|
|
@@ -9,6 +9,7 @@ export declare class UnifiProtect implements iDisposable {
|
|
|
9
9
|
static readonly ownCameras: Map<string, OwnUnifiCamera>;
|
|
10
10
|
private _deviceStates;
|
|
11
11
|
private _idMap;
|
|
12
|
+
private _eventMap;
|
|
12
13
|
private _lastUpdate;
|
|
13
14
|
constructor(settings: iUnifiProtectOptions);
|
|
14
15
|
private reconnect;
|
|
@@ -16,5 +17,6 @@ export declare class UnifiProtect implements iDisposable {
|
|
|
16
17
|
static addDevice(camera: OwnUnifiCamera): void;
|
|
17
18
|
private initialize;
|
|
18
19
|
private onMessage;
|
|
20
|
+
private rememberAddEvent;
|
|
19
21
|
private initializeCamera;
|
|
20
22
|
}
|
|
@@ -11,6 +11,7 @@ class UnifiProtect {
|
|
|
11
11
|
this.unifiLogger = new unifi_logger_1.UnifiLogger(enums_1.LogSource.UnifiProtect);
|
|
12
12
|
this._deviceStates = new Map();
|
|
13
13
|
this._idMap = new Map();
|
|
14
|
+
this._eventMap = new Map();
|
|
14
15
|
this._lastUpdate = new Date(0);
|
|
15
16
|
this._api = new unifi_protect_1.ProtectApi(this.unifiLogger);
|
|
16
17
|
this.reconnect(settings);
|
|
@@ -23,6 +24,7 @@ class UnifiProtect {
|
|
|
23
24
|
}, 5 * 60 * 1000);
|
|
24
25
|
}
|
|
25
26
|
reconnect(settings) {
|
|
27
|
+
this._eventMap = new Map();
|
|
26
28
|
this._api
|
|
27
29
|
.login(settings.nvrAddress, settings.username, settings.password)
|
|
28
30
|
.then((_loggedIn) => {
|
|
@@ -52,7 +54,7 @@ class UnifiProtect {
|
|
|
52
54
|
this._api.on('message', this.onMessage.bind(this));
|
|
53
55
|
}
|
|
54
56
|
onMessage(packet) {
|
|
55
|
-
var _a, _b;
|
|
57
|
+
var _a, _b, _c, _d;
|
|
56
58
|
const payload = packet.payload;
|
|
57
59
|
this._lastUpdate = new Date();
|
|
58
60
|
switch (packet.header.modelKey) {
|
|
@@ -61,8 +63,15 @@ class UnifiProtect {
|
|
|
61
63
|
default:
|
|
62
64
|
// Lookup the device.
|
|
63
65
|
let id = packet.header.id;
|
|
66
|
+
let baseEvent;
|
|
64
67
|
if (packet.header.action === 'add') {
|
|
65
|
-
|
|
68
|
+
const addEvent = packet.payload;
|
|
69
|
+
id = (_a = addEvent.camera) !== null && _a !== void 0 ? _a : addEvent.cameraId;
|
|
70
|
+
this.rememberAddEvent(packet, addEvent);
|
|
71
|
+
}
|
|
72
|
+
else if (packet.header.action === 'update' && this._eventMap.has(id)) {
|
|
73
|
+
baseEvent = this._eventMap.get(id);
|
|
74
|
+
id = (_c = (_b = baseEvent === null || baseEvent === void 0 ? void 0 : baseEvent.camera) !== null && _b !== void 0 ? _b : baseEvent === null || baseEvent === void 0 ? void 0 : baseEvent.cameraId) !== null && _c !== void 0 ? _c : '';
|
|
66
75
|
}
|
|
67
76
|
const ownName = this._idMap.get(id);
|
|
68
77
|
if (!ownName) {
|
|
@@ -70,14 +79,22 @@ class UnifiProtect {
|
|
|
70
79
|
}
|
|
71
80
|
const ownCamera = UnifiProtect.ownCameras.get(ownName);
|
|
72
81
|
if (ownCamera !== undefined) {
|
|
73
|
-
ownCamera.update(packet);
|
|
82
|
+
ownCamera.update(packet, baseEvent);
|
|
74
83
|
break;
|
|
75
84
|
}
|
|
76
85
|
break;
|
|
77
86
|
}
|
|
78
87
|
// Update the internal list we maintain.
|
|
79
88
|
if (packet.header.action === 'update') {
|
|
80
|
-
this._deviceStates.set(packet.header.id, Object.assign((
|
|
89
|
+
this._deviceStates.set(packet.header.id, Object.assign((_d = this._deviceStates.get(packet.header.id)) !== null && _d !== void 0 ? _d : {}, payload));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
rememberAddEvent(packet, addEvent) {
|
|
93
|
+
if (packet.header.modelKey === 'event') {
|
|
94
|
+
this._eventMap.set(addEvent.id, addEvent);
|
|
95
|
+
utils_1.Utils.guardedTimeout(() => {
|
|
96
|
+
this._eventMap.delete(addEvent.id);
|
|
97
|
+
}, 5 * 60 * 1000, this);
|
|
81
98
|
}
|
|
82
99
|
}
|
|
83
100
|
initializeCamera(data) {
|