@switchbot/homebridge-switchbot 3.5.1-beta.1 → 3.5.1-beta.11
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.
- package/README.md +16 -0
- package/dist/device/blindtilt.d.ts +15 -6
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +203 -255
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +196 -218
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -4
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +203 -249
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +10 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +329 -378
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +99 -142
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +19 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +203 -264
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +28 -32
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +186 -225
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +9 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +198 -227
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +106 -231
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +12 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +192 -232
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +91 -157
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +287 -367
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -5
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +171 -216
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +93 -158
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +94 -155
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +84 -142
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +99 -124
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -6
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +170 -253
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +12 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +105 -129
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +45 -51
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +17 -17
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +2 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +9 -9
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +19 -19
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +24 -11
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +90 -68
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +2 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +15 -17
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +2 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +76 -76
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +35 -35
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +9 -9
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +9 -9
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +15 -15
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +288 -271
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -191
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +19 -0
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +279 -0
- package/dist/types/bledevicestatus.d.ts.map +1 -0
- package/dist/types/bledevicestatus.js +2 -0
- package/dist/types/bledevicestatus.js.map +1 -0
- package/dist/types/devicelist.d.ts +89 -0
- package/dist/types/devicelist.d.ts.map +1 -0
- package/dist/types/devicelist.js +6 -0
- package/dist/types/devicelist.js.map +1 -0
- package/dist/types/deviceresponse.d.ts +13 -0
- package/dist/types/deviceresponse.d.ts.map +1 -0
- package/dist/types/deviceresponse.js +2 -0
- package/dist/types/deviceresponse.js.map +1 -0
- package/dist/types/devicestatus.d.ts +149 -0
- package/dist/types/devicestatus.d.ts.map +1 -0
- package/dist/types/devicestatus.js +3 -0
- package/dist/types/devicestatus.js.map +1 -0
- package/dist/types/devicewebhookstatus.d.ts +156 -0
- package/dist/types/devicewebhookstatus.d.ts.map +1 -0
- package/dist/types/devicewebhookstatus.js +2 -0
- package/dist/types/devicewebhookstatus.js.map +1 -0
- package/dist/types/irdevicelist.d.ts +10 -0
- package/dist/types/irdevicelist.d.ts.map +1 -0
- package/dist/types/irdevicelist.js +2 -0
- package/dist/types/irdevicelist.js.map +1 -0
- package/dist/types/pushbody.d.ts +6 -0
- package/dist/types/pushbody.d.ts.map +1 -0
- package/dist/types/pushbody.js +2 -0
- package/dist/types/pushbody.js.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +1 -1
- package/package.json +10 -10
- package/src/device/blindtilt.ts +224 -264
- package/src/device/bot.ts +208 -221
- package/src/device/ceilinglight.ts +211 -261
- package/src/device/colorbulb.ts +334 -397
- package/src/device/contact.ts +111 -146
- package/src/device/curtain.ts +220 -283
- package/src/device/device.ts +194 -245
- package/src/device/fan.ts +214 -230
- package/src/device/hub.ts +126 -246
- package/src/device/humidifier.ts +216 -243
- package/src/device/iosensor.ts +114 -166
- package/src/device/lightstrip.ts +302 -377
- package/src/device/lock.ts +187 -221
- package/src/device/meter.ts +116 -177
- package/src/device/meterplus.ts +117 -174
- package/src/device/motion.ts +99 -144
- package/src/device/plug.ts +110 -128
- package/src/device/robotvacuumcleaner.ts +189 -252
- package/src/device/waterdetector.ts +123 -139
- package/src/irdevice/airconditioner.ts +47 -52
- package/src/irdevice/airpurifier.ts +19 -18
- package/src/irdevice/camera.ts +11 -10
- package/src/irdevice/fan.ts +21 -20
- package/src/irdevice/irdevice.ts +95 -70
- package/src/irdevice/light.ts +17 -18
- package/src/irdevice/other.ts +78 -77
- package/src/irdevice/tv.ts +37 -36
- package/src/irdevice/vacuumcleaner.ts +11 -10
- package/src/irdevice/waterheater.ts +11 -10
- package/src/platform.ts +290 -272
- package/src/settings.ts +30 -239
- package/src/types/bledevicestatus.ts +305 -0
- package/src/types/devicelist.ts +124 -0
- package/src/types/deviceresponse.ts +15 -0
- package/src/types/devicestatus.ts +178 -0
- package/src/types/devicewebhookstatus.ts +196 -0
- package/src/types/irdevicelist.ts +15 -0
- package/src/types/pushbody.ts +9 -0
- package/src/utils.ts +33 -0
package/src/irdevice/irdevice.ts
CHANGED
|
@@ -6,8 +6,9 @@ import { request } from 'undici';
|
|
|
6
6
|
import { Devices } from '../settings.js';
|
|
7
7
|
|
|
8
8
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
9
|
-
import type { API, HAP, Logging, PlatformAccessory } from 'homebridge';
|
|
10
|
-
import type { SwitchBotPlatformConfig, irDevicesConfig
|
|
9
|
+
import type { API, HAP, Logging, PlatformAccessory, Service, CharacteristicValue } from 'homebridge';
|
|
10
|
+
import type { SwitchBotPlatformConfig, irDevicesConfig } from '../settings.js';
|
|
11
|
+
import type { irdevice } from '../types/irdevicelist.js';
|
|
11
12
|
|
|
12
13
|
export abstract class irdeviceBase {
|
|
13
14
|
public readonly api: API;
|
|
@@ -52,16 +53,16 @@ export abstract class irdeviceBase {
|
|
|
52
53
|
async getDeviceLogSettings(device: irdevice & irDevicesConfig): Promise<void> {
|
|
53
54
|
if (this.platform.debugMode) {
|
|
54
55
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
55
|
-
this.debugWarnLog(
|
|
56
|
+
await this.debugWarnLog(`Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
56
57
|
} else if (device.logging) {
|
|
57
58
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
58
|
-
this.debugWarnLog(
|
|
59
|
+
await this.debugWarnLog(`Using Device Config Logging: ${this.deviceLogging}`);
|
|
59
60
|
} else if (this.config.logging) {
|
|
60
61
|
this.deviceLogging = this.accessory.context.logging = this.config.logging;
|
|
61
|
-
this.debugWarnLog(
|
|
62
|
+
await this.debugWarnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
|
|
62
63
|
} else {
|
|
63
64
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
64
|
-
this.debugWarnLog(
|
|
65
|
+
await this.debugWarnLog(`Logging Not Set, Using: ${this.deviceLogging}`);
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
|
|
@@ -136,7 +137,7 @@ export abstract class irdeviceBase {
|
|
|
136
137
|
const config = Object.assign({}, deviceConfig, irairConfig, irpurConfig, ircamConfig, irfanConfig, irlightConfig, otherConfig,
|
|
137
138
|
irtvConfig, irvcConfig, irwhConfig);
|
|
138
139
|
if (Object.entries(config).length !== 0) {
|
|
139
|
-
this.debugSuccessLog(
|
|
140
|
+
this.debugSuccessLog(`Config: ${JSON.stringify(config)}`);
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
|
|
@@ -171,7 +172,7 @@ export abstract class irdeviceBase {
|
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
174
|
const version = deviceFirmwareVersion.toString();
|
|
174
|
-
this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
|
|
175
|
+
await this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
|
|
175
176
|
let deviceVersion: string;
|
|
176
177
|
if (version?.includes('.') === false) {
|
|
177
178
|
const replace = version?.replace(/^V|-.*$/g, '');
|
|
@@ -179,7 +180,7 @@ export abstract class irdeviceBase {
|
|
|
179
180
|
const validVersion = match?.join('.');
|
|
180
181
|
deviceVersion = validVersion ?? '0.0.0';
|
|
181
182
|
} else {
|
|
182
|
-
deviceVersion = version
|
|
183
|
+
deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
183
184
|
}
|
|
184
185
|
accessory
|
|
185
186
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -200,21 +201,48 @@ export abstract class irdeviceBase {
|
|
|
200
201
|
});
|
|
201
202
|
}
|
|
202
203
|
|
|
204
|
+
async successfulStatusCodes(statusCode: any, deviceStatus: any) {
|
|
205
|
+
return (statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Update the characteristic value and log the change.
|
|
210
|
+
*
|
|
211
|
+
* @param Service: Service
|
|
212
|
+
* @param Characteristic: Characteristic
|
|
213
|
+
* @param CharacteristicValue: CharacteristicValue | undefined
|
|
214
|
+
* @param CharacteristicName: string
|
|
215
|
+
* @return: void
|
|
216
|
+
*
|
|
217
|
+
*/
|
|
218
|
+
async updateCharacteristic(Service: Service, Characteristic: any,
|
|
219
|
+
CharacteristicValue: CharacteristicValue | undefined, CharacteristicName: string): Promise<void> {
|
|
220
|
+
if (CharacteristicValue === undefined) {
|
|
221
|
+
await await this.debugLog(`${CharacteristicName}: ${CharacteristicValue}`);
|
|
222
|
+
} else {
|
|
223
|
+
Service.updateCharacteristic(Characteristic, CharacteristicValue);
|
|
224
|
+
await await this.debugLog(`updateCharacteristic ${CharacteristicName}: ${CharacteristicValue}`);
|
|
225
|
+
await await this.debugWarnLog(`context before: ${this.accessory.context[CharacteristicName]}`);
|
|
226
|
+
this.accessory.context[CharacteristicName] = CharacteristicValue;
|
|
227
|
+
await await this.debugWarnLog(`context after: ${this.accessory.context[CharacteristicName]}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
203
231
|
async pushStatusCodes(statusCode: any, deviceStatus: any) {
|
|
204
|
-
this.debugWarnLog(
|
|
205
|
-
this.debugWarnLog(
|
|
206
|
-
this.debugWarnLog(
|
|
232
|
+
await this.debugWarnLog(`statusCode: ${statusCode}`);
|
|
233
|
+
await this.debugWarnLog(`deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
234
|
+
await this.debugWarnLog(`deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
207
235
|
}
|
|
208
236
|
|
|
209
237
|
async successfulPushChange(statusCode: any, deviceStatus: any, bodyChange: any) {
|
|
210
|
-
this.debugSuccessLog(
|
|
238
|
+
this.debugSuccessLog(`statusCode: ${statusCode} & deviceStatus `
|
|
211
239
|
+ `StatusCode: ${deviceStatus.statusCode}`);
|
|
212
|
-
this.successLog(
|
|
240
|
+
this.successLog('request to SwitchBot API,'
|
|
213
241
|
+ ` body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
214
242
|
}
|
|
215
243
|
|
|
216
244
|
async pushChangeError(e: Error) {
|
|
217
|
-
this.errorLog(
|
|
245
|
+
this.errorLog(`failed pushChanges with ${this.device.connectionType}`
|
|
218
246
|
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
219
247
|
}
|
|
220
248
|
|
|
@@ -277,69 +305,66 @@ export abstract class irdeviceBase {
|
|
|
277
305
|
async statusCode(statusCode: number): Promise<void> {
|
|
278
306
|
switch (statusCode) {
|
|
279
307
|
case 151:
|
|
280
|
-
this.errorLog(
|
|
308
|
+
this.errorLog(`Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
281
309
|
break;
|
|
282
310
|
case 152:
|
|
283
|
-
this.errorLog(
|
|
311
|
+
this.errorLog(`Device not found, statusCode: ${statusCode}`);
|
|
284
312
|
break;
|
|
285
313
|
case 160:
|
|
286
|
-
this.errorLog(
|
|
314
|
+
this.errorLog(`Command is not supported, statusCode: ${statusCode}`);
|
|
287
315
|
break;
|
|
288
316
|
case 161:
|
|
289
|
-
this.errorLog(
|
|
317
|
+
this.errorLog(`Device is offline, statusCode: ${statusCode}`);
|
|
290
318
|
break;
|
|
291
319
|
case 171:
|
|
292
|
-
this.errorLog(
|
|
293
|
-
+ `Hub: ${this.device.hubDeviceId}`);
|
|
320
|
+
this.errorLog(`Hub Device is offline, statusCode: ${statusCode}. Hub: ${this.device.hubDeviceId}`);
|
|
294
321
|
break;
|
|
295
322
|
case 190:
|
|
296
|
-
this.errorLog(
|
|
297
|
-
+ `
|
|
323
|
+
this.errorLog('Device internal error due to device states not synchronized with server, Or command format is invalid,'
|
|
324
|
+
+ ` statusCode: ${statusCode}`);
|
|
298
325
|
break;
|
|
299
326
|
case 100:
|
|
300
|
-
this.debugLog(
|
|
327
|
+
await this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
|
|
301
328
|
break;
|
|
302
329
|
case 200:
|
|
303
|
-
this.debugLog(
|
|
330
|
+
await this.debugLog(`Request successful, statusCode: ${statusCode}`);
|
|
304
331
|
break;
|
|
305
332
|
case 400:
|
|
306
|
-
this.errorLog(
|
|
307
|
-
+ `
|
|
333
|
+
this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request'
|
|
334
|
+
+ ` payload, statusCode: ${statusCode}`);
|
|
308
335
|
break;
|
|
309
336
|
case 401:
|
|
310
|
-
this.errorLog(
|
|
311
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
337
|
+
this.errorLog(`Unauthorized, Authorization for the API is required, but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
312
338
|
break;
|
|
313
339
|
case 403:
|
|
314
|
-
this.errorLog(
|
|
315
|
-
+ `
|
|
340
|
+
this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not'
|
|
341
|
+
+ ` found, statusCode: ${statusCode}`);
|
|
316
342
|
break;
|
|
317
343
|
case 404:
|
|
318
|
-
this.errorLog(
|
|
319
|
-
+ `statusCode: ${statusCode}`);
|
|
344
|
+
this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
|
|
320
345
|
break;
|
|
321
346
|
case 406:
|
|
322
|
-
this.errorLog(
|
|
323
|
-
+ `
|
|
347
|
+
this.errorLog('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server,'
|
|
348
|
+
+ ` statusCode: ${statusCode}`);
|
|
324
349
|
break;
|
|
325
350
|
case 415:
|
|
326
|
-
this.errorLog(
|
|
327
|
-
+ `
|
|
351
|
+
this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server,'
|
|
352
|
+
+ ` statusCode: ${statusCode}`);
|
|
328
353
|
break;
|
|
329
354
|
case 422:
|
|
330
|
-
this.errorLog(
|
|
331
|
-
+ `
|
|
355
|
+
this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for APIs'
|
|
356
|
+
+ ` for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
332
357
|
break;
|
|
333
358
|
case 429:
|
|
334
|
-
this.errorLog(
|
|
335
|
-
+ `
|
|
359
|
+
this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window,'
|
|
360
|
+
+ ` statusCode: ${statusCode}`);
|
|
336
361
|
break;
|
|
337
362
|
case 500:
|
|
338
|
-
this.errorLog(
|
|
339
|
-
+ `
|
|
363
|
+
this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare,'
|
|
364
|
+
+ ` statusCode: ${statusCode}`);
|
|
340
365
|
break;
|
|
341
366
|
default:
|
|
342
|
-
this.infoLog(
|
|
367
|
+
this.infoLog('Unknown statusCode: '
|
|
343
368
|
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
344
369
|
}
|
|
345
370
|
}
|
|
@@ -347,65 +372,65 @@ export abstract class irdeviceBase {
|
|
|
347
372
|
/**
|
|
348
373
|
* Logging for Device
|
|
349
374
|
*/
|
|
350
|
-
infoLog(...log: any[]): void {
|
|
351
|
-
if (this.enablingDeviceLogging()) {
|
|
352
|
-
this.log.info(String(...log));
|
|
375
|
+
async infoLog(...log: any[]): Promise<void> {
|
|
376
|
+
if (await this.enablingDeviceLogging()) {
|
|
377
|
+
this.log.info(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
353
378
|
}
|
|
354
379
|
}
|
|
355
380
|
|
|
356
|
-
successLog(...log: any[]): void {
|
|
357
|
-
if (this.enablingDeviceLogging()) {
|
|
358
|
-
this.
|
|
381
|
+
async successLog(...log: any[]): Promise<void> {
|
|
382
|
+
if (await this.enablingDeviceLogging()) {
|
|
383
|
+
this.log.success(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
359
384
|
}
|
|
360
385
|
}
|
|
361
386
|
|
|
362
|
-
debugSuccessLog(...log: any[]): void {
|
|
363
|
-
if (this.enablingDeviceLogging()) {
|
|
387
|
+
async debugSuccessLog(...log: any[]): Promise<void> {
|
|
388
|
+
if (await this.enablingDeviceLogging()) {
|
|
364
389
|
if (this.deviceLogging?.includes('debug')) {
|
|
365
|
-
this.log.success(
|
|
390
|
+
this.log.success(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
366
391
|
}
|
|
367
392
|
}
|
|
368
393
|
}
|
|
369
394
|
|
|
370
|
-
warnLog(...log: any[]): void {
|
|
371
|
-
if (this.enablingDeviceLogging()) {
|
|
372
|
-
this.log.warn(String(...log));
|
|
395
|
+
async warnLog(...log: any[]): Promise<void> {
|
|
396
|
+
if (await this.enablingDeviceLogging()) {
|
|
397
|
+
this.log.warn(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
373
398
|
}
|
|
374
399
|
}
|
|
375
400
|
|
|
376
|
-
debugWarnLog(...log: any[]): void {
|
|
377
|
-
if (this.enablingDeviceLogging()) {
|
|
401
|
+
async debugWarnLog(...log: any[]): Promise<void> {
|
|
402
|
+
if (await this.enablingDeviceLogging()) {
|
|
378
403
|
if (this.deviceLogging?.includes('debug')) {
|
|
379
|
-
this.log.warn(
|
|
404
|
+
this.log.warn(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
380
405
|
}
|
|
381
406
|
}
|
|
382
407
|
}
|
|
383
408
|
|
|
384
|
-
errorLog(...log: any[]): void {
|
|
385
|
-
if (this.enablingDeviceLogging()) {
|
|
386
|
-
this.log.error(String(...log));
|
|
409
|
+
async errorLog(...log: any[]): Promise<void> {
|
|
410
|
+
if (await this.enablingDeviceLogging()) {
|
|
411
|
+
this.log.error(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
387
412
|
}
|
|
388
413
|
}
|
|
389
414
|
|
|
390
|
-
debugErrorLog(...log: any[]): void {
|
|
391
|
-
if (this.enablingDeviceLogging()) {
|
|
415
|
+
async debugErrorLog(...log: any[]): Promise<void> {
|
|
416
|
+
if (await this.enablingDeviceLogging()) {
|
|
392
417
|
if (this.deviceLogging?.includes('debug')) {
|
|
393
|
-
this.log.error(
|
|
418
|
+
this.log.error(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
394
419
|
}
|
|
395
420
|
}
|
|
396
421
|
}
|
|
397
422
|
|
|
398
|
-
debugLog(...log: any[]): void {
|
|
399
|
-
if (this.enablingDeviceLogging()) {
|
|
423
|
+
async debugLog(...log: any[]): Promise<void> {
|
|
424
|
+
if (await this.enablingDeviceLogging()) {
|
|
400
425
|
if (this.deviceLogging === 'debug') {
|
|
401
|
-
this.log.info(
|
|
426
|
+
this.log.info(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
402
427
|
} else {
|
|
403
|
-
this.log.debug(String(...log));
|
|
428
|
+
this.log.debug(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
404
429
|
}
|
|
405
430
|
}
|
|
406
431
|
}
|
|
407
432
|
|
|
408
|
-
enablingDeviceLogging(): boolean {
|
|
433
|
+
async enablingDeviceLogging(): Promise<boolean> {
|
|
409
434
|
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
410
435
|
}
|
|
411
436
|
}
|
package/src/irdevice/light.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { irdeviceBase } from './irdevice.js';
|
|
6
6
|
|
|
7
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
|
-
import type { irDevicesConfig
|
|
8
|
+
import type { irDevicesConfig } from '../settings.js';
|
|
9
|
+
import type { irdevice } from '../types/irdevicelist.js';
|
|
9
10
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -126,7 +127,7 @@ export class Light extends irdeviceBase {
|
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
129
|
-
this.debugLog(
|
|
130
|
+
await this.debugLog(`On: ${value}`);
|
|
130
131
|
|
|
131
132
|
this.LightBulb!.On = value;
|
|
132
133
|
if (this.LightBulb?.On) {
|
|
@@ -143,7 +144,7 @@ export class Light extends irdeviceBase {
|
|
|
143
144
|
}
|
|
144
145
|
|
|
145
146
|
async ProgrammableSwitchOutputStateSetOn(value: CharacteristicValue): Promise<void> {
|
|
146
|
-
this.debugLog(
|
|
147
|
+
await this.debugLog(`On: ${value}`);
|
|
147
148
|
|
|
148
149
|
this.ProgrammableSwitchOn!.ProgrammableSwitchOutputState = value;
|
|
149
150
|
if (this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState === 1) {
|
|
@@ -157,7 +158,7 @@ export class Light extends irdeviceBase {
|
|
|
157
158
|
}
|
|
158
159
|
|
|
159
160
|
async ProgrammableSwitchOutputStateSetOff(value: CharacteristicValue): Promise<void> {
|
|
160
|
-
this.debugLog(
|
|
161
|
+
await this.debugLog(`On: ${value}`);
|
|
161
162
|
|
|
162
163
|
this.ProgrammableSwitchOff!.ProgrammableSwitchOutputState = value;
|
|
163
164
|
if (this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState === 1) {
|
|
@@ -183,7 +184,7 @@ export class Light extends irdeviceBase {
|
|
|
183
184
|
* Light - "command" "channelSub" "default" = previous channel
|
|
184
185
|
*/
|
|
185
186
|
async pushLightOnChanges(On: boolean): Promise<void> {
|
|
186
|
-
this.debugLog(
|
|
187
|
+
await this.debugLog(`pushLightOnChanges On: ${On}, disablePushOn: ${this.disablePushOn}`);
|
|
187
188
|
if (On === true && this.disablePushOn === false) {
|
|
188
189
|
const commandType: string = await this.commandType();
|
|
189
190
|
const command: string = await this.commandOn();
|
|
@@ -197,7 +198,7 @@ export class Light extends irdeviceBase {
|
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
async pushLightOffChanges(On: boolean): Promise<void> {
|
|
200
|
-
this.debugLog(
|
|
201
|
+
await this.debugLog(`pushLightOffChanges On: ${On}, disablePushOff: ${this.disablePushOff}`);
|
|
201
202
|
if (On === false && this.disablePushOff === false) {
|
|
202
203
|
const commandType: string = await this.commandType();
|
|
203
204
|
const command: string = await this.commandOff();
|
|
@@ -211,9 +212,9 @@ export class Light extends irdeviceBase {
|
|
|
211
212
|
}
|
|
212
213
|
|
|
213
214
|
async pushChanges(bodyChange: any, On: boolean): Promise<void> {
|
|
214
|
-
this.debugLog(
|
|
215
|
+
this.debugLog('pushChanges');
|
|
215
216
|
if (this.device.connectionType === 'OpenAPI') {
|
|
216
|
-
this.infoLog(
|
|
217
|
+
this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
217
218
|
try {
|
|
218
219
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
219
220
|
const deviceStatus: any = await body.json();
|
|
@@ -231,43 +232,41 @@ export class Light extends irdeviceBase {
|
|
|
231
232
|
await this.pushChangeError(e);
|
|
232
233
|
}
|
|
233
234
|
} else {
|
|
234
|
-
this.warnLog(
|
|
235
|
+
this.warnLog('Connection Type: '
|
|
235
236
|
+ `${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
236
237
|
}
|
|
237
238
|
}
|
|
238
239
|
|
|
239
240
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
241
|
+
await this.debugLog('updateHomeKitCharacteristics');
|
|
240
242
|
if (!this.device.irlight?.stateless) {
|
|
241
243
|
// On
|
|
242
244
|
if (this.LightBulb?.On === undefined) {
|
|
243
|
-
this.debugLog(
|
|
245
|
+
await this.debugLog(`On: ${this.LightBulb?.On}`);
|
|
244
246
|
} else {
|
|
245
247
|
this.accessory.context.On = this.LightBulb.On;
|
|
246
248
|
this.LightBulb?.Service.updateCharacteristic(this.hap.Characteristic.On, this.LightBulb.On);
|
|
247
|
-
this.debugLog(
|
|
249
|
+
await this.debugLog(`updateCharacteristic On: ${this.LightBulb.On}`);
|
|
248
250
|
}
|
|
249
251
|
} else {
|
|
250
252
|
// On Stateful Programmable Switch
|
|
251
253
|
if (this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState === undefined) {
|
|
252
|
-
this.debugLog(
|
|
253
|
-
+ ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState}`);
|
|
254
|
+
await this.debugLog(`ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState}`);
|
|
254
255
|
} else {
|
|
255
256
|
this.accessory.context.ProgrammableSwitchOutputStateOn = this.ProgrammableSwitchOn.ProgrammableSwitchOutputState;
|
|
256
257
|
this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState,
|
|
257
258
|
this.ProgrammableSwitchOn.ProgrammableSwitchOutputState);
|
|
258
|
-
this.debugLog(
|
|
259
|
+
this.debugLog('updateCharacteristic'
|
|
259
260
|
+ ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOn.ProgrammableSwitchOutputState}`);
|
|
260
261
|
}
|
|
261
262
|
// Off Stateful Programmable Switch
|
|
262
263
|
if (this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState === undefined) {
|
|
263
|
-
this.debugLog(
|
|
264
|
-
+ ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
|
|
264
|
+
await this.debugLog(`ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
|
|
265
265
|
} else {
|
|
266
266
|
this.accessory.context.ProgrammableSwitchOutputStateOff = this.ProgrammableSwitchOff.ProgrammableSwitchOutputState;
|
|
267
267
|
this.ProgrammableSwitchOff.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState,
|
|
268
268
|
this.ProgrammableSwitchOff.ProgrammableSwitchOutputState);
|
|
269
|
-
this.debugLog(
|
|
270
|
-
+ ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
|
|
269
|
+
await this.debugLog(`updateCharacteristic ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
|
|
271
270
|
}
|
|
272
271
|
}
|
|
273
272
|
}
|