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.
@@ -1,17 +1,69 @@
1
+ "use strict";
1
2
  // OpusRepacketizer is borrowed from scrypted
2
3
  // Original source: https://github.com/koush/scrypted/blob/c13ba09889c3e0d9d3724cb7d49253c9d787fb97/plugins/homekit/src/types/camera/opus-repacketizer.ts
3
- "use strict";
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- Object.defineProperty(exports, "OpusRepacketizer", {
8
- enumerable: true,
9
- get: ()=>OpusRepacketizer
10
- });
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.OpusRepacketizer = void 0;
6
+ // https://datatracker.ietf.org/doc/html/rfc6716
7
+ // INPUT
8
+ // 0 1 2 3
9
+ // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
10
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
11
+ // | config |s|0|0| |
12
+ // +-+-+-+-+-+-+-+-+ |
13
+ // | Compressed frame 1 (N-1 bytes)... :
14
+ // : |
15
+ // | |
16
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
17
+ // OUTPUT
18
+ // 0 1 2 3
19
+ // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
20
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
21
+ // | config |s|1|1|1|p| M | Padding length (Optional) :
22
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
23
+ // : N1 (1-2 bytes): N2 (1-2 bytes): ... : N[M-1] |
24
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
25
+ // | |
26
+ // : Compressed frame 1 (N1 bytes)... :
27
+ // | |
28
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29
+ // | |
30
+ // : Compressed frame 2 (N2 bytes)... :
31
+ // | |
32
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33
+ // | |
34
+ // : ... :
35
+ // | |
36
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37
+ // | |
38
+ // : Compressed frame M... :
39
+ // | |
40
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41
+ // : Opus Padding (Optional)... |
42
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43
+ // Figure 6: A CBR Code 3 Packet
44
+ // In the VBR case, the (optional) padding length is followed by M-1
45
+ // frame lengths (indicated by "N1" to "N[M-1]" in Figure 7), each
46
+ // encoded in a one- or two-byte sequence as described above. The
47
+ // packet MUST contain enough data for the M-1 lengths after removing
48
+ // the (optional) padding, and the sum of these lengths MUST be no
49
+ // larger than the number of bytes remaining in the packet after
50
+ // decoding them [R7]. The compressed data for all M frames follows,
51
+ // each frame consisting of the indicated number of bytes, with the
52
+ // final frame consuming any remaining bytes before the final padding,
53
+ // as illustrated in Figure 6. The number of header bytes (TOC byte,
54
+ // frame count byte, padding length bytes, and frame length bytes), plus
55
+ // the signaled length of the first M-1 frames themselves, plus the
56
+ // signaled length of the padding MUST be no larger than N, the total
57
+ // size of the packet.
11
58
  class OpusRepacketizer {
59
+ constructor(framesPerPacket) {
60
+ this.framesPerPacket = framesPerPacket;
61
+ this.packets = [];
62
+ }
12
63
  // repacketize a packet with a single frame into a packet with multiple frames.
13
64
  repacketize(packet) {
14
- if (this.framesPerPacket === 1) return packet;
65
+ if (this.framesPerPacket === 1)
66
+ return packet;
15
67
  if (packet.payload[0] & 0b00000011) {
16
68
  throw new Error('expected opus packet with a single frame.');
17
69
  }
@@ -19,26 +71,17 @@ class OpusRepacketizer {
19
71
  if (this.packets.length !== this.framesPerPacket) {
20
72
  return;
21
73
  }
22
- const first = this.packets[0], depacketized = this.packets.map((p)=>p.payload.subarray(1));
74
+ const first = this.packets[0], depacketized = this.packets.map((p) => p.payload.subarray(1));
23
75
  this.packets = [];
24
76
  let config = first.payload[0];
25
77
  config |= 0b00000011;
26
- const frameCount = 0b10000000 | this.framesPerPacket, newHeader = [
27
- config,
28
- frameCount
29
- ];
78
+ const frameCount = 0b10000000 | this.framesPerPacket, newHeader = [config, frameCount];
30
79
  // depacketize by stripping off the config byte
31
80
  // M-1 length bytes
32
- newHeader.push(...depacketized.slice(0, -1).map((data)=>data.length));
33
- const headerBuffer = Buffer.from(newHeader), payload = Buffer.concat([
34
- headerBuffer,
35
- ...depacketized
36
- ]);
81
+ newHeader.push(...depacketized.slice(0, -1).map((data) => data.length));
82
+ const headerBuffer = Buffer.from(newHeader), payload = Buffer.concat([headerBuffer, ...depacketized]);
37
83
  packet.payload = payload;
38
84
  return packet;
39
85
  }
40
- constructor(framesPerPacket){
41
- this.framesPerPacket = framesPerPacket;
42
- this.packets = [];
43
- }
44
86
  }
87
+ exports.OpusRepacketizer = OpusRepacketizer;
package/lib/outlet.js CHANGED
@@ -1,41 +1,31 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "Outlet", {
6
- enumerable: true,
7
- get: ()=>Outlet
8
- });
9
- const _baseDeviceAccessory = require("./base-device-accessory");
10
- const _hap = require("./hap");
11
- const _util = require("ring-client-api/util");
12
- class Outlet 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
- on
19
- }
20
- }
21
- });
22
- }
23
- constructor(device, accessory, config){
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Outlet = 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 Outlet 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.Outlet,
32
- getValue: (data)=>Boolean(data.on),
33
- setValue: (value)=>this.setOnState(value)
17
+ getValue: (data) => Boolean(data.on),
18
+ setValue: (value) => this.setOnState(value),
34
19
  });
35
20
  this.registerCharacteristic({
36
21
  characteristicType: Characteristic.OutletInUse,
37
22
  serviceType: Service.Outlet,
38
- getValue: (data)=>Boolean(data.on)
23
+ getValue: (data) => Boolean(data.on),
39
24
  });
40
25
  }
26
+ setOnState(on) {
27
+ (0, util_1.logInfo)(`Turning ${this.device.name} ${on ? 'On' : 'Off'}`);
28
+ return this.device.setInfo({ device: { v1: { on } } });
29
+ }
41
30
  }
31
+ exports.Outlet = Outlet;
@@ -1,81 +1,77 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "PanicButtons", {
6
- enumerable: true,
7
- get: ()=>PanicButtons
8
- });
9
- const _hap = require("./hap");
10
- const _baseDataAccessory = require("./base-data-accessory");
11
- const _util = require("ring-client-api/util");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PanicButtons = void 0;
4
+ const hap_1 = require("./hap");
5
+ const base_data_accessory_1 = require("./base-data-accessory");
6
+ const util_1 = require("ring-client-api/util");
12
7
  const burglarStates = [
13
8
  'burglar-alarm',
14
9
  'user-verified-burglar-alarm',
15
- 'burglar-accelerated-alarm'
10
+ 'burglar-accelerated-alarm',
16
11
  ], fireStates = [
17
12
  'fire-alarm',
18
13
  'user-verified-co-or-fire-alarm',
19
- 'fire-accelerated-alarm'
14
+ 'fire-accelerated-alarm',
20
15
  ];
21
- function matchesAnyAlarmState({ alarmInfo }, targetStates) {
16
+ function matchesAnyAlarmState({ alarmInfo }, targetStates) {
22
17
  return Boolean(alarmInfo && targetStates.includes(alarmInfo.state));
23
18
  }
24
- class PanicButtons extends _baseDataAccessory.BaseDataAccessory {
25
- initBase() {
26
- const { Characteristic , Service } = _hap.hap;
27
- this.registerCharacteristic({
28
- characteristicType: Characteristic.Manufacturer,
29
- serviceType: Service.AccessoryInformation,
30
- getValue: (data)=>data.manufacturerName || 'Ring'
31
- });
32
- this.registerCharacteristic({
33
- characteristicType: Characteristic.Model,
34
- serviceType: Service.AccessoryInformation,
35
- getValue: ()=>'Panic Buttons for ' + this.device.location.name
36
- });
37
- this.registerCharacteristic({
38
- characteristicType: Characteristic.SerialNumber,
39
- serviceType: Service.AccessoryInformation,
40
- getValue: ()=>'None'
41
- });
42
- super.initBase();
43
- }
44
- constructor(device, accessory, config){
19
+ class PanicButtons extends base_data_accessory_1.BaseDataAccessory {
20
+ constructor(device, accessory, config) {
45
21
  super();
46
22
  this.device = device;
47
23
  this.accessory = accessory;
48
24
  this.config = config;
49
- const { Characteristic , Service } = _hap.hap, locationName = device.location.name;
25
+ const { Characteristic, Service } = hap_1.hap, locationName = device.location.name;
50
26
  this.registerCharacteristic({
51
27
  characteristicType: Characteristic.On,
52
28
  serviceType: Service.Switch,
53
29
  serviceSubType: 'Burglar',
54
30
  name: 'Burglar Alarm',
55
- getValue: (data)=>matchesAnyAlarmState(data, burglarStates),
56
- setValue: (on)=>{
31
+ getValue: (data) => matchesAnyAlarmState(data, burglarStates),
32
+ setValue: (on) => {
57
33
  if (on) {
58
- (0, _util.logInfo)(`Burglar Alarm activated for ${locationName}`);
34
+ (0, util_1.logInfo)(`Burglar Alarm activated for ${locationName}`);
59
35
  return this.device.location.triggerBurglarAlarm();
60
36
  }
61
- (0, _util.logInfo)(`Burglar Alarm turned off for ${locationName}`);
37
+ (0, util_1.logInfo)(`Burglar Alarm turned off for ${locationName}`);
62
38
  return this.device.location.setAlarmMode('none');
63
- }
39
+ },
64
40
  });
65
41
  this.registerCharacteristic({
66
42
  characteristicType: Characteristic.On,
67
43
  serviceType: Service.Switch,
68
44
  serviceSubType: 'Fire',
69
45
  name: 'Fire Alarm',
70
- getValue: (data)=>matchesAnyAlarmState(data, fireStates),
71
- setValue: (on)=>{
46
+ getValue: (data) => matchesAnyAlarmState(data, fireStates),
47
+ setValue: (on) => {
72
48
  if (on) {
73
- (0, _util.logInfo)(`Fire Alarm activated for ${locationName}`);
49
+ (0, util_1.logInfo)(`Fire Alarm activated for ${locationName}`);
74
50
  return this.device.location.triggerFireAlarm();
75
51
  }
76
- (0, _util.logInfo)(`Fire Alarm turned off for ${locationName}`);
52
+ (0, util_1.logInfo)(`Fire Alarm turned off for ${locationName}`);
77
53
  return this.device.location.setAlarmMode('none');
78
- }
54
+ },
79
55
  });
80
56
  }
57
+ initBase() {
58
+ const { Characteristic, Service } = hap_1.hap;
59
+ this.registerCharacteristic({
60
+ characteristicType: Characteristic.Manufacturer,
61
+ serviceType: Service.AccessoryInformation,
62
+ getValue: (data) => data.manufacturerName || 'Ring',
63
+ });
64
+ this.registerCharacteristic({
65
+ characteristicType: Characteristic.Model,
66
+ serviceType: Service.AccessoryInformation,
67
+ getValue: () => 'Panic Buttons for ' + this.device.location.name,
68
+ });
69
+ this.registerCharacteristic({
70
+ characteristicType: Characteristic.SerialNumber,
71
+ serviceType: Service.AccessoryInformation,
72
+ getValue: () => 'None',
73
+ });
74
+ super.initBase();
75
+ }
81
76
  }
77
+ exports.PanicButtons = PanicButtons;