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