@switchbot/homebridge-switchbot 3.5.0-beta.9 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +4 -1
- package/CHANGELOG.md +4 -1
- package/config.schema.json +166 -24
- package/dist/device/blindtilt.d.ts +21 -96
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +439 -817
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +27 -72
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +835 -865
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +15 -69
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +287 -653
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +15 -76
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +354 -732
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -66
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +268 -576
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +18 -89
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +431 -851
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +60 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +739 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +63 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +698 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +15 -60
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +257 -631
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +11 -66
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +266 -629
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +12 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +215 -615
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +12 -70
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +336 -645
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +17 -63
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +290 -595
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +15 -64
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +211 -608
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +15 -65
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +205 -615
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +12 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +202 -563
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +10 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +125 -484
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +13 -63
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +233 -549
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +11 -63
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +170 -493
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +22 -16
- package/dist/homebridge-ui/server.js +1 -1
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +10 -50
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +340 -468
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -39
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +105 -319
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +7 -36
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +44 -285
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +7 -43
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +92 -350
- 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 +369 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +12 -45
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +118 -362
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +19 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +438 -570
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +91 -339
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +7 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +45 -285
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +7 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +47 -291
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +22 -8
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +342 -191
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +64 -17
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +16 -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/eslint.config.js +96 -0
- package/package.json +20 -16
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +472 -888
- package/src/device/bot.ts +893 -968
- package/src/device/ceilinglight.ts +304 -709
- package/src/device/colorbulb.ts +370 -803
- package/src/device/contact.ts +301 -611
- package/src/device/curtain.ts +460 -908
- package/src/device/device.ts +755 -0
- package/src/device/fan.ts +749 -0
- package/src/device/hub.ts +294 -664
- package/src/device/humidifier.ts +299 -696
- package/src/device/iosensor.ts +251 -644
- package/src/device/lightstrip.ts +362 -712
- package/src/device/lock.ts +328 -653
- package/src/device/meter.ts +247 -637
- package/src/device/meterplus.ts +240 -644
- package/src/device/motion.ts +230 -598
- package/src/device/plug.ts +139 -525
- package/src/device/robotvacuumcleaner.ts +258 -593
- package/src/device/waterdetector.ts +191 -522
- package/src/homebridge-ui/public/index.html +22 -16
- package/src/homebridge-ui/server.ts +1 -1
- package/src/index.ts +4 -3
- package/src/irdevice/airconditioner.ts +370 -527
- package/src/irdevice/airpurifier.ts +132 -356
- package/src/irdevice/camera.ts +58 -311
- package/src/irdevice/fan.ts +109 -379
- package/src/irdevice/irdevice.ts +382 -0
- package/src/irdevice/light.ts +157 -412
- package/src/irdevice/other.ts +507 -648
- package/src/irdevice/tv.ts +121 -375
- package/src/irdevice/vacuumcleaner.ts +59 -311
- package/src/irdevice/waterheater.ts +61 -320
- package/src/platform.ts +395 -259
- package/src/settings.ts +118 -609
- package/src/utils.ts +642 -1
- package/.github/npm-version-script.cjs +0 -81
- package/src/device/waterdetector.json +0 -11
|
@@ -1,74 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* vacuumcleaner.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
2
5
|
import { request } from 'undici';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
6
|
+
import { Devices } from '../settings.js';
|
|
7
|
+
import { irdeviceBase } from './irdevice.js';
|
|
8
|
+
|
|
9
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
10
|
+
import type { irDevicesConfig, irdevice } from '../settings.js';
|
|
11
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
5
12
|
|
|
6
13
|
/**
|
|
7
14
|
* Platform Accessory
|
|
8
15
|
* An instance of this class is created for each accessory your platform registers
|
|
9
16
|
* Each accessory may expose multiple services of different service types.
|
|
10
17
|
*/
|
|
11
|
-
export class VacuumCleaner {
|
|
12
|
-
public readonly api: API;
|
|
13
|
-
public readonly log: Logging;
|
|
14
|
-
public readonly config!: SwitchBotPlatformConfig;
|
|
15
|
-
protected readonly hap: HAP;
|
|
18
|
+
export class VacuumCleaner extends irdeviceBase {
|
|
16
19
|
// Services
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// Config
|
|
24
|
-
deviceLogging!: string;
|
|
25
|
-
disablePushOn?: boolean;
|
|
26
|
-
disablePushOff?: boolean;
|
|
20
|
+
private Switch: {
|
|
21
|
+
Name: CharacteristicValue;
|
|
22
|
+
Service: Service;
|
|
23
|
+
On: CharacteristicValue;
|
|
24
|
+
};
|
|
27
25
|
|
|
28
26
|
constructor(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
readonly platform: SwitchBotPlatform,
|
|
28
|
+
accessory: PlatformAccessory,
|
|
29
|
+
device: irdevice & irDevicesConfig,
|
|
32
30
|
) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
this.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.
|
|
47
|
-
.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
.
|
|
51
|
-
|
|
52
|
-
// get the Television service if it exists, otherwise create a new Television service
|
|
53
|
-
// you can create multiple services for each accessory
|
|
54
|
-
const switchService = `${accessory.displayName} ${device.remoteType}`;
|
|
55
|
-
(this.switchService = accessory.getService(this.hap.Service.Switch)
|
|
56
|
-
|| accessory.addService(this.hap.Service.Switch)), switchService;
|
|
57
|
-
|
|
58
|
-
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
|
-
|
|
63
|
-
// handle on / off events using the On characteristic
|
|
64
|
-
this.switchService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
31
|
+
super(platform, accessory, device);
|
|
32
|
+
|
|
33
|
+
// Initialize Switch Service
|
|
34
|
+
accessory.context.Switch = accessory.context.Switch ?? {};
|
|
35
|
+
this.Switch = {
|
|
36
|
+
Name: accessory.context.Switch.Name ?? `${accessory.displayName} ${device.remoteType}`,
|
|
37
|
+
Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
|
|
38
|
+
On: accessory.context.On ?? false,
|
|
39
|
+
};
|
|
40
|
+
accessory.context.Switch = this.Switch as object;
|
|
41
|
+
|
|
42
|
+
this.Switch.Service
|
|
43
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
|
|
44
|
+
.getCharacteristic(this.hap.Characteristic.On)
|
|
45
|
+
.onGet(() => {
|
|
46
|
+
return this.Switch.On;
|
|
47
|
+
})
|
|
48
|
+
.onSet(this.OnSet.bind(this));
|
|
65
49
|
}
|
|
66
50
|
|
|
67
51
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
68
52
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
|
|
69
53
|
|
|
70
|
-
|
|
71
|
-
|
|
54
|
+
// Set the requested state
|
|
55
|
+
this.Switch.On = value;
|
|
56
|
+
if (this.Switch.On) {
|
|
72
57
|
await this.pushOnChanges();
|
|
73
58
|
} else {
|
|
74
59
|
await this.pushOffChanges();
|
|
@@ -82,8 +67,9 @@ export class VacuumCleaner {
|
|
|
82
67
|
* Vacuum Cleaner "command" "turnOn" "default" set to ON state
|
|
83
68
|
*/
|
|
84
69
|
async pushOnChanges(): Promise<void> {
|
|
85
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges
|
|
86
|
-
|
|
70
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges`
|
|
71
|
+
+ ` On: ${this.Switch.On}, disablePushOn: ${this.disablePushOn}`);
|
|
72
|
+
if (this.Switch.On && !this.disablePushOn) {
|
|
87
73
|
const commandType: string = await this.commandType();
|
|
88
74
|
const command: string = await this.commandOn();
|
|
89
75
|
const bodyChange = JSON.stringify({
|
|
@@ -96,10 +82,9 @@ export class VacuumCleaner {
|
|
|
96
82
|
}
|
|
97
83
|
|
|
98
84
|
async pushOffChanges(): Promise<void> {
|
|
99
|
-
this.debugLog(
|
|
100
|
-
|
|
101
|
-
)
|
|
102
|
-
if (!this.On && !this.disablePushOff) {
|
|
85
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges`
|
|
86
|
+
+ ` On: ${this.Switch.On}, disablePushOff: ${this.disablePushOff}`);
|
|
87
|
+
if (!this.Switch.On && !this.disablePushOff) {
|
|
103
88
|
const commandType: string = await this.commandType();
|
|
104
89
|
const command: string = await this.commandOff();
|
|
105
90
|
const bodyChange = JSON.stringify({
|
|
@@ -126,8 +111,10 @@ export class VacuumCleaner {
|
|
|
126
111
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
127
112
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
128
113
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
129
|
-
this.
|
|
114
|
+
this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
|
|
130
115
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
116
|
+
this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
117
|
+
+ ` request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
131
118
|
this.updateHomeKitCharacteristics();
|
|
132
119
|
} else {
|
|
133
120
|
this.statusCode(statusCode);
|
|
@@ -135,266 +122,27 @@ export class VacuumCleaner {
|
|
|
135
122
|
}
|
|
136
123
|
} catch (e: any) {
|
|
137
124
|
this.apiError(e);
|
|
138
|
-
this.errorLog(
|
|
139
|
-
|
|
140
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
141
|
-
);
|
|
125
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChange`
|
|
126
|
+
+ ` with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
142
127
|
}
|
|
143
128
|
} else {
|
|
144
|
-
this.warnLog(
|
|
145
|
-
|
|
146
|
-
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
147
|
-
);
|
|
129
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
130
|
+
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
148
131
|
}
|
|
149
132
|
}
|
|
150
133
|
|
|
151
134
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
152
135
|
// On
|
|
153
|
-
if (this.On === undefined) {
|
|
154
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
155
|
-
} else {
|
|
156
|
-
this.accessory.context.On = this.On;
|
|
157
|
-
this.switchService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
158
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
163
|
-
if (device.disablePushOn === undefined) {
|
|
164
|
-
this.disablePushOn = false;
|
|
165
|
-
} else {
|
|
166
|
-
this.disablePushOn = device.disablePushOn;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
171
|
-
if (device.disablePushOff === undefined) {
|
|
172
|
-
this.disablePushOff = false;
|
|
136
|
+
if (this.Switch.On === undefined) {
|
|
137
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Switch.On}`);
|
|
173
138
|
} else {
|
|
174
|
-
this.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
async commandType(): Promise<string> {
|
|
179
|
-
let commandType: string;
|
|
180
|
-
if (this.device.customize) {
|
|
181
|
-
commandType = 'customize';
|
|
182
|
-
} else {
|
|
183
|
-
commandType = 'command';
|
|
184
|
-
}
|
|
185
|
-
return commandType;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
async commandOn(): Promise<string> {
|
|
189
|
-
let command: string;
|
|
190
|
-
if (this.device.customize && this.device.customOn) {
|
|
191
|
-
command = this.device.customOn;
|
|
192
|
-
} else {
|
|
193
|
-
command = 'turnOn';
|
|
194
|
-
}
|
|
195
|
-
return command;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async commandOff(): Promise<string> {
|
|
199
|
-
let command: string;
|
|
200
|
-
if (this.device.customize && this.device.customOff) {
|
|
201
|
-
command = this.device.customOff;
|
|
202
|
-
} else {
|
|
203
|
-
command = 'turnOff';
|
|
204
|
-
}
|
|
205
|
-
return command;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
async statusCode(statusCode: number): Promise<void> {
|
|
209
|
-
switch (statusCode) {
|
|
210
|
-
case 151:
|
|
211
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
212
|
-
break;
|
|
213
|
-
case 152:
|
|
214
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
215
|
-
break;
|
|
216
|
-
case 160:
|
|
217
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
218
|
-
break;
|
|
219
|
-
case 161:
|
|
220
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
221
|
-
break;
|
|
222
|
-
case 171:
|
|
223
|
-
this.errorLog(
|
|
224
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
225
|
-
`Hub: ${this.device.hubDeviceId}`,
|
|
226
|
-
);
|
|
227
|
-
break;
|
|
228
|
-
case 190:
|
|
229
|
-
this.errorLog(
|
|
230
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
231
|
-
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
232
|
-
);
|
|
233
|
-
break;
|
|
234
|
-
case 100:
|
|
235
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
236
|
-
break;
|
|
237
|
-
case 200:
|
|
238
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
239
|
-
break;
|
|
240
|
-
case 400:
|
|
241
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
242
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
243
|
-
break;
|
|
244
|
-
case 401:
|
|
245
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
246
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
247
|
-
break;
|
|
248
|
-
case 403:
|
|
249
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
250
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
251
|
-
break;
|
|
252
|
-
case 404:
|
|
253
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
254
|
-
+ `statusCode: ${statusCode}`);
|
|
255
|
-
break;
|
|
256
|
-
case 406:
|
|
257
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
258
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
259
|
-
break;
|
|
260
|
-
case 415:
|
|
261
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
262
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
263
|
-
break;
|
|
264
|
-
case 422:
|
|
265
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
|
|
266
|
-
+ `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
267
|
-
break;
|
|
268
|
-
case 429:
|
|
269
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
270
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
271
|
-
break;
|
|
272
|
-
case 500:
|
|
273
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
274
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
275
|
-
break;
|
|
276
|
-
default:
|
|
277
|
-
this.infoLog(
|
|
278
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
279
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
280
|
-
);
|
|
139
|
+
this.accessory.context.On = this.Switch.On;
|
|
140
|
+
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
|
|
141
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Switch.On}`);
|
|
281
142
|
}
|
|
282
143
|
}
|
|
283
144
|
|
|
284
145
|
async apiError(e: any): Promise<void> {
|
|
285
|
-
this.
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
async deviceContext() {
|
|
289
|
-
if (this.On === undefined) {
|
|
290
|
-
this.On = false;
|
|
291
|
-
} else {
|
|
292
|
-
this.On = this.accessory.context.On;
|
|
293
|
-
}
|
|
294
|
-
if (this.FirmwareRevision === undefined) {
|
|
295
|
-
this.FirmwareRevision = this.platform.version;
|
|
296
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
|
|
301
|
-
let config = {};
|
|
302
|
-
if (device.irvc) {
|
|
303
|
-
config = device.irvc;
|
|
304
|
-
}
|
|
305
|
-
if (device.logging !== undefined) {
|
|
306
|
-
config['logging'] = device.logging;
|
|
307
|
-
}
|
|
308
|
-
if (device.connectionType !== undefined) {
|
|
309
|
-
config['connectionType'] = device.connectionType;
|
|
310
|
-
}
|
|
311
|
-
if (device.external !== undefined) {
|
|
312
|
-
config['external'] = device.external;
|
|
313
|
-
}
|
|
314
|
-
if (device.customOn !== undefined) {
|
|
315
|
-
config['customOn'] = device.customOn;
|
|
316
|
-
}
|
|
317
|
-
if (device.customOff !== undefined) {
|
|
318
|
-
config['customOff'] = device.customOff;
|
|
319
|
-
}
|
|
320
|
-
if (device.customize !== undefined) {
|
|
321
|
-
config['customize'] = device.customize;
|
|
322
|
-
}
|
|
323
|
-
if (device.disablePushOn !== undefined) {
|
|
324
|
-
config['disablePushOn'] = device.disablePushOn;
|
|
325
|
-
}
|
|
326
|
-
if (device.disablePushOff !== undefined) {
|
|
327
|
-
config['disablePushOff'] = device.disablePushOff;
|
|
328
|
-
}
|
|
329
|
-
if (Object.entries(config).length !== 0) {
|
|
330
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
335
|
-
if (this.platform.debugMode) {
|
|
336
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
337
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
338
|
-
} else if (device.logging) {
|
|
339
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
340
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
341
|
-
} else if (this.platform.config.options?.logging) {
|
|
342
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
343
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
344
|
-
} else {
|
|
345
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
346
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* Logging for Device
|
|
352
|
-
*/
|
|
353
|
-
infoLog(...log: any[]): void {
|
|
354
|
-
if (this.enablingDeviceLogging()) {
|
|
355
|
-
this.platform.log.info(String(...log));
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
warnLog(...log: any[]): void {
|
|
360
|
-
if (this.enablingDeviceLogging()) {
|
|
361
|
-
this.platform.log.warn(String(...log));
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
debugWarnLog(...log: any[]): void {
|
|
366
|
-
if (this.enablingDeviceLogging()) {
|
|
367
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
368
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
errorLog(...log: any[]): void {
|
|
374
|
-
if (this.enablingDeviceLogging()) {
|
|
375
|
-
this.platform.log.error(String(...log));
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
debugErrorLog(...log: any[]): void {
|
|
380
|
-
if (this.enablingDeviceLogging()) {
|
|
381
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
382
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
debugLog(...log: any[]): void {
|
|
388
|
-
if (this.enablingDeviceLogging()) {
|
|
389
|
-
if (this.deviceLogging === 'debug') {
|
|
390
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
391
|
-
} else {
|
|
392
|
-
this.platform.log.debug(String(...log));
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
enablingDeviceLogging(): boolean {
|
|
398
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
146
|
+
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
399
147
|
}
|
|
400
148
|
}
|