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/thermostat.js CHANGED
@@ -1,50 +1,42 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "Thermostat", {
6
- enumerable: true,
7
- get: ()=>Thermostat
8
- });
9
- const _rxjs = require("rxjs");
10
- const _operators = require("rxjs/operators");
11
- const _ringClientApi = require("ring-client-api");
12
- const _util = require("ring-client-api/util");
13
- const _baseDeviceAccessory = require("./base-device-accessory");
14
- const _hap = require("./hap");
15
- class Thermostat extends _baseDeviceAccessory.BaseDeviceAccessory {
16
- constructor(device, accessory, config){
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Thermostat = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const ring_client_api_1 = require("ring-client-api");
7
+ const util_1 = require("ring-client-api/util");
8
+ const base_device_accessory_1 = require("./base-device-accessory");
9
+ const hap_1 = require("./hap");
10
+ class Thermostat extends base_device_accessory_1.BaseDeviceAccessory {
11
+ constructor(device, accessory, config) {
17
12
  super();
18
13
  this.device = device;
19
14
  this.accessory = accessory;
20
15
  this.config = config;
21
- const { Characteristic , Service } = _hap.hap;
16
+ const { Characteristic, Service } = hap_1.hap;
22
17
  // Component Device (Temperature Sensor)
23
- this.onTemperature = this.device.onComponentDevices.pipe((0, _operators.switchMap)((devices)=>{
24
- const temperatureSensor = devices.find(({ deviceType })=>deviceType === _ringClientApi.RingDeviceType.TemperatureSensor);
18
+ this.onTemperature = this.device.onComponentDevices.pipe((0, operators_1.switchMap)((devices) => {
19
+ const temperatureSensor = devices.find(({ deviceType }) => deviceType === ring_client_api_1.RingDeviceType.TemperatureSensor);
25
20
  if (!temperatureSensor) {
26
21
  return [];
27
22
  }
28
- (0, _util.logDebug)(`Discovered a component temperature sensor for ${this.device.name}`);
29
- return temperatureSensor.onData.pipe((0, _operators.map)(({ celsius: temperature })=>{
30
- (0, _util.logDebug)(`Component temperature sensor for ${this.device.name} reported ${temperature} degrees`);
23
+ (0, util_1.logDebug)(`Discovered a component temperature sensor for ${this.device.name}`);
24
+ return temperatureSensor.onData.pipe((0, operators_1.map)(({ celsius: temperature }) => {
25
+ (0, util_1.logDebug)(`Component temperature sensor for ${this.device.name} reported ${temperature} degrees`);
31
26
  return temperature;
32
- }), (0, _operators.distinctUntilChanged)());
27
+ }), (0, operators_1.distinctUntilChanged)());
33
28
  }));
34
29
  // Required Characteristics
35
30
  this.registerObservableCharacteristic({
36
31
  characteristicType: Characteristic.CurrentHeatingCoolingState,
37
32
  serviceType: Service.Thermostat,
38
- onValue: (0, _rxjs.combineLatest)([
39
- this.onTemperature,
40
- this.device.onData
41
- ]).pipe((0, _operators.map)(([temperature, { setPoint , mode }])=>{
33
+ onValue: (0, rxjs_1.combineLatest)([this.onTemperature, this.device.onData]).pipe((0, operators_1.map)(([temperature, { setPoint, mode }]) => {
42
34
  if (mode === 'off') {
43
35
  // The thermostat is set to 'off', so the thermostat is neither heating nor cooling
44
36
  return Characteristic.CurrentHeatingCoolingState.OFF;
45
37
  }
46
38
  if (!temperature || !setPoint) {
47
- (0, _util.logError)(`Could not determine 'CurrentHeatingCoolingState' for ${this.device.name} given temperature: ${temperature}, set point: ${setPoint} and mode: ${mode}. Reporting 'off' state as a fallback.`);
39
+ (0, util_1.logError)(`Could not determine 'CurrentHeatingCoolingState' for ${this.device.name} given temperature: ${temperature}, set point: ${setPoint} and mode: ${mode}. Reporting 'off' state as a fallback.`);
48
40
  return Characteristic.CurrentHeatingCoolingState.OFF;
49
41
  }
50
42
  // Checking with a threshold to avoid floating point weirdness
@@ -58,7 +50,8 @@ class Thermostat extends _baseDeviceAccessory.BaseDeviceAccessory {
58
50
  // and the thermostat is set to 'cool', so the thermostat is cooling
59
51
  return Characteristic.CurrentHeatingCoolingState.COOL;
60
52
  }
61
- if (currentTemperatureIsLowerThanTarget && (mode === 'heat' || mode === 'aux')) {
53
+ if (currentTemperatureIsLowerThanTarget &&
54
+ (mode === 'heat' || mode === 'aux')) {
62
55
  // The current temperature is lower than the target temperature,
63
56
  // and the thermostat is set to 'heat' or 'aux' (emergency heat), so the thermostat is heating
64
57
  return Characteristic.CurrentHeatingCoolingState.HEAT;
@@ -67,13 +60,13 @@ class Thermostat extends _baseDeviceAccessory.BaseDeviceAccessory {
67
60
  // but the current thermostat mode would only increase the difference,
68
61
  // so the thermostat is neither heating nor cooling
69
62
  return Characteristic.CurrentHeatingCoolingState.OFF;
70
- }))
63
+ })),
71
64
  });
72
65
  this.registerCharacteristic({
73
66
  characteristicType: Characteristic.TargetHeatingCoolingState,
74
67
  serviceType: Service.Thermostat,
75
- getValue: ({ mode })=>{
76
- switch(mode){
68
+ getValue: ({ mode }) => {
69
+ switch (mode) {
77
70
  case 'off':
78
71
  return Characteristic.TargetHeatingCoolingState.OFF;
79
72
  case 'heat':
@@ -83,9 +76,9 @@ class Thermostat extends _baseDeviceAccessory.BaseDeviceAccessory {
83
76
  return Characteristic.TargetHeatingCoolingState.COOL;
84
77
  }
85
78
  },
86
- setValue: (targetHeatingCoolingState)=>{
87
- const mode = (()=>{
88
- switch(targetHeatingCoolingState){
79
+ setValue: (targetHeatingCoolingState) => {
80
+ const mode = (() => {
81
+ switch (targetHeatingCoolingState) {
89
82
  case Characteristic.TargetHeatingCoolingState.OFF:
90
83
  return 'off';
91
84
  case Characteristic.TargetHeatingCoolingState.HEAT:
@@ -97,100 +90,90 @@ class Thermostat extends _baseDeviceAccessory.BaseDeviceAccessory {
97
90
  }
98
91
  })();
99
92
  if (!mode) {
100
- (0, _util.logError)(`Couldn’t match ${targetHeatingCoolingState} to a recognized mode string.`);
93
+ (0, util_1.logError)(`Couldn’t match ${targetHeatingCoolingState} to a recognized mode string.`);
101
94
  return;
102
95
  }
103
- (0, _util.logInfo)(`Setting ${this.device.name} mode to ${mode}`);
104
- return this.device.setInfo({
105
- device: {
106
- v1: {
107
- mode
108
- }
109
- }
110
- });
111
- }
96
+ (0, util_1.logInfo)(`Setting ${this.device.name} mode to ${mode}`);
97
+ return this.device.setInfo({ device: { v1: { mode } } });
98
+ },
112
99
  });
113
100
  // Only allow 'TargetHeatingCoolingState's which can be mapped to Ring modes
114
101
  // Specifically, this omits .AUTO
115
- this.getService(Service.Thermostat).getCharacteristic(Characteristic.TargetHeatingCoolingState).setProps({
102
+ this.getService(Service.Thermostat)
103
+ .getCharacteristic(Characteristic.TargetHeatingCoolingState)
104
+ .setProps({
116
105
  validValues: [
117
106
  Characteristic.TargetHeatingCoolingState.OFF,
118
107
  Characteristic.TargetHeatingCoolingState.HEAT,
119
- Characteristic.TargetHeatingCoolingState.COOL
120
- ]
108
+ Characteristic.TargetHeatingCoolingState.COOL,
109
+ ],
121
110
  });
122
111
  this.registerObservableCharacteristic({
123
112
  characteristicType: Characteristic.CurrentTemperature,
124
113
  serviceType: Service.Thermostat,
125
- onValue: this.onTemperature.pipe((0, _operators.map)((temperature)=>{
114
+ onValue: this.onTemperature.pipe((0, operators_1.map)((temperature) => {
126
115
  if (!temperature) {
127
- (0, _util.logError)(`Could not determine 'CurrentTemperature' for ${this.device.name} given temperature: ${temperature}. Returning 22 degrees celsius as a fallback.`);
116
+ (0, util_1.logError)(`Could not determine 'CurrentTemperature' for ${this.device.name} given temperature: ${temperature}. Returning 22 degrees celsius as a fallback.`);
128
117
  return 22;
129
118
  }
130
119
  // Documentation: https://developers.homebridge.io/#/characteristic/CurrentTemperature
131
120
  // 'Characteristic.CurrentTemperature' supports 0.1 increments
132
121
  return Number(Number(temperature).toFixed(1));
133
- }))
122
+ })),
134
123
  });
135
124
  this.registerCharacteristic({
136
125
  characteristicType: Characteristic.TargetTemperature,
137
126
  serviceType: Service.Thermostat,
138
- getValue: ({ setPoint })=>{
127
+ getValue: ({ setPoint }) => {
139
128
  return setPoint;
140
129
  },
141
- setValue: (setPoint)=>{
142
- (0, _util.logInfo)(`Setting ${this.device.name} target temperature to ${setPoint}`);
130
+ setValue: (setPoint) => {
131
+ (0, util_1.logInfo)(`Setting ${this.device.name} target temperature to ${setPoint}`);
143
132
  // Documentation: https://developers.homebridge.io/#/characteristic/TargetTemperature
144
133
  // 'Characteristic.TargetTemperature' has a valid range from 10 to 38 degrees celsius,
145
134
  // but devices may support a different range. When limits differ, accept the more strict.
146
135
  const setPointMin = Math.max(this.device.data.setPointMin || 10, 10), setPointMax = Math.min(this.device.data.setPointMax || 38, 38);
147
136
  if (setPoint < setPointMin || setPoint > setPointMax) {
148
- (0, _util.logError)(`Ignoring request to set ${this.device.name} target temperature to ${setPoint}. Target temperature must be between ${setPointMin} and ${setPointMax}.`);
137
+ (0, util_1.logError)(`Ignoring request to set ${this.device.name} target temperature to ${setPoint}. Target temperature must be between ${setPointMin} and ${setPointMax}.`);
149
138
  return;
150
139
  }
151
- return this.device.setInfo({
152
- device: {
153
- v1: {
154
- setPoint
155
- }
156
- }
157
- });
158
- }
140
+ return this.device.setInfo({ device: { v1: { setPoint } } });
141
+ },
159
142
  });
160
143
  if (this.device.data.setPointMin || this.device.data.setPointMax) {
161
144
  // Documentation: https://developers.homebridge.io/#/characteristic/TargetTemperature
162
145
  // 'Characteristic.TargetTemperature' has a valid range from 10 to 38 degrees celsius,
163
146
  // but devices may support a different range. When limits differ, accept the more strict.
164
147
  const setPointMin = Math.max(this.device.data.setPointMin || 10, 10), setPointMax = Math.min(this.device.data.setPointMax || 38, 38);
165
- (0, _util.logDebug)(`Setting ${this.device.name} target temperature range to ${setPointMin}–${setPointMax}`);
166
- this.getService(Service.Thermostat).getCharacteristic(Characteristic.TargetTemperature).setProps({
148
+ (0, util_1.logDebug)(`Setting ${this.device.name} target temperature range to ${setPointMin}–${setPointMax}`);
149
+ this.getService(Service.Thermostat)
150
+ .getCharacteristic(Characteristic.TargetTemperature)
151
+ .setProps({
167
152
  minValue: setPointMin,
168
153
  maxValue: setPointMax,
169
- validValueRanges: [
170
- setPointMin,
171
- setPointMax
172
- ]
154
+ validValueRanges: [setPointMin, setPointMax],
173
155
  });
174
156
  }
175
157
  this.registerCharacteristic({
176
158
  characteristicType: Characteristic.TemperatureDisplayUnits,
177
159
  serviceType: Service.Thermostat,
178
- getValue: ()=>{
160
+ getValue: () => {
179
161
  // Neither thermostats nor their component devices (e.g. temperature sensors)
180
162
  // appear to include the unit preference. Hardcoding Fahrenheit as the default.
181
163
  return Characteristic.TemperatureDisplayUnits.FAHRENHEIT;
182
164
  },
183
- setValue: ()=>{
184
- // noop
185
- // Setting display unit is unsupported
186
- }
165
+ setValue: () => {
166
+ // noop
167
+ // Setting display unit is unsupported
168
+ },
187
169
  });
188
170
  // Setting 'TemperatureDisplayUnits' is unsupported by the Ring API.
189
171
  // We’ve defaulted to Fahrenheit above, so only allowing .FAHRENHEIT.
190
- this.getService(Service.Thermostat).getCharacteristic(Characteristic.TemperatureDisplayUnits).setProps({
191
- validValues: [
192
- Characteristic.TemperatureDisplayUnits.FAHRENHEIT
193
- ]
172
+ this.getService(Service.Thermostat)
173
+ .getCharacteristic(Characteristic.TemperatureDisplayUnits)
174
+ .setProps({
175
+ validValues: [Characteristic.TemperatureDisplayUnits.FAHRENHEIT],
194
176
  });
195
177
  }
196
178
  }
179
+ exports.Thermostat = Thermostat;
@@ -1,36 +1,26 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "UnknownZWaveSwitchSwitch", {
6
- enumerable: true,
7
- get: ()=>UnknownZWaveSwitchSwitch
8
- });
9
- const _baseDeviceAccessory = require("./base-device-accessory");
10
- const _hap = require("./hap");
11
- const _util = require("ring-client-api/util");
12
- class UnknownZWaveSwitchSwitch extends _baseDeviceAccessory.BaseDeviceAccessory {
13
- setOnState(on) {
14
- (0, _util.logInfo)(`Turning ${this.device.name} ${on ? 'On' : 'Off'}`);
15
- return this.device.setInfo({
16
- device: {
17
- v1: {
18
- basicValue: on ? 255 : 0
19
- }
20
- }
21
- });
22
- }
23
- constructor(device, accessory, config){
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnknownZWaveSwitchSwitch = void 0;
4
+ const base_device_accessory_1 = require("./base-device-accessory");
5
+ const hap_1 = require("./hap");
6
+ const util_1 = require("ring-client-api/util");
7
+ class UnknownZWaveSwitchSwitch extends base_device_accessory_1.BaseDeviceAccessory {
8
+ constructor(device, accessory, config) {
24
9
  super();
25
10
  this.device = device;
26
11
  this.accessory = accessory;
27
12
  this.config = config;
28
- const { Characteristic , Service } = _hap.hap;
13
+ const { Characteristic, Service } = hap_1.hap;
29
14
  this.registerCharacteristic({
30
15
  characteristicType: Characteristic.On,
31
16
  serviceType: Service.Switch,
32
- getValue: (data)=>Boolean(data.basicValue),
33
- setValue: (value)=>this.setOnState(value)
17
+ getValue: (data) => Boolean(data.basicValue),
18
+ setValue: (value) => this.setOnState(value),
34
19
  });
35
20
  }
21
+ setOnState(on) {
22
+ (0, util_1.logInfo)(`Turning ${this.device.name} ${on ? 'On' : 'Off'}`);
23
+ return this.device.setInfo({ device: { v1: { basicValue: on ? 255 : 0 } } });
24
+ }
36
25
  }
26
+ exports.UnknownZWaveSwitchSwitch = UnknownZWaveSwitchSwitch;
package/lib/util.js CHANGED
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "generateMacAddress", {
6
- enumerable: true,
7
- get: ()=>generateMacAddress
8
- });
9
- const _crypto = require("crypto");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateMacAddress = void 0;
4
+ const crypto_1 = require("crypto");
10
5
  function generateMacAddress(uuid) {
11
- const sha1sum = (0, _crypto.createHash)('sha1');
6
+ const sha1sum = (0, crypto_1.createHash)('sha1');
12
7
  sha1sum.update(uuid);
13
8
  const s = sha1sum.digest('hex');
14
9
  let i = 0;
15
- return 'xx:xx:xx:xx:xx:xx'.replace(/[x]/g, ()=>s[i++]).toUpperCase();
10
+ return 'xx:xx:xx:xx:xx:xx'.replace(/[x]/g, () => s[i++]).toUpperCase();
16
11
  }
12
+ exports.generateMacAddress = generateMacAddress;
@@ -1,32 +1,32 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "WaterSensor", {
6
- enumerable: true,
7
- get: ()=>WaterSensor
8
- });
9
- const _baseDeviceAccessory = require("./base-device-accessory");
10
- const _hap = require("./hap");
11
- const _operators = require("rxjs/operators");
12
- const _util = require("ring-client-api/util");
13
- class WaterSensor extends _baseDeviceAccessory.BaseDeviceAccessory {
14
- constructor(device, accessory, config){
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WaterSensor = void 0;
4
+ const base_device_accessory_1 = require("./base-device-accessory");
5
+ const hap_1 = require("./hap");
6
+ const operators_1 = require("rxjs/operators");
7
+ const util_1 = require("ring-client-api/util");
8
+ class WaterSensor extends base_device_accessory_1.BaseDeviceAccessory {
9
+ constructor(device, accessory, config) {
15
10
  super();
16
11
  this.device = device;
17
12
  this.accessory = accessory;
18
13
  this.config = config;
19
- const { Characteristic: { LeakDetected } } = _hap.hap, leakService = this.getService(_hap.hap.Service.LeakSensor), onWaterDetected = device.onData.pipe((0, _operators.map)((data)=>{
20
- return data.faulted ? LeakDetected.LEAK_DETECTED : LeakDetected.LEAK_NOT_DETECTED;
21
- }), (0, _operators.distinctUntilChanged)());
14
+ const { Characteristic: { LeakDetected }, } = hap_1.hap, leakService = this.getService(hap_1.hap.Service.LeakSensor), onWaterDetected = device.onData.pipe((0, operators_1.map)((data) => {
15
+ return data.faulted
16
+ ? LeakDetected.LEAK_DETECTED
17
+ : LeakDetected.LEAK_NOT_DETECTED;
18
+ }), (0, operators_1.distinctUntilChanged)());
22
19
  this.initSensorService(leakService);
23
20
  this.registerObservableCharacteristic({
24
21
  characteristicType: LeakDetected,
25
22
  serviceType: leakService,
26
- onValue: onWaterDetected
23
+ onValue: onWaterDetected,
27
24
  });
28
- onWaterDetected.pipe((0, _operators.filter)((faulted)=>Boolean(faulted))).subscribe(()=>{
29
- (0, _util.logInfo)(device.name + ' Detected Water');
25
+ onWaterDetected
26
+ .pipe((0, operators_1.filter)((faulted) => Boolean(faulted)))
27
+ .subscribe(() => {
28
+ (0, util_1.logInfo)(device.name + ' Detected Water');
30
29
  });
31
30
  }
32
31
  }
32
+ exports.WaterSensor = WaterSensor;
package/package.json CHANGED
@@ -1,23 +1,26 @@
1
1
  {
2
2
  "name": "homebridge-ring",
3
- "version": "11.5.0",
3
+ "version": "11.5.2",
4
4
  "description": "Homebridge plugin for Ring doorbells, cameras, security alarm system and smart lighting",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
- "build": "rm -rf lib && swc $PWD -d lib && swc homebridge-ui -d lib/homebridge-ui && mv ../homebridge-ui/build ./lib/homebridge-ui/public",
8
- "lint": "eslint . --ext .ts && tsc --noEmit"
7
+ "build": "rm -rf lib && tsc && cp -r ../homebridge-ui/build ./lib/homebridge-ui/public",
8
+ "lint": "eslint . --ext .ts && tsc --noEmit",
9
+ "dev": "concurrently -c yellow,blue --kill-others \"npm:dev:build\" \"npm:dev:run\" ",
10
+ "dev:build": "tsc --watch --preserveWatchOutput",
11
+ "dev:run": "nodemon --watch . --watch ../ring-client-api/lib --exec 'RING_DEBUG=true homebridge -P ./ -U ../../.homebridge'"
9
12
  },
10
13
  "dependencies": {
11
14
  "@homebridge/camera-utils": "^2.2.0",
12
15
  "@homebridge/plugin-ui-utils": "^0.0.19",
13
- "ring-client-api": "11.5.0"
16
+ "ring-client-api": "11.5.2"
14
17
  },
15
18
  "devDependencies": {
16
- "@swc/cli": "^0.1.57",
17
- "@swc/core": "^1.3.16",
19
+ "concurrently": "^7.5.0",
18
20
  "eslint-config-shared": "0.0.0",
19
21
  "homebridge": "1.5.1",
20
22
  "homebridge-ui": "0.0.0",
23
+ "nodemon": "^2.0.20",
21
24
  "tsconfig": "0.0.0",
22
25
  "typescript": "4.8.4"
23
26
  },
package/lib/server.js DELETED
@@ -1,58 +0,0 @@
1
- /* eslint-disable no-console */ "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- const _pluginUiUtils = require("@homebridge/plugin-ui-utils");
6
- const _restClient = require("ring-client-api/rest-client");
7
- class PluginUiServer extends _pluginUiUtils.HomebridgePluginUiServer {
8
- constructor(){
9
- super();
10
- this.generateCode = async ({ email , password })=>{
11
- console.log(`Logging in with email '${email}'`);
12
- this.restClient = new _restClient.RingRestClient({
13
- email,
14
- password
15
- });
16
- try {
17
- const { refresh_token } = await this.restClient.getCurrentAuth();
18
- // If we get here, 2fa was not required. I'm not sure this is possible anymore, but it's here just in case
19
- return {
20
- refreshToken: refresh_token
21
- };
22
- } catch (e) {
23
- if (this.restClient.promptFor2fa) {
24
- console.log(this.restClient.promptFor2fa);
25
- return {
26
- codePrompt: this.restClient.promptFor2fa
27
- };
28
- }
29
- console.error(e);
30
- throw new _pluginUiUtils.RequestError(e.message, e);
31
- }
32
- };
33
- this.generateToken = async ({ email , password , code })=>{
34
- // use the existing restClient to avoid sending a token again
35
- this.restClient = this.restClient || new _restClient.RingRestClient({
36
- email,
37
- password
38
- });
39
- console.log(`Getting token for ${email} with code ${code}`);
40
- try {
41
- const authResponse = await this.restClient.getAuth(code);
42
- return {
43
- refreshToken: authResponse.refresh_token
44
- };
45
- } catch (e) {
46
- console.error('Incorrect 2fa Code');
47
- throw new _pluginUiUtils.RequestError('Please check the code and try again', e);
48
- }
49
- };
50
- this.onRequest('/send-code', this.generateCode);
51
- this.onRequest('/token', this.generateToken);
52
- this.ready();
53
- }
54
- }
55
- function startPluginUiServer() {
56
- return new PluginUiServer();
57
- }
58
- startPluginUiServer();