iobroker.ring 5.0.6 → 5.0.9

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.
@@ -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";
@@ -45,22 +48,47 @@ var EventState;
45
48
  EventState[EventState["ReactingOnDoorbell"] = 3] = "ReactingOnDoorbell";
46
49
  })(EventState || (EventState = {}));
47
50
  class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
48
- get lastLiveStreamDir() {
49
- return this._lastLiveStreamDir;
50
- }
51
- get lastSnapShotDir() {
52
- return this._lastSnapShotDir;
53
- }
54
- get lastHDSnapShotDir() {
55
- return this._lastHDSnapShotDir;
56
- }
57
- get ringDevice() {
58
- return this._ringDevice;
51
+ constructor(ringDevice, location, adapter, apiClient) {
52
+ super(location, adapter, apiClient, OwnRingCamera.evaluateKind(ringDevice.deviceType, adapter, ringDevice), `${ringDevice.id}`, ringDevice.data.description);
53
+ this._lastLightCommand = 0;
54
+ this._lastLiveStreamUrl = "";
55
+ this._lastLiveStreamTimestamp = 0;
56
+ this._lastSnapShotUrl = "";
57
+ this._lastSnapshotTimestamp = 0;
58
+ this._snapshotCount = 0;
59
+ this._lastHDSnapShotUrl = "";
60
+ this._lastHDSnapshotTimestamp = 0;
61
+ this._HDsnapshotCount = 0;
62
+ this._liveStreamCount = 0;
63
+ this._state = EventState.Idle;
64
+ this._lastLiveStreamDir = "";
65
+ this._lastSnapShotDir = "";
66
+ this._lastHDSnapShotDir = "";
67
+ this._motionEventBlocker = new event_blocker_1.EventBlocker(this._adapter.config.ignore_events_Motion, this._adapter.config.keep_ignoring_if_retriggered);
68
+ this._doorbellEventBlocker = new event_blocker_1.EventBlocker(this._adapter.config.ignore_events_Doorbell, this._adapter.config.keep_ignoring_if_retriggered);
69
+ this._durationLiveStream = this._adapter.config.recordtime_livestream;
70
+ this._ringDevice = ringDevice;
71
+ this.infoChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_INFO}`;
72
+ this.historyChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_HISTORY}`;
73
+ this.lightChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_LIGHT}`;
74
+ this.snapshotChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_SNAPSHOT}`;
75
+ this.HDsnapshotChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_HDSNAPSHOT}`;
76
+ this.liveStreamChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_LIVESTREAM}`;
77
+ this.eventsChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_EVENTS}`;
78
+ this.recreateDeviceObjectTree();
79
+ this.updateDeviceInfoObject(ringDevice.data);
80
+ this.updateHealth();
81
+ this.updateHistory();
82
+ this.updateSnapshotObject();
83
+ this.updateHDSnapshotObject();
84
+ this.updateLiveStreamObject();
85
+ this.autoSched();
86
+ this.subscribeToEvents();
59
87
  }
60
88
  async startLivestream(duration) {
61
89
  this.silly(`${this.shortId}.startLivestream()`);
62
90
  duration !== null && duration !== void 0 ? duration : (duration = this._durationLiveStream);
63
- const { visURL, visPath, fullPath } = await this.prepareLivestreamTargetFile().catch(reason => {
91
+ const { visURL, visPath, fullPath } = await this.prepareLivestreamTargetFile().catch((reason) => {
64
92
  this.catcher("Couldn't prepare Livestream Target File.", reason);
65
93
  return { visURL: "", visPath: "", fullPath: "" };
66
94
  });
@@ -75,9 +103,9 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
75
103
  }
76
104
  const tempPath = (await file_service_1.FileService.getTempDir(this._adapter)) + `/temp_${this.shortId}_livestream.mp4`;
77
105
  const liveCall = await this._ringDevice.streamVideo({
78
- video: this.videoFilter(this._adapter.config.overlay_Livestream),
106
+ video: image_service_1.ImageService.videoFilter(this._adapter.config.overlay_Livestream, this._adapter.dateFormat, this._adapter.language, this._ringDevice.data.description),
79
107
  output: ["-t", duration.toString(), tempPath],
80
- }).catch(reason => {
108
+ }).catch((reason) => {
81
109
  this.catcher("Couldn't create Livestream.", reason);
82
110
  return null;
83
111
  });
@@ -86,9 +114,9 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
86
114
  await this.updateLivestreamRequest(false);
87
115
  return;
88
116
  }
89
- const liveCallSucceeded = await rxjs.firstValueFrom(liveCall.onCallEnded).then(_result => {
117
+ const liveCallSucceeded = await rxjs.firstValueFrom(liveCall.onCallEnded).then((_result) => {
90
118
  return true;
91
- }).catch(reason => {
119
+ }).catch((reason) => {
92
120
  this.catcher("Couldn't create HD Snapshot.", reason);
93
121
  return null;
94
122
  });
@@ -123,7 +151,7 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
123
151
  var _a;
124
152
  this.silly(`${this.shortId}.takeHDSnapshot()`);
125
153
  // const duration = 2.0;
126
- const { visURL, visPath } = await file_service_1.FileService.getVisUrl(this._adapter, this.fullId, "HDSnapshot.jpg").catch(reason => {
154
+ const { visURL, visPath } = await file_service_1.FileService.getVisUrl(this._adapter, this.fullId, "HDSnapshot.jpg").catch((reason) => {
127
155
  this.catcher("Couldn't get Vis URL.", reason);
128
156
  return { visURL: "", visPath: "" };
129
157
  });
@@ -147,10 +175,10 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
147
175
  const { night_contrast, night_sharpen } = this.getActiveNightImageOptions();
148
176
  const tempPath = (await file_service_1.FileService.getTempDir(this._adapter)) + `/temp_${this.shortId}_livestream.jpg`;
149
177
  const liveCall = await this._ringDevice.streamVideo({
150
- video: this.videoFilter(this._adapter.config.overlay_HDsnapshot, night_contrast ? this._adapter.config.contrast_HDsnapshot : 0),
178
+ 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
179
  // output: ["-t", duration.toString(), "-f", "mjpeg", "-q:v", 3, "-frames:v", 1, tempPath]
152
180
  output: ["-f", "mjpeg", "-q:v", 3, "-frames:v", 1, tempPath]
153
- }).catch(reason => {
181
+ }).catch((reason) => {
154
182
  this.catcher("Couldn't create HD Snapshot.", reason);
155
183
  return null;
156
184
  });
@@ -159,9 +187,9 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
159
187
  await this.updateHDSnapshotRequest(false);
160
188
  return;
161
189
  }
162
- const liveCallSucceeded = await rxjs.firstValueFrom(liveCall.onCallEnded).then(_result => {
190
+ const liveCallSucceeded = await rxjs.firstValueFrom(liveCall.onCallEnded).then((_result) => {
163
191
  return true;
164
- }).catch(reason => {
192
+ }).catch((reason) => {
165
193
  this.catcher("Couldn't create HD Snapshot.", reason);
166
194
  return null;
167
195
  });
@@ -175,11 +203,13 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
175
203
  }
176
204
  let jpg = fs.readFileSync(tempPath);
177
205
  if (night_sharpen && this._adapter.config.sharpen_HDsnapshot && this._adapter.config.sharpen_HDsnapshot > 0) {
178
- const sharpen = this._adapter.config.sharpen_HDsnapshot == 1 ? undefined : { sigma: this._adapter.config.sharpen_HDsnapshot - 1 };
206
+ const sharpen = this._adapter.config.sharpen_HDsnapshot == 1
207
+ ? undefined
208
+ : { sigma: this._adapter.config.sharpen_HDsnapshot - 1 };
179
209
  jpg = (_a = await (0, sharp_1.default)(jpg)
180
210
  .sharpen(sharpen)
181
211
  .toBuffer()
182
- .catch(reason => {
212
+ .catch((reason) => {
183
213
  this.catcher("Couldn't sharpen HD Snapshot.", reason);
184
214
  return null;
185
215
  })) !== null && _a !== void 0 ? _a : jpg;
@@ -223,15 +253,6 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
223
253
  await this.updateSnapshotRequest(false);
224
254
  return;
225
255
  }
226
- /*
227
- const image = await this._ringDevice.getNextSnapshot({uuid: uuid}).catch((reason) => {
228
- if (eventBased) {
229
- this.warn("Taking Snapshot on Event failed. Will try again after livestream finished.");
230
- } else {
231
- this.catcher("Couldn't get Snapshot from api.", reason);
232
- }
233
- })
234
- */
235
256
  const image = await this._ringDevice.getNextSnapshot({ force: true, uuid: uuid })
236
257
  .then((result) => result)
237
258
  .catch((err) => {
@@ -259,11 +280,12 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
259
280
  }
260
281
  let image_txt = image;
261
282
  if (this._adapter.config.overlay_snapshot) {
262
- image_txt = await this.addText(image)
263
- .catch(reason => {
264
- this.catcher("Couldn't add text to Snapshot.", reason);
265
- return reason;
266
- });
283
+ image_txt =
284
+ 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`))
285
+ .catch((reason) => {
286
+ this.catcher("Couldn't add text to Snapshot.", reason);
287
+ return reason;
288
+ });
267
289
  }
268
290
  if (this._lastSnapShotDir !== "" && this._adapter.config.del_old_snapshot) {
269
291
  file_service_1.FileService.deleteFileIfExistSync(this._lastSnapShotDir, this._adapter);
@@ -280,42 +302,6 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
280
302
  await this.updateSnapshotObject();
281
303
  this.debug(`Done creating snapshot to ${fullPath}`);
282
304
  }
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
305
  async updateHistory() {
320
306
  this.silly(`Update History`);
321
307
  this._ringDevice.getEvents({ limit: 50 })
@@ -340,90 +326,6 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
340
326
  this.updateHistoryObject(this.lastAction);
341
327
  });
342
328
  }
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
329
  async processUserInput(channelID, stateID, state) {
428
330
  switch (channelID) {
429
331
  case "":
@@ -461,7 +363,7 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
461
363
  const targetVal = state.val;
462
364
  this._adapter.log.debug(`Get Snapshot request for ${this.shortId} to value ${targetVal}`);
463
365
  if (targetVal) {
464
- await this.takeSnapshot().catch(reason => {
366
+ await this.takeSnapshot().catch((reason) => {
465
367
  this.updateSnapshotRequest();
466
368
  this.catcher("Couldn't retrieve Snapshot.", reason);
467
369
  });
@@ -491,7 +393,7 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
491
393
  const targetVal = state.val;
492
394
  this._adapter.log.debug(`Get Livestream request for ${this.shortId} to value ${targetVal}`);
493
395
  if (targetVal) {
494
- await this.startLivestream().catch(reason => {
396
+ await this.startLivestream().catch((reason) => {
495
397
  this.updateLivestreamRequest();
496
398
  this.catcher("Couldn't retrieve Livestream.", reason);
497
399
  });
@@ -510,8 +412,82 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
510
412
  this._adapter.log.error(`Unknown State/Switch with channel "${channelID}" and state "${stateID}"`);
511
413
  }
512
414
  }
415
+ async recreateDeviceObjectTree() {
416
+ this.silly(`Recreate DeviceObjectTree`);
417
+ this._adapter.createDevice(this.fullId, {
418
+ name: `Device ${this.shortId} ("${this._ringDevice.data.description}")`,
419
+ });
420
+ this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_INFO, { name: `Info ${this.shortId}` });
421
+ this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_SNAPSHOT, { name: `Snapshot ${this.shortId}` });
422
+ this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_HDSNAPSHOT, { name: `HD Snapshot ${this.shortId}` });
423
+ this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_LIVESTREAM, { name: `Livestream ${this.shortId}` });
424
+ this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_HISTORY);
425
+ this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_EVENTS);
426
+ if (this._ringDevice.hasLight) {
427
+ this.debug(`Device with Light Capabilities detected`);
428
+ this._adapter.createChannel(this.fullId, constants_1.CHANNEL_NAME_LIGHT, { name: `Light ${this.shortId}` });
429
+ this._adapter.upsertState(`${this.lightChannelId}.${constants_1.STATE_ID_LIGHT_SWITCH}`, constants_1.COMMON_LIGHT_SWITCH, false, true, true);
430
+ }
431
+ this._lastSnapShotDir = await this._adapter.tryGetStringState(`${this.snapshotChannelId}.file`);
432
+ this._lastHDSnapShotDir = await this._adapter.tryGetStringState(`${this.HDsnapshotChannelId}.file`);
433
+ this._lastLiveStreamDir = await this._adapter.tryGetStringState(`${this.liveStreamChannelId}.file`);
434
+ if (this._adapter.config.auto_snapshot === undefined)
435
+ this._adapter.config.auto_snapshot = false;
436
+ if (this._adapter.config.auto_HDsnapshot === undefined)
437
+ this._adapter.config.auto_HDsnapshot = false;
438
+ if (this._adapter.config.auto_livestream === undefined)
439
+ this._adapter.config.auto_livestream = false;
440
+ this._adapter.upsertState(`${this.fullId}.${constants_1.STATE_ID_DEBUG_REQUEST}`, constants_1.COMMON_DEBUG_REQUEST, false, true, true);
441
+ this._adapter.upsertState(`${this.snapshotChannelId}.auto`, constants_1.COMMON_SNAPSHOT_AUTO, this._adapter.config.auto_snapshot, true, true);
442
+ this._adapter.upsertState(`${this.HDsnapshotChannelId}.auto`, constants_1.COMMON_HDSNAPSHOT_AUTO, this._adapter.config.auto_HDsnapshot, true, true);
443
+ this._adapter.upsertState(`${this.liveStreamChannelId}.auto`, constants_1.COMMON_LIVESTREAM_AUTO, this._adapter.config.auto_livestream, true, true);
444
+ // Remove legacy states
445
+ this._adapter.delObject(`${this.snapshotChannelId}.snapshot_request`);
446
+ this._adapter.delObject(`${this.snapshotChannelId}.snapshot_file`);
447
+ this._adapter.delObject(`${this.snapshotChannelId}.snapshot_url`);
448
+ this._adapter.delObject(`${this.liveStreamChannelId}.livestream_request`);
449
+ this._adapter.delObject(`${this.liveStreamChannelId}.livestream_file`);
450
+ this._adapter.delObject(`${this.liveStreamChannelId}.livestream_url`);
451
+ }
452
+ async prepareLivestreamTargetFile() {
453
+ const { visURL, visPath } = await file_service_1.FileService.getVisUrl(this._adapter, this.fullId, "Livestream.mp4").catch((reason) => {
454
+ this.catcher("Couldn't get Vis URL.", reason);
455
+ return { visURL: "", visPath: "" };
456
+ });
457
+ return new Promise(async (resolve, reject) => {
458
+ if (!visURL || !visPath) {
459
+ reject("Vis not available");
460
+ }
461
+ 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);
462
+ const folderPrepared = await file_service_1.FileService.prepareFolder(dirname).catch((reason) => {
463
+ this.catcher("Couldn't prepare folder.", reason);
464
+ return false;
465
+ });
466
+ if (!folderPrepared) {
467
+ this.warn(`Failed to prepare Livestream folder ("${fullPath}")`);
468
+ reject("Failed to prepare Livestream folder");
469
+ return;
470
+ }
471
+ file_service_1.FileService.deleteFileIfExistSync(fullPath, this._adapter);
472
+ resolve({ visURL: visURL, visPath: visPath, fullPath: fullPath });
473
+ });
474
+ }
475
+ getActiveNightImageOptions() {
476
+ let night_contrast = false;
477
+ let night_sharpen = false;
478
+ if (this._adapter.Sunrise > 0 && this._adapter.Sunset > 0) {
479
+ const today = Date.now();
480
+ this.silly(`Now: ${today}, sunrise: ${this._adapter.Sunrise}, sunset: ${this._adapter.Sunset}`);
481
+ const isNight = today < this._adapter.Sunrise || today > this._adapter.Sunset;
482
+ this.debug(`is Night: ${isNight}`);
483
+ night_contrast = this._adapter.config.night_contrast_HDsnapshot && isNight || !this._adapter.config.night_contrast_HDsnapshot;
484
+ night_sharpen = this._adapter.config.night_sharpen_HDsnapshot && isNight || !this._adapter.config.night_sharpen_HDsnapshot;
485
+ }
486
+ return { night_contrast, night_sharpen };
487
+ }
513
488
  updateByDevice(ringDevice) {
514
- this.ringDevice = ringDevice;
489
+ this._ringDevice = ringDevice;
490
+ this.subscribeToEvents();
515
491
  this._state = EventState.Idle;
516
492
  this.update(ringDevice.data);
517
493
  }
@@ -519,7 +495,6 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
519
495
  this.debug(`Received Update`);
520
496
  this.updateDeviceInfoObject(data);
521
497
  this.updateHealth();
522
- // noinspection JSIgnoredPromiseFromCall
523
498
  this.updateHistory();
524
499
  this.updateSnapshotObject();
525
500
  this.updateHDSnapshotObject();
@@ -530,95 +505,6 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
530
505
  this._adapter.upsertState(`${this.liveStreamChannelId}.${constants_1.STATE_ID_LIVESTREAM_DURATION}`, constants_1.COMMON_LIVESTREAM_DURATION, this._durationLiveStream, true);
531
506
  this.debug(`Livestream duration set to: ${val}`);
532
507
  }
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
508
  updateHealth() {
623
509
  this.silly(`Update Health`);
624
510
  this._ringDevice.getHealth().then(this.updateHealthObject.bind(this));
@@ -626,19 +512,28 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
626
512
  autoSched() {
627
513
  const media = [
628
514
  {
629
- name: "Snaspshot", val: this._adapter.config.save_snapshot, fct: () => {
515
+ name: "Snaspshot",
516
+ val: this._adapter.config.save_snapshot,
517
+ fct: () => {
630
518
  this.takeSnapshot();
631
- }, start: 0
519
+ },
520
+ start: 0
632
521
  },
633
522
  {
634
- name: "HD Snapshot", val: this._adapter.config.save_HDsnapshot, fct: () => {
523
+ name: "HD Snapshot",
524
+ val: this._adapter.config.save_HDsnapshot,
525
+ fct: () => {
635
526
  this.takeHDSnapshot();
636
- }, start: 2
527
+ },
528
+ start: 2
637
529
  },
638
530
  {
639
- name: "Livestream", val: this._adapter.config.save_livestream, fct: () => {
531
+ name: "Livestream",
532
+ val: this._adapter.config.save_livestream,
533
+ fct: () => {
640
534
  this.startLivestream();
641
- }, start: 4
535
+ },
536
+ start: 4
642
537
  }
643
538
  ];
644
539
  for (const m of media) {
@@ -662,43 +557,6 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
662
557
  }
663
558
  }
664
559
  }
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
560
  async subscribeToEvents() {
703
561
  this.silly(`Start device subscriptions`);
704
562
  await this._ringDevice.subscribeToDingEvents().catch((r) => {
@@ -815,42 +673,24 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
815
673
  this._adapter.upsertState(`${this.eventsChannelId}.message`, constants_1.COMMON_EVENTS_MESSAGE, value.aps.alert);
816
674
  }
817
675
  onMotion(value) {
818
- if (!value) {
676
+ if (value && this._motionEventBlocker.checkBlock()) {
677
+ this.debug(`ignore Motion event...`);
819
678
  return;
820
679
  }
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
680
  this.debug(`Received Motion Event (${util.inspect(value, true, 1)})`);
832
- this._adapter.upsertState(`${this.eventsChannelId}.motion`, constants_1.COMMON_MOTION, true);
833
- setTimeout(() => {
834
- this._adapter.upsertState(`${this.eventsChannelId}.motion`, constants_1.COMMON_EVENTS_DOORBELL, false);
835
- }, this._adapter.config.ignore_events_Motion * 1000 - 100);
681
+ this._adapter.upsertState(`${this.eventsChannelId}.motion`, constants_1.COMMON_MOTION, value);
836
682
  value && this.conditionalRecording(EventState.ReactingOnMotion);
837
683
  }
838
684
  onDoorbell(value) {
839
- const timeSinceLastDoorbell = new Date().getTime() - this._lastDoorbellEvent;
840
- if (this._adapter.config.keep_ignoring_if_retriggered) {
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)`);
685
+ if (value && this._doorbellEventBlocker.checkBlock()) {
686
+ this.debug(`ignore Doorbell event...`);
845
687
  return;
846
688
  }
847
- this.info(`Doorbell pressed --> Will ignore additional presses for the next ${this._adapter.config.ignore_events_Doorbell}s.`);
848
689
  this.debug(`Received Doorbell Event (${util.inspect(value, true, 1)})`);
849
- this._lastDoorbellEvent = new Date().getTime();
850
690
  this._adapter.upsertState(`${this.eventsChannelId}.doorbell`, constants_1.COMMON_EVENTS_DOORBELL, true);
851
691
  setTimeout(() => {
852
692
  this._adapter.upsertState(`${this.eventsChannelId}.doorbell`, constants_1.COMMON_EVENTS_DOORBELL, false);
853
- }, 5000);
693
+ }, 1000);
854
694
  this.conditionalRecording(EventState.ReactingOnDoorbell, value.ding.image_uuid);
855
695
  }
856
696
  async conditionalRecording(state, uuid) {