@switchbot/homebridge-switchbot 3.5.0-beta.4 → 3.5.0-beta.41
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/CHANGELOG.md +4 -1
- package/config.schema.json +120 -17
- package/dist/device/blindtilt.d.ts +21 -94
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +351 -757
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +25 -71
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +587 -761
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -67
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +213 -588
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -74
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +255 -634
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -65
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +208 -532
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -86
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +339 -787
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +59 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +671 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +51 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +504 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +15 -59
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +246 -597
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +10 -65
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +211 -572
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +178 -585
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -68
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +256 -569
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -62
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +214 -543
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -63
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +174 -578
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +13 -64
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +163 -578
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +141 -520
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +86 -453
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -62
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +144 -452
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +9 -70
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +125 -665
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +2 -2
- package/dist/index.js +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -48
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +309 -419
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +7 -38
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +72 -304
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +6 -35
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +34 -278
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +6 -39
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +67 -311
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +40 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +512 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +6 -34
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +23 -272
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +18 -47
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +352 -546
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -39
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +82 -321
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +6 -35
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -284
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -35
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +42 -287
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +343 -198
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +41 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +0 -552
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +77 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +638 -1
- package/dist/utils.js.map +1 -1
- package/package.json +16 -15
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +377 -783
- package/src/device/bot.ts +620 -845
- package/src/device/ceilinglight.ts +226 -608
- package/src/device/colorbulb.ts +268 -657
- package/src/device/contact.ts +233 -554
- package/src/device/curtain.ts +359 -811
- package/src/device/device.ts +699 -0
- package/src/device/fan.ts +553 -0
- package/src/device/hub.ts +273 -625
- package/src/device/humidifier.ts +241 -619
- package/src/device/iosensor.ts +204 -611
- package/src/device/lightstrip.ts +277 -597
- package/src/device/lock.ts +251 -583
- package/src/device/meter.ts +199 -601
- package/src/device/meterplus.ts +188 -603
- package/src/device/motion.ts +160 -542
- package/src/device/plug.ts +96 -481
- package/src/device/robotvacuumcleaner.ts +165 -478
- package/src/device/waterdetector.ts +142 -689
- package/src/homebridge-ui/public/index.html +2 -2
- package/src/index.ts +1 -1
- package/src/irdevice/airconditioner.ts +330 -446
- package/src/irdevice/airpurifier.ts +89 -321
- package/src/irdevice/camera.ts +42 -293
- package/src/irdevice/fan.ts +78 -327
- package/src/irdevice/irdevice.ts +528 -0
- package/src/irdevice/light.ts +32 -287
- package/src/irdevice/other.ts +396 -615
- package/src/irdevice/tv.ts +100 -339
- package/src/irdevice/vacuumcleaner.ts +49 -305
- package/src/irdevice/waterheater.ts +50 -310
- package/src/platform.ts +353 -206
- package/src/settings.ts +57 -566
- package/src/utils.ts +642 -1
package/src/irdevice/light.ts
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* light.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
2
5
|
import { request } from 'undici';
|
|
6
|
+
import { irdeviceBase } from './irdevice.js';
|
|
3
7
|
import { SwitchBotPlatform } from '../platform.js';
|
|
4
|
-
import { Devices, irDevicesConfig, irdevice
|
|
8
|
+
import { Devices, irDevicesConfig, irdevice } from '../settings.js';
|
|
9
|
+
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* Platform Accessory
|
|
8
13
|
* An instance of this class is created for each accessory your platform registers
|
|
9
14
|
* Each accessory may expose multiple services of different service types.
|
|
10
15
|
*/
|
|
11
|
-
export class Light {
|
|
12
|
-
public readonly api: API;
|
|
13
|
-
public readonly log: Logging;
|
|
14
|
-
public readonly config!: SwitchBotPlatformConfig;
|
|
15
|
-
protected readonly hap: HAP;
|
|
16
|
+
export class Light extends irdeviceBase {
|
|
16
17
|
// Services
|
|
17
|
-
|
|
18
|
+
private LightBulb!: {
|
|
19
|
+
Service: Service;
|
|
20
|
+
On: CharacteristicValue;
|
|
21
|
+
};
|
|
22
|
+
|
|
18
23
|
ProgrammableSwitchServiceOn?: Service;
|
|
19
24
|
ProgrammableSwitchServiceOff?: Service;
|
|
20
25
|
|
|
@@ -24,52 +29,31 @@ export class Light {
|
|
|
24
29
|
ProgrammableSwitchOutputStateOn?: CharacteristicValue;
|
|
25
30
|
ProgrammableSwitchEventOff?: CharacteristicValue;
|
|
26
31
|
ProgrammableSwitchOutputStateOff?: CharacteristicValue;
|
|
27
|
-
FirmwareRevision!: CharacteristicValue;
|
|
28
|
-
|
|
29
|
-
// Config
|
|
30
|
-
deviceLogging!: string;
|
|
31
|
-
disablePushOn?: boolean;
|
|
32
|
-
disablePushOff?: boolean;
|
|
33
32
|
|
|
34
33
|
constructor(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
readonly platform: SwitchBotPlatform,
|
|
35
|
+
accessory: PlatformAccessory,
|
|
36
|
+
device: irdevice & irDevicesConfig,
|
|
38
37
|
) {
|
|
39
|
-
|
|
40
|
-
this.log = this.platform.log;
|
|
41
|
-
this.config = this.platform.config;
|
|
42
|
-
this.hap = this.api.hap;
|
|
43
|
-
// default placeholders
|
|
44
|
-
this.deviceLogs(device);
|
|
45
|
-
this.deviceContext();
|
|
46
|
-
this.disablePushOnChanges(device);
|
|
47
|
-
this.disablePushOffChanges(device);
|
|
48
|
-
this.deviceConfig(device);
|
|
49
|
-
|
|
50
|
-
// set accessory information
|
|
51
|
-
accessory
|
|
52
|
-
.getService(this.hap.Service.AccessoryInformation)!
|
|
53
|
-
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
54
|
-
.setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
|
|
55
|
-
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
56
|
-
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
38
|
+
super(platform, accessory, device);
|
|
57
39
|
|
|
58
40
|
if (!device.irlight?.stateless) {
|
|
41
|
+
// Initialize LightBulb property
|
|
42
|
+
this.LightBulb = {
|
|
43
|
+
Service: accessory.getService(this.hap.Service.Lightbulb)!,
|
|
44
|
+
On: accessory.context.On || false,
|
|
45
|
+
};
|
|
59
46
|
// get the Light service if it exists, otherwise create a new Light service
|
|
60
47
|
// you can create multiple services for each accessory
|
|
61
|
-
const
|
|
62
|
-
(this.
|
|
63
|
-
|| accessory.addService(this.hap.Service.Lightbulb)),
|
|
48
|
+
const LightBulbService = `${accessory.displayName} ${device.remoteType}`;
|
|
49
|
+
(this.LightBulb.Service = accessory.getService(this.hap.Service.Lightbulb)
|
|
50
|
+
|| accessory.addService(this.hap.Service.Lightbulb)), LightBulbService;
|
|
64
51
|
|
|
65
52
|
|
|
66
|
-
this.
|
|
67
|
-
if (!this.lightBulbService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
68
|
-
this.lightBulbService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
69
|
-
}
|
|
53
|
+
this.LightBulb.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
70
54
|
|
|
71
55
|
// handle on / off events using the On characteristic
|
|
72
|
-
this.
|
|
56
|
+
this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
73
57
|
} else {
|
|
74
58
|
|
|
75
59
|
// create a new Stateful Programmable Switch On service
|
|
@@ -79,9 +63,6 @@ export class Light {
|
|
|
79
63
|
|
|
80
64
|
|
|
81
65
|
this.ProgrammableSwitchServiceOn.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} On`);
|
|
82
|
-
if (!this.ProgrammableSwitchServiceOn.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
83
|
-
this.ProgrammableSwitchServiceOn.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} On`);
|
|
84
|
-
}
|
|
85
66
|
|
|
86
67
|
this.ProgrammableSwitchServiceOn.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
|
|
87
68
|
validValueRanges: [0, 0],
|
|
@@ -105,9 +86,6 @@ export class Light {
|
|
|
105
86
|
|
|
106
87
|
|
|
107
88
|
this.ProgrammableSwitchServiceOff.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Off`);
|
|
108
|
-
if (!this.ProgrammableSwitchServiceOff.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
109
|
-
this.ProgrammableSwitchServiceOff.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Off`);
|
|
110
|
-
}
|
|
111
89
|
|
|
112
90
|
this.ProgrammableSwitchServiceOff.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
|
|
113
91
|
validValueRanges: [0, 0],
|
|
@@ -245,8 +223,10 @@ export class Light {
|
|
|
245
223
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
246
224
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
247
225
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
248
|
-
this.
|
|
226
|
+
this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
|
|
249
227
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
228
|
+
this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
229
|
+
+ ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
|
|
250
230
|
this.accessory.context.On = this.On;
|
|
251
231
|
this.updateHomeKitCharacteristics();
|
|
252
232
|
} else {
|
|
@@ -275,7 +255,7 @@ export class Light {
|
|
|
275
255
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
276
256
|
} else {
|
|
277
257
|
this.accessory.context.On = this.On;
|
|
278
|
-
this.
|
|
258
|
+
this.LightBulb.Service?.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
279
259
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
280
260
|
}
|
|
281
261
|
} else {
|
|
@@ -304,131 +284,9 @@ export class Light {
|
|
|
304
284
|
}
|
|
305
285
|
}
|
|
306
286
|
|
|
307
|
-
async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
308
|
-
if (device.disablePushOn === undefined) {
|
|
309
|
-
this.disablePushOn = false;
|
|
310
|
-
} else {
|
|
311
|
-
this.disablePushOn = device.disablePushOn;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
316
|
-
if (device.disablePushOff === undefined) {
|
|
317
|
-
this.disablePushOff = false;
|
|
318
|
-
} else {
|
|
319
|
-
this.disablePushOff = device.disablePushOff;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
async commandType(): Promise<string> {
|
|
324
|
-
let commandType: string;
|
|
325
|
-
if (this.device.customize) {
|
|
326
|
-
commandType = 'customize';
|
|
327
|
-
} else {
|
|
328
|
-
commandType = 'command';
|
|
329
|
-
}
|
|
330
|
-
return commandType;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
async commandOn(): Promise<string> {
|
|
334
|
-
let command: string;
|
|
335
|
-
if (this.device.customize && this.device.customOn) {
|
|
336
|
-
command = this.device.customOn;
|
|
337
|
-
} else {
|
|
338
|
-
command = 'turnOn';
|
|
339
|
-
}
|
|
340
|
-
return command;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
async commandOff(): Promise<string> {
|
|
344
|
-
let command: string;
|
|
345
|
-
if (this.device.customize && this.device.customOff) {
|
|
346
|
-
command = this.device.customOff;
|
|
347
|
-
} else {
|
|
348
|
-
command = 'turnOff';
|
|
349
|
-
}
|
|
350
|
-
return command;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
async statusCode(statusCode: number): Promise<void> {
|
|
354
|
-
switch (statusCode) {
|
|
355
|
-
case 151:
|
|
356
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
357
|
-
break;
|
|
358
|
-
case 152:
|
|
359
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
360
|
-
break;
|
|
361
|
-
case 160:
|
|
362
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
363
|
-
break;
|
|
364
|
-
case 161:
|
|
365
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
366
|
-
break;
|
|
367
|
-
case 171:
|
|
368
|
-
this.errorLog(
|
|
369
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
370
|
-
`Hub: ${this.device.hubDeviceId}`,
|
|
371
|
-
);
|
|
372
|
-
break;
|
|
373
|
-
case 190:
|
|
374
|
-
this.errorLog(
|
|
375
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
376
|
-
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
377
|
-
);
|
|
378
|
-
break;
|
|
379
|
-
case 100:
|
|
380
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
381
|
-
break;
|
|
382
|
-
case 200:
|
|
383
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
384
|
-
break;
|
|
385
|
-
case 400:
|
|
386
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
387
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
388
|
-
break;
|
|
389
|
-
case 401:
|
|
390
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
391
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
392
|
-
break;
|
|
393
|
-
case 403:
|
|
394
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
395
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
396
|
-
break;
|
|
397
|
-
case 404:
|
|
398
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
399
|
-
+ `statusCode: ${statusCode}`);
|
|
400
|
-
break;
|
|
401
|
-
case 406:
|
|
402
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
403
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
404
|
-
break;
|
|
405
|
-
case 415:
|
|
406
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
407
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
408
|
-
break;
|
|
409
|
-
case 422:
|
|
410
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
|
|
411
|
-
+ `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
412
|
-
break;
|
|
413
|
-
case 429:
|
|
414
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
415
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
416
|
-
break;
|
|
417
|
-
case 500:
|
|
418
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
419
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
420
|
-
break;
|
|
421
|
-
default:
|
|
422
|
-
this.infoLog(
|
|
423
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
424
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
425
|
-
);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
287
|
async apiError(e: any): Promise<void> {
|
|
430
288
|
if (this.device.irlight?.stateless) {
|
|
431
|
-
this.
|
|
289
|
+
this.LightBulb.Service?.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
432
290
|
} else {
|
|
433
291
|
this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
|
|
434
292
|
this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
@@ -436,117 +294,4 @@ export class Light {
|
|
|
436
294
|
this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
437
295
|
}
|
|
438
296
|
}
|
|
439
|
-
|
|
440
|
-
async deviceContext() {
|
|
441
|
-
if (this.On === undefined) {
|
|
442
|
-
this.On = false;
|
|
443
|
-
} else {
|
|
444
|
-
this.On = this.accessory.context.On;
|
|
445
|
-
}
|
|
446
|
-
if (this.FirmwareRevision === undefined) {
|
|
447
|
-
this.FirmwareRevision = this.platform.version;
|
|
448
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
|
|
453
|
-
let config = {};
|
|
454
|
-
if (device.irlight) {
|
|
455
|
-
config = device.irlight;
|
|
456
|
-
}
|
|
457
|
-
if (device.logging !== undefined) {
|
|
458
|
-
config['logging'] = device.logging;
|
|
459
|
-
}
|
|
460
|
-
if (device.connectionType !== undefined) {
|
|
461
|
-
config['connectionType'] = device.connectionType;
|
|
462
|
-
}
|
|
463
|
-
if (device.external !== undefined) {
|
|
464
|
-
config['external'] = device.external;
|
|
465
|
-
}
|
|
466
|
-
if (device.customOn !== undefined) {
|
|
467
|
-
config['customOn'] = device.customOn;
|
|
468
|
-
}
|
|
469
|
-
if (device.customOff !== undefined) {
|
|
470
|
-
config['customOff'] = device.customOff;
|
|
471
|
-
}
|
|
472
|
-
if (device.customize !== undefined) {
|
|
473
|
-
config['customize'] = device.customize;
|
|
474
|
-
}
|
|
475
|
-
if (device.disablePushOn !== undefined) {
|
|
476
|
-
config['disablePushOn'] = device.disablePushOn;
|
|
477
|
-
}
|
|
478
|
-
if (device.disablePushOff !== undefined) {
|
|
479
|
-
config['disablePushOff'] = device.disablePushOff;
|
|
480
|
-
}
|
|
481
|
-
if (Object.entries(config).length !== 0) {
|
|
482
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
487
|
-
if (this.platform.debugMode) {
|
|
488
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
489
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
490
|
-
} else if (device.logging) {
|
|
491
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
492
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
493
|
-
} else if (this.platform.config.options?.logging) {
|
|
494
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
495
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
496
|
-
} else {
|
|
497
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
498
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* Logging for Device
|
|
504
|
-
*/
|
|
505
|
-
infoLog(...log: any[]): void {
|
|
506
|
-
if (this.enablingDeviceLogging()) {
|
|
507
|
-
this.platform.log.info(String(...log));
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
warnLog(...log: any[]): void {
|
|
512
|
-
if (this.enablingDeviceLogging()) {
|
|
513
|
-
this.platform.log.warn(String(...log));
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
debugWarnLog(...log: any[]): void {
|
|
518
|
-
if (this.enablingDeviceLogging()) {
|
|
519
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
520
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
errorLog(...log: any[]): void {
|
|
526
|
-
if (this.enablingDeviceLogging()) {
|
|
527
|
-
this.platform.log.error(String(...log));
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
debugErrorLog(...log: any[]): void {
|
|
532
|
-
if (this.enablingDeviceLogging()) {
|
|
533
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
534
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
debugLog(...log: any[]): void {
|
|
540
|
-
if (this.enablingDeviceLogging()) {
|
|
541
|
-
if (this.deviceLogging === 'debug') {
|
|
542
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
543
|
-
} else {
|
|
544
|
-
this.platform.log.debug(String(...log));
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
enablingDeviceLogging(): boolean {
|
|
550
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
551
|
-
}
|
|
552
297
|
}
|