@switchbot/homebridge-switchbot 3.5.0-beta.22 → 3.5.0-beta.24
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/config.schema.json +23 -2
- package/dist/device/blindtilt.d.ts +21 -98
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +332 -785
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +25 -75
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +566 -778
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -71
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +168 -606
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -78
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +218 -655
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -69
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +196 -553
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -90
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +324 -810
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +58 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +629 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/hub.d.ts +15 -63
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +223 -610
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +10 -69
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +192 -595
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -68
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +156 -599
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -72
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +204 -591
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -66
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +199 -566
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -67
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +152 -592
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +13 -68
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +151 -599
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -73
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +129 -540
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -61
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +71 -476
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -66
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +122 -471
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +9 -66
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +105 -478
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +5 -36
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +228 -337
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +5 -34
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +19 -267
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +5 -34
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +13 -261
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +5 -34
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +13 -260
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +39 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +502 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +5 -34
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +13 -267
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +18 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +349 -551
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +79 -325
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +6 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +38 -288
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +39 -291
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +15 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/utils.d.ts +68 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +71 -0
- package/dist/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/device/blindtilt.ts +356 -809
- package/src/device/bot.ts +601 -865
- package/src/device/ceilinglight.ts +182 -628
- package/src/device/colorbulb.ts +235 -683
- package/src/device/contact.ts +220 -575
- package/src/device/curtain.ts +344 -836
- package/src/device/device.ts +655 -0
- package/src/device/hub.ts +246 -636
- package/src/device/humidifier.ts +224 -645
- package/src/device/iosensor.ts +181 -625
- package/src/device/lightstrip.ts +230 -622
- package/src/device/lock.ts +236 -607
- package/src/device/meter.ts +177 -616
- package/src/device/meterplus.ts +175 -624
- package/src/device/motion.ts +147 -563
- package/src/device/plug.ts +81 -505
- package/src/device/robotvacuumcleaner.ts +139 -494
- package/src/device/waterdetector.ts +126 -506
- package/src/irdevice/airconditioner.ts +228 -353
- package/src/irdevice/airpurifier.ts +23 -282
- package/src/irdevice/camera.ts +18 -277
- package/src/irdevice/fan.ts +18 -275
- package/src/irdevice/irdevice.ts +518 -0
- package/src/irdevice/light.ts +18 -283
- package/src/irdevice/other.ts +394 -621
- package/src/irdevice/tv.ts +97 -344
- package/src/irdevice/vacuumcleaner.ts +46 -310
- package/src/irdevice/waterheater.ts +47 -315
- package/src/settings.ts +20 -3
- package/src/utils.ts +71 -0
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* airpurifier.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 AirPurifier {
|
|
12
|
-
public readonly api: API;
|
|
13
|
-
public readonly log: Logging;
|
|
14
|
-
public readonly config!: SwitchBotPlatformConfig;
|
|
15
|
-
protected readonly hap: HAP;
|
|
16
|
+
export class AirPurifier extends irdeviceBase {
|
|
16
17
|
// Services
|
|
17
18
|
airPurifierService!: Service;
|
|
18
19
|
|
|
@@ -22,7 +23,6 @@ export class AirPurifier {
|
|
|
22
23
|
CurrentAPTemp!: CharacteristicValue;
|
|
23
24
|
CurrentAPMode!: CharacteristicValue;
|
|
24
25
|
RotationSpeed!: CharacteristicValue;
|
|
25
|
-
FirmwareRevision!: CharacteristicValue;
|
|
26
26
|
CurrentAPFanSpeed!: CharacteristicValue;
|
|
27
27
|
CurrentTemperature!: CharacteristicValue;
|
|
28
28
|
CurrentAirPurifierState!: CharacteristicValue;
|
|
@@ -38,34 +38,24 @@ export class AirPurifier {
|
|
|
38
38
|
CurrentFanSpeed!: number;
|
|
39
39
|
static PURIFYING_AIR: number;
|
|
40
40
|
|
|
41
|
-
// Config
|
|
42
|
-
disablePushOn?: boolean;
|
|
43
|
-
disablePushOff?: boolean;
|
|
44
|
-
deviceLogging!: string;
|
|
45
|
-
|
|
46
41
|
constructor(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
readonly platform: SwitchBotPlatform,
|
|
43
|
+
accessory: PlatformAccessory,
|
|
44
|
+
device: irdevice & irDevicesConfig,
|
|
50
45
|
) {
|
|
51
|
-
|
|
52
|
-
this.log = this.platform.log;
|
|
53
|
-
this.config = this.platform.config;
|
|
54
|
-
this.hap = this.api.hap;
|
|
55
|
-
// default placeholders
|
|
56
|
-
this.deviceLogs(device);
|
|
57
|
-
this.deviceContext();
|
|
58
|
-
this.disablePushOnChanges(device);
|
|
59
|
-
this.disablePushOffChanges(device);
|
|
60
|
-
this.deviceConfig(device);
|
|
46
|
+
super(platform, accessory, device);
|
|
61
47
|
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
.
|
|
65
|
-
|
|
66
|
-
.
|
|
67
|
-
|
|
68
|
-
|
|
48
|
+
// default placeholders
|
|
49
|
+
if (this.Active === undefined) {
|
|
50
|
+
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
51
|
+
} else {
|
|
52
|
+
this.Active = this.accessory.context.Active;
|
|
53
|
+
}
|
|
54
|
+
if (this.CurrentTemperature === undefined) {
|
|
55
|
+
this.CurrentTemperature = 24;
|
|
56
|
+
} else {
|
|
57
|
+
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
58
|
+
}
|
|
69
59
|
|
|
70
60
|
// get the Television service if it exists, otherwise create a new Television service
|
|
71
61
|
// you can create multiple services for each accessory
|
|
@@ -74,9 +64,6 @@ export class AirPurifier {
|
|
|
74
64
|
|| accessory.addService(this.hap.Service.AirPurifier)), airPurifierService;
|
|
75
65
|
|
|
76
66
|
this.airPurifierService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
77
|
-
if (!this.airPurifierService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
78
|
-
this.airPurifierService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
79
|
-
}
|
|
80
67
|
// handle on / off events using the Active characteristic
|
|
81
68
|
this.airPurifierService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
82
69
|
|
|
@@ -280,256 +267,10 @@ export class AirPurifier {
|
|
|
280
267
|
}
|
|
281
268
|
}
|
|
282
269
|
|
|
283
|
-
async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
284
|
-
if (device.disablePushOn === undefined) {
|
|
285
|
-
this.disablePushOn = false;
|
|
286
|
-
} else {
|
|
287
|
-
this.disablePushOn = device.disablePushOn;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
292
|
-
if (device.disablePushOff === undefined) {
|
|
293
|
-
this.disablePushOff = false;
|
|
294
|
-
} else {
|
|
295
|
-
this.disablePushOff = device.disablePushOff;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
async commandType(): Promise<string> {
|
|
300
|
-
let commandType: string;
|
|
301
|
-
if (this.device.customize) {
|
|
302
|
-
commandType = 'customize';
|
|
303
|
-
} else {
|
|
304
|
-
commandType = 'command';
|
|
305
|
-
}
|
|
306
|
-
return commandType;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
async commandOn(): Promise<string> {
|
|
310
|
-
let command: string;
|
|
311
|
-
if (this.device.customize && this.device.customOn) {
|
|
312
|
-
command = this.device.customOn;
|
|
313
|
-
} else {
|
|
314
|
-
command = 'turnOn';
|
|
315
|
-
}
|
|
316
|
-
return command;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
async commandOff(): Promise<string> {
|
|
320
|
-
let command: string;
|
|
321
|
-
if (this.device.customize && this.device.customOff) {
|
|
322
|
-
command = this.device.customOff;
|
|
323
|
-
} else {
|
|
324
|
-
command = 'turnOff';
|
|
325
|
-
}
|
|
326
|
-
return command;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
async statusCode(statusCode: number): Promise<void> {
|
|
330
|
-
switch (statusCode) {
|
|
331
|
-
case 151:
|
|
332
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
333
|
-
break;
|
|
334
|
-
case 152:
|
|
335
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
336
|
-
break;
|
|
337
|
-
case 160:
|
|
338
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
339
|
-
break;
|
|
340
|
-
case 161:
|
|
341
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
342
|
-
break;
|
|
343
|
-
case 171:
|
|
344
|
-
this.errorLog(
|
|
345
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
346
|
-
`Hub: ${this.device.hubDeviceId}`,
|
|
347
|
-
);
|
|
348
|
-
break;
|
|
349
|
-
case 190:
|
|
350
|
-
this.errorLog(
|
|
351
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
352
|
-
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
353
|
-
);
|
|
354
|
-
break;
|
|
355
|
-
case 100:
|
|
356
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
357
|
-
break;
|
|
358
|
-
case 200:
|
|
359
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
360
|
-
break;
|
|
361
|
-
case 400:
|
|
362
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
363
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
364
|
-
break;
|
|
365
|
-
case 401:
|
|
366
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
367
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
368
|
-
break;
|
|
369
|
-
case 403:
|
|
370
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
371
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
372
|
-
break;
|
|
373
|
-
case 404:
|
|
374
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
375
|
-
+ `statusCode: ${statusCode}`);
|
|
376
|
-
break;
|
|
377
|
-
case 406:
|
|
378
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
379
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
380
|
-
break;
|
|
381
|
-
case 415:
|
|
382
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
383
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
384
|
-
break;
|
|
385
|
-
case 422:
|
|
386
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
|
|
387
|
-
+ `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
388
|
-
break;
|
|
389
|
-
case 429:
|
|
390
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
391
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
392
|
-
break;
|
|
393
|
-
case 500:
|
|
394
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
395
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
396
|
-
break;
|
|
397
|
-
default:
|
|
398
|
-
this.infoLog(
|
|
399
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
400
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
401
|
-
);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
270
|
async apiError(e: any): Promise<void> {
|
|
406
271
|
this.airPurifierService.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, e);
|
|
407
272
|
this.airPurifierService.updateCharacteristic(this.hap.Characteristic.CurrentAirPurifierState, e);
|
|
408
273
|
this.airPurifierService.updateCharacteristic(this.hap.Characteristic.TargetAirPurifierState, e);
|
|
409
274
|
this.airPurifierService.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
410
275
|
}
|
|
411
|
-
|
|
412
|
-
private deviceContext() {
|
|
413
|
-
if (this.Active === undefined) {
|
|
414
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
415
|
-
} else {
|
|
416
|
-
this.Active = this.accessory.context.Active;
|
|
417
|
-
}
|
|
418
|
-
if (this.CurrentTemperature === undefined) {
|
|
419
|
-
this.CurrentTemperature = 24;
|
|
420
|
-
} else {
|
|
421
|
-
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
422
|
-
}
|
|
423
|
-
if (this.FirmwareRevision === undefined) {
|
|
424
|
-
this.FirmwareRevision = this.platform.version;
|
|
425
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
|
|
430
|
-
let config = {};
|
|
431
|
-
if (device.irpur) {
|
|
432
|
-
config = device.irpur;
|
|
433
|
-
}
|
|
434
|
-
if (device.logging !== undefined) {
|
|
435
|
-
config['logging'] = device.logging;
|
|
436
|
-
}
|
|
437
|
-
if (device.connectionType !== undefined) {
|
|
438
|
-
config['connectionType'] = device.connectionType;
|
|
439
|
-
}
|
|
440
|
-
if (device.external !== undefined) {
|
|
441
|
-
config['external'] = device.external;
|
|
442
|
-
}
|
|
443
|
-
if (device.customOn !== undefined) {
|
|
444
|
-
config['customOn'] = device.customOn;
|
|
445
|
-
}
|
|
446
|
-
if (device.customOff !== undefined) {
|
|
447
|
-
config['customOff'] = device.customOff;
|
|
448
|
-
}
|
|
449
|
-
if (device.customize !== undefined) {
|
|
450
|
-
config['customize'] = device.customize;
|
|
451
|
-
}
|
|
452
|
-
if (device.disablePushOn !== undefined) {
|
|
453
|
-
config['disablePushOn'] = device.disablePushOn;
|
|
454
|
-
}
|
|
455
|
-
if (device.disablePushOff !== undefined) {
|
|
456
|
-
config['disablePushOff'] = device.disablePushOff;
|
|
457
|
-
}
|
|
458
|
-
if (Object.entries(config).length !== 0) {
|
|
459
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
464
|
-
if (this.platform.debugMode) {
|
|
465
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
466
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
467
|
-
} else if (device.logging) {
|
|
468
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
469
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
470
|
-
} else if (this.platform.config.options?.logging) {
|
|
471
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
472
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
473
|
-
} else {
|
|
474
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
475
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Logging for Device
|
|
481
|
-
*/
|
|
482
|
-
successLog(...log: any[]): void {
|
|
483
|
-
if (this.enablingDeviceLogging()) {
|
|
484
|
-
this.platform.log.success(String(...log));
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
infoLog(...log: any[]): void {
|
|
489
|
-
if (this.enablingDeviceLogging()) {
|
|
490
|
-
this.platform.log.info(String(...log));
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
warnLog(...log: any[]): void {
|
|
495
|
-
if (this.enablingDeviceLogging()) {
|
|
496
|
-
this.platform.log.warn(String(...log));
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
debugWarnLog(...log: any[]): void {
|
|
501
|
-
if (this.enablingDeviceLogging()) {
|
|
502
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
503
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
errorLog(...log: any[]): void {
|
|
509
|
-
if (this.enablingDeviceLogging()) {
|
|
510
|
-
this.platform.log.error(String(...log));
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
debugErrorLog(...log: any[]): void {
|
|
515
|
-
if (this.enablingDeviceLogging()) {
|
|
516
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
517
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
debugLog(...log: any[]): void {
|
|
523
|
-
if (this.enablingDeviceLogging()) {
|
|
524
|
-
if (this.deviceLogging === 'debug') {
|
|
525
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
526
|
-
} else {
|
|
527
|
-
this.platform.log.debug(String(...log));
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
enablingDeviceLogging(): boolean {
|
|
533
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
534
|
-
}
|
|
535
276
|
}
|
package/src/irdevice/camera.ts
CHANGED
|
@@ -1,53 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* camera.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 Camera {
|
|
12
|
-
public readonly api: API;
|
|
13
|
-
public readonly log: Logging;
|
|
14
|
-
public readonly config!: SwitchBotPlatformConfig;
|
|
15
|
-
protected readonly hap: HAP;
|
|
16
|
+
export class Camera extends irdeviceBase {
|
|
16
17
|
// Services
|
|
17
18
|
switchService!: Service;
|
|
18
19
|
|
|
19
20
|
// Characteristic Values
|
|
20
21
|
On!: CharacteristicValue;
|
|
21
|
-
FirmwareRevision!: CharacteristicValue;
|
|
22
|
-
|
|
23
|
-
// Config
|
|
24
|
-
deviceLogging!: string;
|
|
25
|
-
disablePushOn?: boolean;
|
|
26
|
-
disablePushOff?: boolean;
|
|
27
22
|
|
|
28
23
|
constructor(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
readonly platform: SwitchBotPlatform,
|
|
25
|
+
accessory: PlatformAccessory,
|
|
26
|
+
device: irdevice & irDevicesConfig,
|
|
32
27
|
) {
|
|
33
|
-
|
|
34
|
-
this.log = this.platform.log;
|
|
35
|
-
this.config = this.platform.config;
|
|
36
|
-
this.hap = this.api.hap;
|
|
37
|
-
// default placeholders
|
|
38
|
-
this.deviceLogs(device);
|
|
39
|
-
this.deviceContext();
|
|
40
|
-
this.disablePushOnChanges(device);
|
|
41
|
-
this.disablePushOffChanges(device);
|
|
42
|
-
this.deviceConfig(device);
|
|
28
|
+
super(platform, accessory, device);
|
|
43
29
|
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
30
|
+
// default placeholders
|
|
31
|
+
if (this.On === undefined) {
|
|
32
|
+
this.On = false;
|
|
33
|
+
} else {
|
|
34
|
+
this.On = accessory.context.On;
|
|
35
|
+
}
|
|
51
36
|
|
|
52
37
|
// get the Television service if it exists, otherwise create a new Television service
|
|
53
38
|
// you can create multiple services for each accessory
|
|
@@ -56,9 +41,6 @@ export class Camera {
|
|
|
56
41
|
|| accessory.addService(this.hap.Service.Switch)), switchService;
|
|
57
42
|
|
|
58
43
|
this.switchService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
59
|
-
if (!this.switchService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
60
|
-
this.switchService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
61
|
-
}
|
|
62
44
|
|
|
63
45
|
// handle on / off events using the On characteristic
|
|
64
46
|
this.switchService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
@@ -164,248 +146,7 @@ export class Camera {
|
|
|
164
146
|
}
|
|
165
147
|
}
|
|
166
148
|
|
|
167
|
-
async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
168
|
-
if (device.disablePushOn === undefined) {
|
|
169
|
-
this.disablePushOn = false;
|
|
170
|
-
} else {
|
|
171
|
-
this.disablePushOn = device.disablePushOn;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
176
|
-
if (device.disablePushOff === undefined) {
|
|
177
|
-
this.disablePushOff = false;
|
|
178
|
-
} else {
|
|
179
|
-
this.disablePushOff = device.disablePushOff;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
async commandType(): Promise<string> {
|
|
184
|
-
let commandType: string;
|
|
185
|
-
if (this.device.customize) {
|
|
186
|
-
commandType = 'customize';
|
|
187
|
-
} else {
|
|
188
|
-
commandType = 'command';
|
|
189
|
-
}
|
|
190
|
-
return commandType;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async commandOn(): Promise<string> {
|
|
194
|
-
let command: string;
|
|
195
|
-
if (this.device.customize && this.device.customOn) {
|
|
196
|
-
command = this.device.customOn;
|
|
197
|
-
} else {
|
|
198
|
-
command = 'turnOn';
|
|
199
|
-
}
|
|
200
|
-
return command;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
async commandOff(): Promise<string> {
|
|
204
|
-
let command: string;
|
|
205
|
-
if (this.device.customize && this.device.customOff) {
|
|
206
|
-
command = this.device.customOff;
|
|
207
|
-
} else {
|
|
208
|
-
command = 'turnOff';
|
|
209
|
-
}
|
|
210
|
-
return command;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
async statusCode(statusCode: number): Promise<void> {
|
|
214
|
-
switch (statusCode) {
|
|
215
|
-
case 151:
|
|
216
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
217
|
-
break;
|
|
218
|
-
case 152:
|
|
219
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
220
|
-
break;
|
|
221
|
-
case 160:
|
|
222
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
223
|
-
break;
|
|
224
|
-
case 161:
|
|
225
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
226
|
-
break;
|
|
227
|
-
case 171:
|
|
228
|
-
this.errorLog(
|
|
229
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
230
|
-
`Hub: ${this.device.hubDeviceId}`,
|
|
231
|
-
);
|
|
232
|
-
break;
|
|
233
|
-
case 190:
|
|
234
|
-
this.errorLog(
|
|
235
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
236
|
-
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
237
|
-
);
|
|
238
|
-
break;
|
|
239
|
-
case 100:
|
|
240
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
241
|
-
break;
|
|
242
|
-
case 200:
|
|
243
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
244
|
-
break;
|
|
245
|
-
case 400:
|
|
246
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
247
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
248
|
-
break;
|
|
249
|
-
case 401:
|
|
250
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
251
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
252
|
-
break;
|
|
253
|
-
case 403:
|
|
254
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
255
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
256
|
-
break;
|
|
257
|
-
case 404:
|
|
258
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
259
|
-
+ `statusCode: ${statusCode}`);
|
|
260
|
-
break;
|
|
261
|
-
case 406:
|
|
262
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
263
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
264
|
-
break;
|
|
265
|
-
case 415:
|
|
266
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
267
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
268
|
-
break;
|
|
269
|
-
case 422:
|
|
270
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
|
|
271
|
-
+ `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
272
|
-
break;
|
|
273
|
-
case 429:
|
|
274
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
275
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
276
|
-
break;
|
|
277
|
-
case 500:
|
|
278
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
279
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
280
|
-
break;
|
|
281
|
-
default:
|
|
282
|
-
this.infoLog(
|
|
283
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
284
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
149
|
async apiError(e: any): Promise<void> {
|
|
290
150
|
this.switchService.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
291
151
|
}
|
|
292
|
-
|
|
293
|
-
async deviceContext() {
|
|
294
|
-
if (this.On === undefined) {
|
|
295
|
-
this.On = false;
|
|
296
|
-
} else {
|
|
297
|
-
this.On = this.accessory.context.On;
|
|
298
|
-
}
|
|
299
|
-
if (this.FirmwareRevision === undefined) {
|
|
300
|
-
this.FirmwareRevision = this.platform.version;
|
|
301
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
|
|
306
|
-
let config = {};
|
|
307
|
-
if (device.ircam) {
|
|
308
|
-
config = device.ircam;
|
|
309
|
-
}
|
|
310
|
-
if (device.logging !== undefined) {
|
|
311
|
-
config['logging'] = device.logging;
|
|
312
|
-
}
|
|
313
|
-
if (device.connectionType !== undefined) {
|
|
314
|
-
config['connectionType'] = device.connectionType;
|
|
315
|
-
}
|
|
316
|
-
if (device.external !== undefined) {
|
|
317
|
-
config['external'] = device.external;
|
|
318
|
-
}
|
|
319
|
-
if (device.customOn !== undefined) {
|
|
320
|
-
config['customOn'] = device.customOn;
|
|
321
|
-
}
|
|
322
|
-
if (device.customOff !== undefined) {
|
|
323
|
-
config['customOff'] = device.customOff;
|
|
324
|
-
}
|
|
325
|
-
if (device.customize !== undefined) {
|
|
326
|
-
config['customize'] = device.customize;
|
|
327
|
-
}
|
|
328
|
-
if (device.disablePushOn !== undefined) {
|
|
329
|
-
config['disablePushOn'] = device.disablePushOn;
|
|
330
|
-
}
|
|
331
|
-
if (device.disablePushOff !== undefined) {
|
|
332
|
-
config['disablePushOff'] = device.disablePushOff;
|
|
333
|
-
}
|
|
334
|
-
if (Object.entries(config).length !== 0) {
|
|
335
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
340
|
-
if (this.platform.debugMode) {
|
|
341
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
342
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
343
|
-
} else if (device.logging) {
|
|
344
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
345
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
346
|
-
} else if (this.platform.config.options?.logging) {
|
|
347
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
348
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
349
|
-
} else {
|
|
350
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
351
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Logging for Device
|
|
357
|
-
*/
|
|
358
|
-
successLog(...log: any[]): void {
|
|
359
|
-
if (this.enablingDeviceLogging()) {
|
|
360
|
-
this.platform.log.success(String(...log));
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
infoLog(...log: any[]): void {
|
|
365
|
-
if (this.enablingDeviceLogging()) {
|
|
366
|
-
this.platform.log.info(String(...log));
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
warnLog(...log: any[]): void {
|
|
371
|
-
if (this.enablingDeviceLogging()) {
|
|
372
|
-
this.platform.log.warn(String(...log));
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
debugWarnLog(...log: any[]): void {
|
|
377
|
-
if (this.enablingDeviceLogging()) {
|
|
378
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
379
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
errorLog(...log: any[]): void {
|
|
385
|
-
if (this.enablingDeviceLogging()) {
|
|
386
|
-
this.platform.log.error(String(...log));
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
debugErrorLog(...log: any[]): void {
|
|
391
|
-
if (this.enablingDeviceLogging()) {
|
|
392
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
393
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
debugLog(...log: any[]): void {
|
|
399
|
-
if (this.enablingDeviceLogging()) {
|
|
400
|
-
if (this.deviceLogging === 'debug') {
|
|
401
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
402
|
-
} else {
|
|
403
|
-
this.platform.log.debug(String(...log));
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
enablingDeviceLogging(): boolean {
|
|
409
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
410
|
-
}
|
|
411
152
|
}
|