eufy-security-client 2.4.2 → 2.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +12 -0
  2. package/build/error.d.ts +57 -57
  3. package/build/error.js +155 -155
  4. package/build/eufysecurity.d.ts +162 -161
  5. package/build/eufysecurity.js +2104 -2091
  6. package/build/eufysecurity.js.map +1 -1
  7. package/build/http/api.d.ts +90 -90
  8. package/build/http/api.js +1407 -1407
  9. package/build/http/api.js.map +1 -1
  10. package/build/http/cache.d.ts +8 -8
  11. package/build/http/cache.js +33 -33
  12. package/build/http/const.d.ts +3 -3
  13. package/build/http/const.js +8545 -8545
  14. package/build/http/device.d.ts +360 -360
  15. package/build/http/device.js +2793 -2793
  16. package/build/http/device.js.map +1 -1
  17. package/build/http/error.d.ts +28 -28
  18. package/build/http/error.js +76 -76
  19. package/build/http/index.d.ts +10 -10
  20. package/build/http/index.js +29 -29
  21. package/build/http/interfaces.d.ts +202 -202
  22. package/build/http/interfaces.js +2 -2
  23. package/build/http/models.d.ts +561 -561
  24. package/build/http/models.js +2 -2
  25. package/build/http/parameter.d.ts +5 -5
  26. package/build/http/parameter.js +75 -75
  27. package/build/http/station.d.ts +292 -292
  28. package/build/http/station.js +6780 -6780
  29. package/build/http/station.js.map +1 -1
  30. package/build/http/types.d.ts +945 -945
  31. package/build/http/types.js +6070 -6070
  32. package/build/http/utils.d.ts +37 -37
  33. package/build/http/utils.js +370 -370
  34. package/build/index.d.ts +7 -7
  35. package/build/index.js +25 -25
  36. package/build/interfaces.d.ts +113 -113
  37. package/build/interfaces.js +2 -2
  38. package/build/mqtt/interface.d.ts +6 -6
  39. package/build/mqtt/interface.js +2 -2
  40. package/build/mqtt/model.d.ts +24 -24
  41. package/build/mqtt/model.js +2 -2
  42. package/build/mqtt/service.d.ts +30 -30
  43. package/build/mqtt/service.js +168 -168
  44. package/build/mqtt/service.js.map +1 -1
  45. package/build/p2p/ble.d.ts +47 -47
  46. package/build/p2p/ble.js +188 -188
  47. package/build/p2p/ble.js.map +1 -1
  48. package/build/p2p/error.d.ts +24 -24
  49. package/build/p2p/error.js +67 -67
  50. package/build/p2p/index.d.ts +8 -8
  51. package/build/p2p/index.js +27 -27
  52. package/build/p2p/interfaces.d.ts +162 -162
  53. package/build/p2p/interfaces.js +2 -2
  54. package/build/p2p/models.d.ts +146 -146
  55. package/build/p2p/models.js +2 -2
  56. package/build/p2p/session.d.ts +168 -168
  57. package/build/p2p/session.js +2087 -2087
  58. package/build/p2p/session.js.map +1 -1
  59. package/build/p2p/talkback.d.ts +10 -10
  60. package/build/p2p/talkback.js +22 -22
  61. package/build/p2p/types.d.ts +923 -923
  62. package/build/p2p/types.js +957 -957
  63. package/build/p2p/utils.d.ts +56 -56
  64. package/build/p2p/utils.js +653 -653
  65. package/build/push/client.d.ts +51 -51
  66. package/build/push/client.js +311 -311
  67. package/build/push/client.js.map +1 -1
  68. package/build/push/index.d.ts +5 -5
  69. package/build/push/index.js +24 -24
  70. package/build/push/interfaces.d.ts +19 -19
  71. package/build/push/interfaces.js +2 -2
  72. package/build/push/models.d.ts +292 -292
  73. package/build/push/models.js +30 -30
  74. package/build/push/parser.d.ts +28 -28
  75. package/build/push/parser.js +215 -215
  76. package/build/push/parser.js.map +1 -1
  77. package/build/push/service.d.ts +45 -45
  78. package/build/push/service.js +643 -643
  79. package/build/push/service.js.map +1 -1
  80. package/build/push/types.d.ts +176 -176
  81. package/build/push/types.js +192 -192
  82. package/build/push/utils.d.ts +7 -7
  83. package/build/push/utils.js +102 -102
  84. package/build/utils.d.ts +16 -13
  85. package/build/utils.js +207 -191
  86. package/build/utils.js.map +1 -1
  87. package/package.json +10 -10
@@ -1,371 +1,371 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomNumber = exports.hexWeek = exports.hexTime = exports.hexDate = exports.encodePasscode = exports.SmartSafeByteWriter = exports.getAdvancedLockTimezone = exports.getEufyTimezone = exports.getHB3DetectionMode = exports.isHB3DetectionModeEnabled = exports.getDistances = exports.getBlocklist = exports.decryptAPIData = exports.encryptAPIData = exports.calculateCellularSignalLevel = exports.calculateWifiSignalLevel = exports.switchNotificationMode = exports.isNotificationSwitchMode = exports.getAbsoluteFilePath = exports.getTimezoneGMTString = exports.pad = exports.isGreaterEqualMinVersion = void 0;
4
- const crypto_1 = require("crypto");
5
- const const_1 = require("./const");
6
- const types_1 = require("./types");
7
- const normalizeVersionString = function (version) {
8
- const trimmed = version ? version.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1") : "";
9
- const pieces = trimmed.split(RegExp("\\."));
10
- const parts = [];
11
- let value, piece, num, i;
12
- for (i = 0; i < pieces.length; i += 1) {
13
- piece = pieces[i].replace(RegExp("\\D"), "");
14
- num = parseInt(piece, 10);
15
- if (isNaN(num)) {
16
- num = 0;
17
- }
18
- parts.push(num);
19
- }
20
- const partsLength = parts.length;
21
- for (i = partsLength - 1; i >= 0; i -= 1) {
22
- value = parts[i];
23
- if (value === 0) {
24
- parts.length -= 1;
25
- }
26
- else {
27
- break;
28
- }
29
- }
30
- return parts;
31
- };
32
- const isGreaterEqualMinVersion = function (minimal_version, current_version) {
33
- const x = normalizeVersionString(minimal_version);
34
- const y = normalizeVersionString(current_version);
35
- const size = Math.min(x.length, y.length);
36
- let i;
37
- for (i = 0; i < size; i += 1) {
38
- if (x[i] !== y[i]) {
39
- return x[i] < y[i] ? true : false;
40
- }
41
- }
42
- if (x.length === y.length) {
43
- return true;
44
- }
45
- return (x.length < y.length) ? true : false;
46
- };
47
- exports.isGreaterEqualMinVersion = isGreaterEqualMinVersion;
48
- const pad = function (num) {
49
- const norm = Math.floor(Math.abs(num));
50
- return (norm < 10 ? "0" : "") + norm;
51
- };
52
- exports.pad = pad;
53
- const getTimezoneGMTString = function () {
54
- const tzo = -new Date().getTimezoneOffset();
55
- const dif = tzo >= 0 ? "+" : "-";
56
- return `GMT${dif}${(0, exports.pad)(tzo / 60)}:${(0, exports.pad)(tzo % 60)}`;
57
- };
58
- exports.getTimezoneGMTString = getTimezoneGMTString;
59
- const getAbsoluteFilePath = function (device_type, channel, filename) {
60
- if (device_type === types_1.DeviceType.FLOODLIGHT) {
61
- return `/mnt/data/Camera${String(channel).padStart(2, "0")}/${filename}.dat`;
62
- }
63
- return `/media/mmcblk0p1/Camera${String(channel).padStart(2, "0")}/${filename}.dat`;
64
- };
65
- exports.getAbsoluteFilePath = getAbsoluteFilePath;
66
- const isNotificationSwitchMode = function (value, mode) {
67
- if (value === 1)
68
- value = 240;
69
- return (value & mode) !== 0;
70
- };
71
- exports.isNotificationSwitchMode = isNotificationSwitchMode;
72
- const switchNotificationMode = function (currentValue, mode, enable) {
73
- let result = 0;
74
- if (!enable && currentValue === 1 /* ALL */) {
75
- currentValue = 240;
76
- }
77
- if (enable) {
78
- result = mode | currentValue;
79
- }
80
- else {
81
- result = ~mode & currentValue;
82
- }
83
- if ((0, exports.isNotificationSwitchMode)(result, types_1.NotificationSwitchMode.SCHEDULE) && (0, exports.isNotificationSwitchMode)(result, types_1.NotificationSwitchMode.APP) && (0, exports.isNotificationSwitchMode)(result, types_1.NotificationSwitchMode.GEOFENCE) && (0, exports.isNotificationSwitchMode)(result, types_1.NotificationSwitchMode.KEYPAD)) {
84
- result = 1; /* ALL */
85
- }
86
- return result;
87
- };
88
- exports.switchNotificationMode = switchNotificationMode;
89
- const calculateWifiSignalLevel = function (device, rssi) {
90
- if (device.isWiredDoorbell()) {
91
- if (rssi >= -65) {
92
- return types_1.SignalLevel.FULL;
93
- }
94
- if (rssi >= -75) {
95
- return types_1.SignalLevel.STRONG;
96
- }
97
- return rssi >= -80 ? types_1.SignalLevel.NORMAL : types_1.SignalLevel.WEAK;
98
- }
99
- else if (device.isCamera2Product()) {
100
- if (rssi >= 0) {
101
- return types_1.SignalLevel.NO_SIGNAL;
102
- }
103
- if (rssi >= -65) {
104
- return types_1.SignalLevel.FULL;
105
- }
106
- if (rssi >= -75) {
107
- return types_1.SignalLevel.STRONG;
108
- }
109
- return rssi >= -85 ? types_1.SignalLevel.NORMAL : types_1.SignalLevel.WEAK;
110
- }
111
- else if (device.isFloodLight()) {
112
- if (rssi >= 0) {
113
- return types_1.SignalLevel.NO_SIGNAL;
114
- }
115
- if (rssi >= -60) {
116
- return types_1.SignalLevel.FULL;
117
- }
118
- if (rssi >= -70) {
119
- return types_1.SignalLevel.STRONG;
120
- }
121
- return rssi >= -80 ? types_1.SignalLevel.NORMAL : types_1.SignalLevel.WEAK;
122
- }
123
- else if (device.isBatteryDoorbell()) {
124
- if (rssi >= -65) {
125
- return types_1.SignalLevel.FULL;
126
- }
127
- if (rssi >= -75) {
128
- return types_1.SignalLevel.STRONG;
129
- }
130
- return rssi >= -85 ? types_1.SignalLevel.NORMAL : types_1.SignalLevel.WEAK;
131
- }
132
- else {
133
- if (rssi >= 0) {
134
- return types_1.SignalLevel.NO_SIGNAL;
135
- }
136
- if (rssi >= -65) {
137
- return types_1.SignalLevel.FULL;
138
- }
139
- if (rssi >= -75) {
140
- return types_1.SignalLevel.STRONG;
141
- }
142
- return rssi >= -85 ? types_1.SignalLevel.NORMAL : types_1.SignalLevel.WEAK;
143
- }
144
- };
145
- exports.calculateWifiSignalLevel = calculateWifiSignalLevel;
146
- const calculateCellularSignalLevel = function (rssi) {
147
- if (rssi >= 0) {
148
- return types_1.SignalLevel.NO_SIGNAL;
149
- }
150
- if (rssi >= -90) {
151
- return types_1.SignalLevel.FULL;
152
- }
153
- if (rssi >= -95) {
154
- return types_1.SignalLevel.STRONG;
155
- }
156
- return rssi >= -105 ? types_1.SignalLevel.NORMAL : types_1.SignalLevel.WEAK;
157
- };
158
- exports.calculateCellularSignalLevel = calculateCellularSignalLevel;
159
- const encryptAPIData = (data, key) => {
160
- const cipher = (0, crypto_1.createCipheriv)("aes-256-cbc", key, key.slice(0, 16));
161
- return (cipher.update(data, "utf8", "base64") +
162
- cipher.final("base64"));
163
- };
164
- exports.encryptAPIData = encryptAPIData;
165
- const decryptAPIData = (data, key) => {
166
- const cipher = (0, crypto_1.createDecipheriv)("aes-256-cbc", key, key.slice(0, 16));
167
- return Buffer.concat([
168
- cipher.update(data, "base64"),
169
- cipher.final()
170
- ]);
171
- };
172
- exports.decryptAPIData = decryptAPIData;
173
- const getBlocklist = function (directions) {
174
- const result = [];
175
- for (let distance = 1; distance <= 5; distance++) {
176
- let i = 0;
177
- let j = 0;
178
- let k = 1;
179
- for (const directionDistance of directions) {
180
- if (directionDistance >= distance) {
181
- j += k;
182
- }
183
- k <<= 1;
184
- }
185
- if (j == 0) {
186
- i = 65535;
187
- }
188
- else if (!(j == 255 || j == 65535)) {
189
- i = (j ^ 255) + 65280;
190
- }
191
- result.push(65535 & i);
192
- }
193
- return result;
194
- };
195
- exports.getBlocklist = getBlocklist;
196
- const getDistances = function (blocklist) {
197
- const result = [3, 3, 3, 3, 3, 3, 3, 3];
198
- let calcDistance = 0;
199
- for (const blockElement of blocklist) {
200
- let valueOf = blockElement ^ 65535;
201
- calcDistance++;
202
- if (valueOf !== 0) {
203
- for (let i = 0; i < result.length; i++) {
204
- const intValue = valueOf & 1;
205
- if (intValue > 0) {
206
- result[i] = calcDistance;
207
- }
208
- valueOf = valueOf >> 1;
209
- }
210
- }
211
- }
212
- return result;
213
- };
214
- exports.getDistances = getDistances;
215
- const isHB3DetectionModeEnabled = function (value, type) {
216
- if (type === types_1.HB3DetectionTypes.HUMAN_RECOGNITION) {
217
- return (type & value) == type && (value & 65536) == 65536;
218
- }
219
- else if (type === types_1.HB3DetectionTypes.HUMAN_DETECTION) {
220
- return (type & value) == type && (value & 1) == 1;
221
- }
222
- return (type & value) == type;
223
- };
224
- exports.isHB3DetectionModeEnabled = isHB3DetectionModeEnabled;
225
- const getHB3DetectionMode = function (value, type, enable) {
226
- let result = 0;
227
- if (!enable) {
228
- if (type === types_1.HB3DetectionTypes.HUMAN_RECOGNITION) {
229
- const tmp = (type & value) == type ? type ^ value : value;
230
- result = (value & 65536) == 65536 ? tmp ^ 65536 : tmp;
231
- }
232
- else if (type === types_1.HB3DetectionTypes.HUMAN_DETECTION) {
233
- const tmp = (type & value) == type ? type ^ value : value;
234
- result = (value & 1) == 1 ? tmp ^ 1 : tmp;
235
- }
236
- else {
237
- result = type ^ value;
238
- }
239
- }
240
- else {
241
- if (type === types_1.HB3DetectionTypes.HUMAN_RECOGNITION) {
242
- result = type | value | 65536;
243
- }
244
- else if (type === types_1.HB3DetectionTypes.HUMAN_DETECTION) {
245
- result = type | value | 1;
246
- }
247
- else {
248
- result = type | value;
249
- }
250
- }
251
- return result;
252
- };
253
- exports.getHB3DetectionMode = getHB3DetectionMode;
254
- const getEufyTimezone = function () {
255
- for (const timezone of const_1.timeZoneData) {
256
- if (timezone.timeId === Intl.DateTimeFormat().resolvedOptions().timeZone) {
257
- return timezone;
258
- }
259
- }
260
- return undefined;
261
- };
262
- exports.getEufyTimezone = getEufyTimezone;
263
- const getAdvancedLockTimezone = function (stationSN) {
264
- const timezone = (0, exports.getEufyTimezone)();
265
- if (timezone !== undefined) {
266
- if (stationSN.startsWith("T8520") && (0, exports.isGreaterEqualMinVersion)("1.2.8.6", stationSN))
267
- return `${timezone.timeZoneGMT}|1.${timezone.timeSn}`;
268
- else
269
- return timezone.timeZoneGMT;
270
- }
271
- return "";
272
- };
273
- exports.getAdvancedLockTimezone = getAdvancedLockTimezone;
274
- class SmartSafeByteWriter {
275
- constructor() {
276
- this.split_byte = -95;
277
- this.data = Buffer.from([]);
278
- }
279
- write(bytes) {
280
- const tmp_data = Buffer.from(bytes);
281
- this.data = Buffer.concat([this.data, Buffer.from([this.split_byte]), Buffer.from([tmp_data.length & 255]), tmp_data]);
282
- this.split_byte += 1;
283
- }
284
- getData() {
285
- return this.data;
286
- }
287
- }
288
- exports.SmartSafeByteWriter = SmartSafeByteWriter;
289
- /*export const generateHash = function(data: Buffer): number {
290
- let result = 0;
291
- for (const value of data) {
292
- result = result ^ value;
293
- }
294
- return result;
295
- }
296
-
297
- export const encodeSmartSafeData = function(command: number, payload: Buffer): Buffer {
298
- const header = Buffer.from(SmartSafe.DATA_HEADER);
299
- const size = Buffer.allocUnsafe(2);
300
- size.writeInt16LE(payload.length + 9);
301
- const versionCode = Buffer.from([SmartSafe.VERSION_CODE]);
302
- const dataType = Buffer.from([-1]);
303
- const commandCode = Buffer.from([command]);
304
- const packageFlag = Buffer.from([-64]);
305
- const data = Buffer.concat([header, size, versionCode, dataType, commandCode, packageFlag, payload]);
306
- const hash = generateHash(data);
307
- return Buffer.concat([data, Buffer.from([hash])]);
308
- }*/
309
- const encodePasscode = function (pass) {
310
- let result = "";
311
- for (let i = 0; i < pass.length; i++)
312
- result += pass.charCodeAt(i).toString(16);
313
- return result;
314
- };
315
- exports.encodePasscode = encodePasscode;
316
- const hexDate = function (date) {
317
- const buf = Buffer.allocUnsafe(4);
318
- buf.writeUint8(date.getDate());
319
- buf.writeUint8(date.getMonth() + 1, 1);
320
- buf.writeUint16BE(date.getFullYear(), 2);
321
- return buf.readUInt32LE().toString(16).padStart(8, "0");
322
- };
323
- exports.hexDate = hexDate;
324
- const hexTime = function (date) {
325
- const buf = Buffer.allocUnsafe(2);
326
- buf.writeUint8(date.getHours());
327
- buf.writeUint8(date.getMinutes(), 1);
328
- return buf.readUInt16BE().toString(16).padStart(4, "0");
329
- };
330
- exports.hexTime = hexTime;
331
- const hexWeek = function (schedule) {
332
- const SUNDAY = 1;
333
- const MONDAY = 2;
334
- const TUESDAY = 4;
335
- const WEDNESDAY = 8;
336
- const THUERSDAY = 16;
337
- const FRIDAY = 32;
338
- const SATURDAY = 64;
339
- let result = 0;
340
- if (schedule.week !== undefined) {
341
- if (schedule.week.sunday) {
342
- result |= SUNDAY;
343
- }
344
- if (schedule.week.monday) {
345
- result |= MONDAY;
346
- }
347
- if (schedule.week.tuesday) {
348
- result |= TUESDAY;
349
- }
350
- if (schedule.week.wednesday) {
351
- result |= WEDNESDAY;
352
- }
353
- if (schedule.week.thursday) {
354
- result |= THUERSDAY;
355
- }
356
- if (schedule.week.friday) {
357
- result |= FRIDAY;
358
- }
359
- if (schedule.week.saturday) {
360
- result |= SATURDAY;
361
- }
362
- return result.toString(16);
363
- }
364
- return "ff";
365
- };
366
- exports.hexWeek = hexWeek;
367
- const randomNumber = function (min, max) {
368
- return Math.floor(Math.random() * (max - min + 1)) + min;
369
- };
370
- exports.randomNumber = randomNumber;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randomNumber = exports.hexWeek = exports.hexTime = exports.hexDate = exports.encodePasscode = exports.SmartSafeByteWriter = exports.getAdvancedLockTimezone = exports.getEufyTimezone = exports.getHB3DetectionMode = exports.isHB3DetectionModeEnabled = exports.getDistances = exports.getBlocklist = exports.decryptAPIData = exports.encryptAPIData = exports.calculateCellularSignalLevel = exports.calculateWifiSignalLevel = exports.switchNotificationMode = exports.isNotificationSwitchMode = exports.getAbsoluteFilePath = exports.getTimezoneGMTString = exports.pad = exports.isGreaterEqualMinVersion = void 0;
4
+ const crypto_1 = require("crypto");
5
+ const const_1 = require("./const");
6
+ const types_1 = require("./types");
7
+ const normalizeVersionString = function (version) {
8
+ const trimmed = version ? version.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1") : "";
9
+ const pieces = trimmed.split(RegExp("\\."));
10
+ const parts = [];
11
+ let value, piece, num, i;
12
+ for (i = 0; i < pieces.length; i += 1) {
13
+ piece = pieces[i].replace(RegExp("\\D"), "");
14
+ num = parseInt(piece, 10);
15
+ if (isNaN(num)) {
16
+ num = 0;
17
+ }
18
+ parts.push(num);
19
+ }
20
+ const partsLength = parts.length;
21
+ for (i = partsLength - 1; i >= 0; i -= 1) {
22
+ value = parts[i];
23
+ if (value === 0) {
24
+ parts.length -= 1;
25
+ }
26
+ else {
27
+ break;
28
+ }
29
+ }
30
+ return parts;
31
+ };
32
+ const isGreaterEqualMinVersion = function (minimal_version, current_version) {
33
+ const x = normalizeVersionString(minimal_version);
34
+ const y = normalizeVersionString(current_version);
35
+ const size = Math.min(x.length, y.length);
36
+ let i;
37
+ for (i = 0; i < size; i += 1) {
38
+ if (x[i] !== y[i]) {
39
+ return x[i] < y[i] ? true : false;
40
+ }
41
+ }
42
+ if (x.length === y.length) {
43
+ return true;
44
+ }
45
+ return (x.length < y.length) ? true : false;
46
+ };
47
+ exports.isGreaterEqualMinVersion = isGreaterEqualMinVersion;
48
+ const pad = function (num) {
49
+ const norm = Math.floor(Math.abs(num));
50
+ return (norm < 10 ? "0" : "") + norm;
51
+ };
52
+ exports.pad = pad;
53
+ const getTimezoneGMTString = function () {
54
+ const tzo = -new Date().getTimezoneOffset();
55
+ const dif = tzo >= 0 ? "+" : "-";
56
+ return `GMT${dif}${(0, exports.pad)(tzo / 60)}:${(0, exports.pad)(tzo % 60)}`;
57
+ };
58
+ exports.getTimezoneGMTString = getTimezoneGMTString;
59
+ const getAbsoluteFilePath = function (device_type, channel, filename) {
60
+ if (device_type === types_1.DeviceType.FLOODLIGHT) {
61
+ return `/mnt/data/Camera${String(channel).padStart(2, "0")}/${filename}.dat`;
62
+ }
63
+ return `/media/mmcblk0p1/Camera${String(channel).padStart(2, "0")}/${filename}.dat`;
64
+ };
65
+ exports.getAbsoluteFilePath = getAbsoluteFilePath;
66
+ const isNotificationSwitchMode = function (value, mode) {
67
+ if (value === 1)
68
+ value = 240;
69
+ return (value & mode) !== 0;
70
+ };
71
+ exports.isNotificationSwitchMode = isNotificationSwitchMode;
72
+ const switchNotificationMode = function (currentValue, mode, enable) {
73
+ let result = 0;
74
+ if (!enable && currentValue === 1 /* ALL */) {
75
+ currentValue = 240;
76
+ }
77
+ if (enable) {
78
+ result = mode | currentValue;
79
+ }
80
+ else {
81
+ result = ~mode & currentValue;
82
+ }
83
+ if ((0, exports.isNotificationSwitchMode)(result, types_1.NotificationSwitchMode.SCHEDULE) && (0, exports.isNotificationSwitchMode)(result, types_1.NotificationSwitchMode.APP) && (0, exports.isNotificationSwitchMode)(result, types_1.NotificationSwitchMode.GEOFENCE) && (0, exports.isNotificationSwitchMode)(result, types_1.NotificationSwitchMode.KEYPAD)) {
84
+ result = 1; /* ALL */
85
+ }
86
+ return result;
87
+ };
88
+ exports.switchNotificationMode = switchNotificationMode;
89
+ const calculateWifiSignalLevel = function (device, rssi) {
90
+ if (device.isWiredDoorbell()) {
91
+ if (rssi >= -65) {
92
+ return types_1.SignalLevel.FULL;
93
+ }
94
+ if (rssi >= -75) {
95
+ return types_1.SignalLevel.STRONG;
96
+ }
97
+ return rssi >= -80 ? types_1.SignalLevel.NORMAL : types_1.SignalLevel.WEAK;
98
+ }
99
+ else if (device.isCamera2Product()) {
100
+ if (rssi >= 0) {
101
+ return types_1.SignalLevel.NO_SIGNAL;
102
+ }
103
+ if (rssi >= -65) {
104
+ return types_1.SignalLevel.FULL;
105
+ }
106
+ if (rssi >= -75) {
107
+ return types_1.SignalLevel.STRONG;
108
+ }
109
+ return rssi >= -85 ? types_1.SignalLevel.NORMAL : types_1.SignalLevel.WEAK;
110
+ }
111
+ else if (device.isFloodLight()) {
112
+ if (rssi >= 0) {
113
+ return types_1.SignalLevel.NO_SIGNAL;
114
+ }
115
+ if (rssi >= -60) {
116
+ return types_1.SignalLevel.FULL;
117
+ }
118
+ if (rssi >= -70) {
119
+ return types_1.SignalLevel.STRONG;
120
+ }
121
+ return rssi >= -80 ? types_1.SignalLevel.NORMAL : types_1.SignalLevel.WEAK;
122
+ }
123
+ else if (device.isBatteryDoorbell()) {
124
+ if (rssi >= -65) {
125
+ return types_1.SignalLevel.FULL;
126
+ }
127
+ if (rssi >= -75) {
128
+ return types_1.SignalLevel.STRONG;
129
+ }
130
+ return rssi >= -85 ? types_1.SignalLevel.NORMAL : types_1.SignalLevel.WEAK;
131
+ }
132
+ else {
133
+ if (rssi >= 0) {
134
+ return types_1.SignalLevel.NO_SIGNAL;
135
+ }
136
+ if (rssi >= -65) {
137
+ return types_1.SignalLevel.FULL;
138
+ }
139
+ if (rssi >= -75) {
140
+ return types_1.SignalLevel.STRONG;
141
+ }
142
+ return rssi >= -85 ? types_1.SignalLevel.NORMAL : types_1.SignalLevel.WEAK;
143
+ }
144
+ };
145
+ exports.calculateWifiSignalLevel = calculateWifiSignalLevel;
146
+ const calculateCellularSignalLevel = function (rssi) {
147
+ if (rssi >= 0) {
148
+ return types_1.SignalLevel.NO_SIGNAL;
149
+ }
150
+ if (rssi >= -90) {
151
+ return types_1.SignalLevel.FULL;
152
+ }
153
+ if (rssi >= -95) {
154
+ return types_1.SignalLevel.STRONG;
155
+ }
156
+ return rssi >= -105 ? types_1.SignalLevel.NORMAL : types_1.SignalLevel.WEAK;
157
+ };
158
+ exports.calculateCellularSignalLevel = calculateCellularSignalLevel;
159
+ const encryptAPIData = (data, key) => {
160
+ const cipher = (0, crypto_1.createCipheriv)("aes-256-cbc", key, key.slice(0, 16));
161
+ return (cipher.update(data, "utf8", "base64") +
162
+ cipher.final("base64"));
163
+ };
164
+ exports.encryptAPIData = encryptAPIData;
165
+ const decryptAPIData = (data, key) => {
166
+ const cipher = (0, crypto_1.createDecipheriv)("aes-256-cbc", key, key.slice(0, 16));
167
+ return Buffer.concat([
168
+ cipher.update(data, "base64"),
169
+ cipher.final()
170
+ ]);
171
+ };
172
+ exports.decryptAPIData = decryptAPIData;
173
+ const getBlocklist = function (directions) {
174
+ const result = [];
175
+ for (let distance = 1; distance <= 5; distance++) {
176
+ let i = 0;
177
+ let j = 0;
178
+ let k = 1;
179
+ for (const directionDistance of directions) {
180
+ if (directionDistance >= distance) {
181
+ j += k;
182
+ }
183
+ k <<= 1;
184
+ }
185
+ if (j == 0) {
186
+ i = 65535;
187
+ }
188
+ else if (!(j == 255 || j == 65535)) {
189
+ i = (j ^ 255) + 65280;
190
+ }
191
+ result.push(65535 & i);
192
+ }
193
+ return result;
194
+ };
195
+ exports.getBlocklist = getBlocklist;
196
+ const getDistances = function (blocklist) {
197
+ const result = [3, 3, 3, 3, 3, 3, 3, 3];
198
+ let calcDistance = 0;
199
+ for (const blockElement of blocklist) {
200
+ let valueOf = blockElement ^ 65535;
201
+ calcDistance++;
202
+ if (valueOf !== 0) {
203
+ for (let i = 0; i < result.length; i++) {
204
+ const intValue = valueOf & 1;
205
+ if (intValue > 0) {
206
+ result[i] = calcDistance;
207
+ }
208
+ valueOf = valueOf >> 1;
209
+ }
210
+ }
211
+ }
212
+ return result;
213
+ };
214
+ exports.getDistances = getDistances;
215
+ const isHB3DetectionModeEnabled = function (value, type) {
216
+ if (type === types_1.HB3DetectionTypes.HUMAN_RECOGNITION) {
217
+ return (type & value) == type && (value & 65536) == 65536;
218
+ }
219
+ else if (type === types_1.HB3DetectionTypes.HUMAN_DETECTION) {
220
+ return (type & value) == type && (value & 1) == 1;
221
+ }
222
+ return (type & value) == type;
223
+ };
224
+ exports.isHB3DetectionModeEnabled = isHB3DetectionModeEnabled;
225
+ const getHB3DetectionMode = function (value, type, enable) {
226
+ let result = 0;
227
+ if (!enable) {
228
+ if (type === types_1.HB3DetectionTypes.HUMAN_RECOGNITION) {
229
+ const tmp = (type & value) == type ? type ^ value : value;
230
+ result = (value & 65536) == 65536 ? tmp ^ 65536 : tmp;
231
+ }
232
+ else if (type === types_1.HB3DetectionTypes.HUMAN_DETECTION) {
233
+ const tmp = (type & value) == type ? type ^ value : value;
234
+ result = (value & 1) == 1 ? tmp ^ 1 : tmp;
235
+ }
236
+ else {
237
+ result = type ^ value;
238
+ }
239
+ }
240
+ else {
241
+ if (type === types_1.HB3DetectionTypes.HUMAN_RECOGNITION) {
242
+ result = type | value | 65536;
243
+ }
244
+ else if (type === types_1.HB3DetectionTypes.HUMAN_DETECTION) {
245
+ result = type | value | 1;
246
+ }
247
+ else {
248
+ result = type | value;
249
+ }
250
+ }
251
+ return result;
252
+ };
253
+ exports.getHB3DetectionMode = getHB3DetectionMode;
254
+ const getEufyTimezone = function () {
255
+ for (const timezone of const_1.timeZoneData) {
256
+ if (timezone.timeId === Intl.DateTimeFormat().resolvedOptions().timeZone) {
257
+ return timezone;
258
+ }
259
+ }
260
+ return undefined;
261
+ };
262
+ exports.getEufyTimezone = getEufyTimezone;
263
+ const getAdvancedLockTimezone = function (stationSN) {
264
+ const timezone = (0, exports.getEufyTimezone)();
265
+ if (timezone !== undefined) {
266
+ if (stationSN.startsWith("T8520") && (0, exports.isGreaterEqualMinVersion)("1.2.8.6", stationSN))
267
+ return `${timezone.timeZoneGMT}|1.${timezone.timeSn}`;
268
+ else
269
+ return timezone.timeZoneGMT;
270
+ }
271
+ return "";
272
+ };
273
+ exports.getAdvancedLockTimezone = getAdvancedLockTimezone;
274
+ class SmartSafeByteWriter {
275
+ constructor() {
276
+ this.split_byte = -95;
277
+ this.data = Buffer.from([]);
278
+ }
279
+ write(bytes) {
280
+ const tmp_data = Buffer.from(bytes);
281
+ this.data = Buffer.concat([this.data, Buffer.from([this.split_byte]), Buffer.from([tmp_data.length & 255]), tmp_data]);
282
+ this.split_byte += 1;
283
+ }
284
+ getData() {
285
+ return this.data;
286
+ }
287
+ }
288
+ exports.SmartSafeByteWriter = SmartSafeByteWriter;
289
+ /*export const generateHash = function(data: Buffer): number {
290
+ let result = 0;
291
+ for (const value of data) {
292
+ result = result ^ value;
293
+ }
294
+ return result;
295
+ }
296
+
297
+ export const encodeSmartSafeData = function(command: number, payload: Buffer): Buffer {
298
+ const header = Buffer.from(SmartSafe.DATA_HEADER);
299
+ const size = Buffer.allocUnsafe(2);
300
+ size.writeInt16LE(payload.length + 9);
301
+ const versionCode = Buffer.from([SmartSafe.VERSION_CODE]);
302
+ const dataType = Buffer.from([-1]);
303
+ const commandCode = Buffer.from([command]);
304
+ const packageFlag = Buffer.from([-64]);
305
+ const data = Buffer.concat([header, size, versionCode, dataType, commandCode, packageFlag, payload]);
306
+ const hash = generateHash(data);
307
+ return Buffer.concat([data, Buffer.from([hash])]);
308
+ }*/
309
+ const encodePasscode = function (pass) {
310
+ let result = "";
311
+ for (let i = 0; i < pass.length; i++)
312
+ result += pass.charCodeAt(i).toString(16);
313
+ return result;
314
+ };
315
+ exports.encodePasscode = encodePasscode;
316
+ const hexDate = function (date) {
317
+ const buf = Buffer.allocUnsafe(4);
318
+ buf.writeUint8(date.getDate());
319
+ buf.writeUint8(date.getMonth() + 1, 1);
320
+ buf.writeUint16BE(date.getFullYear(), 2);
321
+ return buf.readUInt32LE().toString(16).padStart(8, "0");
322
+ };
323
+ exports.hexDate = hexDate;
324
+ const hexTime = function (date) {
325
+ const buf = Buffer.allocUnsafe(2);
326
+ buf.writeUint8(date.getHours());
327
+ buf.writeUint8(date.getMinutes(), 1);
328
+ return buf.readUInt16BE().toString(16).padStart(4, "0");
329
+ };
330
+ exports.hexTime = hexTime;
331
+ const hexWeek = function (schedule) {
332
+ const SUNDAY = 1;
333
+ const MONDAY = 2;
334
+ const TUESDAY = 4;
335
+ const WEDNESDAY = 8;
336
+ const THUERSDAY = 16;
337
+ const FRIDAY = 32;
338
+ const SATURDAY = 64;
339
+ let result = 0;
340
+ if (schedule.week !== undefined) {
341
+ if (schedule.week.sunday) {
342
+ result |= SUNDAY;
343
+ }
344
+ if (schedule.week.monday) {
345
+ result |= MONDAY;
346
+ }
347
+ if (schedule.week.tuesday) {
348
+ result |= TUESDAY;
349
+ }
350
+ if (schedule.week.wednesday) {
351
+ result |= WEDNESDAY;
352
+ }
353
+ if (schedule.week.thursday) {
354
+ result |= THUERSDAY;
355
+ }
356
+ if (schedule.week.friday) {
357
+ result |= FRIDAY;
358
+ }
359
+ if (schedule.week.saturday) {
360
+ result |= SATURDAY;
361
+ }
362
+ return result.toString(16);
363
+ }
364
+ return "ff";
365
+ };
366
+ exports.hexWeek = hexWeek;
367
+ const randomNumber = function (min, max) {
368
+ return Math.floor(Math.random() * (max - min + 1)) + min;
369
+ };
370
+ exports.randomNumber = randomNumber;
371
371
  //# sourceMappingURL=utils.js.map