@switchbot/homebridge-switchbot 1.8.2 → 1.8.3-beta.0

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 (104) hide show
  1. package/.eslintrc +1 -1
  2. package/.vscode/extensions.json +5 -0
  3. package/.vscode/settings.json +15 -0
  4. package/dist/devices/bots.d.ts +34 -35
  5. package/dist/devices/bots.d.ts.map +1 -1
  6. package/dist/devices/bots.js +241 -184
  7. package/dist/devices/bots.js.map +1 -1
  8. package/dist/devices/colorbulb.d.ts +50 -50
  9. package/dist/devices/colorbulb.d.ts.map +1 -1
  10. package/dist/devices/colorbulb.js +145 -131
  11. package/dist/devices/colorbulb.js.map +1 -1
  12. package/dist/devices/contact.d.ts +27 -29
  13. package/dist/devices/contact.d.ts.map +1 -1
  14. package/dist/devices/contact.js +138 -115
  15. package/dist/devices/contact.js.map +1 -1
  16. package/dist/devices/curtains.d.ts +29 -31
  17. package/dist/devices/curtains.d.ts.map +1 -1
  18. package/dist/devices/curtains.js +211 -176
  19. package/dist/devices/curtains.js.map +1 -1
  20. package/dist/devices/humidifiers.d.ts +33 -33
  21. package/dist/devices/humidifiers.d.ts.map +1 -1
  22. package/dist/devices/humidifiers.js +214 -189
  23. package/dist/devices/humidifiers.js.map +1 -1
  24. package/dist/devices/meters.d.ts +30 -31
  25. package/dist/devices/meters.d.ts.map +1 -1
  26. package/dist/devices/meters.js +124 -100
  27. package/dist/devices/meters.js.map +1 -1
  28. package/dist/devices/motion.d.ts +25 -26
  29. package/dist/devices/motion.d.ts.map +1 -1
  30. package/dist/devices/motion.js +120 -102
  31. package/dist/devices/motion.js.map +1 -1
  32. package/dist/devices/plugs.d.ts +23 -23
  33. package/dist/devices/plugs.d.ts.map +1 -1
  34. package/dist/devices/plugs.js +81 -63
  35. package/dist/devices/plugs.js.map +1 -1
  36. package/dist/index.d.ts +2 -2
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +22 -3
  39. package/dist/index.js.map +1 -1
  40. package/dist/irdevices/airconditioners.d.ts +6 -6
  41. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  42. package/dist/irdevices/airconditioners.js +105 -79
  43. package/dist/irdevices/airconditioners.js.map +1 -1
  44. package/dist/irdevices/airpurifiers.d.ts +5 -5
  45. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  46. package/dist/irdevices/airpurifiers.js +56 -42
  47. package/dist/irdevices/airpurifiers.js.map +1 -1
  48. package/dist/irdevices/cameras.d.ts +5 -5
  49. package/dist/irdevices/cameras.d.ts.map +1 -1
  50. package/dist/irdevices/cameras.js +31 -27
  51. package/dist/irdevices/cameras.js.map +1 -1
  52. package/dist/irdevices/fans.d.ts +5 -5
  53. package/dist/irdevices/fans.d.ts.map +1 -1
  54. package/dist/irdevices/fans.js +45 -38
  55. package/dist/irdevices/fans.js.map +1 -1
  56. package/dist/irdevices/lights.d.ts +5 -5
  57. package/dist/irdevices/lights.d.ts.map +1 -1
  58. package/dist/irdevices/lights.js +37 -33
  59. package/dist/irdevices/lights.js.map +1 -1
  60. package/dist/irdevices/others.d.ts +5 -5
  61. package/dist/irdevices/others.d.ts.map +1 -1
  62. package/dist/irdevices/others.js +34 -29
  63. package/dist/irdevices/others.js.map +1 -1
  64. package/dist/irdevices/tvs.d.ts +5 -5
  65. package/dist/irdevices/tvs.d.ts.map +1 -1
  66. package/dist/irdevices/tvs.js +91 -76
  67. package/dist/irdevices/tvs.js.map +1 -1
  68. package/dist/irdevices/vacuumcleaners.d.ts +5 -5
  69. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  70. package/dist/irdevices/vacuumcleaners.js +31 -27
  71. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  72. package/dist/irdevices/waterheaters.d.ts +5 -5
  73. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  74. package/dist/irdevices/waterheaters.js +31 -27
  75. package/dist/irdevices/waterheaters.js.map +1 -1
  76. package/dist/platform.d.ts +12 -12
  77. package/dist/platform.d.ts.map +1 -1
  78. package/dist/platform.js +241 -172
  79. package/dist/platform.js.map +1 -1
  80. package/dist/settings.d.ts +1 -1
  81. package/dist/settings.d.ts.map +1 -1
  82. package/dist/settings.js +4 -4
  83. package/dist/settings.js.map +1 -1
  84. package/package.json +72 -71
  85. package/src/devices/bots.ts +927 -442
  86. package/src/devices/colorbulb.ts +473 -246
  87. package/src/devices/contact.ts +381 -208
  88. package/src/devices/curtains.ts +613 -321
  89. package/src/devices/humidifiers.ts +594 -323
  90. package/src/devices/meters.ts +331 -186
  91. package/src/devices/motion.ts +327 -184
  92. package/src/devices/plugs.ts +175 -107
  93. package/src/index.ts +5 -5
  94. package/src/irdevices/airconditioners.ts +360 -149
  95. package/src/irdevices/airpurifiers.ts +178 -80
  96. package/src/irdevices/cameras.ts +109 -51
  97. package/src/irdevices/fans.ts +174 -77
  98. package/src/irdevices/lights.ts +110 -57
  99. package/src/irdevices/others.ts +137 -62
  100. package/src/irdevices/tvs.ts +249 -124
  101. package/src/irdevices/vacuumcleaners.ts +112 -52
  102. package/src/irdevices/waterheaters.ts +115 -53
  103. package/src/platform.ts +768 -357
  104. package/src/settings.ts +17 -23
@@ -1,22 +1,21 @@
1
-
2
- import { AxiosResponse } from 'axios';
3
- import { interval, Subject } from 'rxjs';
4
- import { SwitchBotPlatform } from '../platform';
5
- import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
7
- import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload, deviceStatus } from '../settings';
1
+ import * as axios from "axios";
2
+ import * as rxjs from "rxjs";
3
+ import * as platform_1 from "../platform";
4
+ import * as operators from "rxjs/operators";
5
+ import * as homebridge from "homebridge";
6
+ import * as settings from "../settings";
8
7
 
9
8
  export class Plug {
10
9
  // Services
11
- private service: Service;
10
+ private service: homebridge.Service;
12
11
 
13
12
  // Characteristic Values
14
- On!: CharacteristicValue;
15
- OnCached!: CharacteristicValue;
13
+ On!: homebridge.CharacteristicValue;
14
+ OnCached!: homebridge.CharacteristicValue;
16
15
 
17
16
  // OpenAPI Others
18
- power: deviceStatus['power'];
19
- deviceStatus!: deviceStatusResponse;
17
+ power: settings.deviceStatus["power"];
18
+ deviceStatus!: settings.deviceStatusResponse;
20
19
 
21
20
  // Config
22
21
  scanDuration!: number;
@@ -25,12 +24,12 @@ export class Plug {
25
24
 
26
25
  // Updates
27
26
  plugUpdateInProgress!: boolean;
28
- doPlugUpdate!: Subject<void>;
27
+ doPlugUpdate!: rxjs.Subject<void>;
29
28
 
30
29
  constructor(
31
- private readonly platform: SwitchBotPlatform,
32
- private accessory: PlatformAccessory,
33
- public device: device & devicesConfig,
30
+ private readonly platform: platform_1.SwitchBotPlatform,
31
+ private accessory: homebridge.PlatformAccessory,
32
+ public device: settings.device & settings.devicesConfig,
34
33
  ) {
35
34
  // default placeholders
36
35
  this.logs(device);
@@ -43,11 +42,8 @@ export class Plug {
43
42
  this.On = this.accessory.context.On;
44
43
  }
45
44
 
46
- // Plug Config
47
- this.debugLog(`Plug: ${this.accessory.displayName} Config: (offline: ${device.offline})`);
48
-
49
45
  // this is subject we use to track when we need to POST changes to the SwitchBot API
50
- this.doPlugUpdate = new Subject();
46
+ this.doPlugUpdate = new rxjs.Subject();
51
47
  this.plugUpdateInProgress = false;
52
48
 
53
49
  // Retrieve initial values and updateHomekit
@@ -56,15 +52,22 @@ export class Plug {
56
52
  // set accessory information
57
53
  accessory
58
54
  .getService(this.platform.Service.AccessoryInformation)!
59
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
60
- .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-PLUG-SP11')
61
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
55
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
56
+ .setCharacteristic(
57
+ this.platform.Characteristic.Model,
58
+ "SWITCHBOT-PLUG-SP11",
59
+ )
60
+ .setCharacteristic(
61
+ this.platform.Characteristic.SerialNumber,
62
+ device.deviceId!,
63
+ );
62
64
 
63
65
  // get the WindowCovering service if it exists, otherwise create a new WindowCovering service
64
66
  // you can create multiple services for each accessory
65
67
  (this.service =
66
68
  accessory.getService(this.platform.Service.Outlet) ||
67
- accessory.addService(this.platform.Service.Outlet)), `${device.deviceName} ${device.deviceType}`;
69
+ accessory.addService(this.platform.Service.Outlet)),
70
+ `${device.deviceName} ${device.deviceType}`;
68
71
 
69
72
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
70
73
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -72,20 +75,25 @@ export class Plug {
72
75
 
73
76
  // set the service name, this is what is displayed as the default name on the Home app
74
77
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
75
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
78
+ this.service.setCharacteristic(
79
+ this.platform.Characteristic.Name,
80
+ accessory.displayName,
81
+ );
76
82
 
77
83
  // each service must implement at-minimum the "required characteristics" for the given service type
78
84
  // see https://developers.homebridge.io/#/service/WindowCovering
79
85
 
80
86
  // create handlers for required characteristics
81
- this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
87
+ this.service
88
+ .getCharacteristic(this.platform.Characteristic.On)
89
+ .onSet(this.OnSet.bind(this));
82
90
 
83
91
  // Update Homekit
84
92
  this.updateHomeKitCharacteristics();
85
93
 
86
94
  // Start an update interval
87
- interval(this.deviceRefreshRate * 1000)
88
- .pipe(skipWhile(() => this.plugUpdateInProgress))
95
+ rxjs.interval(this.deviceRefreshRate * 1000)
96
+ .pipe(operators.skipWhile(() => this.plugUpdateInProgress))
89
97
  .subscribe(() => {
90
98
  this.refreshStatus();
91
99
  });
@@ -94,23 +102,23 @@ export class Plug {
94
102
  // We put in a debounce of 100ms so we don't make duplicate calls
95
103
  this.doPlugUpdate
96
104
  .pipe(
97
- tap(() => {
105
+ operators.tap(() => {
98
106
  this.plugUpdateInProgress = true;
99
107
  }),
100
- debounceTime(this.platform.config.options!.pushRate! * 1000),
108
+ operators.debounceTime(this.platform.config.options!.pushRate! * 1000),
101
109
  )
102
110
  .subscribe(async () => {
103
111
  try {
104
112
  await this.pushChanges();
105
113
  } catch (e: any) {
106
- this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges`);
107
- if (this.deviceLogging === 'debug') {
108
- this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges,`
109
- + ` Error Message: ${JSON.stringify(e.message)}`);
110
- }
111
- if (this.platform.debugMode) {
112
- this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges,`
113
- + ` Error: ${JSON.stringify(e)}`);
114
+ this.errorLog(
115
+ `Plug: ${this.accessory.displayName} failed pushChanges`,
116
+ );
117
+ if (this.deviceLogging.includes("debug")) {
118
+ this.errorLog(
119
+ `Plug: ${this.accessory.displayName} failed pushChanges,` +
120
+ ` Error Message: ${JSON.stringify(e.message)}`,
121
+ );
114
122
  }
115
123
  this.apiError(e);
116
124
  }
@@ -120,7 +128,7 @@ export class Plug {
120
128
 
121
129
  parseStatus() {
122
130
  switch (this.power) {
123
- case 'on':
131
+ case "on":
124
132
  this.On = true;
125
133
  break;
126
134
  default:
@@ -131,57 +139,74 @@ export class Plug {
131
139
 
132
140
  private async refreshStatus() {
133
141
  try {
134
- this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
135
- this.debugLog(`Plug: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
142
+ this.deviceStatus = (
143
+ await this.platform.axios.get(
144
+ `${settings.DeviceURL}/${this.device.deviceId}/status`,
145
+ )
146
+ ).data;
147
+ this.debugLog(
148
+ `Plug: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(
149
+ this.deviceStatus,
150
+ )}`,
151
+ );
136
152
  this.power = this.deviceStatus.body.power;
137
153
  this.parseStatus();
138
154
  this.updateHomeKitCharacteristics();
139
155
  } catch (e: any) {
140
- this.errorLog(`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
141
- if (this.deviceLogging === 'debug') {
142
- this.errorLog(`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
143
- + ` Error Message: ${JSON.stringify(e.message)}`);
144
- }
145
- if (this.platform.debugMode) {
146
- this.errorLog(`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
147
- + ` Error: ${JSON.stringify(e)}`);
156
+ this.errorLog(
157
+ `Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`,
158
+ );
159
+ if (this.deviceLogging.includes("debug")) {
160
+ this.errorLog(
161
+ `Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
162
+ ` Error Message: ${JSON.stringify(e.message)}`,
163
+ );
148
164
  }
149
165
  this.apiError(e);
150
166
  }
151
167
  }
152
168
 
153
169
  /**
154
- * Pushes the requested changes to the SwitchBot API
155
- * deviceType commandType Command command parameter Description
156
- * Plug - "command" "turnOff" "default" = set to OFF state
157
- * Plug - "command" "turnOn" "default" = set to ON state
158
- */
170
+ * Pushes the requested changes to the SwitchBot API
171
+ * deviceType commandType Command command parameter Description
172
+ * Plug - "command" "turnOff" "default" = set to OFF state
173
+ * Plug - "command" "turnOn" "default" = set to ON state
174
+ */
159
175
  async pushChanges() {
160
176
  if (this.On !== this.OnCached) {
161
177
  const payload = {
162
- commandType: 'command',
163
- parameter: 'default',
164
- } as payload;
178
+ commandType: "command",
179
+ parameter: "default",
180
+ } as settings.payload;
165
181
 
166
182
  if (this.On) {
167
- payload.command = 'turnOn';
183
+ payload.command = "turnOn";
168
184
  } else {
169
- payload.command = 'turnOff';
185
+ payload.command = "turnOff";
170
186
  }
171
187
 
172
- this.infoLog(`Plug: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
173
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
188
+ this.infoLog(
189
+ `Plug: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
190
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
191
+ );
174
192
 
175
193
  // Make the API request
176
- const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
177
- this.debugLog(`Plug: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
194
+ const push: any = await this.platform.axios.post(
195
+ `${settings.DeviceURL}/${this.device.deviceId}/commands`,
196
+ payload,
197
+ );
198
+ this.debugLog(
199
+ `Plug: ${this.accessory.displayName} pushchanges: ${JSON.stringify(
200
+ push.data,
201
+ )}`,
202
+ );
178
203
  this.statusCode(push);
179
204
  this.OnCached = this.On;
180
205
  this.accessory.context.On = this.OnCached;
181
206
  }
182
- interval(5000)
183
- .pipe(skipWhile(() => this.plugUpdateInProgress))
184
- .pipe(take(1))
207
+ rxjs.interval(5000)
208
+ .pipe(operators.skipWhile(() => this.plugUpdateInProgress))
209
+ .pipe(operators.take(1))
185
210
  .subscribe(() => {
186
211
  this.refreshStatus();
187
212
  });
@@ -191,8 +216,13 @@ export class Plug {
191
216
  if (this.On === undefined) {
192
217
  this.debugLog(`Plug: ${this.accessory.displayName} On: ${this.On}`);
193
218
  } else {
194
- this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
195
- this.debugLog(`Plug: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
219
+ this.service.updateCharacteristic(
220
+ this.platform.Characteristic.On,
221
+ this.On,
222
+ );
223
+ this.debugLog(
224
+ `Plug: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
225
+ );
196
226
  }
197
227
  }
198
228
 
@@ -201,119 +231,155 @@ export class Plug {
201
231
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
202
232
  }
203
233
 
204
- private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
234
+ private statusCode(push: axios.AxiosResponse<{ statusCode: number }>) {
205
235
  switch (push.data.statusCode) {
206
236
  case 151:
207
- this.errorLog(`Plug: ${this.accessory.displayName} Command not supported by this device type.`);
237
+ this.errorLog(
238
+ `Plug: ${this.accessory.displayName} Command not supported by this device type.`,
239
+ );
208
240
  break;
209
241
  case 152:
210
242
  this.errorLog(`Plug: ${this.accessory.displayName} Device not found.`);
211
243
  break;
212
244
  case 160:
213
- this.errorLog(`Plug: ${this.accessory.displayName} Command is not supported.`);
245
+ this.errorLog(
246
+ `Plug: ${this.accessory.displayName} Command is not supported.`,
247
+ );
214
248
  break;
215
249
  case 161:
216
250
  this.errorLog(`Plug: ${this.accessory.displayName} Device is offline.`);
217
251
  this.offlineOff();
218
252
  break;
219
253
  case 171:
220
- this.errorLog(`Plug: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
254
+ this.errorLog(
255
+ `Plug: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
256
+ );
221
257
  this.offlineOff();
222
258
  break;
223
259
  case 190:
224
- this.errorLog(`Plug: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
225
- + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
260
+ this.errorLog(
261
+ `Plug: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
262
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`,
263
+ );
226
264
  break;
227
265
  case 100:
228
- this.debugLog(`Plug: ${this.accessory.displayName} Command successfully sent.`);
266
+ this.debugLog(
267
+ `Plug: ${this.accessory.displayName} Command successfully sent.`,
268
+ );
229
269
  break;
230
270
  default:
231
- this.debugLog(`Plug: ${this.accessory.displayName} Unknown statusCode.`);
271
+ this.debugLog(
272
+ `Plug: ${this.accessory.displayName} Unknown statusCode.`,
273
+ );
232
274
  }
233
275
  }
234
276
 
235
277
  private offlineOff() {
236
278
  if (this.device.offline) {
237
279
  this.On = false;
238
- this.service.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
280
+ this.service
281
+ .getCharacteristic(this.platform.Characteristic.On)
282
+ .updateValue(this.On);
239
283
  }
240
284
  }
241
285
 
242
286
  /**
243
287
  * Handle requests to set the value of the "On" characteristic
244
288
  */
245
- OnSet(value: CharacteristicValue) {
289
+ OnSet(value: homebridge.CharacteristicValue) {
246
290
  this.debugLog(`Plug: ${this.accessory.displayName} - Set On: ${value}`);
247
291
 
248
292
  this.On = value;
249
293
  this.doPlugUpdate.next();
250
294
  }
251
295
 
252
- config(device: device & devicesConfig) {
296
+ config(device: settings.device & settings.devicesConfig) {
253
297
  let config = {};
254
298
  if (device.plug) {
255
299
  config = device.plug;
256
300
  }
257
301
  if (device.ble !== undefined) {
258
- config['ble'] = device.ble;
302
+ config["ble"] = device.ble;
259
303
  }
260
304
  if (device.logging !== undefined) {
261
- config['logging'] = device.logging;
305
+ config["logging"] = device.logging;
262
306
  }
263
307
  if (device.refreshRate !== undefined) {
264
- config['refreshRate'] = device.refreshRate;
308
+ config["refreshRate"] = device.refreshRate;
265
309
  }
266
310
  if (device.scanDuration !== undefined) {
267
- config['scanDuration'] = device.scanDuration;
311
+ config["scanDuration"] = device.scanDuration;
268
312
  }
269
313
  if (Object.entries(config).length !== 0) {
270
- this.warnLog(`Plug: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
314
+ this.warnLog(
315
+ `Plug: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`,
316
+ );
271
317
  }
272
318
  }
273
319
 
274
- refreshRate(device: device & devicesConfig) {
320
+ refreshRate(device: settings.device & settings.devicesConfig) {
275
321
  if (device.refreshRate) {
276
- this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
277
- this.debugLog(`Plug: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
322
+ this.deviceRefreshRate = this.accessory.context.refreshRate =
323
+ device.refreshRate;
324
+ this.debugLog(
325
+ `Plug: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`,
326
+ );
278
327
  } else if (this.platform.config.options!.refreshRate) {
279
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
280
- this.debugLog(`Plug: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
328
+ this.deviceRefreshRate = this.accessory.context.refreshRate =
329
+ this.platform.config.options!.refreshRate;
330
+ this.debugLog(
331
+ `Plug: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`,
332
+ );
281
333
  }
282
334
  }
283
335
 
284
- scan(device: device & devicesConfig) {
336
+ scan(device: settings.device & settings.devicesConfig) {
285
337
  if (device.scanDuration) {
286
- this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
338
+ this.scanDuration = this.accessory.context.scanDuration =
339
+ device.scanDuration;
287
340
  if (device.ble) {
288
- this.debugLog(`Plug: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
341
+ this.debugLog(
342
+ `Plug: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`,
343
+ );
289
344
  }
290
345
  } else {
291
346
  this.scanDuration = this.accessory.context.scanDuration = 1;
292
347
  if (this.device.ble) {
293
- this.debugLog(`Plug: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
348
+ this.debugLog(
349
+ `Plug: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`,
350
+ );
294
351
  }
295
352
  }
296
353
  }
297
354
 
298
- logs(device: device & devicesConfig) {
355
+ logs(device: settings.device & settings.devicesConfig) {
299
356
  if (this.platform.debugMode) {
300
- this.deviceLogging = this.accessory.context.logging = 'debugMode';
301
- this.debugLog(`Plug: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
357
+ this.deviceLogging = this.accessory.context.logging = "debugMode";
358
+ this.debugLog(
359
+ `Plug: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
360
+ );
302
361
  } else if (device.logging) {
303
362
  this.deviceLogging = this.accessory.context.logging = device.logging;
304
- this.debugLog(`Plug: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
363
+ this.debugLog(
364
+ `Plug: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
365
+ );
305
366
  } else if (this.platform.config.options?.logging) {
306
- this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
307
- this.debugLog(`Plug: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
367
+ this.deviceLogging = this.accessory.context.logging =
368
+ this.platform.config.options?.logging;
369
+ this.debugLog(
370
+ `Plug: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
371
+ );
308
372
  } else {
309
- this.deviceLogging = this.accessory.context.logging = 'standard';
310
- this.debugLog(`Plug: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
373
+ this.deviceLogging = this.accessory.context.logging = "standard";
374
+ this.debugLog(
375
+ `Plug: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
376
+ );
311
377
  }
312
378
  }
313
379
 
314
380
  /**
315
- * Logging for Device
316
- */
381
+ * Logging for Device
382
+ */
317
383
  infoLog(...log: any[]) {
318
384
  if (this.enablingDeviceLogging()) {
319
385
  this.platform.log.info(String(...log));
@@ -334,8 +400,8 @@ export class Plug {
334
400
 
335
401
  debugLog(...log: any[]) {
336
402
  if (this.enablingDeviceLogging()) {
337
- if (this.deviceLogging === 'debug') {
338
- this.platform.log.info('[DEBUG]', String(...log));
403
+ if (this.deviceLogging === "debug") {
404
+ this.platform.log.info("[DEBUG]", String(...log));
339
405
  } else {
340
406
  this.platform.log.debug(String(...log));
341
407
  }
@@ -343,6 +409,8 @@ export class Plug {
343
409
  }
344
410
 
345
411
  enablingDeviceLogging(): boolean {
346
- return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
412
+ return (
413
+ this.deviceLogging.includes("debug") || this.deviceLogging === "standard"
414
+ );
347
415
  }
348
- }
416
+ }
package/src/index.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { API } from 'homebridge';
2
- import { PLATFORM_NAME } from './settings';
3
- import { SwitchBotPlatform } from './platform';
1
+ import * as homebridge from "homebridge";
2
+ import * as settings from "./settings";
3
+ import * as platform from "./platform";
4
4
 
5
5
  /**
6
6
  * This method registers the platform with Homebridge
7
7
  */
8
- export = (api: API): void => {
9
- api.registerPlatform(PLATFORM_NAME, SwitchBotPlatform);
8
+ export = (api: homebridge.API): void => {
9
+ api.registerPlatform(settings.PLATFORM_NAME, platform.SwitchBotPlatform);
10
10
  };