ring-client-api 10.0.0-beta.4 → 10.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [10.0.0-beta.5](https://github.com/dgreif/ring/compare/v10.0.0-beta.4...v10.0.0-beta.5) (2022-04-10)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **cameras:** wait to activate session until connected ([9a49389](https://github.com/dgreif/ring/commit/9a49389aa434cc5df4cfb4ba039bad0f2a30f756))
11
+ * handle push notification for unknown camera ([cc8fc2a](https://github.com/dgreif/ring/commit/cc8fc2a6377084515d3b169a85644b2a2b13235e))
12
+ * hide ECONNRESET errors from push receiver ([1196d96](https://github.com/dgreif/ring/commit/1196d96e67e26952f18dfbe75103419a7261bd1e))
13
+ * restore dual battery level calculations ([26fa84d](https://github.com/dgreif/ring/commit/26fa84dbd4bbcea8208fd0ade81c54c407aabf63))
14
+ * update dependencies ([4b97fb3](https://github.com/dgreif/ring/commit/4b97fb33623248147997944bab3de4ea3c2e5ee2))
15
+
5
16
  ## [10.0.0-beta.4](https://github.com/dgreif/ring/compare/v10.0.0-beta.3...v10.0.0-beta.4) (2022-04-03)
6
17
 
7
18
 
package/lib/api/api.js CHANGED
@@ -126,7 +126,7 @@ class RingApi extends subscribed_1.Subscribed {
126
126
  }
127
127
  }));
128
128
  pushReceiver.onNotification(({ message }) => {
129
- var _a;
129
+ var _a, _b;
130
130
  const dataJson = (_a = message.data) === null || _a === void 0 ? void 0 : _a.gcmData;
131
131
  try {
132
132
  const notification = JSON.parse(dataJson);
@@ -134,7 +134,7 @@ class RingApi extends subscribed_1.Subscribed {
134
134
  // We may get notification that are not for a ding/motion, which can be ignored
135
135
  return;
136
136
  }
137
- camerasById[notification.ding.doorbot_id].processPushNotification(notification);
137
+ (_b = camerasById[notification.ding.doorbot_id]) === null || _b === void 0 ? void 0 : _b.processPushNotification(notification);
138
138
  }
139
139
  catch (e) {
140
140
  (0, util_1.logError)(e);
package/lib/api/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -236,7 +236,7 @@ class LiveCallRingEdge extends subscribed_1.Subscribed {
236
236
  return;
237
237
  }
238
238
  this.activated = true;
239
- yield (0, rxjs_1.firstValueFrom)(this.onCallAnswered);
239
+ yield (0, rxjs_1.firstValueFrom)(this.pc.onConnectionState.pipe((0, operators_1.filter)((state) => state === 'connected')));
240
240
  (0, util_1.logInfo)('Activating Session');
241
241
  this.sendSessionMessage('activate_session');
242
242
  });
@@ -145,7 +145,8 @@ class LiveCall extends subscribed_1.Subscribed {
145
145
  return;
146
146
  }
147
147
  this.activated = true;
148
- yield (0, rxjs_1.firstValueFrom)(this.onCallAnswered);
148
+ yield (0, rxjs_1.firstValueFrom)(this.pc.onConnectionState.pipe((0, operators_1.filter)((state) => state === 'connected')));
149
+ (0, util_1.logInfo)('Activating Session');
149
150
  this.sendMessage({ method: 'activate_session' });
150
151
  this.sendMessage({
151
152
  video_enabled: true,
@@ -6,7 +6,9 @@ import { DeepPartial } from './util';
6
6
  import { Subscribed } from './subscribed';
7
7
  import { FfmpegOptions, LiveCall } from './live-call';
8
8
  import { LiveCallRingEdge } from './live-call-ring-edge';
9
- export declare function getBatteryLevel({ health }: Pick<CameraData, 'health'>): number | null;
9
+ export declare function getBatteryLevel(data: Pick<CameraData, 'battery_life' | 'battery_life_2'> & {
10
+ health?: Partial<CameraData['health']>;
11
+ }): number | null;
10
12
  export declare function getSearchQueryString(options: CameraEventOptions | (HistoryOptions & {
11
13
  accountId: string;
12
14
  })): string;
@@ -19,17 +19,34 @@ const subscribed_1 = require("./subscribed");
19
19
  const live_call_1 = require("./live-call");
20
20
  const live_call_ring_edge_1 = require("./live-call-ring-edge");
21
21
  const maxSnapshotRefreshSeconds = 15, fullDayMs = 24 * 60 * 60 * 1000;
22
+ function parseBatteryLife(batteryLife) {
23
+ if (batteryLife === null || batteryLife === undefined) {
24
+ return null;
25
+ }
26
+ const batteryLevel = typeof batteryLife === 'number'
27
+ ? batteryLife
28
+ : Number.parseFloat(batteryLife);
29
+ if (isNaN(batteryLevel)) {
30
+ return null;
31
+ }
32
+ return batteryLevel;
33
+ }
22
34
  function getStartOfToday() {
23
35
  return new Date(new Date().toLocaleDateString()).getTime();
24
36
  }
25
37
  function getEndOfToday() {
26
38
  return getStartOfToday() + fullDayMs - 1;
27
39
  }
28
- function getBatteryLevel({ health }) {
29
- if (!health.battery_percentage && !health.battery_present) {
40
+ function getBatteryLevel(data) {
41
+ const levels = [
42
+ parseBatteryLife(data.battery_life),
43
+ parseBatteryLife(data.battery_life_2),
44
+ ].filter((level) => level !== null), { health } = data;
45
+ if (!levels.length ||
46
+ (health && !health.battery_percentage && !health.battery_present)) {
30
47
  return null;
31
48
  }
32
- return health.battery_percentage || 0;
49
+ return Math.min(...levels);
33
50
  }
34
51
  exports.getBatteryLevel = getBatteryLevel;
35
52
  function getSearchQueryString(options) {
@@ -117,7 +134,7 @@ class RingCamera extends subscribed_1.Subscribed {
117
134
  return this.data.alerts.battery === 'low';
118
135
  }
119
136
  get isCharging() {
120
- return Boolean(this.data.health.ac_power || this.data.health.ext_power_state);
137
+ return this.initialData.external_connection;
121
138
  }
122
139
  get operatingOnBattery() {
123
140
  return this.hasBattery && this.data.settings.power_mode !== 'wired';
package/lib/api/util.js CHANGED
@@ -18,6 +18,7 @@ const colors_1 = require("colors");
18
18
  const readline_1 = require("readline");
19
19
  const uuid_1 = require("uuid");
20
20
  const systeminformation_1 = require("systeminformation");
21
+ const logger_1 = __importDefault(require("@eneris/push-receiver/dist/utils/logger"));
21
22
  const debugLogger = (0, debug_1.default)('ring'), uuidNamespace = 'e53ffdc0-e91d-4ce1-bec2-df939d94739d';
22
23
  let logger = {
23
24
  logInfo(message) {
@@ -120,3 +121,9 @@ function randomString(length) {
120
121
  return uuid.replace(/-/g, '').substring(0, length).toLowerCase();
121
122
  }
122
123
  exports.randomString = randomString;
124
+ // Override push receiver logging to avoid ECONNRESET errors leaking
125
+ function logPushReceiver(...args) {
126
+ logDebug('[Push Receiver]');
127
+ logDebug(args[0]);
128
+ }
129
+ logger_1.default.error = logPushReceiver;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const api_1 = require("../../api");
4
+ describe('Ring Camera', () => {
5
+ describe('battery level', () => {
6
+ it('should handle string battery life', () => {
7
+ expect((0, api_1.getBatteryLevel)({
8
+ battery_life: '49',
9
+ })).toEqual(49);
10
+ });
11
+ it('should handle null battery life', () => {
12
+ expect((0, api_1.getBatteryLevel)({ battery_life: null })).toEqual(null);
13
+ });
14
+ it('should handle right battery only', () => {
15
+ expect((0, api_1.getBatteryLevel)({ battery_life: null, battery_life_2: 24 })).toEqual(24);
16
+ });
17
+ it('should handle left battery only', () => {
18
+ expect((0, api_1.getBatteryLevel)({ battery_life: 76, battery_life_2: null })).toEqual(76);
19
+ });
20
+ it('should handle dual batteries', () => {
21
+ expect((0, api_1.getBatteryLevel)({ battery_life: '92', battery_life_2: 84 })).toEqual(84);
22
+ expect((0, api_1.getBatteryLevel)({ battery_life: '92', battery_life_2: 100 })).toEqual(92);
23
+ });
24
+ });
25
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ring-client-api",
3
- "version": "10.0.0-beta.4",
3
+ "version": "10.0.0-beta.5",
4
4
  "description": "Unofficial API for Ring doorbells, cameras, security alarm system and smart lighting",
5
5
  "main": "lib/api/index.js",
6
6
  "bin": {
@@ -10,7 +10,7 @@
10
10
  "scripts": {
11
11
  "start": "concurrently -c yellow,blue --kill-others \"npm:hb\" \"npm:watch:ui\"",
12
12
  "watch:ui": "npm start --prefix homebridge-ui",
13
- "test": "eslint '**/*.ts'",
13
+ "test": "jest && eslint '**/*.ts'",
14
14
  "watch:tests": "jest --watch",
15
15
  "lint": "eslint '**/*.ts' --fix",
16
16
  "build": "rm -rf lib && tsc --declaration",
@@ -58,42 +58,42 @@
58
58
  "@eneris/push-receiver": "^3.0.1",
59
59
  "@homebridge/camera-utils": "2.1.0",
60
60
  "@homebridge/plugin-ui-utils": "0.0.19",
61
- "@koush/werift": "0.14.5-beta7",
61
+ "@koush/werift": "0.14.5-beta9",
62
62
  "@types/socket.io-client": "1.4.36",
63
63
  "colors": "1.4.0",
64
- "debug": "4.3.3",
64
+ "debug": "4.3.4",
65
65
  "got": "11.8.3",
66
- "rxjs": "7.5.2",
66
+ "rxjs": "7.5.5",
67
67
  "socket.io-client": "2.4.0",
68
- "systeminformation": "5.10.7",
68
+ "systeminformation": "5.11.9",
69
69
  "uuid": "8.3.2",
70
- "ws": "8.4.2"
70
+ "ws": "8.5.0"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@types/debug": "4.1.7",
74
- "@types/jest": "27.4.0",
75
- "@types/node": "17.0.10",
74
+ "@types/jest": "27.4.1",
75
+ "@types/node": "17.0.23",
76
76
  "@types/uuid": "8.3.4",
77
- "@types/ws": "^8.2.2",
78
- "@typescript-eslint/eslint-plugin": "5.10.0",
79
- "@typescript-eslint/parser": "5.10.0",
80
- "concurrently": "^7.0.0",
77
+ "@types/ws": "^8.5.3",
78
+ "@typescript-eslint/eslint-plugin": "5.18.0",
79
+ "@typescript-eslint/parser": "5.18.0",
80
+ "concurrently": "^7.1.0",
81
81
  "conventional-github-releaser": "3.1.5",
82
- "dotenv": "14.2.0",
83
- "esbuild": "^0.14.19",
84
- "eslint": "8.7.0",
85
- "eslint-config-prettier": "8.3.0",
86
- "eslint-plugin-jest": "25.7.0",
82
+ "dotenv": "16.0.0",
83
+ "esbuild": "^0.14.34",
84
+ "eslint": "8.13.0",
85
+ "eslint-config-prettier": "8.5.0",
86
+ "eslint-plugin-jest": "26.1.4",
87
87
  "eslint-plugin-prettier": "4.0.0",
88
- "express": "4.17.2",
88
+ "express": "4.17.3",
89
89
  "homebridge": "1.4.0",
90
- "jest": "27.4.7",
91
- "prettier": "2.5.1",
90
+ "jest": "27.5.1",
91
+ "prettier": "2.6.2",
92
92
  "reflect-metadata": "0.1.13",
93
93
  "rimraf": "3.0.2",
94
94
  "standard-version": "9.3.2",
95
- "ts-jest": "27.1.3",
96
- "typescript": "4.5.5"
95
+ "ts-jest": "27.1.4",
96
+ "typescript": "4.6.3"
97
97
  },
98
98
  "engines": {
99
99
  "node": "^12.20 || ^14 || ^16",