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,21 +1,18 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "BaseAccessory", {
6
- enumerable: true,
7
- get: ()=>BaseAccessory
8
- });
9
- const _hap = require("./hap");
10
- const _operators = require("rxjs/operators");
11
- const _rxjs = require("rxjs");
12
- const _config = require("./config");
13
- const _homebridge = require("homebridge");
14
- const _util = require("ring-client-api/util");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseAccessory = void 0;
4
+ const hap_1 = require("./hap");
5
+ const operators_1 = require("rxjs/operators");
6
+ const rxjs_1 = require("rxjs");
7
+ const config_1 = require("./config");
8
+ const util_1 = require("ring-client-api/util");
15
9
  function isServiceInstance(serviceType) {
16
10
  return typeof serviceType === 'object';
17
11
  }
18
12
  class BaseAccessory {
13
+ constructor() {
14
+ this.servicesInUse = [];
15
+ }
19
16
  initBase() {
20
17
  this.pruneUnusedServices();
21
18
  }
@@ -23,11 +20,16 @@ class BaseAccessory {
23
20
  if (isServiceInstance(serviceType)) {
24
21
  return serviceType;
25
22
  }
26
- if (_config.debug) {
23
+ if (config_1.debug) {
27
24
  name = 'TEST ' + name;
28
25
  }
29
- const existingService = subType ? this.accessory.getServiceById(serviceType, subType) : this.accessory.getService(serviceType), service = existingService || this.accessory.addService(serviceType, name, subType);
30
- if (_config.debug && existingService && existingService.displayName && name !== existingService.displayName) {
26
+ const existingService = subType
27
+ ? this.accessory.getServiceById(serviceType, subType)
28
+ : this.accessory.getService(serviceType), service = existingService || this.accessory.addService(serviceType, name, subType);
29
+ if (config_1.debug &&
30
+ existingService &&
31
+ existingService.displayName &&
32
+ name !== existingService.displayName) {
31
33
  throw new Error(`Overlapping services for device ${this.device.name} - ${name} != ${existingService.displayName} - ${serviceType}`);
32
34
  }
33
35
  if (!this.servicesInUse.includes(service)) {
@@ -35,30 +37,31 @@ class BaseAccessory {
35
37
  }
36
38
  return service;
37
39
  }
38
- registerObservableCharacteristic({ characteristicType , serviceType , serviceSubType , onValue , setValue , name , requestUpdate }) {
39
- const service = this.getService(serviceType, name, serviceSubType), characteristic = service.getCharacteristic(characteristicType), onCachedValue = onValue.pipe((0, _operators.shareReplay)(1));
40
- onCachedValue.subscribe((value)=>{
40
+ registerObservableCharacteristic({ characteristicType, serviceType, serviceSubType, onValue, setValue, name, requestUpdate, }) {
41
+ const service = this.getService(serviceType, name, serviceSubType), characteristic = service.getCharacteristic(characteristicType), onCachedValue = onValue.pipe((0, operators_1.shareReplay)(1));
42
+ onCachedValue.subscribe((value) => {
41
43
  characteristic.updateValue(value);
42
44
  });
43
45
  if (requestUpdate) {
44
46
  // Only register for GET if an async request should be made to get an updated value
45
- onCachedValue.pipe((0, _operators.take)(1)).subscribe(()=>{
47
+ onCachedValue.pipe((0, operators_1.take)(1)).subscribe(() => {
46
48
  // allow GET once a value is cached
47
- characteristic.on(_homebridge.CharacteristicEventTypes.GET, async (callback)=>{
49
+ characteristic.on("get" /* CharacteristicEventTypes.GET */, async (callback) => {
48
50
  try {
49
- const value = await (0, _rxjs.firstValueFrom)(onCachedValue);
51
+ const value = await (0, rxjs_1.firstValueFrom)(onCachedValue);
50
52
  callback(null, value);
51
53
  requestUpdate();
52
- } catch (e) {
54
+ }
55
+ catch (e) {
53
56
  callback(e);
54
57
  }
55
58
  });
56
59
  });
57
60
  }
58
61
  if (setValue) {
59
- characteristic.on(_homebridge.CharacteristicEventTypes.SET, (newValue, callback)=>{
60
- Promise.resolve(setValue(newValue)).catch((e)=>{
61
- (0, _util.logError)(e);
62
+ characteristic.on("set" /* CharacteristicEventTypes.SET */, (newValue, callback) => {
63
+ Promise.resolve(setValue(newValue)).catch((e) => {
64
+ (0, util_1.logError)(e);
62
65
  });
63
66
  callback();
64
67
  });
@@ -66,17 +69,16 @@ class BaseAccessory {
66
69
  }
67
70
  pruneUnusedServices() {
68
71
  const safeServiceUUIDs = [
69
- _hap.hap.Service.CameraRTPStreamManagement.UUID,
70
- _hap.hap.Service.CameraControl.UUID
72
+ hap_1.hap.Service.CameraRTPStreamManagement.UUID,
73
+ hap_1.hap.Service.CameraControl.UUID,
71
74
  ];
72
- this.accessory.services.forEach((service)=>{
73
- if (!this.servicesInUse.includes(service) && !safeServiceUUIDs.includes(service.UUID)) {
74
- (0, _util.logInfo)('Pruning unused service', service.UUID, service.displayName || service.name, 'from', this.device.name);
75
+ this.accessory.services.forEach((service) => {
76
+ if (!this.servicesInUse.includes(service) &&
77
+ !safeServiceUUIDs.includes(service.UUID)) {
78
+ (0, util_1.logInfo)('Pruning unused service', service.UUID, service.displayName || service.name, 'from', this.device.name);
75
79
  this.accessory.removeService(service);
76
80
  }
77
81
  });
78
82
  }
79
- constructor(){
80
- this.servicesInUse = [];
81
- }
82
83
  }
84
+ exports.BaseAccessory = BaseAccessory;
@@ -1,64 +1,64 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "BaseDataAccessory", {
6
- enumerable: true,
7
- get: ()=>BaseDataAccessory
8
- });
9
- const _baseAccessory = require("./base-accessory");
10
- const _rxjs = require("rxjs");
11
- const _operators = require("rxjs/operators");
12
- const _homebridge = require("homebridge");
13
- const _util = require("ring-client-api/util");
14
- class BaseDataAccessory extends _baseAccessory.BaseAccessory {
15
- registerCharacteristic({ characteristicType , serviceType , getValue , setValue , setValueDebounceTime =0 , name , requestUpdate , serviceSubType }) {
16
- const service = this.getService(serviceType, name, serviceSubType), characteristic = service.getCharacteristic(characteristicType), { device } = this;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseDataAccessory = void 0;
4
+ const base_accessory_1 = require("./base-accessory");
5
+ const rxjs_1 = require("rxjs");
6
+ const operators_1 = require("rxjs/operators");
7
+ const util_1 = require("ring-client-api/util");
8
+ class BaseDataAccessory extends base_accessory_1.BaseAccessory {
9
+ registerCharacteristic({ characteristicType, serviceType, getValue, setValue, setValueDebounceTime = 0, name, requestUpdate, serviceSubType, }) {
10
+ const service = this.getService(serviceType, name, serviceSubType), characteristic = service.getCharacteristic(characteristicType), { device } = this;
17
11
  if (requestUpdate) {
18
12
  // Only register for GET if an async request should be made to get an updated value
19
- characteristic.on(_homebridge.CharacteristicEventTypes.GET, (callback)=>{
13
+ characteristic.on("get" /* CharacteristicEventTypes.GET */, (callback) => {
20
14
  try {
21
15
  const value = getValue(device.data);
22
16
  callback(null, value);
23
17
  requestUpdate();
24
- } catch (e) {
18
+ }
19
+ catch (e) {
25
20
  callback(e);
26
21
  }
27
22
  });
28
23
  }
29
24
  if (setValue && setValueDebounceTime) {
30
- const onValueToSet = new _rxjs.Subject();
31
- characteristic.on(_homebridge.CharacteristicEventTypes.SET, (newValue, callback)=>{
25
+ const onValueToSet = new rxjs_1.Subject();
26
+ characteristic.on("set" /* CharacteristicEventTypes.SET */, (newValue, callback) => {
32
27
  onValueToSet.next(newValue);
33
28
  callback();
34
29
  });
35
- onValueToSet.pipe((0, _operators.debounceTime)(setValueDebounceTime)).subscribe(setValue);
36
- } else if (setValue) {
37
- characteristic.on(_homebridge.CharacteristicEventTypes.SET, (newValue, callback)=>{
38
- Promise.resolve(setValue(newValue)).catch(_util.logError);
30
+ onValueToSet.pipe((0, operators_1.debounceTime)(setValueDebounceTime)).subscribe(setValue);
31
+ }
32
+ else if (setValue) {
33
+ characteristic.on("set" /* CharacteristicEventTypes.SET */, (newValue, callback) => {
34
+ Promise.resolve(setValue(newValue)).catch(util_1.logError);
39
35
  callback();
40
36
  });
41
37
  }
42
- this.device.onData.pipe((0, _operators.map)(getValue), (0, _operators.distinctUntilChanged)()).subscribe((value)=>characteristic.updateValue(value));
38
+ ;
39
+ this.device.onData
40
+ .pipe((0, operators_1.map)(getValue), (0, operators_1.distinctUntilChanged)())
41
+ .subscribe((value) => characteristic.updateValue(value));
43
42
  }
44
- registerLevelCharacteristic({ characteristicType , serviceType , getValue , setValue , requestUpdate }) {
43
+ registerLevelCharacteristic({ characteristicType, serviceType, getValue, setValue, requestUpdate, }) {
45
44
  let targetLevel;
46
45
  this.registerCharacteristic({
47
46
  characteristicType,
48
47
  serviceType,
49
- getValue: (data)=>{
48
+ getValue: (data) => {
50
49
  const newLevel = getValue(data);
51
50
  if (newLevel === targetLevel) {
52
51
  targetLevel = undefined;
53
52
  }
54
53
  return targetLevel === undefined ? newLevel : targetLevel;
55
54
  },
56
- setValue: (level)=>{
55
+ setValue: (level) => {
57
56
  targetLevel = level;
58
57
  setValue(level);
59
58
  },
60
59
  setValueDebounceTime: 500,
61
- requestUpdate
60
+ requestUpdate,
62
61
  });
63
62
  }
64
63
  }
64
+ exports.BaseDataAccessory = BaseDataAccessory;
@@ -1,30 +1,33 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "BaseDeviceAccessory", {
6
- enumerable: true,
7
- get: ()=>BaseDeviceAccessory
8
- });
9
- const _hap = require("./hap");
10
- const _baseDataAccessory = require("./base-data-accessory");
11
- function getBatteryLevel({ batteryLevel , batteryStatus }) {
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseDeviceAccessory = void 0;
4
+ const hap_1 = require("./hap");
5
+ const base_data_accessory_1 = require("./base-data-accessory");
6
+ function getBatteryLevel({ batteryLevel, batteryStatus }) {
12
7
  if (batteryLevel !== undefined) {
13
8
  return batteryLevel;
14
- } else if (batteryStatus === 'full' || batteryStatus === 'charged') {
9
+ }
10
+ else if (batteryStatus === 'full' || batteryStatus === 'charged') {
15
11
  return 100;
16
- } else if (batteryStatus === 'ok' || batteryStatus === 'charging') {
12
+ }
13
+ else if (batteryStatus === 'ok' || batteryStatus === 'charging') {
17
14
  return 50;
18
15
  }
19
16
  return 0;
20
17
  }
21
18
  function getStatusLowBattery(data) {
22
- const { StatusLowBattery } = _hap.hap.Characteristic, batteryLevel = getBatteryLevel(data);
23
- return batteryLevel > 20 ? StatusLowBattery.BATTERY_LEVEL_NORMAL : StatusLowBattery.BATTERY_LEVEL_LOW;
19
+ const { StatusLowBattery } = hap_1.hap.Characteristic, batteryLevel = getBatteryLevel(data);
20
+ return batteryLevel > 20
21
+ ? StatusLowBattery.BATTERY_LEVEL_NORMAL
22
+ : StatusLowBattery.BATTERY_LEVEL_LOW;
24
23
  }
25
- function getBatteryChargingState({ batteryStatus , batteryBackup , acStatus }) {
26
- const { ChargingState } = _hap.hap.Characteristic;
27
- if (batteryStatus === 'charging' || batteryStatus === 'charged' || batteryBackup === 'charged' || batteryBackup === 'charging' || acStatus === 'ok') {
24
+ function getBatteryChargingState({ batteryStatus, batteryBackup, acStatus, }) {
25
+ const { ChargingState } = hap_1.hap.Characteristic;
26
+ if (batteryStatus === 'charging' ||
27
+ batteryStatus === 'charged' ||
28
+ batteryBackup === 'charged' ||
29
+ batteryBackup === 'charging' ||
30
+ acStatus === 'ok') {
28
31
  return ChargingState.CHARGING;
29
32
  }
30
33
  if (batteryBackup === 'inUse' || acStatus === 'error') {
@@ -32,76 +35,79 @@ function getBatteryChargingState({ batteryStatus , batteryBackup , acStatus })
32
35
  }
33
36
  return ChargingState.NOT_CHARGEABLE;
34
37
  }
35
- function hasBatteryStatus({ batteryStatus }) {
38
+ function hasBatteryStatus({ batteryStatus }) {
36
39
  return batteryStatus !== 'none';
37
40
  }
38
- class BaseDeviceAccessory extends _baseDataAccessory.BaseDataAccessory {
41
+ class BaseDeviceAccessory extends base_data_accessory_1.BaseDataAccessory {
39
42
  initBase() {
40
- const { device: { data: initialData } , device } = this, { Characteristic , Service } = _hap.hap;
43
+ const { device: { data: initialData }, device, } = this, { Characteristic, Service } = hap_1.hap;
41
44
  this.registerCharacteristic({
42
45
  characteristicType: Characteristic.Manufacturer,
43
46
  serviceType: Service.AccessoryInformation,
44
- getValue: (data)=>data.manufacturerName || 'Ring'
47
+ getValue: (data) => data.manufacturerName || 'Ring',
45
48
  });
46
49
  this.registerCharacteristic({
47
50
  characteristicType: Characteristic.Model,
48
51
  serviceType: Service.AccessoryInformation,
49
- getValue: (data)=>data.deviceType
52
+ getValue: (data) => data.deviceType,
50
53
  });
51
54
  this.registerCharacteristic({
52
55
  characteristicType: Characteristic.SerialNumber,
53
56
  serviceType: Service.AccessoryInformation,
54
- getValue: (data)=>data.serialNumber || 'Unknown'
57
+ getValue: (data) => data.serialNumber || 'Unknown',
55
58
  });
56
59
  if ('volume' in initialData && 'setVolume' in device) {
57
60
  this.registerCharacteristic({
58
61
  characteristicType: Characteristic.Mute,
59
62
  serviceType: Service.Speaker,
60
- getValue: ()=>false
63
+ getValue: () => false,
61
64
  });
62
65
  this.registerLevelCharacteristic({
63
66
  characteristicType: Characteristic.Volume,
64
67
  serviceType: Service.Speaker,
65
- getValue: (data)=>{
68
+ getValue: (data) => {
66
69
  return data.volume ? data.volume * 100 : 0;
67
70
  },
68
- setValue: (volume)=>device.setVolume(volume / 100)
71
+ setValue: (volume) => device.setVolume(volume / 100),
69
72
  });
70
73
  }
71
74
  if (hasBatteryStatus(initialData)) {
72
75
  this.registerCharacteristic({
73
76
  characteristicType: Characteristic.BatteryLevel,
74
77
  serviceType: Service.BatteryService,
75
- getValue: getBatteryLevel
78
+ getValue: getBatteryLevel,
76
79
  });
77
80
  this.registerCharacteristic({
78
81
  characteristicType: Characteristic.StatusLowBattery,
79
82
  serviceType: Service.BatteryService,
80
- getValue: getStatusLowBattery
83
+ getValue: getStatusLowBattery,
81
84
  });
82
85
  this.registerCharacteristic({
83
86
  characteristicType: Characteristic.ChargingState,
84
87
  serviceType: Service.BatteryService,
85
- getValue: getBatteryChargingState
88
+ getValue: getBatteryChargingState,
86
89
  });
87
90
  }
88
91
  super.initBase();
89
92
  }
90
93
  initSensorService(serviceType) {
91
- const { Characteristic } = _hap.hap;
94
+ const { Characteristic } = hap_1.hap;
92
95
  this.registerCharacteristic({
93
96
  characteristicType: Characteristic.StatusTampered,
94
97
  serviceType,
95
- getValue: (data)=>{
96
- return data.tamperStatus === 'ok' ? Characteristic.StatusTampered.NOT_TAMPERED : Characteristic.StatusTampered.TAMPERED;
97
- }
98
+ getValue: (data) => {
99
+ return data.tamperStatus === 'ok'
100
+ ? Characteristic.StatusTampered.NOT_TAMPERED
101
+ : Characteristic.StatusTampered.TAMPERED;
102
+ },
98
103
  });
99
104
  if (hasBatteryStatus(this.device.data)) {
100
105
  this.registerCharacteristic({
101
106
  characteristicType: Characteristic.StatusLowBattery,
102
107
  serviceType,
103
- getValue: (data)=>getStatusLowBattery(data)
108
+ getValue: (data) => getStatusLowBattery(data),
104
109
  });
105
110
  }
106
111
  }
107
112
  }
113
+ exports.BaseDeviceAccessory = BaseDeviceAccessory;
package/lib/beam.js CHANGED
@@ -1,74 +1,64 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "Beam", {
6
- enumerable: true,
7
- get: ()=>Beam
8
- });
9
- const _ringClientApi = require("ring-client-api");
10
- const _hap = require("./hap");
11
- const _baseDeviceAccessory = require("./base-device-accessory");
12
- const _util = require("ring-client-api/util");
13
- class Beam extends _baseDeviceAccessory.BaseDeviceAccessory {
14
- setOnState(on) {
15
- (0, _util.logInfo)(`Turning ${this.device.name} ${on ? 'On' : 'Off'}`);
16
- const { beamDurationSeconds } = this.config, duration = beamDurationSeconds ? Math.min(beamDurationSeconds, 32767) : undefined;
17
- if (this.isLightGroup && this.groupId) {
18
- return this.device.location.setLightGroup(this.groupId, on, duration);
19
- }
20
- const data = on ? {
21
- lightMode: 'on',
22
- duration
23
- } : {
24
- lightMode: 'default'
25
- };
26
- return this.device.sendCommand('light-mode.set', data);
27
- }
28
- setLevelState(level) {
29
- (0, _util.logInfo)(`Setting brightness of ${this.device.name} to ${level}%`);
30
- return this.device.setInfo({
31
- device: {
32
- v1: {
33
- level: level / 100
34
- }
35
- }
36
- });
37
- }
38
- constructor(device, accessory, config){
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Beam = void 0;
4
+ const ring_client_api_1 = require("ring-client-api");
5
+ const hap_1 = require("./hap");
6
+ const base_device_accessory_1 = require("./base-device-accessory");
7
+ const util_1 = require("ring-client-api/util");
8
+ class Beam extends base_device_accessory_1.BaseDeviceAccessory {
9
+ constructor(device, accessory, config) {
39
10
  super();
40
11
  this.device = device;
41
12
  this.accessory = accessory;
42
13
  this.config = config;
43
- this.isLightGroup = this.device.data.deviceType === _ringClientApi.RingDeviceType.BeamsLightGroupSwitch;
14
+ this.isLightGroup = this.device.data.deviceType === ring_client_api_1.RingDeviceType.BeamsLightGroupSwitch;
44
15
  this.groupId = this.device.data.groupId;
45
- const { Characteristic , Service } = _hap.hap, { MotionSensor } = Service, { data: { deviceType } } = this.device;
46
- if (deviceType !== _ringClientApi.RingDeviceType.BeamsMotionSensor) {
16
+ const { Characteristic, Service } = hap_1.hap, { MotionSensor } = Service, { data: { deviceType }, } = this.device;
17
+ if (deviceType !== ring_client_api_1.RingDeviceType.BeamsMotionSensor) {
47
18
  this.registerCharacteristic({
48
19
  characteristicType: Characteristic.On,
49
20
  serviceType: Service.Lightbulb,
50
- getValue: (data)=>Boolean(data.on),
51
- setValue: (value)=>this.setOnState(value)
21
+ getValue: (data) => Boolean(data.on),
22
+ setValue: (value) => this.setOnState(value),
52
23
  });
53
24
  this.getService(Service.Lightbulb).setPrimaryService(true);
54
25
  }
55
- if (deviceType === _ringClientApi.RingDeviceType.BeamsMultiLevelSwitch) {
26
+ if (deviceType === ring_client_api_1.RingDeviceType.BeamsMultiLevelSwitch) {
56
27
  this.registerLevelCharacteristic({
57
28
  characteristicType: Characteristic.Brightness,
58
29
  serviceType: Service.Lightbulb,
59
- getValue: (data)=>{
30
+ getValue: (data) => {
60
31
  return data.level && !isNaN(data.level) ? 100 * data.level : 0;
61
32
  },
62
- setValue: (value)=>this.setLevelState(value)
33
+ setValue: (value) => this.setLevelState(value),
63
34
  });
64
35
  }
65
- if (device.data.motionStatus !== undefined && device.data.motionSensorEnabled !== false) {
36
+ if (device.data.motionStatus !== undefined &&
37
+ device.data.motionSensorEnabled !== false) {
66
38
  this.registerCharacteristic({
67
- characteristicType: _hap.hap.Characteristic.MotionDetected,
39
+ characteristicType: hap_1.hap.Characteristic.MotionDetected,
68
40
  serviceType: MotionSensor,
69
- getValue: (data)=>data.motionStatus === 'faulted'
41
+ getValue: (data) => data.motionStatus === 'faulted',
70
42
  });
71
43
  this.initSensorService(MotionSensor);
72
44
  }
73
45
  }
46
+ setOnState(on) {
47
+ (0, util_1.logInfo)(`Turning ${this.device.name} ${on ? 'On' : 'Off'}`);
48
+ const { beamDurationSeconds } = this.config, duration = beamDurationSeconds
49
+ ? Math.min(beamDurationSeconds, 32767)
50
+ : undefined;
51
+ if (this.isLightGroup && this.groupId) {
52
+ return this.device.location.setLightGroup(this.groupId, on, duration);
53
+ }
54
+ const data = on ? { lightMode: 'on', duration } : { lightMode: 'default' };
55
+ return this.device.sendCommand('light-mode.set', data);
56
+ }
57
+ setLevelState(level) {
58
+ (0, util_1.logInfo)(`Setting brightness of ${this.device.name} to ${level}%`);
59
+ return this.device.setInfo({
60
+ device: { v1: { level: level / 100 } },
61
+ });
62
+ }
74
63
  }
64
+ exports.Beam = Beam;
@@ -1,36 +1,22 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "BrightnessOnly", {
6
- enumerable: true,
7
- get: ()=>BrightnessOnly
8
- });
9
- const _baseDeviceAccessory = require("./base-device-accessory");
10
- const _hap = require("./hap");
11
- const _util = require("ring-client-api/util");
12
- class BrightnessOnly extends _baseDeviceAccessory.BaseDeviceAccessory {
13
- setLevelState(brightness) {
14
- (0, _util.logInfo)(`Setting brightness of ${this.device.name} to ${brightness}%`);
15
- return this.device.setInfo({
16
- device: {
17
- v1: {
18
- brightness: brightness / 100
19
- }
20
- }
21
- });
22
- }
23
- constructor(device, accessory, config){
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BrightnessOnly = 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 BrightnessOnly 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, { context } = accessory;
29
- if (device.data.brightness !== undefined && !isNaN(device.data.brightness)) {
13
+ const { Characteristic, Service } = hap_1.hap, { context } = accessory;
14
+ if (device.data.brightness !== undefined &&
15
+ !isNaN(device.data.brightness)) {
30
16
  this.registerLevelCharacteristic({
31
17
  characteristicType: Characteristic.Brightness,
32
18
  serviceType: Service.Lightbulb,
33
- getValue: (data)=>{
19
+ getValue: (data) => {
34
20
  if (!data.brightness || isNaN(data.brightness)) {
35
21
  return 0;
36
22
  }
@@ -38,23 +24,30 @@ class BrightnessOnly extends _baseDeviceAccessory.BaseDeviceAccessory {
38
24
  context.brightness = data.brightness * 100;
39
25
  return context.brightness;
40
26
  },
41
- setValue: (brightness)=>{
27
+ setValue: (brightness) => {
42
28
  if (brightness) {
43
29
  context.brightness = brightness;
44
30
  }
45
31
  return this.setLevelState(brightness);
46
- }
32
+ },
47
33
  });
48
34
  this.registerCharacteristic({
49
35
  characteristicType: Characteristic.On,
50
36
  serviceType: Service.Lightbulb,
51
- getValue: (data)=>Boolean(data.brightness),
52
- setValue: (on)=>{
37
+ getValue: (data) => Boolean(data.brightness),
38
+ setValue: (on) => {
53
39
  const brightness = context.brightness || 100;
54
40
  return this.setLevelState(on ? brightness : 0);
55
- }
41
+ },
56
42
  });
57
43
  this.getService(Service.Lightbulb).setPrimaryService(true);
58
44
  }
59
45
  }
46
+ setLevelState(brightness) {
47
+ (0, util_1.logInfo)(`Setting brightness of ${this.device.name} to ${brightness}%`);
48
+ return this.device.setInfo({
49
+ device: { v1: { brightness: brightness / 100 } },
50
+ });
51
+ }
60
52
  }
53
+ exports.BrightnessOnly = BrightnessOnly;