iobroker.ring 5.0.6 → 5.0.7
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 +5 -0
- package/admin/i18n/nl.json +1 -1
- package/build/lib/constants.js.map +1 -1
- package/build/lib/lastAction.js.map +1 -1
- package/build/lib/ownRingCamera.js +163 -294
- package/build/lib/ownRingCamera.js.map +1 -1
- package/build/lib/ownRingDevice.js.map +1 -1
- package/build/lib/ownRingIntercom.js.map +1 -1
- package/build/lib/ownRingLocation.js +6 -4
- package/build/lib/ownRingLocation.js.map +1 -1
- package/build/lib/ringApiClient.js +2 -4
- package/build/lib/ringApiClient.js.map +1 -1
- package/build/lib/services/event-blocker.js +34 -0
- package/build/lib/services/event-blocker.js.map +1 -0
- package/build/lib/services/file-service.js +2 -2
- package/build/lib/services/file-service.js.map +1 -1
- package/build/lib/services/image-service.js +53 -0
- package/build/lib/services/image-service.js.map +1 -0
- package/build/lib/services/text-service.js +92 -0
- package/build/lib/services/text-service.js.map +1 -0
- package/build/lib/tools.js.map +1 -1
- package/build/main.js +92 -92
- package/build/main.js.map +1 -1
- package/io-package.json +14 -14
- package/package.json +8 -8
|
@@ -37,6 +37,9 @@ const constants_1 = require("./constants");
|
|
|
37
37
|
const lastAction_1 = require("./lastAction");
|
|
38
38
|
const file_service_1 = require("./services/file-service");
|
|
39
39
|
const ownRingDevice_1 = require("./ownRingDevice");
|
|
40
|
+
const event_blocker_1 = require("./services/event-blocker");
|
|
41
|
+
const image_service_1 = require("./services/image-service");
|
|
42
|
+
const text_service_1 = require("./services/text-service");
|
|
40
43
|
var EventState;
|
|
41
44
|
(function (EventState) {
|
|
42
45
|
EventState[EventState["Idle"] = 0] = "Idle";
|
|
@@ -57,10 +60,14 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
57
60
|
get ringDevice() {
|
|
58
61
|
return this._ringDevice;
|
|
59
62
|
}
|
|
63
|
+
set ringDevice(device) {
|
|
64
|
+
this._ringDevice = device;
|
|
65
|
+
this.subscribeToEvents();
|
|
66
|
+
}
|
|
60
67
|
async startLivestream(duration) {
|
|
61
68
|
this.silly(`${this.shortId}.startLivestream()`);
|
|
62
69
|
duration !== null && duration !== void 0 ? duration : (duration = this._durationLiveStream);
|
|
63
|
-
const { visURL, visPath, fullPath } = await this.prepareLivestreamTargetFile().catch(reason => {
|
|
70
|
+
const { visURL, visPath, fullPath } = await this.prepareLivestreamTargetFile().catch((reason) => {
|
|
64
71
|
this.catcher("Couldn't prepare Livestream Target File.", reason);
|
|
65
72
|
return { visURL: "", visPath: "", fullPath: "" };
|
|
66
73
|
});
|
|
@@ -75,9 +82,9 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
75
82
|
}
|
|
76
83
|
const tempPath = (await file_service_1.FileService.getTempDir(this._adapter)) + `/temp_${this.shortId}_livestream.mp4`;
|
|
77
84
|
const liveCall = await this._ringDevice.streamVideo({
|
|
78
|
-
video:
|
|
85
|
+
video: image_service_1.ImageService.videoFilter(this._adapter.config.overlay_Livestream, this._adapter.dateFormat, this._adapter.language, this._ringDevice.data.description),
|
|
79
86
|
output: ["-t", duration.toString(), tempPath],
|
|
80
|
-
}).catch(reason => {
|
|
87
|
+
}).catch((reason) => {
|
|
81
88
|
this.catcher("Couldn't create Livestream.", reason);
|
|
82
89
|
return null;
|
|
83
90
|
});
|
|
@@ -86,9 +93,9 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
86
93
|
await this.updateLivestreamRequest(false);
|
|
87
94
|
return;
|
|
88
95
|
}
|
|
89
|
-
const liveCallSucceeded = await rxjs.firstValueFrom(liveCall.onCallEnded).then(_result => {
|
|
96
|
+
const liveCallSucceeded = await rxjs.firstValueFrom(liveCall.onCallEnded).then((_result) => {
|
|
90
97
|
return true;
|
|
91
|
-
}).catch(reason => {
|
|
98
|
+
}).catch((reason) => {
|
|
92
99
|
this.catcher("Couldn't create HD Snapshot.", reason);
|
|
93
100
|
return null;
|
|
94
101
|
});
|
|
@@ -123,7 +130,7 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
123
130
|
var _a;
|
|
124
131
|
this.silly(`${this.shortId}.takeHDSnapshot()`);
|
|
125
132
|
// const duration = 2.0;
|
|
126
|
-
const { visURL, visPath } = await file_service_1.FileService.getVisUrl(this._adapter, this.fullId, "HDSnapshot.jpg").catch(reason => {
|
|
133
|
+
const { visURL, visPath } = await file_service_1.FileService.getVisUrl(this._adapter, this.fullId, "HDSnapshot.jpg").catch((reason) => {
|
|
127
134
|
this.catcher("Couldn't get Vis URL.", reason);
|
|
128
135
|
return { visURL: "", visPath: "" };
|
|
129
136
|
});
|
|
@@ -147,10 +154,10 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
147
154
|
const { night_contrast, night_sharpen } = this.getActiveNightImageOptions();
|
|
148
155
|
const tempPath = (await file_service_1.FileService.getTempDir(this._adapter)) + `/temp_${this.shortId}_livestream.jpg`;
|
|
149
156
|
const liveCall = await this._ringDevice.streamVideo({
|
|
150
|
-
video:
|
|
157
|
+
video: image_service_1.ImageService.videoFilter(this._adapter.config.overlay_HDsnapshot, this._adapter.dateFormat, this._adapter.language, this._ringDevice.data.description, night_contrast ? this._adapter.config.contrast_HDsnapshot : 0),
|
|
151
158
|
// output: ["-t", duration.toString(), "-f", "mjpeg", "-q:v", 3, "-frames:v", 1, tempPath]
|
|
152
159
|
output: ["-f", "mjpeg", "-q:v", 3, "-frames:v", 1, tempPath]
|
|
153
|
-
}).catch(reason => {
|
|
160
|
+
}).catch((reason) => {
|
|
154
161
|
this.catcher("Couldn't create HD Snapshot.", reason);
|
|
155
162
|
return null;
|
|
156
163
|
});
|
|
@@ -159,9 +166,9 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
159
166
|
await this.updateHDSnapshotRequest(false);
|
|
160
167
|
return;
|
|
161
168
|
}
|
|
162
|
-
const liveCallSucceeded = await rxjs.firstValueFrom(liveCall.onCallEnded).then(_result => {
|
|
169
|
+
const liveCallSucceeded = await rxjs.firstValueFrom(liveCall.onCallEnded).then((_result) => {
|
|
163
170
|
return true;
|
|
164
|
-
}).catch(reason => {
|
|
171
|
+
}).catch((reason) => {
|
|
165
172
|
this.catcher("Couldn't create HD Snapshot.", reason);
|
|
166
173
|
return null;
|
|
167
174
|
});
|
|
@@ -175,11 +182,13 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
175
182
|
}
|
|
176
183
|
let jpg = fs.readFileSync(tempPath);
|
|
177
184
|
if (night_sharpen && this._adapter.config.sharpen_HDsnapshot && this._adapter.config.sharpen_HDsnapshot > 0) {
|
|
178
|
-
const sharpen = this._adapter.config.sharpen_HDsnapshot == 1
|
|
185
|
+
const sharpen = this._adapter.config.sharpen_HDsnapshot == 1
|
|
186
|
+
? undefined
|
|
187
|
+
: { sigma: this._adapter.config.sharpen_HDsnapshot - 1 };
|
|
179
188
|
jpg = (_a = await (0, sharp_1.default)(jpg)
|
|
180
189
|
.sharpen(sharpen)
|
|
181
190
|
.toBuffer()
|
|
182
|
-
.catch(reason => {
|
|
191
|
+
.catch((reason) => {
|
|
183
192
|
this.catcher("Couldn't sharpen HD Snapshot.", reason);
|
|
184
193
|
return null;
|
|
185
194
|
})) !== null && _a !== void 0 ? _a : jpg;
|
|
@@ -259,11 +268,12 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
259
268
|
}
|
|
260
269
|
let image_txt = image;
|
|
261
270
|
if (this._adapter.config.overlay_snapshot) {
|
|
262
|
-
image_txt =
|
|
263
|
-
.
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
271
|
+
image_txt =
|
|
272
|
+
await image_service_1.ImageService.addTextToJpgBuffer(image, this._ringDevice.data.description, (0, strftime_1.default)(`${text_service_1.TextService.getTodayName(this._adapter.language)}, ${text_service_1.TextService.getDateFormat(this._adapter.dateFormat)} %T`))
|
|
273
|
+
.catch((reason) => {
|
|
274
|
+
this.catcher("Couldn't add text to Snapshot.", reason);
|
|
275
|
+
return reason;
|
|
276
|
+
});
|
|
267
277
|
}
|
|
268
278
|
if (this._lastSnapShotDir !== "" && this._adapter.config.del_old_snapshot) {
|
|
269
279
|
file_service_1.FileService.deleteFileIfExistSync(this._lastSnapShotDir, this._adapter);
|
|
@@ -280,42 +290,6 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
280
290
|
await this.updateSnapshotObject();
|
|
281
291
|
this.debug(`Done creating snapshot to ${fullPath}`);
|
|
282
292
|
}
|
|
283
|
-
async prepareLivestreamTargetFile() {
|
|
284
|
-
const { visURL, visPath } = await file_service_1.FileService.getVisUrl(this._adapter, this.fullId, "Livestream.mp4").catch(reason => {
|
|
285
|
-
this.catcher("Couldn't get Vis URL.", reason);
|
|
286
|
-
return { visURL: "", visPath: "" };
|
|
287
|
-
});
|
|
288
|
-
return new Promise(async (resolve, reject) => {
|
|
289
|
-
if (!visURL || !visPath) {
|
|
290
|
-
reject("Vis not available");
|
|
291
|
-
}
|
|
292
|
-
const { fullPath, dirname } = file_service_1.FileService.getPath(this._adapter.config.path_livestream, this._adapter.config.filename_livestream, ++this._liveStreamCount, this.shortId, this.fullId, this.kind);
|
|
293
|
-
const folderPrepared = await file_service_1.FileService.prepareFolder(dirname).catch(reason => {
|
|
294
|
-
this.catcher("Couldn't prepare folder.", reason);
|
|
295
|
-
return false;
|
|
296
|
-
});
|
|
297
|
-
if (!folderPrepared) {
|
|
298
|
-
this.warn(`Failed to prepare Livestream folder ("${fullPath}")`);
|
|
299
|
-
reject("Failed to prepare Livestream folder");
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
file_service_1.FileService.deleteFileIfExistSync(fullPath, this._adapter);
|
|
303
|
-
resolve({ visURL: visURL, visPath: visPath, fullPath: fullPath });
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
getActiveNightImageOptions() {
|
|
307
|
-
let night_contrast = false;
|
|
308
|
-
let night_sharpen = false;
|
|
309
|
-
if (this._adapter.Sunrise > 0 && this._adapter.Sunset > 0) {
|
|
310
|
-
const today = Date.now();
|
|
311
|
-
this.silly(`Now: ${today}, sunrise: ${this._adapter.Sunrise}, sunset: ${this._adapter.Sunset}`);
|
|
312
|
-
const isNight = today < this._adapter.Sunrise || today > this._adapter.Sunset;
|
|
313
|
-
this.debug(`is Night: ${isNight}`);
|
|
314
|
-
night_contrast = this._adapter.config.night_contrast_HDsnapshot && isNight || !this._adapter.config.night_contrast_HDsnapshot;
|
|
315
|
-
night_sharpen = this._adapter.config.night_sharpen_HDsnapshot && isNight || !this._adapter.config.night_sharpen_HDsnapshot;
|
|
316
|
-
}
|
|
317
|
-
return { night_contrast, night_sharpen };
|
|
318
|
-
}
|
|
319
293
|
async updateHistory() {
|
|
320
294
|
this.silly(`Update History`);
|
|
321
295
|
this._ringDevice.getEvents({ limit: 50 })
|
|
@@ -340,90 +314,6 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
340
314
|
this.updateHistoryObject(this.lastAction);
|
|
341
315
|
});
|
|
342
316
|
}
|
|
343
|
-
getDay() {
|
|
344
|
-
const en = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
|
|
345
|
-
const de = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"];
|
|
346
|
-
const ru = ["Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота", "Воскресенье"];
|
|
347
|
-
const pt = ["segunda-feira", "terça-feira", "quarta-feira", "quinta-feira", "sexta-feira", "sábado", "domingo"];
|
|
348
|
-
const nl = ["maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag", "zondag"];
|
|
349
|
-
const fr = ["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"];
|
|
350
|
-
const it = ["lunedì", "martedì", "mercoledì", "giovedì", "venerdì", "sabato", "domenica"];
|
|
351
|
-
const es = ["Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo"];
|
|
352
|
-
const pl = ["Poniedziałek", "Wtorek", "Środa", "Czwartek", "Piątek", "Sobota", "Niedziela"];
|
|
353
|
-
const uk = ["понеділок", "вівторок", "середа", "четвер", "п'ятниця", "субота", "неділя"];
|
|
354
|
-
const zh = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"];
|
|
355
|
-
const dow = (new Date().getDay() + 6) % 7;
|
|
356
|
-
switch (this._adapter.language) {
|
|
357
|
-
case "en":
|
|
358
|
-
return en[dow];
|
|
359
|
-
case "de":
|
|
360
|
-
return de[dow];
|
|
361
|
-
case "ru":
|
|
362
|
-
return ru[dow];
|
|
363
|
-
case "pt":
|
|
364
|
-
return pt[dow];
|
|
365
|
-
case "nl":
|
|
366
|
-
return nl[dow];
|
|
367
|
-
case "fr":
|
|
368
|
-
return fr[dow];
|
|
369
|
-
case "it":
|
|
370
|
-
return it[dow];
|
|
371
|
-
case "es":
|
|
372
|
-
return es[dow];
|
|
373
|
-
case "uk":
|
|
374
|
-
return uk[dow];
|
|
375
|
-
case "pl":
|
|
376
|
-
return pl[dow];
|
|
377
|
-
case "uk":
|
|
378
|
-
return uk[dow];
|
|
379
|
-
case "zh-cn":
|
|
380
|
-
return zh[dow];
|
|
381
|
-
}
|
|
382
|
-
return en[dow];
|
|
383
|
-
}
|
|
384
|
-
set ringDevice(device) {
|
|
385
|
-
this._ringDevice = device;
|
|
386
|
-
this.subscribeToEvents();
|
|
387
|
-
}
|
|
388
|
-
constructor(ringDevice, location, adapter, apiClient) {
|
|
389
|
-
super(location, adapter, apiClient, OwnRingCamera.evaluateKind(ringDevice.deviceType, adapter, ringDevice), `${ringDevice.id}`, ringDevice.data.description);
|
|
390
|
-
this._durationLiveStream = this._adapter.config.recordtime_livestream;
|
|
391
|
-
this._lastLightCommand = 0;
|
|
392
|
-
this._lastLiveStreamUrl = "";
|
|
393
|
-
this._lastLiveStreamDir = "";
|
|
394
|
-
this._lastLiveStreamTimestamp = 0;
|
|
395
|
-
this._lastSnapShotUrl = "";
|
|
396
|
-
this._lastSnapShotDir = "";
|
|
397
|
-
this._lastSnapshotTimestamp = 0;
|
|
398
|
-
this._snapshotCount = 0;
|
|
399
|
-
this._lastHDSnapShotUrl = "";
|
|
400
|
-
this._lastHDSnapShotDir = "";
|
|
401
|
-
this._lastHDSnapshotTimestamp = 0;
|
|
402
|
-
this._HDsnapshotCount = 0;
|
|
403
|
-
this._liveStreamCount = 0;
|
|
404
|
-
this._state = EventState.Idle;
|
|
405
|
-
this._lastDoorbellEvent = 0;
|
|
406
|
-
this._lastMotionEvent = 0;
|
|
407
|
-
this._ringDevice = ringDevice;
|
|
408
|
-
this.debug(`Create device`);
|
|
409
|
-
this.infoChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_INFO}`;
|
|
410
|
-
this.historyChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_HISTORY}`;
|
|
411
|
-
this.lightChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_LIGHT}`;
|
|
412
|
-
this.snapshotChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_SNAPSHOT}`;
|
|
413
|
-
this.HDsnapshotChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_HDSNAPSHOT}`;
|
|
414
|
-
this.liveStreamChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_LIVESTREAM}`;
|
|
415
|
-
this.eventsChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_EVENTS}`;
|
|
416
|
-
this.recreateDeviceObjectTree();
|
|
417
|
-
this.updateDeviceInfoObject(ringDevice.data);
|
|
418
|
-
this.updateHealth();
|
|
419
|
-
// noinspection JSIgnoredPromiseFromCall
|
|
420
|
-
this.updateHistory();
|
|
421
|
-
this.updateSnapshotObject();
|
|
422
|
-
this.updateHDSnapshotObject();
|
|
423
|
-
this.updateLiveStreamObject();
|
|
424
|
-
this.ringDevice = ringDevice; // subscribes to the events
|
|
425
|
-
this.autoSched();
|
|
426
|
-
}
|
|
427
317
|
async processUserInput(channelID, stateID, state) {
|
|
428
318
|
switch (channelID) {
|
|
429
319
|
case "":
|
|
@@ -461,7 +351,7 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
461
351
|
const targetVal = state.val;
|
|
462
352
|
this._adapter.log.debug(`Get Snapshot request for ${this.shortId} to value ${targetVal}`);
|
|
463
353
|
if (targetVal) {
|
|
464
|
-
await this.takeSnapshot().catch(reason => {
|
|
354
|
+
await this.takeSnapshot().catch((reason) => {
|
|
465
355
|
this.updateSnapshotRequest();
|
|
466
356
|
this.catcher("Couldn't retrieve Snapshot.", reason);
|
|
467
357
|
});
|
|
@@ -491,7 +381,7 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
491
381
|
const targetVal = state.val;
|
|
492
382
|
this._adapter.log.debug(`Get Livestream request for ${this.shortId} to value ${targetVal}`);
|
|
493
383
|
if (targetVal) {
|
|
494
|
-
await this.startLivestream().catch(reason => {
|
|
384
|
+
await this.startLivestream().catch((reason) => {
|
|
495
385
|
this.updateLivestreamRequest();
|
|
496
386
|
this.catcher("Couldn't retrieve Livestream.", reason);
|
|
497
387
|
});
|
|
@@ -510,6 +400,120 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
510
400
|
this._adapter.log.error(`Unknown State/Switch with channel "${channelID}" and state "${stateID}"`);
|
|
511
401
|
}
|
|
512
402
|
}
|
|
403
|
+
async recreateDeviceObjectTree() {
|
|
404
|
+
this.silly(`Recreate DeviceObjectTree`);
|
|
405
|
+
this._adapter.createDevice(this.fullId, {
|
|
406
|
+
name: `Device ${this.shortId} ("${this._ringDevice.data.description}")`,
|
|
407
|
+
});
|
|
408
|
+
this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_INFO, { name: `Info ${this.shortId}` });
|
|
409
|
+
this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_SNAPSHOT, { name: `Snapshot ${this.shortId}` });
|
|
410
|
+
this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_HDSNAPSHOT, { name: `HD Snapshot ${this.shortId}` });
|
|
411
|
+
this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_LIVESTREAM, { name: `Livestream ${this.shortId}` });
|
|
412
|
+
this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_HISTORY);
|
|
413
|
+
this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_EVENTS);
|
|
414
|
+
if (this._ringDevice.hasLight) {
|
|
415
|
+
this.debug(`Device with Light Capabilities detected`);
|
|
416
|
+
this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_LIGHT, { name: `Light ${this.shortId}` });
|
|
417
|
+
this._adapter.upsertState(`${this.lightChannelId}.${constants_1.STATE_ID_LIGHT_SWITCH}`, constants_1.COMMON_LIGHT_SWITCH, false, true, true);
|
|
418
|
+
}
|
|
419
|
+
this._lastSnapShotDir = await this._adapter.tryGetStringState(`${this.snapshotChannelId}.file`);
|
|
420
|
+
this._lastHDSnapShotDir = await this._adapter.tryGetStringState(`${this.HDsnapshotChannelId}.file`);
|
|
421
|
+
this._lastLiveStreamDir = await this._adapter.tryGetStringState(`${this.liveStreamChannelId}.file`);
|
|
422
|
+
if (this._adapter.config.auto_snapshot === undefined)
|
|
423
|
+
this._adapter.config.auto_snapshot = false;
|
|
424
|
+
if (this._adapter.config.auto_HDsnapshot === undefined)
|
|
425
|
+
this._adapter.config.auto_HDsnapshot = false;
|
|
426
|
+
if (this._adapter.config.auto_livestream === undefined)
|
|
427
|
+
this._adapter.config.auto_livestream = false;
|
|
428
|
+
this._adapter.upsertState(`${this.fullId}.${constants_1.STATE_ID_DEBUG_REQUEST}`, constants_1.COMMON_DEBUG_REQUEST, false, true, true);
|
|
429
|
+
this._adapter.upsertState(`${this.snapshotChannelId}.auto`, constants_1.COMMON_SNAPSHOT_AUTO, this._adapter.config.auto_snapshot, true, true);
|
|
430
|
+
this._adapter.upsertState(`${this.HDsnapshotChannelId}.auto`, constants_1.COMMON_HDSNAPSHOT_AUTO, this._adapter.config.auto_HDsnapshot, true, true);
|
|
431
|
+
this._adapter.upsertState(`${this.liveStreamChannelId}.auto`, constants_1.COMMON_LIVESTREAM_AUTO, this._adapter.config.auto_livestream, true, true);
|
|
432
|
+
// Remove legacy states
|
|
433
|
+
this._adapter.delObject(`${this.snapshotChannelId}.snapshot_request`);
|
|
434
|
+
this._adapter.delObject(`${this.snapshotChannelId}.snapshot_file`);
|
|
435
|
+
this._adapter.delObject(`${this.snapshotChannelId}.snapshot_url`);
|
|
436
|
+
this._adapter.delObject(`${this.liveStreamChannelId}.livestream_request`);
|
|
437
|
+
this._adapter.delObject(`${this.liveStreamChannelId}.livestream_file`);
|
|
438
|
+
this._adapter.delObject(`${this.liveStreamChannelId}.livestream_url`);
|
|
439
|
+
}
|
|
440
|
+
async prepareLivestreamTargetFile() {
|
|
441
|
+
const { visURL, visPath } = await file_service_1.FileService.getVisUrl(this._adapter, this.fullId, "Livestream.mp4").catch((reason) => {
|
|
442
|
+
this.catcher("Couldn't get Vis URL.", reason);
|
|
443
|
+
return { visURL: "", visPath: "" };
|
|
444
|
+
});
|
|
445
|
+
return new Promise(async (resolve, reject) => {
|
|
446
|
+
if (!visURL || !visPath) {
|
|
447
|
+
reject("Vis not available");
|
|
448
|
+
}
|
|
449
|
+
const { fullPath, dirname } = file_service_1.FileService.getPath(this._adapter.config.path_livestream, this._adapter.config.filename_livestream, ++this._liveStreamCount, this.shortId, this.fullId, this.kind);
|
|
450
|
+
const folderPrepared = await file_service_1.FileService.prepareFolder(dirname).catch((reason) => {
|
|
451
|
+
this.catcher("Couldn't prepare folder.", reason);
|
|
452
|
+
return false;
|
|
453
|
+
});
|
|
454
|
+
if (!folderPrepared) {
|
|
455
|
+
this.warn(`Failed to prepare Livestream folder ("${fullPath}")`);
|
|
456
|
+
reject("Failed to prepare Livestream folder");
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
file_service_1.FileService.deleteFileIfExistSync(fullPath, this._adapter);
|
|
460
|
+
resolve({ visURL: visURL, visPath: visPath, fullPath: fullPath });
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
constructor(ringDevice, location, adapter, apiClient) {
|
|
464
|
+
super(location, adapter, apiClient, OwnRingCamera.evaluateKind(ringDevice.deviceType, adapter, ringDevice), `${ringDevice.id}`, ringDevice.data.description);
|
|
465
|
+
this._durationLiveStream = this._adapter.config.recordtime_livestream;
|
|
466
|
+
this._lastLightCommand = 0;
|
|
467
|
+
this._lastLiveStreamUrl = "";
|
|
468
|
+
this._lastLiveStreamTimestamp = 0;
|
|
469
|
+
this._lastSnapShotUrl = "";
|
|
470
|
+
this._lastSnapshotTimestamp = 0;
|
|
471
|
+
this._snapshotCount = 0;
|
|
472
|
+
this._lastHDSnapShotUrl = "";
|
|
473
|
+
this._lastHDSnapshotTimestamp = 0;
|
|
474
|
+
this._HDsnapshotCount = 0;
|
|
475
|
+
this._liveStreamCount = 0;
|
|
476
|
+
this._state = EventState.Idle;
|
|
477
|
+
this._lastLiveStreamDir = "";
|
|
478
|
+
this._lastSnapShotDir = "";
|
|
479
|
+
this._eventBlocker = {
|
|
480
|
+
motion: new event_blocker_1.EventBlocker(),
|
|
481
|
+
ding: new event_blocker_1.EventBlocker(),
|
|
482
|
+
};
|
|
483
|
+
this._lastHDSnapShotDir = "";
|
|
484
|
+
this._ringDevice = ringDevice;
|
|
485
|
+
this.debug(`Create device`);
|
|
486
|
+
this.infoChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_INFO}`;
|
|
487
|
+
this.historyChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_HISTORY}`;
|
|
488
|
+
this.lightChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_LIGHT}`;
|
|
489
|
+
this.snapshotChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_SNAPSHOT}`;
|
|
490
|
+
this.HDsnapshotChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_HDSNAPSHOT}`;
|
|
491
|
+
this.liveStreamChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_LIVESTREAM}`;
|
|
492
|
+
this.eventsChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_EVENTS}`;
|
|
493
|
+
this.recreateDeviceObjectTree();
|
|
494
|
+
this.updateDeviceInfoObject(ringDevice.data);
|
|
495
|
+
this.updateHealth();
|
|
496
|
+
// noinspection JSIgnoredPromiseFromCall
|
|
497
|
+
this.updateHistory();
|
|
498
|
+
this.updateSnapshotObject();
|
|
499
|
+
this.updateHDSnapshotObject();
|
|
500
|
+
this.updateLiveStreamObject();
|
|
501
|
+
this.ringDevice = ringDevice; // subscribes to the events
|
|
502
|
+
this.autoSched();
|
|
503
|
+
}
|
|
504
|
+
getActiveNightImageOptions() {
|
|
505
|
+
let night_contrast = false;
|
|
506
|
+
let night_sharpen = false;
|
|
507
|
+
if (this._adapter.Sunrise > 0 && this._adapter.Sunset > 0) {
|
|
508
|
+
const today = Date.now();
|
|
509
|
+
this.silly(`Now: ${today}, sunrise: ${this._adapter.Sunrise}, sunset: ${this._adapter.Sunset}`);
|
|
510
|
+
const isNight = today < this._adapter.Sunrise || today > this._adapter.Sunset;
|
|
511
|
+
this.debug(`is Night: ${isNight}`);
|
|
512
|
+
night_contrast = this._adapter.config.night_contrast_HDsnapshot && isNight || !this._adapter.config.night_contrast_HDsnapshot;
|
|
513
|
+
night_sharpen = this._adapter.config.night_sharpen_HDsnapshot && isNight || !this._adapter.config.night_sharpen_HDsnapshot;
|
|
514
|
+
}
|
|
515
|
+
return { night_contrast, night_sharpen };
|
|
516
|
+
}
|
|
513
517
|
updateByDevice(ringDevice) {
|
|
514
518
|
this.ringDevice = ringDevice;
|
|
515
519
|
this._state = EventState.Idle;
|
|
@@ -530,95 +534,6 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
530
534
|
this._adapter.upsertState(`${this.liveStreamChannelId}.${constants_1.STATE_ID_LIVESTREAM_DURATION}`, constants_1.COMMON_LIVESTREAM_DURATION, this._durationLiveStream, true);
|
|
531
535
|
this.debug(`Livestream duration set to: ${val}`);
|
|
532
536
|
}
|
|
533
|
-
getDateFormat() {
|
|
534
|
-
let sPattern = "/";
|
|
535
|
-
if (!this._adapter.dateFormat.includes(sPattern)) {
|
|
536
|
-
sPattern = "-";
|
|
537
|
-
if (!this._adapter.dateFormat.includes(sPattern)) {
|
|
538
|
-
sPattern = ".";
|
|
539
|
-
if (!this._adapter.dateFormat.includes(sPattern))
|
|
540
|
-
return "%y/%m/%d";
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
let rDate = "";
|
|
544
|
-
for (const val of this._adapter.dateFormat.split(sPattern)) {
|
|
545
|
-
switch (val) {
|
|
546
|
-
case "YYYY":
|
|
547
|
-
rDate += "%y";
|
|
548
|
-
break;
|
|
549
|
-
case "YY":
|
|
550
|
-
rDate += "%y";
|
|
551
|
-
break;
|
|
552
|
-
case "Y":
|
|
553
|
-
rDate += "%Y";
|
|
554
|
-
break;
|
|
555
|
-
case "MMMM":
|
|
556
|
-
rDate += "%B";
|
|
557
|
-
break;
|
|
558
|
-
case "MMM":
|
|
559
|
-
rDate += "%b";
|
|
560
|
-
break;
|
|
561
|
-
case "MM":
|
|
562
|
-
rDate += "%m";
|
|
563
|
-
break;
|
|
564
|
-
case "M":
|
|
565
|
-
rDate += "%-m";
|
|
566
|
-
break;
|
|
567
|
-
case "DD":
|
|
568
|
-
rDate += "%d";
|
|
569
|
-
break;
|
|
570
|
-
case "D":
|
|
571
|
-
rDate += "%-d";
|
|
572
|
-
break;
|
|
573
|
-
}
|
|
574
|
-
rDate = rDate + sPattern;
|
|
575
|
-
}
|
|
576
|
-
rDate = rDate.slice(0, rDate.length - 1);
|
|
577
|
-
return rDate;
|
|
578
|
-
}
|
|
579
|
-
videoFilter(overlay, startTime = 0) {
|
|
580
|
-
const start = `00:00:0${startTime.toString()}`;
|
|
581
|
-
const filter = `drawtext='
|
|
582
|
-
fontsize=30:
|
|
583
|
-
fontcolor=white:
|
|
584
|
-
x=(main_w-text_w-20):
|
|
585
|
-
y=20:shadowcolor=black:
|
|
586
|
-
shadowx=2:
|
|
587
|
-
shadowy=2:
|
|
588
|
-
text=${this._ringDevice.data.description}',
|
|
589
|
-
drawtext='
|
|
590
|
-
fontsize=30:
|
|
591
|
-
fontcolor=white:
|
|
592
|
-
x=20:
|
|
593
|
-
y=(main_h-text_h-20):
|
|
594
|
-
shadowcolor=black:
|
|
595
|
-
shadowx=2:
|
|
596
|
-
shadowy=2:
|
|
597
|
-
text=%{localtime\\:${this.getDay()}, ${this.getDateFormat()} %T}'`;
|
|
598
|
-
return (overlay && startTime > 0 ? ["-ss", start, "-vf", filter] :
|
|
599
|
-
(overlay ? ["-vf", filter] :
|
|
600
|
-
(startTime > 0 ? ["-ss", start] : [])));
|
|
601
|
-
}
|
|
602
|
-
async addText(jpg) {
|
|
603
|
-
const width = 640;
|
|
604
|
-
const height = 360;
|
|
605
|
-
const font_size = 15;
|
|
606
|
-
const border_dist = 10;
|
|
607
|
-
const text1 = this._ringDevice.data.description;
|
|
608
|
-
const text2 = (0, strftime_1.default)(`${this.getDay()}, ${this.getDateFormat()} %T`);
|
|
609
|
-
const svgText = `
|
|
610
|
-
<svg width="${width}" height="${height}">
|
|
611
|
-
<style>
|
|
612
|
-
.title { fill: white; font-size: ${font_size}px; filter: drop-shadow(2px 2px 1px rgb(0 0 0 / 0.9))}
|
|
613
|
-
</style>
|
|
614
|
-
<text x="${width - border_dist}" y="${border_dist + font_size}" text-anchor="end" class="title">${text1}</text>
|
|
615
|
-
<text x="10" y="${height - border_dist}" text-anchor="start" class="title">${text2}</text>
|
|
616
|
-
</svg>`;
|
|
617
|
-
const svgBuffer = Buffer.from(svgText);
|
|
618
|
-
return (0, sharp_1.default)(jpg)
|
|
619
|
-
.composite([{ input: svgBuffer, left: 0, top: 0 }])
|
|
620
|
-
.toBuffer();
|
|
621
|
-
}
|
|
622
537
|
updateHealth() {
|
|
623
538
|
this.silly(`Update Health`);
|
|
624
539
|
this._ringDevice.getHealth().then(this.updateHealthObject.bind(this));
|
|
@@ -626,19 +541,28 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
626
541
|
autoSched() {
|
|
627
542
|
const media = [
|
|
628
543
|
{
|
|
629
|
-
name: "Snaspshot",
|
|
544
|
+
name: "Snaspshot",
|
|
545
|
+
val: this._adapter.config.save_snapshot,
|
|
546
|
+
fct: () => {
|
|
630
547
|
this.takeSnapshot();
|
|
631
|
-
},
|
|
548
|
+
},
|
|
549
|
+
start: 0
|
|
632
550
|
},
|
|
633
551
|
{
|
|
634
|
-
name: "HD Snapshot",
|
|
552
|
+
name: "HD Snapshot",
|
|
553
|
+
val: this._adapter.config.save_HDsnapshot,
|
|
554
|
+
fct: () => {
|
|
635
555
|
this.takeHDSnapshot();
|
|
636
|
-
},
|
|
556
|
+
},
|
|
557
|
+
start: 2
|
|
637
558
|
},
|
|
638
559
|
{
|
|
639
|
-
name: "Livestream",
|
|
560
|
+
name: "Livestream",
|
|
561
|
+
val: this._adapter.config.save_livestream,
|
|
562
|
+
fct: () => {
|
|
640
563
|
this.startLivestream();
|
|
641
|
-
},
|
|
564
|
+
},
|
|
565
|
+
start: 4
|
|
642
566
|
}
|
|
643
567
|
];
|
|
644
568
|
for (const m of media) {
|
|
@@ -662,43 +586,6 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
662
586
|
}
|
|
663
587
|
}
|
|
664
588
|
}
|
|
665
|
-
async recreateDeviceObjectTree() {
|
|
666
|
-
this.silly(`Recreate DeviceObjectTree`);
|
|
667
|
-
this._adapter.createDevice(this.fullId, {
|
|
668
|
-
name: `Device ${this.shortId} ("${this._ringDevice.data.description}")`,
|
|
669
|
-
});
|
|
670
|
-
this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_INFO, { name: `Info ${this.shortId}` });
|
|
671
|
-
this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_SNAPSHOT, { name: `Snapshot ${this.shortId}` });
|
|
672
|
-
this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_HDSNAPSHOT, { name: `HD Snapshot ${this.shortId}` });
|
|
673
|
-
this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_LIVESTREAM, { name: `Livestream ${this.shortId}` });
|
|
674
|
-
this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_HISTORY);
|
|
675
|
-
this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_EVENTS);
|
|
676
|
-
if (this._ringDevice.hasLight) {
|
|
677
|
-
this.debug(`Device with Light Capabilities detected`);
|
|
678
|
-
this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_LIGHT, { name: `Light ${this.shortId}` });
|
|
679
|
-
this._adapter.upsertState(`${this.lightChannelId}.${constants_1.STATE_ID_LIGHT_SWITCH}`, constants_1.COMMON_LIGHT_SWITCH, false, true, true);
|
|
680
|
-
}
|
|
681
|
-
this._lastSnapShotDir = await this._adapter.tryGetStringState(`${this.snapshotChannelId}.file`);
|
|
682
|
-
this._lastHDSnapShotDir = await this._adapter.tryGetStringState(`${this.HDsnapshotChannelId}.file`);
|
|
683
|
-
this._lastLiveStreamDir = await this._adapter.tryGetStringState(`${this.liveStreamChannelId}.file`);
|
|
684
|
-
if (this._adapter.config.auto_snapshot === undefined)
|
|
685
|
-
this._adapter.config.auto_snapshot = false;
|
|
686
|
-
if (this._adapter.config.auto_HDsnapshot === undefined)
|
|
687
|
-
this._adapter.config.auto_HDsnapshot = false;
|
|
688
|
-
if (this._adapter.config.auto_livestream === undefined)
|
|
689
|
-
this._adapter.config.auto_livestream = false;
|
|
690
|
-
this._adapter.upsertState(`${this.fullId}.${constants_1.STATE_ID_DEBUG_REQUEST}`, constants_1.COMMON_DEBUG_REQUEST, false, true, true);
|
|
691
|
-
this._adapter.upsertState(`${this.snapshotChannelId}.auto`, constants_1.COMMON_SNAPSHOT_AUTO, this._adapter.config.auto_snapshot, true, true);
|
|
692
|
-
this._adapter.upsertState(`${this.HDsnapshotChannelId}.auto`, constants_1.COMMON_HDSNAPSHOT_AUTO, this._adapter.config.auto_HDsnapshot, true, true);
|
|
693
|
-
this._adapter.upsertState(`${this.liveStreamChannelId}.auto`, constants_1.COMMON_LIVESTREAM_AUTO, this._adapter.config.auto_livestream, true, true);
|
|
694
|
-
// Remove legacy states
|
|
695
|
-
this._adapter.delObject(`${this.snapshotChannelId}.snapshot_request`);
|
|
696
|
-
this._adapter.delObject(`${this.snapshotChannelId}.snapshot_file`);
|
|
697
|
-
this._adapter.delObject(`${this.snapshotChannelId}.snapshot_url`);
|
|
698
|
-
this._adapter.delObject(`${this.liveStreamChannelId}.livestream_request`);
|
|
699
|
-
this._adapter.delObject(`${this.liveStreamChannelId}.livestream_file`);
|
|
700
|
-
this._adapter.delObject(`${this.liveStreamChannelId}.livestream_url`);
|
|
701
|
-
}
|
|
702
589
|
async subscribeToEvents() {
|
|
703
590
|
this.silly(`Start device subscriptions`);
|
|
704
591
|
await this._ringDevice.subscribeToDingEvents().catch((r) => {
|
|
@@ -815,38 +702,20 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
|
|
|
815
702
|
this._adapter.upsertState(`${this.eventsChannelId}.message`, constants_1.COMMON_EVENTS_MESSAGE, value.aps.alert);
|
|
816
703
|
}
|
|
817
704
|
onMotion(value) {
|
|
818
|
-
if (
|
|
705
|
+
if (value && this._eventBlocker.motion.checkBlock(this._adapter.config.ignore_events_Motion, this._adapter.config.keep_ignoring_if_retriggered)) {
|
|
706
|
+
this.debug(`ignore Motion event...`);
|
|
819
707
|
return;
|
|
820
708
|
}
|
|
821
|
-
const timeSinceLastMotion = new Date().getTime() - this._lastMotionEvent;
|
|
822
|
-
if (this._adapter.config.keep_ignoring_if_retriggered) {
|
|
823
|
-
this._lastMotionEvent = new Date().getTime();
|
|
824
|
-
}
|
|
825
|
-
if (timeSinceLastMotion < this._adapter.config.ignore_events_Motion * 1000 && timeSinceLastMotion > 0) {
|
|
826
|
-
this.debug(`Received Motion Event, but we are ignoring it due to ignore_events setting. (${timeSinceLastMotion}ms)`);
|
|
827
|
-
return;
|
|
828
|
-
}
|
|
829
|
-
this._lastMotionEvent = new Date().getTime();
|
|
830
|
-
this.info(`Motion Event --> Will ignore additional motions for the next ${this._adapter.config.ignore_events_Motion}s.`);
|
|
831
709
|
this.debug(`Received Motion Event (${util.inspect(value, true, 1)})`);
|
|
832
|
-
this._adapter.upsertState(`${this.eventsChannelId}.motion`, constants_1.COMMON_MOTION,
|
|
833
|
-
setTimeout(() => {
|
|
834
|
-
this._adapter.upsertState(`${this.eventsChannelId}.motion`, constants_1.COMMON_EVENTS_DOORBELL, false);
|
|
835
|
-
}, this._adapter.config.ignore_events_Motion * 1000 - 100);
|
|
710
|
+
this._adapter.upsertState(`${this.eventsChannelId}.motion`, constants_1.COMMON_MOTION, value);
|
|
836
711
|
value && this.conditionalRecording(EventState.ReactingOnMotion);
|
|
837
712
|
}
|
|
838
713
|
onDoorbell(value) {
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
this._lastDoorbellEvent = new Date().getTime();
|
|
842
|
-
}
|
|
843
|
-
if (timeSinceLastDoorbell < this._adapter.config.ignore_events_Doorbell * 1000 && timeSinceLastDoorbell > 0) {
|
|
844
|
-
this.debug(`Received Doorbell Event, but we are still ignoring it due to ignore_events setting. (${timeSinceLastDoorbell}ms)`);
|
|
714
|
+
if (value && this._eventBlocker.doorbell.checkBlock(this._adapter.config.ignore_events_Doorbell, this._adapter.config.keep_ignoring_if_retriggered)) {
|
|
715
|
+
this.debug(`ignore Doorbell event...`);
|
|
845
716
|
return;
|
|
846
717
|
}
|
|
847
|
-
this.info(`Doorbell pressed --> Will ignore additional presses for the next ${this._adapter.config.ignore_events_Doorbell}s.`);
|
|
848
718
|
this.debug(`Received Doorbell Event (${util.inspect(value, true, 1)})`);
|
|
849
|
-
this._lastDoorbellEvent = new Date().getTime();
|
|
850
719
|
this._adapter.upsertState(`${this.eventsChannelId}.doorbell`, constants_1.COMMON_EVENTS_DOORBELL, true);
|
|
851
720
|
setTimeout(() => {
|
|
852
721
|
this._adapter.upsertState(`${this.eventsChannelId}.doorbell`, constants_1.COMMON_EVENTS_DOORBELL, false);
|