homebridge-ring 11.5.0 → 11.5.2
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/lib/base-accessory.js +36 -34
- package/lib/base-data-accessory.js +28 -28
- package/lib/base-device-accessory.js +40 -34
- package/lib/beam.js +38 -48
- package/lib/brightness-only.js +23 -30
- package/lib/camera-source.js +229 -263
- package/lib/camera.js +74 -67
- package/lib/chime.js +39 -37
- package/lib/co-alarm.js +13 -15
- package/lib/config.js +18 -29
- package/lib/contact-sensor.js +13 -15
- package/lib/fan.js +23 -37
- package/lib/flood-freeze-sensor.js +28 -24
- package/lib/freeze-sensor.js +19 -19
- package/lib/hap.js +4 -15
- package/lib/homebridge-ui/server.js +21 -32
- package/lib/index.js +7 -12
- package/lib/location-mode-switch.js +39 -42
- package/lib/lock.js +28 -29
- package/lib/motion-sensor.js +10 -14
- package/lib/multi-level-switch.js +24 -38
- package/lib/opus-repacketizer.js +66 -23
- package/lib/outlet.js +16 -26
- package/lib/panic-buttons.js +41 -45
- package/lib/ring-platform.js +186 -175
- package/lib/security-panel.js +84 -74
- package/lib/smoke-alarm.js +13 -15
- package/lib/smoke-co-listener.js +18 -18
- package/lib/switch.js +15 -25
- package/lib/target-value-timer.js +4 -8
- package/lib/temperature-sensor.js +11 -15
- package/lib/thermostat.js +60 -77
- package/lib/unknown-zwave-switch.js +15 -25
- package/lib/util.js +6 -10
- package/lib/water-sensor.js +19 -19
- package/package.json +9 -6
- package/lib/server.js +0 -58
package/lib/ring-platform.js
CHANGED
|
@@ -1,152 +1,184 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const _switch = require("./switch");
|
|
33
|
-
const _camera = require("./camera");
|
|
34
|
-
const _panicButtons = require("./panic-buttons");
|
|
35
|
-
const _util = require("ring-client-api/util");
|
|
36
|
-
const _floodFreezeSensor = require("./flood-freeze-sensor");
|
|
37
|
-
const _freezeSensor = require("./freeze-sensor");
|
|
38
|
-
const _temperatureSensor = require("./temperature-sensor");
|
|
39
|
-
const _waterSensor = require("./water-sensor");
|
|
40
|
-
const _locationModeSwitch = require("./location-mode-switch");
|
|
41
|
-
const _thermostat = require("./thermostat");
|
|
42
|
-
const _unknownZwaveSwitch = require("./unknown-zwave-switch");
|
|
43
|
-
const _util1 = require("./util");
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RingPlatform = exports.pluginName = exports.platformName = void 0;
|
|
4
|
+
const ring_client_api_1 = require("ring-client-api");
|
|
5
|
+
const hap_1 = require("./hap");
|
|
6
|
+
const security_panel_1 = require("./security-panel");
|
|
7
|
+
const chime_1 = require("./chime");
|
|
8
|
+
const brightness_only_1 = require("./brightness-only");
|
|
9
|
+
const contact_sensor_1 = require("./contact-sensor");
|
|
10
|
+
const motion_sensor_1 = require("./motion-sensor");
|
|
11
|
+
const lock_1 = require("./lock");
|
|
12
|
+
const smoke_alarm_1 = require("./smoke-alarm");
|
|
13
|
+
const co_alarm_1 = require("./co-alarm");
|
|
14
|
+
const smoke_co_listener_1 = require("./smoke-co-listener");
|
|
15
|
+
const config_1 = require("./config");
|
|
16
|
+
const beam_1 = require("./beam");
|
|
17
|
+
const multi_level_switch_1 = require("./multi-level-switch");
|
|
18
|
+
const fan_1 = require("./fan");
|
|
19
|
+
const outlet_1 = require("./outlet");
|
|
20
|
+
const switch_1 = require("./switch");
|
|
21
|
+
const camera_1 = require("./camera");
|
|
22
|
+
const panic_buttons_1 = require("./panic-buttons");
|
|
23
|
+
const util_1 = require("ring-client-api/util");
|
|
24
|
+
const flood_freeze_sensor_1 = require("./flood-freeze-sensor");
|
|
25
|
+
const freeze_sensor_1 = require("./freeze-sensor");
|
|
26
|
+
const temperature_sensor_1 = require("./temperature-sensor");
|
|
27
|
+
const water_sensor_1 = require("./water-sensor");
|
|
28
|
+
const location_mode_switch_1 = require("./location-mode-switch");
|
|
29
|
+
const thermostat_1 = require("./thermostat");
|
|
30
|
+
const unknown_zwave_switch_1 = require("./unknown-zwave-switch");
|
|
31
|
+
const util_2 = require("./util");
|
|
44
32
|
const ignoreHiddenDeviceTypes = [
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
33
|
+
ring_client_api_1.RingDeviceType.RingNetAdapter,
|
|
34
|
+
ring_client_api_1.RingDeviceType.ZigbeeAdapter,
|
|
35
|
+
ring_client_api_1.RingDeviceType.CodeVault,
|
|
36
|
+
ring_client_api_1.RingDeviceType.SecurityAccessCode,
|
|
37
|
+
ring_client_api_1.RingDeviceType.ZWaveAdapter,
|
|
38
|
+
ring_client_api_1.RingDeviceType.ZWaveExtender,
|
|
39
|
+
ring_client_api_1.RingDeviceType.BeamsDevice,
|
|
40
|
+
ring_client_api_1.RingDeviceType.PanicButton,
|
|
53
41
|
];
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
exports.platformName = 'Ring';
|
|
43
|
+
exports.pluginName = 'homebridge-ring';
|
|
56
44
|
function getAccessoryClass(device) {
|
|
57
|
-
const { deviceType
|
|
45
|
+
const { deviceType } = device;
|
|
58
46
|
if (device.data.status === 'disabled') {
|
|
59
47
|
return null;
|
|
60
48
|
}
|
|
61
|
-
switch(deviceType){
|
|
62
|
-
case
|
|
63
|
-
case
|
|
64
|
-
case
|
|
65
|
-
case
|
|
66
|
-
return
|
|
67
|
-
case
|
|
68
|
-
return
|
|
69
|
-
case
|
|
70
|
-
return
|
|
71
|
-
case
|
|
72
|
-
return
|
|
73
|
-
case
|
|
74
|
-
return
|
|
75
|
-
case
|
|
76
|
-
case
|
|
77
|
-
case
|
|
78
|
-
return
|
|
79
|
-
case
|
|
80
|
-
return
|
|
81
|
-
case
|
|
82
|
-
return
|
|
83
|
-
case
|
|
84
|
-
return
|
|
85
|
-
case
|
|
86
|
-
case
|
|
87
|
-
case
|
|
88
|
-
case
|
|
89
|
-
case
|
|
90
|
-
return
|
|
91
|
-
case
|
|
92
|
-
return device instanceof
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
case
|
|
104
|
-
return
|
|
49
|
+
switch (deviceType) {
|
|
50
|
+
case ring_client_api_1.RingDeviceType.ContactSensor:
|
|
51
|
+
case ring_client_api_1.RingDeviceType.RetrofitZone:
|
|
52
|
+
case ring_client_api_1.RingDeviceType.TiltSensor:
|
|
53
|
+
case ring_client_api_1.RingDeviceType.GlassbreakSensor:
|
|
54
|
+
return contact_sensor_1.ContactSensor;
|
|
55
|
+
case ring_client_api_1.RingDeviceType.MotionSensor:
|
|
56
|
+
return motion_sensor_1.MotionSensor;
|
|
57
|
+
case ring_client_api_1.RingDeviceType.FloodFreezeSensor:
|
|
58
|
+
return flood_freeze_sensor_1.FloodFreezeSensor;
|
|
59
|
+
case ring_client_api_1.RingDeviceType.FreezeSensor:
|
|
60
|
+
return freeze_sensor_1.FreezeSensor;
|
|
61
|
+
case ring_client_api_1.RingDeviceType.SecurityPanel:
|
|
62
|
+
return security_panel_1.SecurityPanel;
|
|
63
|
+
case ring_client_api_1.RingDeviceType.BaseStation:
|
|
64
|
+
case ring_client_api_1.RingDeviceType.BaseStationPro:
|
|
65
|
+
case ring_client_api_1.RingDeviceType.Keypad:
|
|
66
|
+
return brightness_only_1.BrightnessOnly;
|
|
67
|
+
case ring_client_api_1.RingDeviceType.SmokeAlarm:
|
|
68
|
+
return smoke_alarm_1.SmokeAlarm;
|
|
69
|
+
case ring_client_api_1.RingDeviceType.CoAlarm:
|
|
70
|
+
return co_alarm_1.CoAlarm;
|
|
71
|
+
case ring_client_api_1.RingDeviceType.SmokeCoListener:
|
|
72
|
+
return smoke_co_listener_1.SmokeCoListener;
|
|
73
|
+
case ring_client_api_1.RingDeviceType.BeamsMotionSensor:
|
|
74
|
+
case ring_client_api_1.RingDeviceType.BeamsSwitch:
|
|
75
|
+
case ring_client_api_1.RingDeviceType.BeamsMultiLevelSwitch:
|
|
76
|
+
case ring_client_api_1.RingDeviceType.BeamsTransformerSwitch:
|
|
77
|
+
case ring_client_api_1.RingDeviceType.BeamsLightGroupSwitch:
|
|
78
|
+
return beam_1.Beam;
|
|
79
|
+
case ring_client_api_1.RingDeviceType.MultiLevelSwitch:
|
|
80
|
+
return device instanceof ring_client_api_1.RingDevice &&
|
|
81
|
+
device.categoryId === ring_client_api_1.RingDeviceCategory.Fans
|
|
82
|
+
? fan_1.Fan
|
|
83
|
+
: multi_level_switch_1.MultiLevelSwitch;
|
|
84
|
+
case ring_client_api_1.RingDeviceType.MultiLevelBulb:
|
|
85
|
+
return multi_level_switch_1.MultiLevelSwitch;
|
|
86
|
+
case ring_client_api_1.RingDeviceType.Switch:
|
|
87
|
+
return device instanceof ring_client_api_1.RingDevice &&
|
|
88
|
+
device.categoryId === ring_client_api_1.RingDeviceCategory.Outlets
|
|
89
|
+
? outlet_1.Outlet
|
|
90
|
+
: switch_1.Switch;
|
|
91
|
+
case ring_client_api_1.RingDeviceType.TemperatureSensor:
|
|
92
|
+
return temperature_sensor_1.TemperatureSensor;
|
|
93
|
+
case ring_client_api_1.RingDeviceType.WaterSensor:
|
|
94
|
+
return water_sensor_1.WaterSensor;
|
|
95
|
+
case ring_client_api_1.RingDeviceType.Thermostat:
|
|
96
|
+
return thermostat_1.Thermostat;
|
|
97
|
+
case ring_client_api_1.RingDeviceType.UnknownZWave:
|
|
98
|
+
return unknown_zwave_switch_1.UnknownZWaveSwitchSwitch;
|
|
105
99
|
}
|
|
106
100
|
if (/^lock($|\.)/.test(deviceType)) {
|
|
107
|
-
return
|
|
101
|
+
return lock_1.Lock;
|
|
108
102
|
}
|
|
109
|
-
if (deviceType ===
|
|
103
|
+
if (deviceType === ring_client_api_1.RingDeviceType.Sensor) {
|
|
110
104
|
// Generic sensor that could be any type of sensor, but should at least have `faulted`
|
|
111
105
|
if (device.name.toLowerCase().includes('motion')) {
|
|
112
|
-
return
|
|
106
|
+
return motion_sensor_1.MotionSensor;
|
|
113
107
|
}
|
|
114
|
-
return
|
|
108
|
+
return contact_sensor_1.ContactSensor;
|
|
115
109
|
}
|
|
116
110
|
return null;
|
|
117
111
|
}
|
|
118
112
|
class RingPlatform {
|
|
113
|
+
constructor(log, config, api) {
|
|
114
|
+
this.log = log;
|
|
115
|
+
this.config = config;
|
|
116
|
+
this.api = api;
|
|
117
|
+
this.homebridgeAccessories = {};
|
|
118
|
+
if (!config.disableLogs) {
|
|
119
|
+
(0, util_1.useLogger)({
|
|
120
|
+
logInfo(message) {
|
|
121
|
+
log.info(message);
|
|
122
|
+
},
|
|
123
|
+
logError(message) {
|
|
124
|
+
log.error(message);
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (!config) {
|
|
129
|
+
(0, util_1.logInfo)('No configuration found for platform Ring');
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
config.cameraStatusPollingSeconds = config.cameraStatusPollingSeconds ?? 20;
|
|
133
|
+
config.locationModePollingSeconds = config.locationModePollingSeconds ?? 20;
|
|
134
|
+
this.api.on('didFinishLaunching', () => {
|
|
135
|
+
this.log.debug('didFinishLaunching');
|
|
136
|
+
if (config.refreshToken) {
|
|
137
|
+
this.connectToApi().catch((e) => {
|
|
138
|
+
this.log.error('Error connecting to API');
|
|
139
|
+
this.log.error(e);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
this.log.warn('Plugin is not configured. Visit https://github.com/dgreif/ring/tree/main/packages/homebridge-ring#homebridge-configuration for more information.');
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
this.homebridgeAccessories = {};
|
|
147
|
+
}
|
|
119
148
|
configureAccessory(accessory) {
|
|
120
|
-
(0,
|
|
149
|
+
(0, util_1.logInfo)(`Configuring cached accessory ${accessory.UUID} ${accessory.displayName}`);
|
|
121
150
|
this.log.debug('%j', accessory);
|
|
122
151
|
this.homebridgeAccessories[accessory.UUID] = accessory;
|
|
123
152
|
}
|
|
124
153
|
async connectToApi() {
|
|
125
|
-
const { api
|
|
154
|
+
const { api, config } = this, systemId = (0, config_1.getSystemId)(api), ringApi = new ring_client_api_1.RingApi({
|
|
126
155
|
controlCenterDisplayName: 'homebridge-ring',
|
|
127
156
|
...config,
|
|
128
|
-
systemId
|
|
157
|
+
systemId,
|
|
129
158
|
}), locations = await ringApi.getLocations(), cachedAccessoryIds = Object.keys(this.homebridgeAccessories), platformAccessories = [], externalAccessories = [], activeAccessoryIds = [];
|
|
130
|
-
(0,
|
|
131
|
-
locations.forEach((location)=>{
|
|
132
|
-
(0,
|
|
159
|
+
(0, util_1.logInfo)('Found the following locations:');
|
|
160
|
+
locations.forEach((location) => {
|
|
161
|
+
(0, util_1.logInfo)(` locationId: ${location.id} - ${location.name}`);
|
|
133
162
|
});
|
|
134
|
-
await Promise.all(locations.map(async (location)=>{
|
|
135
|
-
const devices = await location.getDevices(), cameras = location.cameras, chimes = location.chimes, allDevices = [
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
163
|
+
await Promise.all(locations.map(async (location) => {
|
|
164
|
+
const devices = await location.getDevices(), cameras = location.cameras, chimes = location.chimes, allDevices = [...devices, ...cameras, ...chimes], securityPanel = devices.find((x) => x.deviceType === ring_client_api_1.RingDeviceType.SecurityPanel), debugPrefix = config_1.debug ? 'TEST ' : '', hapDevices = allDevices.map((device) => {
|
|
165
|
+
const isCamera = device instanceof ring_client_api_1.RingCamera, cameraIdDifferentiator = isCamera ? 'camera' : '', // this forces bridged cameras from old version of the plugin to be seen as "stale"
|
|
166
|
+
AccessoryClass = (device instanceof ring_client_api_1.RingCamera
|
|
167
|
+
? camera_1.Camera
|
|
168
|
+
: device instanceof ring_client_api_1.RingChime
|
|
169
|
+
? chime_1.Chime
|
|
170
|
+
: getAccessoryClass(device));
|
|
141
171
|
return {
|
|
142
172
|
deviceType: device.deviceType,
|
|
143
173
|
device: device,
|
|
144
174
|
isCamera,
|
|
145
175
|
id: device.id.toString() + cameraIdDifferentiator,
|
|
146
176
|
name: device.name,
|
|
147
|
-
AccessoryClass
|
|
177
|
+
AccessoryClass,
|
|
148
178
|
};
|
|
149
|
-
}), hideDeviceIds = config.hideDeviceIds || [], onlyDeviceTypes = config.onlyDeviceTypes?.length
|
|
179
|
+
}), hideDeviceIds = config.hideDeviceIds || [], onlyDeviceTypes = config.onlyDeviceTypes?.length
|
|
180
|
+
? config.onlyDeviceTypes
|
|
181
|
+
: undefined;
|
|
150
182
|
if (config.showPanicButtons && securityPanel) {
|
|
151
183
|
hapDevices.push({
|
|
152
184
|
deviceType: securityPanel.deviceType,
|
|
@@ -154,48 +186,58 @@ class RingPlatform {
|
|
|
154
186
|
isCamera: false,
|
|
155
187
|
id: securityPanel.id.toString() + 'panic',
|
|
156
188
|
name: 'Panic Buttons',
|
|
157
|
-
AccessoryClass:
|
|
189
|
+
AccessoryClass: panic_buttons_1.PanicButtons,
|
|
158
190
|
});
|
|
159
191
|
}
|
|
160
|
-
if (config.locationModePollingSeconds &&
|
|
192
|
+
if (config.locationModePollingSeconds &&
|
|
193
|
+
(await location.supportsLocationModeSwitching())) {
|
|
161
194
|
hapDevices.push({
|
|
162
195
|
deviceType: 'location.mode',
|
|
163
196
|
device: location,
|
|
164
197
|
isCamera: false,
|
|
165
198
|
id: location.id + 'mode',
|
|
166
199
|
name: location.name + ' Mode',
|
|
167
|
-
AccessoryClass:
|
|
200
|
+
AccessoryClass: location_mode_switch_1.LocationModeSwitch,
|
|
168
201
|
});
|
|
169
202
|
}
|
|
170
|
-
(0,
|
|
171
|
-
hapDevices.forEach(({ deviceType
|
|
172
|
-
const uuid =
|
|
173
|
-
if (!AccessoryClass ||
|
|
203
|
+
(0, util_1.logInfo)(`Configuring ${cameras.length} cameras and ${hapDevices.length} devices for location "${location.name}" - locationId: ${location.id}`);
|
|
204
|
+
hapDevices.forEach(({ deviceType, device, isCamera, id, name, AccessoryClass }) => {
|
|
205
|
+
const uuid = hap_1.hap.uuid.generate(debugPrefix + id), displayName = debugPrefix + name, isExternalCamera = isCamera && this.config.unbridgeCameras;
|
|
206
|
+
if (!AccessoryClass ||
|
|
207
|
+
(config.hideLightGroups &&
|
|
208
|
+
deviceType === ring_client_api_1.RingDeviceType.BeamsLightGroupSwitch) ||
|
|
209
|
+
hideDeviceIds.includes(uuid) ||
|
|
210
|
+
(onlyDeviceTypes && !onlyDeviceTypes.includes(deviceType))) {
|
|
174
211
|
if (!ignoreHiddenDeviceTypes.includes(deviceType)) {
|
|
175
|
-
(0,
|
|
212
|
+
(0, util_1.logInfo)(`Hidden accessory ${uuid} ${deviceType} ${displayName}`);
|
|
176
213
|
}
|
|
177
214
|
return;
|
|
178
215
|
}
|
|
179
216
|
if (isExternalCamera && this.homebridgeAccessories[uuid]) {
|
|
180
217
|
// Camera was previously bridged. Remove it from the platform so that it can be added as an external accessory
|
|
181
218
|
this.log.warn(`Camera ${displayName} was previously bridged. You will need to manually pair it as a new accessory.`);
|
|
182
|
-
this.api.unregisterPlatformAccessories(pluginName, platformName, [
|
|
183
|
-
this.homebridgeAccessories[uuid]
|
|
219
|
+
this.api.unregisterPlatformAccessories(exports.pluginName, exports.platformName, [
|
|
220
|
+
this.homebridgeAccessories[uuid],
|
|
184
221
|
]);
|
|
185
222
|
delete this.homebridgeAccessories[uuid];
|
|
186
223
|
}
|
|
187
|
-
const createHomebridgeAccessory = ()=>{
|
|
188
|
-
const accessory = new api.platformAccessory(displayName, uuid, isCamera
|
|
224
|
+
const createHomebridgeAccessory = () => {
|
|
225
|
+
const accessory = new api.platformAccessory(displayName, uuid, isCamera
|
|
226
|
+
? 17 /* hap.Categories.CAMERA */
|
|
227
|
+
: 11 /* hap.Categories.SECURITY_SYSTEM */);
|
|
189
228
|
if (isExternalCamera) {
|
|
190
|
-
(0,
|
|
229
|
+
(0, util_1.logInfo)(`Configured camera ${uuid} ${deviceType} ${displayName}`);
|
|
191
230
|
externalAccessories.push(accessory);
|
|
192
|
-
}
|
|
193
|
-
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
(0, util_1.logInfo)(`Adding new accessory ${uuid} ${deviceType} ${displayName}`);
|
|
194
234
|
platformAccessories.push(accessory);
|
|
195
235
|
}
|
|
196
|
-
if (isCamera &&
|
|
236
|
+
if (isCamera &&
|
|
237
|
+
!isExternalCamera &&
|
|
238
|
+
typeof hap_1.hap.Accessory.cleanupAccessoryData === 'function') {
|
|
197
239
|
// This is a one-time cleanup that will remove persist files for old external accessories from unbridged cameras
|
|
198
|
-
|
|
240
|
+
hap_1.hap.Accessory.cleanupAccessoryData((0, util_2.generateMacAddress)(accessory.UUID));
|
|
199
241
|
}
|
|
200
242
|
return accessory;
|
|
201
243
|
}, homebridgeAccessory = this.homebridgeAccessories[uuid] || createHomebridgeAccessory(), accessory = new AccessoryClass(device, homebridgeAccessory, config);
|
|
@@ -205,59 +247,28 @@ class RingPlatform {
|
|
|
205
247
|
});
|
|
206
248
|
}));
|
|
207
249
|
if (platformAccessories.length) {
|
|
208
|
-
api.registerPlatformAccessories(pluginName, platformName, platformAccessories);
|
|
250
|
+
api.registerPlatformAccessories(exports.pluginName, exports.platformName, platformAccessories);
|
|
209
251
|
}
|
|
210
252
|
if (externalAccessories.length) {
|
|
211
|
-
api.publishExternalAccessories(pluginName, externalAccessories);
|
|
253
|
+
api.publishExternalAccessories(exports.pluginName, externalAccessories);
|
|
212
254
|
}
|
|
213
|
-
const staleAccessories = cachedAccessoryIds
|
|
214
|
-
|
|
215
|
-
(
|
|
255
|
+
const staleAccessories = cachedAccessoryIds
|
|
256
|
+
.filter((cachedId) => !activeAccessoryIds.includes(cachedId))
|
|
257
|
+
.map((id) => this.homebridgeAccessories[id]);
|
|
258
|
+
staleAccessories.forEach((staleAccessory) => {
|
|
259
|
+
(0, util_1.logInfo)(`Removing stale cached accessory ${staleAccessory.UUID} ${staleAccessory.displayName}`);
|
|
216
260
|
});
|
|
217
261
|
if (staleAccessories.length) {
|
|
218
|
-
this.api.unregisterPlatformAccessories(pluginName, platformName, staleAccessories);
|
|
262
|
+
this.api.unregisterPlatformAccessories(exports.pluginName, exports.platformName, staleAccessories);
|
|
219
263
|
}
|
|
220
|
-
ringApi.onRefreshTokenUpdated.subscribe(({ oldRefreshToken
|
|
264
|
+
ringApi.onRefreshTokenUpdated.subscribe(({ oldRefreshToken, newRefreshToken }) => {
|
|
221
265
|
if (!oldRefreshToken) {
|
|
222
266
|
return;
|
|
223
267
|
}
|
|
224
|
-
(0,
|
|
268
|
+
(0, config_1.updateHomebridgeConfig)(this.api, (configContents) => {
|
|
225
269
|
return configContents.replace(oldRefreshToken, newRefreshToken);
|
|
226
270
|
});
|
|
227
271
|
});
|
|
228
272
|
}
|
|
229
|
-
constructor(log, config, api){
|
|
230
|
-
this.log = log;
|
|
231
|
-
this.config = config;
|
|
232
|
-
this.api = api;
|
|
233
|
-
this.homebridgeAccessories = {};
|
|
234
|
-
if (!config.disableLogs) {
|
|
235
|
-
(0, _util.useLogger)({
|
|
236
|
-
logInfo (message) {
|
|
237
|
-
log.info(message);
|
|
238
|
-
},
|
|
239
|
-
logError (message) {
|
|
240
|
-
log.error(message);
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
if (!config) {
|
|
245
|
-
(0, _util.logInfo)('No configuration found for platform Ring');
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
config.cameraStatusPollingSeconds = config.cameraStatusPollingSeconds ?? 20;
|
|
249
|
-
config.locationModePollingSeconds = config.locationModePollingSeconds ?? 20;
|
|
250
|
-
this.api.on('didFinishLaunching', ()=>{
|
|
251
|
-
this.log.debug('didFinishLaunching');
|
|
252
|
-
if (config.refreshToken) {
|
|
253
|
-
this.connectToApi().catch((e)=>{
|
|
254
|
-
this.log.error('Error connecting to API');
|
|
255
|
-
this.log.error(e);
|
|
256
|
-
});
|
|
257
|
-
} else {
|
|
258
|
-
this.log.warn('Plugin is not configured. Visit https://github.com/dgreif/ring/tree/main/packages/homebridge-ring#homebridge-configuration for more information.');
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
this.homebridgeAccessories = {};
|
|
262
|
-
}
|
|
263
273
|
}
|
|
274
|
+
exports.RingPlatform = RingPlatform;
|