@switchbot/homebridge-switchbot 1.10.2-beta.7 → 1.11.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.
Files changed (99) hide show
  1. package/CHANGELOG.md +20 -3
  2. package/config.schema.json +49 -0
  3. package/dist/device/bot.d.ts +43 -40
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +26 -26
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/colorbulb.d.ts +25 -21
  8. package/dist/device/colorbulb.d.ts.map +1 -1
  9. package/dist/device/colorbulb.js +176 -140
  10. package/dist/device/colorbulb.js.map +1 -1
  11. package/dist/device/contact.d.ts +15 -15
  12. package/dist/device/contact.d.ts.map +1 -1
  13. package/dist/device/contact.js +14 -13
  14. package/dist/device/contact.js.map +1 -1
  15. package/dist/device/curtain.d.ts +25 -22
  16. package/dist/device/curtain.d.ts.map +1 -1
  17. package/dist/device/curtain.js +50 -37
  18. package/dist/device/curtain.js.map +1 -1
  19. package/dist/device/humidifier.d.ts +23 -20
  20. package/dist/device/humidifier.d.ts.map +1 -1
  21. package/dist/device/humidifier.js +38 -38
  22. package/dist/device/humidifier.js.map +1 -1
  23. package/dist/device/lock.d.ts +16 -13
  24. package/dist/device/lock.d.ts.map +1 -1
  25. package/dist/device/lock.js +17 -17
  26. package/dist/device/lock.js.map +1 -1
  27. package/dist/device/meter.d.ts +15 -15
  28. package/dist/device/meter.d.ts.map +1 -1
  29. package/dist/device/meter.js +11 -11
  30. package/dist/device/meter.js.map +1 -1
  31. package/dist/device/motion.d.ts +14 -14
  32. package/dist/device/motion.d.ts.map +1 -1
  33. package/dist/device/motion.js +13 -13
  34. package/dist/device/motion.js.map +1 -1
  35. package/dist/device/plug.d.ts +10 -7
  36. package/dist/device/plug.d.ts.map +1 -1
  37. package/dist/device/plug.js +19 -19
  38. package/dist/device/plug.js.map +1 -1
  39. package/dist/irdevice/airconditioner.d.ts +22 -22
  40. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  41. package/dist/irdevice/airconditioner.js +44 -44
  42. package/dist/irdevice/airconditioner.js.map +1 -1
  43. package/dist/irdevice/airpurifier.d.ts +12 -9
  44. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  45. package/dist/irdevice/airpurifier.js +20 -20
  46. package/dist/irdevice/airpurifier.js.map +1 -1
  47. package/dist/irdevice/camera.d.ts +10 -7
  48. package/dist/irdevice/camera.d.ts.map +1 -1
  49. package/dist/irdevice/camera.js +11 -11
  50. package/dist/irdevice/camera.js.map +1 -1
  51. package/dist/irdevice/fan.d.ts +12 -9
  52. package/dist/irdevice/fan.d.ts.map +1 -1
  53. package/dist/irdevice/fan.js +29 -29
  54. package/dist/irdevice/fan.js.map +1 -1
  55. package/dist/irdevice/light.d.ts +10 -7
  56. package/dist/irdevice/light.d.ts.map +1 -1
  57. package/dist/irdevice/light.js +13 -13
  58. package/dist/irdevice/light.js.map +1 -1
  59. package/dist/irdevice/other.d.ts +12 -9
  60. package/dist/irdevice/other.d.ts.map +1 -1
  61. package/dist/irdevice/other.js +17 -17
  62. package/dist/irdevice/other.js.map +1 -1
  63. package/dist/irdevice/tv.d.ts +13 -10
  64. package/dist/irdevice/tv.d.ts.map +1 -1
  65. package/dist/irdevice/tv.js +25 -25
  66. package/dist/irdevice/tv.js.map +1 -1
  67. package/dist/irdevice/vacuumcleaner.d.ts +10 -7
  68. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  69. package/dist/irdevice/vacuumcleaner.js +13 -13
  70. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  71. package/dist/irdevice/waterheater.d.ts +10 -7
  72. package/dist/irdevice/waterheater.d.ts.map +1 -1
  73. package/dist/irdevice/waterheater.js +16 -16
  74. package/dist/irdevice/waterheater.js.map +1 -1
  75. package/dist/platform.d.ts.map +1 -1
  76. package/dist/settings.d.ts +4 -1
  77. package/dist/settings.d.ts.map +1 -1
  78. package/dist/settings.js.map +1 -1
  79. package/package.json +76 -76
  80. package/src/device/bot.ts +50 -50
  81. package/src/device/colorbulb.ts +206 -157
  82. package/src/device/contact.ts +31 -30
  83. package/src/device/curtain.ts +68 -57
  84. package/src/device/humidifier.ts +65 -53
  85. package/src/device/lock.ts +25 -25
  86. package/src/device/meter.ts +25 -25
  87. package/src/device/motion.ts +27 -27
  88. package/src/device/plug.ts +22 -22
  89. package/src/irdevice/airconditioner.ts +54 -54
  90. package/src/irdevice/airpurifier.ts +30 -30
  91. package/src/irdevice/camera.ts +19 -19
  92. package/src/irdevice/fan.ts +40 -40
  93. package/src/irdevice/light.ts +23 -23
  94. package/src/irdevice/other.ts +25 -25
  95. package/src/irdevice/tv.ts +42 -42
  96. package/src/irdevice/vacuumcleaner.ts +21 -21
  97. package/src/irdevice/waterheater.ts +24 -24
  98. package/src/platform.ts +4 -4
  99. package/src/settings.ts +5 -1
@@ -10,7 +10,7 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
10
10
  */
11
11
  export class Camera {
12
12
  // Services
13
- service!: Service;
13
+ switchService!: Service;
14
14
 
15
15
  // Characteristic Values
16
16
  On!: CharacteristicValue;
@@ -38,7 +38,7 @@ export class Camera {
38
38
 
39
39
  // get the Television service if it exists, otherwise create a new Television service
40
40
  // you can create multiple services for each accessory
41
- (this.service = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
41
+ (this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
42
42
  `${accessory.displayName} Camera`;
43
43
 
44
44
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -47,13 +47,13 @@ export class Camera {
47
47
 
48
48
  // set the service name, this is what is displayed as the default name on the Home app
49
49
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
50
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
50
+ this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
51
51
 
52
52
  // handle on / off events using the On characteristic
53
- this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
53
+ this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
54
54
  }
55
55
 
56
- private OnSet(value: CharacteristicValue) {
56
+ async OnSet(value: CharacteristicValue): Promise<void> {
57
57
  this.debugLog(`Camera: ${this.accessory.displayName} On: ${value}`);
58
58
  this.On = value;
59
59
  if (this.On) {
@@ -63,11 +63,11 @@ export class Camera {
63
63
  }
64
64
  }
65
65
 
66
- private updateHomeKitCharacteristics() {
66
+ async updateHomeKitCharacteristics(): Promise<void> {
67
67
  if (this.On === undefined) {
68
68
  this.debugLog(`Camera: ${this.accessory.displayName} On: ${this.On}`);
69
69
  } else {
70
- this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
70
+ this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
71
71
  this.debugLog(`Camera: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
72
72
  }
73
73
  }
@@ -82,7 +82,7 @@ export class Camera {
82
82
  * Light: "command" "channelAdd" "default" = next channel
83
83
  * Light: "command" "channelSub" "default" = previous channel
84
84
  */
85
- async pushOnChanges() {
85
+ async pushOnChanges(): Promise<void> {
86
86
  if (this.On) {
87
87
  const payload = {
88
88
  commandType: 'command',
@@ -93,7 +93,7 @@ export class Camera {
93
93
  }
94
94
  }
95
95
 
96
- async pushOffChanges() {
96
+ async pushOffChanges(): Promise<void> {
97
97
  if (!this.On) {
98
98
  const payload = {
99
99
  commandType: 'command',
@@ -104,7 +104,7 @@ export class Camera {
104
104
  }
105
105
  }
106
106
 
107
- public async pushChanges(payload: payload) {
107
+ async pushChanges(payload: payload): Promise<void> {
108
108
  try {
109
109
  this.infoLog(
110
110
  `Camera: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
@@ -132,7 +132,7 @@ export class Camera {
132
132
  }
133
133
  }
134
134
 
135
- private statusCode(push: AxiosResponse<{ statusCode: number }>) {
135
+ async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
136
136
  switch (push.data.statusCode) {
137
137
  case 151:
138
138
  this.errorLog(`Camera: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -163,12 +163,12 @@ export class Camera {
163
163
  }
164
164
  }
165
165
 
166
- public apiError(e: any) {
167
- this.service.updateCharacteristic(this.platform.Characteristic.On, e);
166
+ async apiError(e: any): Promise<void> {
167
+ this.switchService.updateCharacteristic(this.platform.Characteristic.On, e);
168
168
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
169
169
  }
170
170
 
171
- config(device: irdevice & irDevicesConfig) {
171
+ async config(device: irdevice & irDevicesConfig): Promise<void> {
172
172
  let config = {};
173
173
  if (device.ircam) {
174
174
  config = device.ircam;
@@ -181,7 +181,7 @@ export class Camera {
181
181
  }
182
182
  }
183
183
 
184
- logs(device: irdevice & irDevicesConfig) {
184
+ async logs(device: irdevice & irDevicesConfig): Promise<void> {
185
185
  if (this.platform.debugMode) {
186
186
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
187
187
  this.debugLog(`Camera: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -200,25 +200,25 @@ export class Camera {
200
200
  /**
201
201
  * Logging for Device
202
202
  */
203
- infoLog(...log: any[]) {
203
+ infoLog(...log: any[]): void {
204
204
  if (this.enablingDeviceLogging()) {
205
205
  this.platform.log.info(String(...log));
206
206
  }
207
207
  }
208
208
 
209
- warnLog(...log: any[]) {
209
+ warnLog(...log: any[]): void {
210
210
  if (this.enablingDeviceLogging()) {
211
211
  this.platform.log.warn(String(...log));
212
212
  }
213
213
  }
214
214
 
215
- errorLog(...log: any[]) {
215
+ errorLog(...log: any[]): void {
216
216
  if (this.enablingDeviceLogging()) {
217
217
  this.platform.log.error(String(...log));
218
218
  }
219
219
  }
220
220
 
221
- debugLog(...log: any[]) {
221
+ debugLog(...log: any[]): void {
222
222
  if (this.enablingDeviceLogging()) {
223
223
  if (this.deviceLogging === 'debug') {
224
224
  this.platform.log.info('[DEBUG]', String(...log));
@@ -10,7 +10,7 @@ import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } f
10
10
  */
11
11
  export class Fan {
12
12
  // Services
13
- service!: Service;
13
+ fanService!: Service;
14
14
 
15
15
  // Characteristic Values
16
16
  Active!: CharacteristicValue;
@@ -48,7 +48,7 @@ export class Fan {
48
48
 
49
49
  // get the Television service if it exists, otherwise create a new Television service
50
50
  // you can create multiple services for each accessory
51
- (this.service = accessory.getService(this.platform.Service.Fanv2) || accessory.addService(this.platform.Service.Fanv2)),
51
+ (this.fanService = accessory.getService(this.platform.Service.Fanv2) || accessory.addService(this.platform.Service.Fanv2)),
52
52
  `${accessory.displayName} Fan`;
53
53
 
54
54
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -57,10 +57,10 @@ export class Fan {
57
57
 
58
58
  // set the service name, this is what is displayed as the default name on the Home app
59
59
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
60
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
60
+ this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
61
61
 
62
62
  // handle on / off events using the Active characteristic
63
- this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
63
+ this.fanService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
64
64
 
65
65
  if (device.irfan?.rotation_speed) {
66
66
  if (device.irfan?.set_minStep) {
@@ -79,7 +79,7 @@ export class Fan {
79
79
  this.maxValue = 100;
80
80
  }
81
81
  // handle Roation Speed events using the RotationSpeed characteristic
82
- this.service
82
+ this.fanService
83
83
  .getCharacteristic(this.platform.Characteristic.RotationSpeed)
84
84
  .setProps({
85
85
  minStep: this.minStep,
@@ -87,9 +87,9 @@ export class Fan {
87
87
  maxValue: this.maxValue,
88
88
  })
89
89
  .onSet(this.RotationSpeedSet.bind(this));
90
- } else if (this.service.testCharacteristic(this.platform.Characteristic.RotationSpeed) && !device.irfan?.swing_mode) {
91
- const characteristic = this.service.getCharacteristic(this.platform.Characteristic.RotationSpeed);
92
- this.service.removeCharacteristic(characteristic);
90
+ } else if (this.fanService.testCharacteristic(this.platform.Characteristic.RotationSpeed) && !device.irfan?.swing_mode) {
91
+ const characteristic = this.fanService.getCharacteristic(this.platform.Characteristic.RotationSpeed);
92
+ this.fanService.removeCharacteristic(characteristic);
93
93
  this.debugLog(`Fan: ${this.accessory.displayName} Rotation Speed Characteristic was removed.`);
94
94
  } else {
95
95
  // eslint-disable-next-line max-len
@@ -101,10 +101,10 @@ export class Fan {
101
101
 
102
102
  if (device.irfan?.swing_mode) {
103
103
  // handle Osolcation events using the SwingMode characteristic
104
- this.service.getCharacteristic(this.platform.Characteristic.SwingMode).onSet(this.SwingModeSet.bind(this));
105
- } else if (this.service.testCharacteristic(this.platform.Characteristic.SwingMode) && !device.irfan?.swing_mode) {
106
- const characteristic = this.service.getCharacteristic(this.platform.Characteristic.SwingMode);
107
- this.service.removeCharacteristic(characteristic);
104
+ this.fanService.getCharacteristic(this.platform.Characteristic.SwingMode).onSet(this.SwingModeSet.bind(this));
105
+ } else if (this.fanService.testCharacteristic(this.platform.Characteristic.SwingMode) && !device.irfan?.swing_mode) {
106
+ const characteristic = this.fanService.getCharacteristic(this.platform.Characteristic.SwingMode);
107
+ this.fanService.removeCharacteristic(characteristic);
108
108
  this.debugLog(`Fan: ${this.accessory.displayName} Swing Mode Characteristic was removed.`);
109
109
  } else {
110
110
  // eslint-disable-next-line max-len
@@ -115,42 +115,42 @@ export class Fan {
115
115
  }
116
116
  }
117
117
 
118
- private SwingModeSet(value: CharacteristicValue) {
118
+ async SwingModeSet(value: CharacteristicValue): Promise<void> {
119
119
  this.debugLog(`Fan: ${this.accessory.displayName} SwingMode: ${value}`);
120
120
  if (value > this.SwingMode) {
121
121
  this.SwingMode = 1;
122
- this.pushFanOnChanges();
123
- this.pushFanSwingChanges();
122
+ await this.pushFanOnChanges();
123
+ await this.pushFanSwingChanges();
124
124
  } else {
125
125
  this.SwingMode = 0;
126
- this.pushFanOnChanges();
127
- this.pushFanSwingChanges();
126
+ await this.pushFanOnChanges();
127
+ await this.pushFanSwingChanges();
128
128
  }
129
129
  this.SwingMode = value;
130
130
  }
131
131
 
132
- private updateHomeKitCharacteristics() {
132
+ async updateHomeKitCharacteristics(): Promise<void> {
133
133
  if (this.Active === undefined) {
134
134
  this.debugLog(`Fan: ${this.accessory.displayName} Active: ${this.Active}`);
135
135
  } else {
136
- this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
136
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
137
137
  this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
138
138
  }
139
139
  if (this.SwingMode === undefined) {
140
140
  this.debugLog(`Fan: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`);
141
141
  } else {
142
- this.service?.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
142
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
143
143
  this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`);
144
144
  }
145
145
  if (this.RotationSpeed === undefined) {
146
146
  this.debugLog(`Fan: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
147
147
  } else {
148
- this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
148
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
149
149
  this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
150
150
  }
151
151
  }
152
152
 
153
- private RotationSpeedSet(value: CharacteristicValue) {
153
+ async RotationSpeedSet(value: CharacteristicValue): Promise<void> {
154
154
  this.debugLog(`Fan: ${this.accessory.displayName} RotationSpeed: ${value}`);
155
155
  if (value > this.RotationSpeed) {
156
156
  this.RotationSpeed = 1;
@@ -163,7 +163,7 @@ export class Fan {
163
163
  this.RotationSpeed = value;
164
164
  }
165
165
 
166
- private ActiveSet(value: CharacteristicValue) {
166
+ async ActiveSet(value: CharacteristicValue): Promise<void> {
167
167
  this.debugLog(`Fan: ${this.accessory.displayName} Active: ${value}`);
168
168
  if (value === this.platform.Characteristic.Active.INACTIVE) {
169
169
  this.pushFanOffChanges();
@@ -184,7 +184,7 @@ export class Fan {
184
184
  * Fan: "command" "middleSpeed" "default" = fan speed to medium
185
185
  * Fan: "command" "highSpeed" "default" = fan speed to high
186
186
  */
187
- async pushFanOnChanges() {
187
+ async pushFanOnChanges(): Promise<void> {
188
188
  if (this.Active !== 1) {
189
189
  const payload = {
190
190
  commandType: 'command',
@@ -195,7 +195,7 @@ export class Fan {
195
195
  }
196
196
  }
197
197
 
198
- async pushFanOffChanges() {
198
+ async pushFanOffChanges(): Promise<void> {
199
199
  const payload = {
200
200
  commandType: 'command',
201
201
  parameter: 'default',
@@ -204,7 +204,7 @@ export class Fan {
204
204
  await this.pushTVChanges(payload);
205
205
  }
206
206
 
207
- async pushFanSpeedUpChanges() {
207
+ async pushFanSpeedUpChanges(): Promise<void> {
208
208
  const payload = {
209
209
  commandType: 'command',
210
210
  parameter: 'default',
@@ -213,7 +213,7 @@ export class Fan {
213
213
  await this.pushTVChanges(payload);
214
214
  }
215
215
 
216
- async pushFanSpeedDownChanges() {
216
+ async pushFanSpeedDownChanges(): Promise<void> {
217
217
  const payload = {
218
218
  commandType: 'command',
219
219
  parameter: 'default',
@@ -222,7 +222,7 @@ export class Fan {
222
222
  await this.pushTVChanges(payload);
223
223
  }
224
224
 
225
- async pushFanSwingChanges() {
225
+ async pushFanSwingChanges(): Promise<void> {
226
226
  const payload = {
227
227
  commandType: 'command',
228
228
  parameter: 'default',
@@ -231,7 +231,7 @@ export class Fan {
231
231
  await this.pushTVChanges(payload);
232
232
  }
233
233
 
234
- public async pushTVChanges(payload: payload) {
234
+ async pushTVChanges(payload: payload): Promise<void> {
235
235
  try {
236
236
  this.infoLog(
237
237
  `Fan: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
@@ -257,7 +257,7 @@ export class Fan {
257
257
  }
258
258
  }
259
259
 
260
- private statusCode(push: AxiosResponse<{ statusCode: number }>) {
260
+ async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
261
261
  switch (push.data.statusCode) {
262
262
  case 151:
263
263
  this.errorLog(`Fan: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -288,14 +288,14 @@ export class Fan {
288
288
  }
289
289
  }
290
290
 
291
- public apiError(e: any) {
292
- this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
293
- this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
294
- this.service.updateCharacteristic(this.platform.Characteristic.SwingMode, e);
291
+ async apiError(e: any): Promise<void> {
292
+ this.fanService.updateCharacteristic(this.platform.Characteristic.Active, e);
293
+ this.fanService.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
294
+ this.fanService.updateCharacteristic(this.platform.Characteristic.SwingMode, e);
295
295
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
296
296
  }
297
297
 
298
- config(device: irdevice & irDevicesConfig) {
298
+ async config(device: irdevice & irDevicesConfig): Promise<void> {
299
299
  let config = {};
300
300
  if (device.irfan) {
301
301
  config = device.irfan;
@@ -308,7 +308,7 @@ export class Fan {
308
308
  }
309
309
  }
310
310
 
311
- logs(device: irdevice & irDevicesConfig) {
311
+ async logs(device: irdevice & irDevicesConfig): Promise<void> {
312
312
  if (this.platform.debugMode) {
313
313
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
314
314
  this.debugLog(`Fan: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -327,25 +327,25 @@ export class Fan {
327
327
  /**
328
328
  * Logging for Device
329
329
  */
330
- infoLog(...log: any[]) {
330
+ infoLog(...log: any[]): void {
331
331
  if (this.enablingDeviceLogging()) {
332
332
  this.platform.log.info(String(...log));
333
333
  }
334
334
  }
335
335
 
336
- warnLog(...log: any[]) {
336
+ warnLog(...log: any[]): void {
337
337
  if (this.enablingDeviceLogging()) {
338
338
  this.platform.log.warn(String(...log));
339
339
  }
340
340
  }
341
341
 
342
- errorLog(...log: any[]) {
342
+ errorLog(...log: any[]): void {
343
343
  if (this.enablingDeviceLogging()) {
344
344
  this.platform.log.error(String(...log));
345
345
  }
346
346
  }
347
347
 
348
- debugLog(...log: any[]) {
348
+ debugLog(...log: any[]): void {
349
349
  if (this.enablingDeviceLogging()) {
350
350
  if (this.deviceLogging === 'debug') {
351
351
  this.platform.log.info('[DEBUG]', String(...log));
@@ -10,7 +10,7 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
10
10
  */
11
11
  export class Light {
12
12
  // Services
13
- service!: Service;
13
+ lightBulbService!: Service;
14
14
 
15
15
  // Characteristic Values
16
16
  On!: CharacteristicValue;
@@ -38,7 +38,7 @@ export class Light {
38
38
 
39
39
  // get the Television service if it exists, otherwise create a new Television service
40
40
  // you can create multiple services for each accessory
41
- (this.service = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
41
+ (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
42
42
  `${accessory.displayName} Light Bulb`;
43
43
 
44
44
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -47,10 +47,10 @@ export class Light {
47
47
 
48
48
  // set the service name, this is what is displayed as the default name on the Home app
49
49
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
50
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
50
+ this.lightBulbService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
51
51
 
52
52
  // handle on / off events using the On characteristic
53
- this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
53
+ this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
54
54
 
55
55
  // handle Brightness events using the Brightness characteristic
56
56
  /* this.service
@@ -68,21 +68,21 @@ export class Light {
68
68
  });*/
69
69
  }
70
70
 
71
- private OnSet(value: CharacteristicValue) {
71
+ async OnSet(value: CharacteristicValue): Promise<void> {
72
72
  this.debugLog(`Light: ${this.accessory.displayName} On: ${value}`);
73
73
  this.On = value;
74
74
  if (this.On) {
75
- this.pushLightOnChanges();
75
+ await this.pushLightOnChanges();
76
76
  } else {
77
- this.pushLightOffChanges();
77
+ await this.pushLightOffChanges();
78
78
  }
79
79
  }
80
80
 
81
- private updateHomeKitCharacteristics() {
81
+ async updateHomeKitCharacteristics(): Promise<void> {
82
82
  if (this.On === undefined) {
83
83
  this.debugLog(`Light: ${this.accessory.displayName} On: ${this.On}`);
84
84
  } else {
85
- this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
85
+ this.lightBulbService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
86
86
  this.debugLog(`Light: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
87
87
  }
88
88
  }
@@ -97,7 +97,7 @@ export class Light {
97
97
  * Light: "command" "channelAdd" "default" = next channel
98
98
  * Light: "command" "channelSub" "default" = previous channel
99
99
  */
100
- async pushLightOnChanges() {
100
+ async pushLightOnChanges(): Promise<void> {
101
101
  if (this.On) {
102
102
  const payload = {
103
103
  commandType: 'command',
@@ -108,7 +108,7 @@ export class Light {
108
108
  }
109
109
  }
110
110
 
111
- async pushLightOffChanges() {
111
+ async pushLightOffChanges(): Promise<void> {
112
112
  if (!this.On) {
113
113
  const payload = {
114
114
  commandType: 'command',
@@ -119,7 +119,7 @@ export class Light {
119
119
  }
120
120
  }
121
121
 
122
- async pushLightBrightnessUpChanges() {
122
+ async pushLightBrightnessUpChanges(): Promise<void> {
123
123
  const payload = {
124
124
  commandType: 'command',
125
125
  parameter: 'default',
@@ -128,7 +128,7 @@ export class Light {
128
128
  await this.pushChanges(payload);
129
129
  }
130
130
 
131
- async pushLightBrightnessDownChanges() {
131
+ async pushLightBrightnessDownChanges(): Promise<void> {
132
132
  const payload = {
133
133
  commandType: 'command',
134
134
  parameter: 'default',
@@ -137,7 +137,7 @@ export class Light {
137
137
  await this.pushChanges(payload);
138
138
  }
139
139
 
140
- public async pushChanges(payload: payload) {
140
+ async pushChanges(payload: payload): Promise<void> {
141
141
  try {
142
142
  this.infoLog(
143
143
  `Light: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
@@ -165,7 +165,7 @@ export class Light {
165
165
  }
166
166
  }
167
167
 
168
- private statusCode(push: AxiosResponse<{ statusCode: number }>) {
168
+ async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void>{
169
169
  switch (push.data.statusCode) {
170
170
  case 151:
171
171
  this.errorLog(`Light: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -196,12 +196,12 @@ export class Light {
196
196
  }
197
197
  }
198
198
 
199
- public apiError(e: any) {
200
- this.service.updateCharacteristic(this.platform.Characteristic.On, e);
199
+ async apiError(e: any): Promise<void> {
200
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, e);
201
201
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
202
202
  }
203
203
 
204
- config(device: irdevice & irDevicesConfig) {
204
+ async config(device: irdevice & irDevicesConfig): Promise<void> {
205
205
  let config = {};
206
206
  if (device.irlight) {
207
207
  config = device.irlight;
@@ -214,7 +214,7 @@ export class Light {
214
214
  }
215
215
  }
216
216
 
217
- logs(device: irdevice & irDevicesConfig) {
217
+ async logs(device: irdevice & irDevicesConfig): Promise<void> {
218
218
  if (this.platform.debugMode) {
219
219
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
220
220
  this.debugLog(`Light: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -233,25 +233,25 @@ export class Light {
233
233
  /**
234
234
  * Logging for Device
235
235
  */
236
- infoLog(...log: any[]) {
236
+ infoLog(...log: any[]): void {
237
237
  if (this.enablingDeviceLogging()) {
238
238
  this.platform.log.info(String(...log));
239
239
  }
240
240
  }
241
241
 
242
- warnLog(...log: any[]) {
242
+ warnLog(...log: any[]): void {
243
243
  if (this.enablingDeviceLogging()) {
244
244
  this.platform.log.warn(String(...log));
245
245
  }
246
246
  }
247
247
 
248
- errorLog(...log: any[]) {
248
+ errorLog(...log: any[]): void {
249
249
  if (this.enablingDeviceLogging()) {
250
250
  this.platform.log.error(String(...log));
251
251
  }
252
252
  }
253
253
 
254
- debugLog(...log: any[]) {
254
+ debugLog(...log: any[]): void {
255
255
  if (this.enablingDeviceLogging()) {
256
256
  if (this.deviceLogging === 'debug') {
257
257
  this.platform.log.info('[DEBUG]', String(...log));