iobroker.ring 6.4.0 → 7.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.
Files changed (50) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +29 -418
  3. package/admin/assets/index-QX4NxbDg.js +693 -0
  4. package/admin/i18n/de.json +3 -1
  5. package/admin/i18n/en.json +3 -1
  6. package/admin/i18n/es.json +3 -2
  7. package/admin/i18n/fr.json +3 -1
  8. package/admin/i18n/it.json +3 -1
  9. package/admin/i18n/nl.json +5 -3
  10. package/admin/i18n/pl.json +3 -1
  11. package/admin/i18n/pt.json +3 -1
  12. package/admin/i18n/ru.json +3 -1
  13. package/admin/i18n/uk.json +3 -1
  14. package/admin/i18n/zh-cn.json +3 -1
  15. package/admin/tab_m.html +13 -34
  16. package/build/lib/constants.js +204 -204
  17. package/build/lib/constants.js.map +1 -1
  18. package/build/lib/lastAction.js +2 -0
  19. package/build/lib/lastAction.js.map +1 -1
  20. package/build/lib/ownRingCamera.js +269 -237
  21. package/build/lib/ownRingCamera.js.map +1 -1
  22. package/build/lib/ownRingDevice.js +57 -44
  23. package/build/lib/ownRingDevice.js.map +1 -1
  24. package/build/lib/ownRingIntercom.js +45 -40
  25. package/build/lib/ownRingIntercom.js.map +1 -1
  26. package/build/lib/ownRingLocation.js +27 -19
  27. package/build/lib/ownRingLocation.js.map +1 -1
  28. package/build/lib/ringApiClient.js +61 -49
  29. package/build/lib/ringApiClient.js.map +1 -1
  30. package/build/lib/services/event-blocker.js +13 -10
  31. package/build/lib/services/event-blocker.js.map +1 -1
  32. package/build/lib/services/file-service.js +29 -27
  33. package/build/lib/services/file-service.js.map +1 -1
  34. package/build/lib/services/image-service.js +8 -4
  35. package/build/lib/services/image-service.js.map +1 -1
  36. package/build/lib/services/text-service.js +169 -85
  37. package/build/lib/services/text-service.js.map +1 -1
  38. package/build/main.js +84 -100
  39. package/build/main.js.map +1 -1
  40. package/io-package.json +26 -25
  41. package/package.json +42 -89
  42. package/admin/admin.d.ts +0 -112
  43. package/admin/convert.js +0 -447
  44. package/admin/index_m.html +0 -318
  45. package/admin/style.css +0 -33
  46. package/admin/tab_m.js +0 -154
  47. package/admin/tsconfig.json +0 -11
  48. package/admin/words.js +0 -470
  49. package/build/lib/tools.js +0 -98
  50. package/build/lib/tools.js.map +0 -1
@@ -38,8 +38,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.OwnRingCamera = void 0;
40
40
  const rxjs = __importStar(require("rxjs"));
41
- const fs = __importStar(require("fs"));
42
- const util = __importStar(require("util"));
41
+ const fs = __importStar(require("node:fs"));
42
+ const util = __importStar(require("node:util"));
43
43
  const sharp_1 = __importDefault(require("sharp"));
44
44
  const strftime_1 = __importDefault(require("strftime"));
45
45
  const node_schedule_1 = __importDefault(require("node-schedule"));
@@ -58,25 +58,39 @@ var EventState;
58
58
  EventState[EventState["ReactingOnDoorbell"] = 3] = "ReactingOnDoorbell";
59
59
  })(EventState || (EventState = {}));
60
60
  class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
61
+ infoChannelId;
62
+ historyChannelId;
63
+ lightChannelId;
64
+ sirenChannelId;
65
+ eventsChannelId;
66
+ snapshotChannelId;
67
+ HDsnapshotChannelId;
68
+ liveStreamChannelId;
69
+ lastAction;
70
+ _ringDevice;
71
+ _durationLiveStream;
72
+ _lastLightCommand = 0;
73
+ _lastLiveStreamUrl = '';
74
+ _lastLiveStreamTimestamp = 0;
75
+ _lastSnapShotUrl = '';
76
+ _lastSnapshotTimestamp = 0;
77
+ _snapshotCount = 0;
78
+ _lastHDSnapShotUrl = '';
79
+ _lastHDSnapshotTimestamp = 0;
80
+ _HDsnapshotCount = 0;
81
+ _liveStreamCount = 0;
82
+ _lastLiveStreamDir = '';
83
+ _lastSnapShotDir = '';
84
+ _lastHDSnapShotDir = '';
85
+ _motionEventBlocker;
86
+ _notifyEventBlocker;
87
+ _doorbellEventBlocker;
88
+ _state = EventState.Idle;
61
89
  constructor(ringDevice, location, adapter, apiClient) {
62
90
  super(location, adapter, apiClient, OwnRingCamera.evaluateKind(ringDevice.deviceType, adapter, ringDevice), `${ringDevice.id}`, ringDevice.data.description);
63
- this._lastLightCommand = 0;
64
- this._lastLiveStreamUrl = "";
65
- this._lastLiveStreamTimestamp = 0;
66
- this._lastSnapShotUrl = "";
67
- this._lastSnapshotTimestamp = 0;
68
- this._snapshotCount = 0;
69
- this._lastHDSnapShotUrl = "";
70
- this._lastHDSnapshotTimestamp = 0;
71
- this._HDsnapshotCount = 0;
72
- this._liveStreamCount = 0;
73
- this._lastLiveStreamDir = "";
74
- this._lastSnapShotDir = "";
75
- this._lastHDSnapShotDir = "";
76
- this._state = EventState.Idle;
77
- this._motionEventBlocker = new event_blocker_1.EventBlocker(this._adapter.config.ignore_events_Motion, this._adapter.config.keep_ignoring_if_retriggered);
78
- this._notifyEventBlocker = new event_blocker_1.EventBlocker(this._adapter.config.ignore_events_Motion, this._adapter.config.keep_ignoring_if_retriggered);
79
- this._doorbellEventBlocker = new event_blocker_1.EventBlocker(this._adapter.config.ignore_events_Doorbell, this._adapter.config.keep_ignoring_if_retriggered);
91
+ this._motionEventBlocker = new event_blocker_1.EventBlocker(this._adapter, this._adapter.config.ignore_events_Motion, this._adapter.config.keep_ignoring_if_retriggered);
92
+ this._notifyEventBlocker = new event_blocker_1.EventBlocker(this._adapter, this._adapter.config.ignore_events_Motion, this._adapter.config.keep_ignoring_if_retriggered);
93
+ this._doorbellEventBlocker = new event_blocker_1.EventBlocker(this._adapter, this._adapter.config.ignore_events_Doorbell, this._adapter.config.keep_ignoring_if_retriggered);
80
94
  this._durationLiveStream = this._adapter.config.recordtime_livestream;
81
95
  this._ringDevice = ringDevice;
82
96
  this.infoChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_INFO}`;
@@ -87,19 +101,19 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
87
101
  this.HDsnapshotChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_HDSNAPSHOT}`;
88
102
  this.liveStreamChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_LIVESTREAM}`;
89
103
  this.eventsChannelId = `${this.fullId}.${constants_1.CHANNEL_NAME_EVENTS}`;
90
- this.recreateDeviceObjectTree();
91
- this.updateDeviceInfoObject(ringDevice.data);
104
+ this.recreateDeviceObjectTree().catch(e => this.catcher("Couldn't create Device Object Tree.", e));
105
+ this.updateDeviceInfoObject(ringDevice.data).catch(e => this.catcher("Couldn't update Device Info Object.", e));
92
106
  this.updateHealth();
93
- this.updateHistory();
107
+ this.updateHistory().catch(e => this.catcher("Couldn't update History.", e));
94
108
  this.autoSched();
95
- this.subscribeToEvents();
109
+ this.subscribeToEvents().catch(e => this.catcher("Couldn't subscribe to events.", e));
96
110
  }
97
111
  async startLivestream(duration) {
98
112
  this.silly(`${this.shortId}.startLivestream()`);
99
- duration !== null && duration !== void 0 ? duration : (duration = this._durationLiveStream);
113
+ duration ??= this._durationLiveStream;
100
114
  const { visURL, visPath, fullPath } = await this.prepareLivestreamTargetFile().catch((reason) => {
101
115
  this.catcher("Couldn't prepare Livestream Target File.", reason);
102
- return { visURL: "", visPath: "", fullPath: "" };
116
+ return { visURL: '', visPath: '', fullPath: '' };
103
117
  });
104
118
  if (!visURL || !visPath || !fullPath) {
105
119
  await this.updateLivestreamRequest(false);
@@ -110,11 +124,13 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
110
124
  await this.updateLivestreamRequest(false);
111
125
  return;
112
126
  }
113
- const tempPath = (await file_service_1.FileService.getTempDir(this._adapter)) + `/temp_${this.shortId}_livestream.mp4`;
114
- const liveCall = await this._ringDevice.streamVideo({
127
+ const tempPath = `${await file_service_1.FileService.getTempDir(this._adapter)}/temp_${this.shortId}_livestream.mp4`;
128
+ const liveCall = await this._ringDevice
129
+ .streamVideo({
115
130
  video: image_service_1.ImageService.videoFilter(this._adapter.config.overlay_Livestream, this._adapter.dateFormat, this._adapter.language, this._ringDevice.data.description),
116
- output: ["-t", duration.toString(), tempPath],
117
- }).catch((reason) => {
131
+ output: ['-t', duration.toString(), tempPath],
132
+ })
133
+ .catch((reason) => {
118
134
  this.catcher("Couldn't create Livestream (stream video).", reason);
119
135
  return null;
120
136
  });
@@ -123,9 +139,12 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
123
139
  await this.updateLivestreamRequest(false);
124
140
  return;
125
141
  }
126
- const liveCallSucceeded = await rxjs.firstValueFrom(liveCall.onCallEnded).then((_result) => {
142
+ const liveCallSucceeded = await rxjs
143
+ .firstValueFrom(liveCall.onCallEnded)
144
+ .then((_result) => {
127
145
  return true;
128
- }).catch((reason) => {
146
+ })
147
+ .catch((reason) => {
129
148
  this.catcher("Couldn't create Livestream (first value).", reason);
130
149
  return null;
131
150
  });
@@ -141,15 +160,15 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
141
160
  this.catcher("Couldn't delete temp file.", err);
142
161
  }
143
162
  });
144
- if (this._lastLiveStreamDir !== "" && this._adapter.config.del_old_livestream) {
163
+ if (this._lastLiveStreamDir !== '' && this._adapter.config.del_old_livestream) {
145
164
  file_service_1.FileService.deleteFileIfExistSync(this._lastLiveStreamDir, this._adapter);
146
165
  }
147
166
  if (visPath) {
148
- this.silly(`Locally storing Filestream (Length: ${video.length})`);
167
+ this.silly(`Locally storing FileStream (Length: ${video.length})`);
149
168
  await file_service_1.FileService.writeFile(visPath, video, this._adapter);
150
169
  this._lastLiveStreamUrl = visURL;
151
170
  }
152
- this.silly(`Writing Filestream (Length: ${video.length}) to "${fullPath}"`);
171
+ this.silly(`Writing FileStream (Length: ${video.length}) to "${fullPath}"`);
153
172
  await file_service_1.FileService.writeFile(fullPath, video, this._adapter);
154
173
  this._lastLiveStreamDir = fullPath;
155
174
  this._lastLiveStreamTimestamp = Date.now();
@@ -157,15 +176,15 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
157
176
  this.debug(`Done creating livestream to ${fullPath}`);
158
177
  }
159
178
  async takeHDSnapshot() {
160
- var _a;
179
+ // from very short Livestream
161
180
  this.silly(`${this.shortId}.takeHDSnapshot()`);
162
181
  // const duration = 2.0;
163
- const { visURL, visPath } = await file_service_1.FileService.getVisUrl(this._adapter, this.fullId, "HDSnapshot.jpg").catch((reason) => {
182
+ const { visURL, visPath } = await file_service_1.FileService.getVisUrl(this._adapter, this.fullId, 'HDSnapshot.jpg').catch((reason) => {
164
183
  this.catcher("Couldn't get Vis URL.", reason);
165
- return { visURL: "", visPath: "" };
184
+ return { visURL: '', visPath: '' };
166
185
  });
167
186
  if (!visURL || !visPath) {
168
- this.warn("Vis not available! Please install e.g. flot or other Vis related adapter");
187
+ this.warn('Vis not available! Please install e.g. flot or other Vis related adapter');
169
188
  await this.updateHDSnapshotRequest(false);
170
189
  return;
171
190
  }
@@ -182,12 +201,14 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
182
201
  return;
183
202
  }
184
203
  const { night_contrast, night_sharpen } = this.getActiveNightImageOptions();
185
- const tempPath = (await file_service_1.FileService.getTempDir(this._adapter)) + `/temp_${this.shortId}_livestream.jpg`;
186
- const liveCall = await this._ringDevice.streamVideo({
204
+ const tempPath = `${await file_service_1.FileService.getTempDir(this._adapter)}/temp_${this.shortId}_livestream.jpg`;
205
+ const liveCall = await this._ringDevice
206
+ .streamVideo({
187
207
  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),
188
208
  // output: ["-t", duration.toString(), "-f", "mjpeg", "-q:v", 3, "-frames:v", 1, tempPath]
189
- output: ["-f", "mjpeg", "-q:v", 3, "-frames:v", 1, tempPath]
190
- }).catch((reason) => {
209
+ output: ['-f', 'mjpeg', '-q:v', 3, '-frames:v', 1, tempPath],
210
+ })
211
+ .catch((reason) => {
191
212
  this.catcher("Couldn't create HD Snapshot (stream Video).", reason);
192
213
  return null;
193
214
  });
@@ -196,9 +217,12 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
196
217
  await this.updateHDSnapshotRequest(false);
197
218
  return;
198
219
  }
199
- const liveCallSucceeded = await rxjs.firstValueFrom(liveCall.onCallEnded).then((_result) => {
220
+ const liveCallSucceeded = await rxjs
221
+ .firstValueFrom(liveCall.onCallEnded)
222
+ .then((_result) => {
200
223
  return true;
201
- }).catch((reason) => {
224
+ })
225
+ .catch((reason) => {
202
226
  this.catcher("Couldn't create HD Snapshot (first value).", reason);
203
227
  return null;
204
228
  });
@@ -207,21 +231,20 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
207
231
  await this.updateHDSnapshotRequest(false);
208
232
  return;
209
233
  }
210
- else {
211
- this.silly("HD Snapshot from livestream created.");
212
- }
234
+ this.silly('HD Snapshot from livestream created.');
213
235
  let jpg = fs.readFileSync(tempPath);
214
236
  if (night_sharpen && this._adapter.config.sharpen_HDsnapshot && this._adapter.config.sharpen_HDsnapshot > 0) {
215
237
  const sharpen = this._adapter.config.sharpen_HDsnapshot == 1
216
238
  ? undefined
217
239
  : { sigma: this._adapter.config.sharpen_HDsnapshot - 1 };
218
- jpg = (_a = await (0, sharp_1.default)(jpg)
219
- .sharpen(sharpen)
220
- .toBuffer()
221
- .catch((reason) => {
222
- this.catcher("Couldn't sharpen HD Snapshot.", reason);
223
- return null;
224
- })) !== null && _a !== void 0 ? _a : jpg;
240
+ jpg =
241
+ (await (0, sharp_1.default)(jpg)
242
+ .sharpen(sharpen)
243
+ .toBuffer()
244
+ .catch((reason) => {
245
+ this.catcher("Couldn't sharpen HD Snapshot.", reason);
246
+ return null;
247
+ })) ?? jpg;
225
248
  }
226
249
  // clean up
227
250
  fs.unlink(tempPath, (err) => {
@@ -229,7 +252,7 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
229
252
  this.catcher(`Couldn't delete temp file ${tempPath}`, err);
230
253
  }
231
254
  });
232
- if (this._lastHDSnapShotDir !== "" && this._adapter.config.del_old_HDsnapshot) {
255
+ if (this._lastHDSnapShotDir !== '' && this._adapter.config.del_old_HDsnapshot) {
233
256
  file_service_1.FileService.deleteFileIfExistSync(this._lastHDSnapShotDir, this._adapter);
234
257
  }
235
258
  if (visPath) {
@@ -252,7 +275,7 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
252
275
  this.debug(`Toggling siren state for ${this.shortId} to ${state}`);
253
276
  try {
254
277
  await this._ringDevice.setSiren(state);
255
- this._adapter.upsertState(`${this.sirenChannelId}.${constants_1.STATE_ID_SIREN_SWITCH}`, constants_1.COMMON_SIREN_SWITCH, state, true);
278
+ await this._adapter.upsertState(`${this.sirenChannelId}.${constants_1.STATE_ID_SIREN_SWITCH}`, constants_1.COMMON_SIREN_SWITCH, state, true);
256
279
  this.debug(`Siren state set to ${state} successfully.`);
257
280
  }
258
281
  catch (err) {
@@ -261,9 +284,9 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
261
284
  }
262
285
  async takeSnapshot(uuid, eventBased = false) {
263
286
  this.silly(`${this.shortId}.takeSnapshot()`);
264
- const { visURL, visPath } = await file_service_1.FileService.getVisUrl(this._adapter, this.fullId, "Snapshot.jpg");
287
+ const { visURL, visPath } = await file_service_1.FileService.getVisUrl(this._adapter, this.fullId, 'Snapshot.jpg');
265
288
  if (!visURL || !visPath) {
266
- this.warn("Vis not available");
289
+ this.warn('Vis not available');
267
290
  }
268
291
  const { fullPath, dirname } = file_service_1.FileService.getPath(this._adapter.config.path_snapshot, this._adapter.config.filename_snapshot, ++this._HDsnapshotCount, this.shortId, this.fullId, this.kind);
269
292
  if (!(await file_service_1.FileService.prepareFolder(dirname))) {
@@ -277,21 +300,22 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
277
300
  await this.updateSnapshotRequest(false);
278
301
  return;
279
302
  }
280
- const image = await this._ringDevice.getNextSnapshot({ force: true, uuid: uuid })
303
+ const image = await this._ringDevice
304
+ .getNextSnapshot({ force: true, uuid: uuid })
281
305
  .then((result) => result)
282
306
  .catch((err) => {
283
307
  if (eventBased) {
284
- this.warn("Taking Snapshot on Event failed.");
308
+ this.warn('Taking Snapshot on Event failed.');
285
309
  }
286
310
  else {
287
311
  this.catcher("Couldn't get Snapshot from api.", err);
288
312
  }
289
- this.updateSnapshotRequest(false);
313
+ this.updateSnapshotRequest(false).catch(err => this.catcher('Cannot update snapshot request.', err));
290
314
  return err;
291
315
  });
292
316
  if (!image.byteLength) {
293
317
  if (eventBased) {
294
- this.warn("Taking Snapshot on Event failed (no image).");
318
+ this.warn('Taking Snapshot on Event failed (no image).');
295
319
  }
296
320
  else {
297
321
  this.warn("Couldn't create snapshot from image");
@@ -299,23 +323,19 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
299
323
  await this.updateSnapshotRequest(false);
300
324
  return;
301
325
  }
302
- else {
303
- this.silly(`Response timestamp: ${image.responseTimestamp},
326
+ this.silly(`Response timestamp: ${image.responseTimestamp},
304
327
  Byte Length: ${image.byteLength},
305
328
  Byte Offset: ${image.byteOffset},
306
329
  Length: ${image.length},
307
330
  Time in ms: ${image.timeMillis}`);
308
- }
309
331
  let image_txt = image;
310
332
  if (this._adapter.config.overlay_snapshot) {
311
- image_txt =
312
- 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`))
313
- .catch((reason) => {
314
- this.catcher("Couldn't add text to Snapshot.", reason);
315
- return reason;
316
- });
333
+ image_txt = 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`)).catch((reason) => {
334
+ this.catcher("Couldn't add text to Snapshot.", reason);
335
+ return reason;
336
+ });
317
337
  }
318
- if (this._lastSnapShotDir !== "" && this._adapter.config.del_old_snapshot) {
338
+ if (this._lastSnapShotDir !== '' && this._adapter.config.del_old_snapshot) {
319
339
  file_service_1.FileService.deleteFileIfExistSync(this._lastSnapShotDir, this._adapter);
320
340
  }
321
341
  this._lastSnapShotUrl = visURL;
@@ -332,16 +352,15 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
332
352
  }
333
353
  async updateHistory() {
334
354
  this.silly(`Update History`);
335
- this._ringDevice.getEvents({ limit: 50 })
336
- .then(async (r) => {
355
+ await this._ringDevice.getEvents({ limit: 50 }).then(async (r) => {
337
356
  this.silly(`Received Event History`);
338
357
  const lastAction = r.events.find((event) => {
339
358
  const kind = event.kind;
340
359
  switch (kind) {
341
- case "motion":
342
- case "ding":
343
- case "alarm":
344
- case "on_demand":
360
+ case 'motion':
361
+ case 'ding':
362
+ case 'alarm':
363
+ case 'on_demand':
345
364
  return true;
346
365
  }
347
366
  return false;
@@ -351,39 +370,39 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
351
370
  }
352
371
  const url = await this._ringDevice.getRecordingUrl(lastAction.ding_id_str);
353
372
  this.lastAction = new lastAction_1.LastAction(lastAction, url);
354
- this.updateHistoryObject(this.lastAction);
373
+ await this.updateHistoryObject(this.lastAction);
355
374
  });
356
375
  }
357
376
  async processUserInput(channelID, stateID, state) {
358
377
  switch (channelID) {
359
- case "":
378
+ case '': {
360
379
  if (stateID !== constants_1.STATE_ID_DEBUG_REQUEST) {
361
380
  return;
362
381
  }
363
382
  const targetVal = state.val;
364
383
  if (targetVal) {
365
384
  this.info(`Device Debug Data for ${this.shortId}: ${util.inspect(this._ringDevice, false, 1)}`);
366
- this._adapter.upsertState(`${this.fullId}.${constants_1.STATE_ID_DEBUG_REQUEST}`, constants_1.COMMON_DEBUG_REQUEST, false);
385
+ await this._adapter.upsertState(`${this.fullId}.${constants_1.STATE_ID_DEBUG_REQUEST}`, constants_1.COMMON_DEBUG_REQUEST, false);
367
386
  }
368
387
  return;
369
- case "Siren":
388
+ }
389
+ case 'Siren':
370
390
  if (!this._ringDevice.hasSiren) {
371
391
  return;
372
392
  }
373
393
  if (stateID === constants_1.STATE_ID_SIREN_SWITCH) {
374
394
  const targetVal = state.val;
375
395
  this.debug(`Set siren for ${this.shortId} to value ${targetVal}`);
376
- this._ringDevice.setSiren(targetVal).then((success) => {
377
- if (success) {
378
- this._adapter.upsertState(`${this.sirenChannelId}.${constants_1.STATE_ID_SIREN_SWITCH}`, constants_1.COMMON_SIREN_SWITCH, targetVal, true);
379
- }
380
- });
396
+ const success = await this._ringDevice.setSiren(targetVal);
397
+ if (success) {
398
+ await this._adapter.upsertState(`${this.sirenChannelId}.${constants_1.STATE_ID_SIREN_SWITCH}`, constants_1.COMMON_SIREN_SWITCH, targetVal, true);
399
+ }
381
400
  }
382
401
  else {
383
402
  this.error(`Unknown State/Switch with channel "${channelID}" and state "${stateID}"`);
384
403
  }
385
404
  break;
386
- case "Light":
405
+ case 'Light':
387
406
  if (!this._ringDevice.hasLight) {
388
407
  return;
389
408
  }
@@ -391,25 +410,24 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
391
410
  const targetVal = state.val;
392
411
  this.debug(`Set light for ${this.shortId} to value ${targetVal}`);
393
412
  this._lastLightCommand = Date.now();
394
- this._ringDevice.setLight(targetVal).then((success) => {
395
- if (success) {
396
- this._adapter.upsertState(`${this.lightChannelId}.light_state`, constants_1.COMMON_LIGHT_STATE, targetVal);
397
- this._adapter.upsertState(`${this.lightChannelId}.light_switch`, constants_1.COMMON_LIGHT_SWITCH, targetVal, true);
398
- setTimeout(() => this.updateHealth.bind(this), 65000);
399
- }
400
- });
413
+ const success = await this._ringDevice.setLight(targetVal);
414
+ if (success) {
415
+ await this._adapter.upsertState(`${this.lightChannelId}.light_state`, constants_1.COMMON_LIGHT_STATE, targetVal);
416
+ await this._adapter.upsertState(`${this.lightChannelId}.light_switch`, constants_1.COMMON_LIGHT_SWITCH, targetVal, true);
417
+ this._adapter.setTimeout(() => void this.updateHealth(), 65000);
418
+ }
401
419
  }
402
420
  else {
403
421
  this.error(`Unknown State/Switch with channel "${channelID}" and state "${stateID}"`);
404
422
  }
405
423
  break;
406
- case "Snapshot":
424
+ case 'Snapshot':
407
425
  if (stateID === constants_1.STATE_ID_SNAPSHOT_REQUEST) {
408
426
  const targetVal = state.val;
409
427
  this.debug(`Get Snapshot request for ${this.shortId} to value ${targetVal}`);
410
428
  if (targetVal) {
411
429
  await this.takeSnapshot().catch((reason) => {
412
- this.updateSnapshotRequest(false);
430
+ this.updateSnapshotRequest(false).catch(e => this.catcher('Cannot update snapshot request', e));
413
431
  this.catcher("Couldn't retrieve Snapshot.", reason);
414
432
  });
415
433
  }
@@ -418,13 +436,13 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
418
436
  this.error(`Unknown State/Switch with channel "${channelID}" and state "${stateID}"`);
419
437
  }
420
438
  break;
421
- case "HD Snapshot":
439
+ case 'HD Snapshot':
422
440
  if (stateID === constants_1.STATE_ID_HDSNAPSHOT_REQUEST) {
423
441
  const targetVal = state.val;
424
442
  this.debug(`Get HDSnapshot request for ${this.shortId} to value ${targetVal}`);
425
443
  if (targetVal) {
426
444
  await this.takeHDSnapshot().catch((reason) => {
427
- this.updateHDSnapshotRequest(false);
445
+ this.updateHDSnapshotRequest(false).catch(e => this.catcher('Cannot update HD snapshot request', e));
428
446
  this.catcher("Couldn't retrieve HDSnapshot.", reason);
429
447
  });
430
448
  }
@@ -433,13 +451,13 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
433
451
  this.error(`Unknown State/Switch with channel "${channelID}" and state "${stateID}"`);
434
452
  }
435
453
  break;
436
- case "Livestream":
454
+ case 'Livestream':
437
455
  if (stateID === constants_1.STATE_ID_LIVESTREAM_REQUEST) {
438
456
  const targetVal = state.val;
439
457
  this.debug(`Get Livestream request for ${this.shortId} to value ${targetVal}`);
440
458
  if (targetVal) {
441
459
  await this.startLivestream().catch((reason) => {
442
- this.updateLivestreamRequest(false);
460
+ this.updateLivestreamRequest(false).catch(e => this.catcher('Cannot update Livestream request', e));
443
461
  this.catcher("Couldn't retrieve Livestream.", reason);
444
462
  });
445
463
  }
@@ -460,49 +478,49 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
460
478
  async recreateDeviceObjectTree() {
461
479
  this.silly(`Recreate DeviceObjectTree`);
462
480
  await this._adapter.setObjectNotExistsAsync(this.fullId, {
463
- type: "device",
481
+ type: 'device',
464
482
  common: {
465
483
  name: `Device ${this.shortId} ("${this._ringDevice.data.description}")`,
466
484
  },
467
485
  native: {},
468
486
  });
469
487
  await this._adapter.setObjectNotExistsAsync(`${this.fullId}.${constants_1.CHANNEL_NAME_INFO}`, {
470
- type: "channel",
488
+ type: 'channel',
471
489
  common: {
472
490
  name: `Info ${this.shortId}`,
473
491
  },
474
492
  native: {},
475
493
  });
476
494
  await this._adapter.setObjectNotExistsAsync(`${this.fullId}.${constants_1.CHANNEL_NAME_SNAPSHOT}`, {
477
- type: "channel",
495
+ type: 'channel',
478
496
  common: {
479
497
  name: `Snapshot ${this.shortId}`,
480
498
  },
481
499
  native: {},
482
500
  });
483
501
  await this._adapter.setObjectNotExistsAsync(`${this.fullId}.${constants_1.CHANNEL_NAME_HDSNAPSHOT}`, {
484
- type: "channel",
502
+ type: 'channel',
485
503
  common: {
486
504
  name: `HD Snapshot ${this.shortId}`,
487
505
  },
488
506
  native: {},
489
507
  });
490
508
  await this._adapter.setObjectNotExistsAsync(`${this.fullId}.${constants_1.CHANNEL_NAME_LIVESTREAM}`, {
491
- type: "channel",
509
+ type: 'channel',
492
510
  common: {
493
511
  name: `Livestream ${this.shortId}`,
494
512
  },
495
513
  native: {},
496
514
  });
497
515
  await this._adapter.setObjectNotExistsAsync(`${this.fullId}.${constants_1.CHANNEL_NAME_HISTORY}`, {
498
- type: "channel",
516
+ type: 'channel',
499
517
  common: {
500
518
  name: `History`,
501
519
  },
502
520
  native: {},
503
521
  });
504
522
  await this._adapter.setObjectNotExistsAsync(`${this.fullId}.${constants_1.CHANNEL_NAME_EVENTS}`, {
505
- type: "channel",
523
+ type: 'channel',
506
524
  common: {
507
525
  name: `Events`,
508
526
  },
@@ -512,7 +530,7 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
512
530
  this.debug(`Device with Siren Capabilities detected`);
513
531
  // Ersetzen von createChannel durch setObjectNotExistsAsync
514
532
  await this._adapter.setObjectNotExistsAsync(`${this.fullId}.${constants_1.CHANNEL_NAME_SIREN}`, {
515
- type: "channel",
533
+ type: 'channel',
516
534
  common: {
517
535
  name: `Siren ${this.shortId}`,
518
536
  },
@@ -524,7 +542,7 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
524
542
  this.debug(`Device with Light Capabilities detected`);
525
543
  // Ersetzen von createChannel durch setObjectNotExistsAsync
526
544
  await this._adapter.setObjectNotExistsAsync(`${this.fullId}.${constants_1.CHANNEL_NAME_LIGHT}`, {
527
- type: "channel",
545
+ type: 'channel',
528
546
  common: {
529
547
  name: `Light ${this.shortId}`,
530
548
  },
@@ -535,51 +553,51 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
535
553
  this._lastSnapShotDir = await this._adapter.tryGetStringState(`${this.snapshotChannelId}.file`);
536
554
  this._lastHDSnapShotDir = await this._adapter.tryGetStringState(`${this.HDsnapshotChannelId}.file`);
537
555
  this._lastLiveStreamDir = await this._adapter.tryGetStringState(`${this.liveStreamChannelId}.file`);
538
- if (this._adapter.config.auto_snapshot === undefined)
556
+ if (this._adapter.config.auto_snapshot === undefined) {
539
557
  this._adapter.config.auto_snapshot = false;
540
- if (this._adapter.config.auto_HDsnapshot === undefined)
558
+ }
559
+ if (this._adapter.config.auto_HDsnapshot === undefined) {
541
560
  this._adapter.config.auto_HDsnapshot = false;
542
- if (this._adapter.config.auto_livestream === undefined)
561
+ }
562
+ if (this._adapter.config.auto_livestream === undefined) {
543
563
  this._adapter.config.auto_livestream = false;
564
+ }
544
565
  await this._adapter.upsertState(`${this.fullId}.${constants_1.STATE_ID_DEBUG_REQUEST}`, constants_1.COMMON_DEBUG_REQUEST, false, true, true);
545
566
  await this._adapter.upsertState(`${this.snapshotChannelId}.${constants_1.STATE_ID_SNAPSHOT_REQUEST}`, constants_1.COMMON_SNAPSHOT_REQUEST, false, true, true);
546
567
  await this._adapter.upsertState(`${this.HDsnapshotChannelId}.${constants_1.STATE_ID_HDSNAPSHOT_REQUEST}`, constants_1.COMMON_HDSNAPSHOT_REQUEST, false, true, true);
547
568
  await this._adapter.upsertState(`${this.liveStreamChannelId}.${constants_1.STATE_ID_LIVESTREAM_REQUEST}`, constants_1.COMMON_LIVESTREAM_REQUEST, false, true, true);
548
- this._adapter.upsertState(`${this.liveStreamChannelId}.${constants_1.STATE_ID_LIVESTREAM_DURATION}`, constants_1.COMMON_LIVESTREAM_DURATION, this._durationLiveStream, true);
549
- this._adapter.upsertState(`${this.eventsChannelId}.ondemand`, constants_1.COMMON_ON_DEMAND, false);
550
- this._adapter.upsertState(`${this.snapshotChannelId}.auto`, constants_1.COMMON_SNAPSHOT_AUTO, this._adapter.config.auto_snapshot);
551
- this._adapter.upsertState(`${this.HDsnapshotChannelId}.auto`, constants_1.COMMON_HDSNAPSHOT_AUTO, this._adapter.config.auto_HDsnapshot);
552
- this._adapter.upsertState(`${this.liveStreamChannelId}.auto`, constants_1.COMMON_LIVESTREAM_AUTO, this._adapter.config.auto_livestream);
569
+ await this._adapter.upsertState(`${this.liveStreamChannelId}.${constants_1.STATE_ID_LIVESTREAM_DURATION}`, constants_1.COMMON_LIVESTREAM_DURATION, this._durationLiveStream, true);
570
+ await this._adapter.upsertState(`${this.eventsChannelId}.ondemand`, constants_1.COMMON_ON_DEMAND, false);
571
+ await this._adapter.upsertState(`${this.snapshotChannelId}.auto`, constants_1.COMMON_SNAPSHOT_AUTO, this._adapter.config.auto_snapshot);
572
+ await this._adapter.upsertState(`${this.HDsnapshotChannelId}.auto`, constants_1.COMMON_HDSNAPSHOT_AUTO, this._adapter.config.auto_HDsnapshot);
573
+ await this._adapter.upsertState(`${this.liveStreamChannelId}.auto`, constants_1.COMMON_LIVESTREAM_AUTO, this._adapter.config.auto_livestream);
553
574
  // Remove legacy states
554
- this._adapter.delObject(`${this.snapshotChannelId}.snapshot_file`);
555
- this._adapter.delObject(`${this.snapshotChannelId}.snapshot_url`);
556
- this._adapter.delObject(`${this.HDsnapshotChannelId}.snapshot_file`);
557
- this._adapter.delObject(`${this.HDsnapshotChannelId}.snapshot_url`);
558
- this._adapter.delObject(`${this.liveStreamChannelId}.livestream_file`);
559
- this._adapter.delObject(`${this.liveStreamChannelId}.livestream_url`);
575
+ await this._adapter.delObjectAsync(`${this.snapshotChannelId}.snapshot_file`);
576
+ await this._adapter.delObjectAsync(`${this.snapshotChannelId}.snapshot_url`);
577
+ await this._adapter.delObjectAsync(`${this.HDsnapshotChannelId}.snapshot_file`);
578
+ await this._adapter.delObjectAsync(`${this.HDsnapshotChannelId}.snapshot_url`);
579
+ await this._adapter.delObjectAsync(`${this.liveStreamChannelId}.livestream_file`);
580
+ await this._adapter.delObjectAsync(`${this.liveStreamChannelId}.livestream_url`);
560
581
  }
561
582
  async prepareLivestreamTargetFile() {
562
- const { visURL, visPath } = await file_service_1.FileService.getVisUrl(this._adapter, this.fullId, "Livestream.mp4").catch((reason) => {
583
+ const { visURL, visPath } = await file_service_1.FileService.getVisUrl(this._adapter, this.fullId, 'Livestream.mp4').catch((reason) => {
563
584
  this.catcher("Couldn't get Vis URL.", reason);
564
- return { visURL: "", visPath: "" };
585
+ return { visURL: '', visPath: '' };
565
586
  });
566
- return new Promise(async (resolve, reject) => {
567
- if (!visURL || !visPath) {
568
- reject("Vis not available");
569
- }
570
- 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);
571
- const folderPrepared = await file_service_1.FileService.prepareFolder(dirname).catch((reason) => {
572
- this.catcher("Couldn't prepare folder.", reason);
573
- return false;
574
- });
575
- if (!folderPrepared) {
576
- this.warn(`Failed to prepare Livestream folder ("${fullPath}")`);
577
- reject("Failed to prepare Livestream folder");
578
- return;
579
- }
580
- file_service_1.FileService.deleteFileIfExistSync(fullPath, this._adapter);
581
- resolve({ visURL: visURL, visPath: visPath, fullPath: fullPath });
587
+ if (!visURL || !visPath) {
588
+ throw new Error('Vis not available');
589
+ }
590
+ 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);
591
+ const folderPrepared = await file_service_1.FileService.prepareFolder(dirname).catch((reason) => {
592
+ this.catcher("Couldn't prepare folder.", reason);
593
+ return false;
582
594
  });
595
+ if (!folderPrepared) {
596
+ this.warn(`Failed to prepare Livestream folder ("${fullPath}")`);
597
+ throw new Error('Failed to prepare Livestream folder');
598
+ }
599
+ file_service_1.FileService.deleteFileIfExistSync(fullPath, this._adapter);
600
+ return { visURL: visURL, visPath: visPath, fullPath: fullPath };
583
601
  }
584
602
  getActiveNightImageOptions() {
585
603
  let night_contrast = false;
@@ -589,73 +607,82 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
589
607
  this.silly(`Now: ${today}, sunrise: ${this._adapter.Sunrise}, sunset: ${this._adapter.Sunset}`);
590
608
  const isNight = today < this._adapter.Sunrise || today > this._adapter.Sunset;
591
609
  this.debug(`is Night: ${isNight}`);
592
- night_contrast = this._adapter.config.night_contrast_HDsnapshot && isNight || !this._adapter.config.night_contrast_HDsnapshot;
593
- night_sharpen = this._adapter.config.night_sharpen_HDsnapshot && isNight || !this._adapter.config.night_sharpen_HDsnapshot;
610
+ night_contrast =
611
+ (this._adapter.config.night_contrast_HDsnapshot && isNight) ||
612
+ !this._adapter.config.night_contrast_HDsnapshot;
613
+ night_sharpen =
614
+ (this._adapter.config.night_sharpen_HDsnapshot && isNight) ||
615
+ !this._adapter.config.night_sharpen_HDsnapshot;
594
616
  }
595
617
  return { night_contrast, night_sharpen };
596
618
  }
597
619
  updateByDevice(ringDevice) {
598
620
  this._ringDevice = ringDevice;
599
- this.subscribeToEvents();
621
+ this.subscribeToEvents().catch(e => this.catcher("Couldn't subscribe to events.", e));
600
622
  this._state = EventState.Idle;
601
- this.update(ringDevice.data);
623
+ this.update(ringDevice.data).catch(e => this.catcher("Couldn't update device data.", e));
602
624
  }
603
- update(data) {
625
+ async update(data) {
604
626
  this.debug(`Received Update`);
605
- this.updateDeviceInfoObject(data);
627
+ await this.updateDeviceInfoObject(data);
606
628
  this.updateHealth();
607
- this.updateHistory();
629
+ this.updateHistory().catch(e => this.catcher("Couldn't update History.", e));
608
630
  }
609
631
  setDurationLivestream(val) {
610
632
  this.silly(`${this.shortId}.durationLivestream()`);
611
633
  this._durationLiveStream = val;
612
- this._adapter.upsertState(`${this.liveStreamChannelId}.${constants_1.STATE_ID_LIVESTREAM_DURATION}`, constants_1.COMMON_LIVESTREAM_DURATION, this._durationLiveStream);
634
+ this._adapter
635
+ .upsertState(`${this.liveStreamChannelId}.${constants_1.STATE_ID_LIVESTREAM_DURATION}`, constants_1.COMMON_LIVESTREAM_DURATION, this._durationLiveStream)
636
+ .catch(e => this.catcher(`Cannot upsert state ${this.liveStreamChannelId}.${constants_1.STATE_ID_LIVESTREAM_DURATION}`, e));
613
637
  this.debug(`Livestream duration set to: ${val}`);
614
638
  }
615
639
  updateHealth() {
616
640
  this.silly(`Update Health`);
617
- this._ringDevice.getHealth().then(this.updateHealthObject.bind(this));
641
+ this._ringDevice
642
+ .getHealth()
643
+ .then(this.updateHealthObject.bind(this))
644
+ .catch(e => this.catcher("Couldn't update Health.", e));
618
645
  }
619
646
  autoSched() {
620
647
  const media = [
621
648
  {
622
- name: "Snaspshot",
649
+ name: 'Snaspshot',
623
650
  val: this._adapter.config.save_snapshot,
624
651
  fct: () => {
625
- this.takeSnapshot();
652
+ this.takeSnapshot().catch(e => this.catcher('Cannot take snapshot', e));
626
653
  },
627
- start: 0
654
+ start: 0,
628
655
  },
629
656
  {
630
- name: "HD Snapshot",
657
+ name: 'HD Snapshot',
631
658
  val: this._adapter.config.save_HDsnapshot,
632
659
  fct: () => {
633
- this.takeHDSnapshot();
660
+ this.takeHDSnapshot().catch(e => this.catcher('Cannot take HD snapshot', e));
634
661
  },
635
- start: 20
662
+ start: 20,
636
663
  },
637
664
  {
638
- name: "Livestream",
665
+ name: 'Livestream',
639
666
  val: this._adapter.config.save_livestream,
640
667
  fct: () => {
641
- this.startLivestream(this._adapter.config.recordtime_auto_livestream);
668
+ this.startLivestream(this._adapter.config.recordtime_auto_livestream).catch(e => this.catcher('Cannot start livestream', e));
642
669
  },
643
- start: 40
644
- }
670
+ start: 40,
671
+ },
645
672
  ];
646
673
  for (const m of media) {
647
674
  if (m.val > 0) {
648
675
  let schedSec = m.start.toString();
649
- let schedMin = "*";
650
- let schedHour = "*";
651
- let schedDay = "*";
676
+ let schedMin = '*';
677
+ let schedHour = '*';
678
+ let schedDay = '*';
652
679
  if (m.val < 60) {
653
680
  schedSec = `*/${m.val.toString()}`;
654
681
  }
655
682
  else if (m.val < 3600) {
656
683
  schedMin = `*/${(m.val / 60).toString()}`;
657
684
  }
658
- else if (m.val < 43.200) {
685
+ else if (m.val < 43.2) {
659
686
  schedHour = `*/${(m.val / 3600).toString()}`;
660
687
  }
661
688
  else {
@@ -663,17 +690,19 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
663
690
  }
664
691
  const t = `${schedSec} ${schedMin} ${schedHour} ${schedDay} * *`;
665
692
  this.info(`Create scheduled Job for ${m.name} at "${t}"`);
666
- node_schedule_1.default.scheduleJob(`Auto save ${m.name}_${this._adapter.name}_${this._adapter.instance}`, t, async () => {
693
+ this._adapter.registerScheduledJob(node_schedule_1.default.scheduleJob(`Auto save ${m.name}_${this._adapter.name}_${this._adapter.instance}`, t, async () => {
667
694
  const recAct = await this._adapter.getStateAsync(`${this.eventsChannelId}.ondemand`);
668
695
  if (!recAct || !recAct.val) {
669
696
  this.info(`Cronjob Auto save ${m.name} starts`);
670
- this._adapter.upsertState(`${this.eventsChannelId}.ondemand`, constants_1.COMMON_ON_DEMAND, true);
697
+ this._adapter
698
+ .upsertState(`${this.eventsChannelId}.ondemand`, constants_1.COMMON_ON_DEMAND, true)
699
+ .catch(e => this.catcher(`Cannot upsert state ${this.eventsChannelId}.ondemand`, e));
671
700
  m.fct(this._adapter.config.recordtime_auto_livestream);
672
701
  }
673
702
  else {
674
703
  this.warn(`Cronjob ${m.name} not executed because another job is already running. Please adapt timer and/or duration time!`);
675
704
  }
676
- });
705
+ }));
677
706
  }
678
707
  }
679
708
  }
@@ -688,7 +717,7 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
688
717
  this._ringDevice.onData.subscribe(this.update.bind(this));
689
718
  this._ringDevice.onMotionDetected.subscribe({
690
719
  next: (motion) => {
691
- this.onMotion(motion);
720
+ this.onMotion(motion).catch(e => this.catcher('Cannot react on motion', e));
692
721
  },
693
722
  error: (err) => {
694
723
  this.catcher(`Motion Observer received error`, err);
@@ -696,7 +725,7 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
696
725
  });
697
726
  this._ringDevice.onDoorbellPressed.subscribe({
698
727
  next: (ding) => {
699
- this.onDoorbell(ding);
728
+ this.onDoorbell(ding).catch(e => this.catcher('Cannot react on doorbell', e));
700
729
  },
701
730
  error: (err) => {
702
731
  this.catcher(`Doorbell Observer received error`, err);
@@ -704,93 +733,91 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
704
733
  });
705
734
  this._ringDevice.onNewNotification.subscribe({
706
735
  next: (ding) => {
707
- this.onNotify(ding);
736
+ this.onNotify(ding).catch(e => this.catcher('Cannot react on notification', e));
708
737
  },
709
738
  error: (err) => {
710
739
  this.catcher(`Notify Observer received error`, err);
711
740
  },
712
741
  });
713
742
  }
714
- updateDeviceInfoObject(data) {
715
- this._adapter.upsertState(`${this.infoChannelId}.id`, constants_1.COMMON_INFO_ID, data.device_id);
716
- this._adapter.upsertState(`${this.infoChannelId}.kind`, constants_1.COMMON_INFO_KIND, data.kind);
717
- this._adapter.upsertState(`${this.infoChannelId}.description`, constants_1.COMMON_INFO_DESCRIPTION, data.description);
718
- this._adapter.upsertState(`${this.infoChannelId}.external_connection`, constants_1.COMMON_INFO_EXTERNAL_CONNECTION, data.external_connection);
719
- this._adapter.upsertState(`${this.infoChannelId}.hasLight`, constants_1.COMMON_INFO_HAS_LIGHT, this._ringDevice.hasLight);
720
- this._adapter.upsertState(`${this.infoChannelId}.hasBattery`, constants_1.COMMON_INFO_HAS_BATTERY, this._ringDevice.hasBattery);
721
- this._adapter.upsertState(`${this.infoChannelId}.hasSiren`, constants_1.COMMON_INFO_HAS_SIREN, this._ringDevice.hasSiren);
743
+ async updateDeviceInfoObject(data) {
744
+ await this._adapter.upsertState(`${this.infoChannelId}.id`, constants_1.COMMON_INFO_ID, data.device_id);
745
+ await this._adapter.upsertState(`${this.infoChannelId}.kind`, constants_1.COMMON_INFO_KIND, data.kind);
746
+ await this._adapter.upsertState(`${this.infoChannelId}.description`, constants_1.COMMON_INFO_DESCRIPTION, data.description);
747
+ await this._adapter.upsertState(`${this.infoChannelId}.external_connection`, constants_1.COMMON_INFO_EXTERNAL_CONNECTION, data.external_connection);
748
+ await this._adapter.upsertState(`${this.infoChannelId}.hasLight`, constants_1.COMMON_INFO_HAS_LIGHT, this._ringDevice.hasLight);
749
+ await this._adapter.upsertState(`${this.infoChannelId}.hasBattery`, constants_1.COMMON_INFO_HAS_BATTERY, this._ringDevice.hasBattery);
750
+ await this._adapter.upsertState(`${this.infoChannelId}.hasSiren`, constants_1.COMMON_INFO_HAS_SIREN, this._ringDevice.hasSiren);
722
751
  }
723
- updateHistoryObject(lastAction) {
724
- this._adapter.upsertState(`${this.historyChannelId}.created_at`, constants_1.COMMON_HISTORY_CREATED_AT, lastAction.event.created_at);
725
- this._adapter.upsertState(`${this.historyChannelId}.history_url`, constants_1.COMMON_HISTORY_URL, lastAction.historyUrl);
726
- this._adapter.upsertState(`${this.historyChannelId}.kind`, constants_1.COMMON_HISTORY_KIND, lastAction.event.kind);
752
+ async updateHistoryObject(lastAction) {
753
+ await this._adapter.upsertState(`${this.historyChannelId}.created_at`, constants_1.COMMON_HISTORY_CREATED_AT, lastAction.event.created_at);
754
+ await this._adapter.upsertState(`${this.historyChannelId}.history_url`, constants_1.COMMON_HISTORY_URL, lastAction.historyUrl);
755
+ await this._adapter.upsertState(`${this.historyChannelId}.kind`, constants_1.COMMON_HISTORY_KIND, lastAction.event.kind);
727
756
  }
728
757
  async updateSnapshotRequest(ack = true) {
729
- this._adapter.upsertState(`${this.eventsChannelId}.ondemand`, constants_1.COMMON_ON_DEMAND, false);
758
+ await this._adapter.upsertState(`${this.eventsChannelId}.ondemand`, constants_1.COMMON_ON_DEMAND, false);
730
759
  // subscribe to true, because user request doesn't change value via upsertState
731
- this._adapter.upsertState(`${this.snapshotChannelId}.${constants_1.STATE_ID_SNAPSHOT_REQUEST}`, constants_1.COMMON_SNAPSHOT_REQUEST, false, ack, true);
760
+ await this._adapter.upsertState(`${this.snapshotChannelId}.${constants_1.STATE_ID_SNAPSHOT_REQUEST}`, constants_1.COMMON_SNAPSHOT_REQUEST, false, ack, true);
732
761
  }
733
762
  async updateHDSnapshotRequest(ack = true) {
734
- this._adapter.upsertState(`${this.eventsChannelId}.ondemand`, constants_1.COMMON_ON_DEMAND, false);
763
+ await this._adapter.upsertState(`${this.eventsChannelId}.ondemand`, constants_1.COMMON_ON_DEMAND, false);
735
764
  // subscribe to true, because user request doesn't change value via upsertState
736
- this._adapter.upsertState(`${this.HDsnapshotChannelId}.${constants_1.STATE_ID_HDSNAPSHOT_REQUEST}`, constants_1.COMMON_HDSNAPSHOT_REQUEST, false, ack, true);
765
+ await this._adapter.upsertState(`${this.HDsnapshotChannelId}.${constants_1.STATE_ID_HDSNAPSHOT_REQUEST}`, constants_1.COMMON_HDSNAPSHOT_REQUEST, false, ack, true);
737
766
  }
738
767
  async updateLivestreamRequest(ack = true) {
739
- this._adapter.upsertState(`${this.eventsChannelId}.ondemand`, constants_1.COMMON_ON_DEMAND, false);
768
+ await this._adapter.upsertState(`${this.eventsChannelId}.ondemand`, constants_1.COMMON_ON_DEMAND, false);
740
769
  // subscribe to true, because user request doesn't change value via upsertState
741
- this._adapter.upsertState(`${this.liveStreamChannelId}.${constants_1.STATE_ID_LIVESTREAM_REQUEST}`, constants_1.COMMON_LIVESTREAM_REQUEST, false, ack, true);
770
+ await this._adapter.upsertState(`${this.liveStreamChannelId}.${constants_1.STATE_ID_LIVESTREAM_REQUEST}`, constants_1.COMMON_LIVESTREAM_REQUEST, false, ack, true);
742
771
  this._durationLiveStream = this._adapter.config.recordtime_livestream;
743
- this._adapter.upsertState(`${this.liveStreamChannelId}.${constants_1.STATE_ID_LIVESTREAM_DURATION}`, constants_1.COMMON_LIVESTREAM_DURATION, this._durationLiveStream, ack);
772
+ await this._adapter.upsertState(`${this.liveStreamChannelId}.${constants_1.STATE_ID_LIVESTREAM_DURATION}`, constants_1.COMMON_LIVESTREAM_DURATION, this._durationLiveStream, ack);
744
773
  }
745
774
  async updateSnapshotObject() {
746
775
  this.debug(`Update Snapshot Object`);
747
776
  if (this._lastSnapshotTimestamp !== 0) {
748
- this._adapter.upsertState(`${this.snapshotChannelId}.file`, constants_1.COMMON_SNAPSHOT_FILE, this._lastSnapShotDir);
749
- this._adapter.upsertState(`${this.snapshotChannelId}.moment`, constants_1.COMMON_SNAPSHOT_MOMENT, this._lastSnapshotTimestamp);
750
- this._adapter.upsertState(`${this.snapshotChannelId}.url`, constants_1.COMMON_SNAPSHOT_URL, this._lastSnapShotUrl);
777
+ await this._adapter.upsertState(`${this.snapshotChannelId}.file`, constants_1.COMMON_SNAPSHOT_FILE, this._lastSnapShotDir);
778
+ await this._adapter.upsertState(`${this.snapshotChannelId}.moment`, constants_1.COMMON_SNAPSHOT_MOMENT, this._lastSnapshotTimestamp);
779
+ await this._adapter.upsertState(`${this.snapshotChannelId}.url`, constants_1.COMMON_SNAPSHOT_URL, this._lastSnapShotUrl);
751
780
  }
752
781
  await this.updateSnapshotRequest();
753
782
  }
754
783
  async updateHDSnapshotObject() {
755
784
  this.debug(`Update HD Snapshot Object`);
756
785
  if (this._lastHDSnapshotTimestamp !== 0) {
757
- this._adapter.upsertState(`${this.HDsnapshotChannelId}.file`, constants_1.COMMON_HDSNAPSHOT_FILE, this._lastHDSnapShotDir);
758
- this._adapter.upsertState(`${this.HDsnapshotChannelId}.moment`, constants_1.COMMON_HDSNAPSHOT_MOMENT, this._lastHDSnapshotTimestamp);
759
- this._adapter.upsertState(`${this.HDsnapshotChannelId}.url`, constants_1.COMMON_HDSNAPSHOT_URL, this._lastHDSnapShotUrl);
786
+ await this._adapter.upsertState(`${this.HDsnapshotChannelId}.file`, constants_1.COMMON_HDSNAPSHOT_FILE, this._lastHDSnapShotDir);
787
+ await this._adapter.upsertState(`${this.HDsnapshotChannelId}.moment`, constants_1.COMMON_HDSNAPSHOT_MOMENT, this._lastHDSnapshotTimestamp);
788
+ await this._adapter.upsertState(`${this.HDsnapshotChannelId}.url`, constants_1.COMMON_HDSNAPSHOT_URL, this._lastHDSnapShotUrl);
760
789
  }
761
790
  await this.updateHDSnapshotRequest();
762
791
  }
763
792
  async updateLiveStreamObject() {
764
793
  this.debug(`Update Livestream Object`);
765
794
  if (this._lastLiveStreamTimestamp !== 0) {
766
- this._adapter.upsertState(`${this.liveStreamChannelId}.file`, constants_1.COMMON_LIVESTREAM_FILE, this._lastLiveStreamDir);
767
- this._adapter.upsertState(`${this.liveStreamChannelId}.url`, constants_1.COMMON_LIVESTREAM_URL, this._lastLiveStreamUrl);
768
- this._adapter.upsertState(`${this.liveStreamChannelId}.moment`, constants_1.COMMON_LIVESTREAM_MOMENT, this._lastLiveStreamTimestamp);
795
+ await this._adapter.upsertState(`${this.liveStreamChannelId}.file`, constants_1.COMMON_LIVESTREAM_FILE, this._lastLiveStreamDir);
796
+ await this._adapter.upsertState(`${this.liveStreamChannelId}.url`, constants_1.COMMON_LIVESTREAM_URL, this._lastLiveStreamUrl);
797
+ await this._adapter.upsertState(`${this.liveStreamChannelId}.moment`, constants_1.COMMON_LIVESTREAM_MOMENT, this._lastLiveStreamTimestamp);
769
798
  }
770
799
  await this.updateLivestreamRequest();
771
800
  }
772
- updateHealthObject(health) {
773
- var _a;
774
- this.debug("Update Health Callback");
775
- let batteryPercent = parseInt((_a = health.battery_percentage) !== null && _a !== void 0 ? _a : "-1");
801
+ async updateHealthObject(health) {
802
+ this.debug('Update Health Callback');
803
+ let batteryPercent = parseInt(health.battery_percentage ?? '-1');
776
804
  if (isNaN(batteryPercent)) {
777
805
  batteryPercent = -1;
778
806
  }
779
- this._adapter.upsertState(`${this.infoChannelId}.battery_percentage`, constants_1.COMMON_INFO_BATTERY_PERCENTAGE, batteryPercent);
780
- this._adapter.upsertState(`${this.infoChannelId}.battery_percentage_category`, constants_1.COMMON_INFO_BATTERY_PERCENTAGE_CATEGORY, health.battery_percentage_category);
781
- this._adapter.upsertState(`${this.infoChannelId}.wifi_name`, constants_1.COMMON_INFO_WIFI_NAME, health.wifi_name);
782
- this._adapter.upsertState(`${this.infoChannelId}.latest_signal_strength`, constants_1.COMMON_INFO_LATEST_SIGNAL_STRENGTH, health.latest_signal_strength);
783
- this._adapter.upsertState(`${this.infoChannelId}.latest_signal_category`, constants_1.COMMON_INFO_LATEST_SIGNAL_CATEGORY, health.latest_signal_category);
784
- this._adapter.upsertState(`${this.infoChannelId}.firmware`, constants_1.COMMON_INFO_FIRMWARE, health.firmware);
785
- if (this._ringDevice.hasLight && (Date.now() - this._lastLightCommand > 60000)) {
807
+ await this._adapter.upsertState(`${this.infoChannelId}.battery_percentage`, constants_1.COMMON_INFO_BATTERY_PERCENTAGE, batteryPercent);
808
+ await this._adapter.upsertState(`${this.infoChannelId}.battery_percentage_category`, constants_1.COMMON_INFO_BATTERY_PERCENTAGE_CATEGORY, health.battery_percentage_category);
809
+ await this._adapter.upsertState(`${this.infoChannelId}.wifi_name`, constants_1.COMMON_INFO_WIFI_NAME, health.wifi_name);
810
+ await this._adapter.upsertState(`${this.infoChannelId}.latest_signal_strength`, constants_1.COMMON_INFO_LATEST_SIGNAL_STRENGTH, health.latest_signal_strength);
811
+ await this._adapter.upsertState(`${this.infoChannelId}.latest_signal_category`, constants_1.COMMON_INFO_LATEST_SIGNAL_CATEGORY, health.latest_signal_category);
812
+ await this._adapter.upsertState(`${this.infoChannelId}.firmware`, constants_1.COMMON_INFO_FIRMWARE, health.firmware);
813
+ if (this._ringDevice.hasLight && Date.now() - this._lastLightCommand > 60000) {
786
814
  // this.silly(JSON.stringify(this._ringDevice.data));
787
815
  const floodlightOn = this._ringDevice.data.health.floodlight_on;
788
816
  this.debug(`Update Light within Health Update Floodlight is ${floodlightOn}`);
789
- this._adapter.upsertState(`${this.lightChannelId}.light_state`, constants_1.COMMON_LIGHT_STATE, floodlightOn);
817
+ await this._adapter.upsertState(`${this.lightChannelId}.light_state`, constants_1.COMMON_LIGHT_STATE, floodlightOn);
790
818
  }
791
819
  }
792
- onNotify(value) {
793
- var _a;
820
+ async onNotify(value) {
794
821
  this.debug(`Received Notify Event (${util.inspect(value, true, 1)})`);
795
822
  if (value) {
796
823
  if (this._notifyEventBlocker.checkBlock()) {
@@ -798,16 +825,16 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
798
825
  return;
799
826
  }
800
827
  if (value.img != null) {
801
- this.notifyRecording(EventState.ReactingOnEvent, value.img.snapshot_uuid);
828
+ await this.notifyRecording(EventState.ReactingOnEvent, value.img.snapshot_uuid);
802
829
  }
803
830
  const subType = value.data.event.ding.subtype;
804
- this._adapter.upsertState(`${this.eventsChannelId}.type`, constants_1.COMMON_EVENTS_TYPE, text_service_1.TextService.getdetectionType(subType, this._adapter.language));
805
- this._adapter.upsertState(`${this.eventsChannelId}.detectionType`, constants_1.COMMON_EVENTS_DETECTIONTYPE, text_service_1.TextService.getdetectionType((_a = value.data.event.ding.detection_type) !== null && _a !== void 0 ? _a : subType, this._adapter.language));
806
- this._adapter.upsertState(`${this.eventsChannelId}.created_at`, constants_1.COMMON_EVENTS_MOMENT, Date.now());
807
- this._adapter.upsertState(`${this.eventsChannelId}.message`, constants_1.COMMON_EVENTS_MESSAGE, value.android_config.body);
831
+ await this._adapter.upsertState(`${this.eventsChannelId}.type`, constants_1.COMMON_EVENTS_TYPE, text_service_1.TextService.getDetectionType(subType, this._adapter.language));
832
+ await this._adapter.upsertState(`${this.eventsChannelId}.detectionType`, constants_1.COMMON_EVENTS_DETECTIONTYPE, text_service_1.TextService.getDetectionType(value.data.event.ding.detection_type ?? subType, this._adapter.language));
833
+ await this._adapter.upsertState(`${this.eventsChannelId}.created_at`, constants_1.COMMON_EVENTS_MOMENT, Date.now());
834
+ await this._adapter.upsertState(`${this.eventsChannelId}.message`, constants_1.COMMON_EVENTS_MESSAGE, value.android_config.body);
808
835
  }
809
836
  }
810
- onMotion(value) {
837
+ async onMotion(value) {
811
838
  // value = true -> motion
812
839
  this.debug(`Received Motion Event (${util.inspect(value, true, 1)})`);
813
840
  if (value) {
@@ -815,19 +842,21 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
815
842
  this.debug(`ignore Motion event...`);
816
843
  return;
817
844
  }
818
- this._adapter.upsertState(`${this.eventsChannelId}.motion`, constants_1.COMMON_MOTION, value);
845
+ await this._adapter.upsertState(`${this.eventsChannelId}.motion`, constants_1.COMMON_MOTION, value);
819
846
  }
820
847
  }
821
- onDoorbell(value) {
848
+ async onDoorbell(value) {
822
849
  this.debug(`Received Doorbell Event (${util.inspect(value, true, 1)})`);
823
850
  if (value) {
824
851
  if (this._doorbellEventBlocker.checkBlock()) {
825
852
  this.debug(`ignore Doorbell event...`);
826
853
  return;
827
854
  }
828
- this._adapter.upsertState(`${this.eventsChannelId}.doorbell`, constants_1.COMMON_EVENTS_DOORBELL, true);
829
- setTimeout(() => {
830
- this._adapter.upsertState(`${this.eventsChannelId}.doorbell`, constants_1.COMMON_EVENTS_DOORBELL, false);
855
+ await this._adapter.upsertState(`${this.eventsChannelId}.doorbell`, constants_1.COMMON_EVENTS_DOORBELL, true);
856
+ this._adapter.setTimeout(() => {
857
+ this._adapter
858
+ .upsertState(`${this.eventsChannelId}.doorbell`, constants_1.COMMON_EVENTS_DOORBELL, false)
859
+ .catch(e => this.catcher(`Cannot upsert state ${this.eventsChannelId}.doorbell`, e));
831
860
  }, 1000);
832
861
  }
833
862
  }
@@ -836,26 +865,29 @@ class OwnRingCamera extends ownRingDevice_1.OwnRingDevice {
836
865
  while (this._state !== EventState.Idle) {
837
866
  this.debug(`delayed notify recording for ${del_cnt}s`);
838
867
  del_cnt++;
839
- await new Promise((resolve) => setTimeout(resolve, 1000));
868
+ await this._adapter.delay(1000);
840
869
  }
841
870
  this.silly(`Start recording for Event "${EventState[state]}"...`);
842
871
  this._state = state;
843
872
  try {
844
873
  /*
845
- if (this._adapter.config.auto_snapshot)
846
- if (subscr && !this._ringDevice.hasBattery)
847
- await this.takeSnapshot(uuid, true);
848
- else
849
- await this.takeSnapshot();
850
- */
851
- this._adapter.config.auto_snapshot && await this.takeSnapshot(uuid, true);
852
- this._adapter.config.auto_HDsnapshot && await this.takeHDSnapshot();
853
- this._adapter.config.auto_livestream && await this.startLivestream(this._adapter.config.recordtime_auto_livestream);
874
+ if (this._adapter.config.auto_snapshot)
875
+ if (subscr && !this._ringDevice.hasBattery)
876
+ await this.takeSnapshot(uuid, true);
877
+ else
878
+ await this.takeSnapshot();
879
+ */
880
+ this._adapter.config.auto_snapshot && (await this.takeSnapshot(uuid, true));
881
+ this._adapter.config.auto_HDsnapshot && (await this.takeHDSnapshot());
882
+ this._adapter.config.auto_livestream &&
883
+ (await this.startLivestream(this._adapter.config.recordtime_auto_livestream));
854
884
  // give some time to evaluate motion state, e.g. for node-red
855
- setTimeout(() => {
856
- this._adapter.upsertState(`${this.eventsChannelId}.motion`, constants_1.COMMON_MOTION, false);
885
+ this._adapter.setTimeout(() => {
886
+ this._adapter
887
+ .upsertState(`${this.eventsChannelId}.motion`, constants_1.COMMON_MOTION, false)
888
+ .catch(e => this.catcher(`Cannot set state ${this.eventsChannelId}.motion to false`, e));
857
889
  }, 200);
858
- this.debug("Recording of event finished.");
890
+ this.debug('Recording of event finished.');
859
891
  }
860
892
  finally {
861
893
  this._state = EventState.Idle;