@switchbot/homebridge-switchbot 1.4.0 → 1.4.1-beta.3
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 +18 -0
- package/config.schema.json +83 -11
- package/dist/devices/bots.d.ts +13 -3
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +162 -105
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +13 -3
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +161 -96
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +13 -3
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +117 -63
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +14 -5
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +198 -140
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +13 -3
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +180 -127
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +13 -3
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +121 -63
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +13 -3
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +104 -45
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +13 -3
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +99 -35
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +11 -3
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +80 -45
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +11 -3
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +68 -31
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +11 -3
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +64 -24
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +11 -3
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +74 -35
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +11 -3
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +65 -25
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +11 -3
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +71 -31
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +11 -3
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +81 -42
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +11 -3
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +64 -24
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +11 -3
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +64 -24
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +10 -10
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +290 -307
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +4 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/nodemon.json +1 -1
- package/package.json +70 -66
- package/src/devices/bots.ts +169 -105
- package/src/devices/colorbulb.ts +170 -99
- package/src/devices/contact.ts +124 -64
- package/src/devices/curtains.ts +207 -145
- package/src/devices/humidifiers.ts +187 -129
- package/src/devices/meters.ts +128 -64
- package/src/devices/motion.ts +110 -45
- package/src/devices/plugs.ts +104 -36
- package/src/irdevices/airconditioners.ts +85 -45
- package/src/irdevices/airpurifiers.ts +73 -31
- package/src/irdevices/cameras.ts +69 -24
- package/src/irdevices/fans.ts +79 -36
- package/src/irdevices/lights.ts +70 -25
- package/src/irdevices/others.ts +76 -31
- package/src/irdevices/tvs.ts +86 -42
- package/src/irdevices/vacuumcleaners.ts +69 -24
- package/src/irdevices/waterheaters.ts +69 -24
- package/src/platform.ts +285 -302
- package/src/settings.ts +4 -1
- package/dist/devices/indoorcam.d.ts +0 -64
- package/dist/devices/indoorcam.d.ts.map +0 -1
- package/dist/devices/indoorcam.js +0 -249
- package/dist/devices/indoorcam.js.map +0 -1
- package/src/devices/indoorcam.ts +0 -309
package/src/irdevices/fans.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { SwitchBotPlatform } from '../platform';
|
|
3
|
-
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
3
|
+
import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
|
|
4
4
|
import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -27,8 +27,7 @@ export class Fan {
|
|
|
27
27
|
minStep?: number;
|
|
28
28
|
minValue?: number;
|
|
29
29
|
maxValue?: number;
|
|
30
|
-
|
|
31
|
-
private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
|
|
30
|
+
deviceLogging!: string;
|
|
32
31
|
|
|
33
32
|
constructor(
|
|
34
33
|
private readonly platform: SwitchBotPlatform,
|
|
@@ -36,6 +35,7 @@ export class Fan {
|
|
|
36
35
|
public device: irdevice & irDevicesConfig,
|
|
37
36
|
) {
|
|
38
37
|
// default placeholders
|
|
38
|
+
this.logs();
|
|
39
39
|
if (this.Active === undefined) {
|
|
40
40
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
41
41
|
} else {
|
|
@@ -96,10 +96,10 @@ export class Fan {
|
|
|
96
96
|
!device.irfan?.swing_mode) {
|
|
97
97
|
const characteristic = this.service.getCharacteristic(this.platform.Characteristic.RotationSpeed);
|
|
98
98
|
this.service.removeCharacteristic(characteristic);
|
|
99
|
-
this.
|
|
99
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Rotation Speed Characteristic was removed.`);
|
|
100
100
|
} else {
|
|
101
101
|
// eslint-disable-next-line max-len
|
|
102
|
-
this.
|
|
102
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Rotation Speed Characteristic was not removed or not added. To Remove Chracteristic, Clear Cache on this Accessory.`);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
if (device.irfan?.swing_mode) {
|
|
@@ -108,16 +108,26 @@ export class Fan {
|
|
|
108
108
|
} else if (this.service.testCharacteristic(this.platform.Characteristic.SwingMode) && !device.irfan?.swing_mode) {
|
|
109
109
|
const characteristic = this.service.getCharacteristic(this.platform.Characteristic.SwingMode);
|
|
110
110
|
this.service.removeCharacteristic(characteristic);
|
|
111
|
-
this.
|
|
111
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Swing Mode Characteristic was removed.`);
|
|
112
112
|
} else {
|
|
113
113
|
// eslint-disable-next-line max-len
|
|
114
|
-
this.
|
|
114
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Swing Mode Characteristic was not removed or not added. To Remove Chracteristic, Clear Cache on this Accessory.`);
|
|
115
115
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
logs() {
|
|
120
|
+
if (this.device.logging) {
|
|
121
|
+
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
122
|
+
} else if (this.platform.config.options?.logging) {
|
|
123
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
124
|
+
} else {
|
|
125
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
119
129
|
private SwingModeSet(value: CharacteristicValue) {
|
|
120
|
-
this.
|
|
130
|
+
this.debugLog(`Fan: ${this.accessory.displayName} SwingMode: ${value}`);
|
|
121
131
|
if (value > this.SwingMode) {
|
|
122
132
|
this.SwingMode = 1;
|
|
123
133
|
this.pushFanOnChanges();
|
|
@@ -132,27 +142,27 @@ export class Fan {
|
|
|
132
142
|
|
|
133
143
|
private updateHomeKitCharacteristics() {
|
|
134
144
|
if (this.Active === undefined) {
|
|
135
|
-
this.
|
|
145
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
136
146
|
} else {
|
|
137
147
|
this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
138
|
-
this.
|
|
148
|
+
this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
139
149
|
}
|
|
140
150
|
if (this.SwingMode === undefined) {
|
|
141
|
-
this.
|
|
151
|
+
this.debugLog(`Fan: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`);
|
|
142
152
|
} else {
|
|
143
153
|
this.service?.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
|
|
144
|
-
this.
|
|
154
|
+
this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`);
|
|
145
155
|
}
|
|
146
156
|
if (this.RotationSpeed === undefined) {
|
|
147
|
-
this.
|
|
157
|
+
this.debugLog(`Fan: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
|
|
148
158
|
} else {
|
|
149
159
|
this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
|
|
150
|
-
this.
|
|
160
|
+
this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
|
|
151
161
|
}
|
|
152
162
|
}
|
|
153
163
|
|
|
154
164
|
private RotationSpeedSet(value: CharacteristicValue) {
|
|
155
|
-
this.
|
|
165
|
+
this.debugLog(`Fan: ${this.accessory.displayName} RotationSpeed: ${value}`);
|
|
156
166
|
if (value > this.RotationSpeed) {
|
|
157
167
|
this.RotationSpeed = 1;
|
|
158
168
|
this.pushFanSpeedUpChanges();
|
|
@@ -165,7 +175,7 @@ export class Fan {
|
|
|
165
175
|
}
|
|
166
176
|
|
|
167
177
|
private ActiveSet(value: CharacteristicValue) {
|
|
168
|
-
this.
|
|
178
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Active: ${value}`);
|
|
169
179
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
170
180
|
this.pushFanOffChanges();
|
|
171
181
|
} else {
|
|
@@ -234,60 +244,93 @@ export class Fan {
|
|
|
234
244
|
|
|
235
245
|
public async pushTVChanges(payload: payload) {
|
|
236
246
|
try {
|
|
237
|
-
this.
|
|
247
|
+
this.infoLog(`Fan: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
238
248
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
239
249
|
|
|
240
250
|
// Make the API request
|
|
241
251
|
const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
242
|
-
this.
|
|
252
|
+
this.debugLog(`Fan: ${this.accessory.displayName} pushTVChanges: ${push.data}`);
|
|
243
253
|
this.statusCode(push);
|
|
244
254
|
this.updateHomeKitCharacteristics();
|
|
245
255
|
} catch (e: any) {
|
|
246
|
-
this.
|
|
247
|
-
if (this.
|
|
248
|
-
this.
|
|
256
|
+
this.errorLog(`Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
257
|
+
if (this.deviceLogging === 'debug') {
|
|
258
|
+
this.errorLog(`Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
249
259
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
250
260
|
}
|
|
251
|
-
if (this.
|
|
252
|
-
this.
|
|
261
|
+
if (this.platform.debugMode) {
|
|
262
|
+
this.errorLog(`Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
253
263
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
254
264
|
}
|
|
255
|
-
this.apiError(
|
|
265
|
+
this.apiError();
|
|
256
266
|
}
|
|
257
267
|
}
|
|
258
268
|
|
|
259
269
|
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
260
270
|
switch (push.data.statusCode) {
|
|
261
271
|
case 151:
|
|
262
|
-
this.
|
|
272
|
+
this.errorLog(`Fan: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
263
273
|
break;
|
|
264
274
|
case 152:
|
|
265
|
-
this.
|
|
275
|
+
this.errorLog(`Fan: ${this.accessory.displayName} Device not found.`);
|
|
266
276
|
break;
|
|
267
277
|
case 160:
|
|
268
|
-
this.
|
|
278
|
+
this.errorLog(`Fan: ${this.accessory.displayName} Command is not supported.`);
|
|
269
279
|
break;
|
|
270
280
|
case 161:
|
|
271
|
-
this.
|
|
281
|
+
this.errorLog(`Fan: ${this.accessory.displayName} Device is offline.`);
|
|
272
282
|
break;
|
|
273
283
|
case 171:
|
|
274
|
-
this.
|
|
284
|
+
this.errorLog(`Fan: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
275
285
|
break;
|
|
276
286
|
case 190:
|
|
277
|
-
this.
|
|
287
|
+
this.errorLog(`Fan: ${this.accessory.displayName} Device internal error due to device states not synchronized`
|
|
278
288
|
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
279
289
|
break;
|
|
280
290
|
case 100:
|
|
281
|
-
this.
|
|
291
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Command successfully sent.`);
|
|
282
292
|
break;
|
|
283
293
|
default:
|
|
284
|
-
this.
|
|
294
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Unknown statusCode.`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
public apiError() {
|
|
299
|
+
throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Logging for Device
|
|
304
|
+
*/
|
|
305
|
+
infoLog(...log: any[]) {
|
|
306
|
+
if (this.enablingDeviceLogging()) {
|
|
307
|
+
this.platform.log.info(String(...log));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
warnLog(...log: any[]) {
|
|
312
|
+
if (this.enablingDeviceLogging()) {
|
|
313
|
+
this.platform.log.warn(String(...log));
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
errorLog(...log: any[]) {
|
|
318
|
+
if (this.enablingDeviceLogging()) {
|
|
319
|
+
this.platform.log.error(String(...log));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
debugLog(...log: any[]) {
|
|
324
|
+
if (this.enablingDeviceLogging()) {
|
|
325
|
+
if (this.deviceLogging === 'debug') {
|
|
326
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
327
|
+
} else {
|
|
328
|
+
this.platform.log.debug(String(...log));
|
|
329
|
+
}
|
|
285
330
|
}
|
|
286
331
|
}
|
|
287
332
|
|
|
288
|
-
|
|
289
|
-
this.
|
|
290
|
-
this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
|
|
291
|
-
this.service.updateCharacteristic(this.platform.Characteristic.SwingMode, e);
|
|
333
|
+
enablingDeviceLogging(): boolean {
|
|
334
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
292
335
|
}
|
|
293
336
|
}
|
package/src/irdevices/lights.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { SwitchBotPlatform } from '../platform';
|
|
3
3
|
import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
|
|
4
|
-
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
4
|
+
import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -17,8 +17,7 @@ export class Light {
|
|
|
17
17
|
OnCached!: CharacteristicValue;
|
|
18
18
|
|
|
19
19
|
// Config
|
|
20
|
-
|
|
21
|
-
private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
|
|
20
|
+
deviceLogging!: string;
|
|
22
21
|
|
|
23
22
|
constructor(
|
|
24
23
|
private readonly platform: SwitchBotPlatform,
|
|
@@ -26,6 +25,7 @@ export class Light {
|
|
|
26
25
|
public device: irdevice & irDevicesConfig,
|
|
27
26
|
) {
|
|
28
27
|
// default placeholders
|
|
28
|
+
this.logs();
|
|
29
29
|
if (this.On === undefined) {
|
|
30
30
|
this.On = false;
|
|
31
31
|
} else {
|
|
@@ -60,7 +60,7 @@ export class Light {
|
|
|
60
60
|
/* this.service
|
|
61
61
|
.getCharacteristic(this.platform.Characteristic.Brightness)
|
|
62
62
|
.on(CharacteristicEventTypes.SET, (value: any, callback: CharacteristicGetCallback) => {
|
|
63
|
-
this.
|
|
63
|
+
this.debugLog(`${this.device.remoteType} ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
64
64
|
this.Brightness = value;
|
|
65
65
|
if (value > this.Brightness) {
|
|
66
66
|
this.pushLightBrightnessUpChanges();
|
|
@@ -72,8 +72,18 @@ export class Light {
|
|
|
72
72
|
});*/
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
logs() {
|
|
76
|
+
if (this.device.logging) {
|
|
77
|
+
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
78
|
+
} else if (this.platform.config.options?.logging) {
|
|
79
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
80
|
+
} else {
|
|
81
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
75
85
|
private OnSet(value: CharacteristicValue) {
|
|
76
|
-
this.
|
|
86
|
+
this.debugLog(`Light: ${this.accessory.displayName} On: ${value}`);
|
|
77
87
|
this.On = value;
|
|
78
88
|
if (this.On) {
|
|
79
89
|
this.pushLightOnChanges();
|
|
@@ -84,10 +94,10 @@ export class Light {
|
|
|
84
94
|
|
|
85
95
|
private updateHomeKitCharacteristics() {
|
|
86
96
|
if (this.On === undefined) {
|
|
87
|
-
this.
|
|
97
|
+
this.debugLog(`Light: ${this.accessory.displayName} On: ${this.On}`);
|
|
88
98
|
} else {
|
|
89
99
|
this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
90
|
-
this.
|
|
100
|
+
this.debugLog(`Light: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
91
101
|
}
|
|
92
102
|
}
|
|
93
103
|
|
|
@@ -143,27 +153,27 @@ export class Light {
|
|
|
143
153
|
|
|
144
154
|
public async pushChanges(payload: payload) {
|
|
145
155
|
try {
|
|
146
|
-
this.
|
|
156
|
+
this.infoLog(`Light: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
147
157
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
148
158
|
|
|
149
159
|
// Make the API request
|
|
150
160
|
const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
151
|
-
this.
|
|
161
|
+
this.debugLog(`Light: ${this.accessory.displayName} pushChanges: ${push.data}`);
|
|
152
162
|
this.statusCode(push);
|
|
153
163
|
this.OnCached = this.On;
|
|
154
164
|
this.accessory.context.On = this.OnCached;
|
|
155
165
|
this.updateHomeKitCharacteristics();
|
|
156
166
|
} catch (e: any) {
|
|
157
|
-
this.
|
|
158
|
-
if (this.
|
|
159
|
-
this.
|
|
167
|
+
this.errorLog(`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
168
|
+
if (this.deviceLogging === 'debug') {
|
|
169
|
+
this.errorLog(`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
160
170
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
161
171
|
}
|
|
162
|
-
if (this.
|
|
163
|
-
this.
|
|
172
|
+
if (this.platform.debugMode) {
|
|
173
|
+
this.errorLog(`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
164
174
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
165
175
|
}
|
|
166
|
-
this.apiError(
|
|
176
|
+
this.apiError();
|
|
167
177
|
}
|
|
168
178
|
}
|
|
169
179
|
|
|
@@ -171,33 +181,68 @@ export class Light {
|
|
|
171
181
|
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
172
182
|
switch (push.data.statusCode) {
|
|
173
183
|
case 151:
|
|
174
|
-
this.
|
|
184
|
+
this.errorLog(`Light: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
175
185
|
break;
|
|
176
186
|
case 152:
|
|
177
|
-
this.
|
|
187
|
+
this.errorLog(`Light: ${this.accessory.displayName} Device not found.`);
|
|
178
188
|
break;
|
|
179
189
|
case 160:
|
|
180
|
-
this.
|
|
190
|
+
this.errorLog(`Light: ${this.accessory.displayName} Command is not supported.`);
|
|
181
191
|
break;
|
|
182
192
|
case 161:
|
|
183
|
-
this.
|
|
193
|
+
this.errorLog(`Light: ${this.accessory.displayName} Device is offline.`);
|
|
184
194
|
break;
|
|
185
195
|
case 171:
|
|
186
|
-
this.
|
|
196
|
+
this.errorLog(`Light: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
187
197
|
break;
|
|
188
198
|
case 190:
|
|
189
|
-
this.
|
|
199
|
+
this.errorLog(`Light: ${this.accessory.displayName} Device internal error due to device states not synchronized`
|
|
190
200
|
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
191
201
|
break;
|
|
192
202
|
case 100:
|
|
193
|
-
this.
|
|
203
|
+
this.debugLog(`Light: ${this.accessory.displayName} Command successfully sent.`);
|
|
194
204
|
break;
|
|
195
205
|
default:
|
|
196
|
-
this.
|
|
206
|
+
this.debugLog(`Light: ${this.accessory.displayName} Unknown statusCode.`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
public apiError() {
|
|
211
|
+
throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Logging for Device
|
|
216
|
+
*/
|
|
217
|
+
infoLog(...log: any[]) {
|
|
218
|
+
if (this.enablingDeviceLogging()) {
|
|
219
|
+
this.platform.log.info(String(...log));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
warnLog(...log: any[]) {
|
|
224
|
+
if (this.enablingDeviceLogging()) {
|
|
225
|
+
this.platform.log.warn(String(...log));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
errorLog(...log: any[]) {
|
|
230
|
+
if (this.enablingDeviceLogging()) {
|
|
231
|
+
this.platform.log.error(String(...log));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
debugLog(...log: any[]) {
|
|
236
|
+
if (this.enablingDeviceLogging()) {
|
|
237
|
+
if (this.deviceLogging === 'debug') {
|
|
238
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
239
|
+
} else {
|
|
240
|
+
this.platform.log.debug(String(...log));
|
|
241
|
+
}
|
|
197
242
|
}
|
|
198
243
|
}
|
|
199
244
|
|
|
200
|
-
|
|
201
|
-
this.
|
|
245
|
+
enablingDeviceLogging(): boolean {
|
|
246
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
202
247
|
}
|
|
203
248
|
}
|
package/src/irdevices/others.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { SwitchBotPlatform } from '../platform';
|
|
3
3
|
import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
|
|
4
|
-
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
4
|
+
import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -17,8 +17,7 @@ export class Others {
|
|
|
17
17
|
ActiveCached!: CharacteristicValue;
|
|
18
18
|
|
|
19
19
|
// Config
|
|
20
|
-
|
|
21
|
-
private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
|
|
20
|
+
deviceLogging!: string;
|
|
22
21
|
|
|
23
22
|
constructor(
|
|
24
23
|
private readonly platform: SwitchBotPlatform,
|
|
@@ -26,6 +25,7 @@ export class Others {
|
|
|
26
25
|
public device: irdevice & irDevicesConfig,
|
|
27
26
|
) {
|
|
28
27
|
// default placeholders
|
|
28
|
+
this.logs();
|
|
29
29
|
if (this.Active === undefined) {
|
|
30
30
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
31
31
|
} else {
|
|
@@ -50,12 +50,22 @@ export class Others {
|
|
|
50
50
|
this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
51
51
|
} else {
|
|
52
52
|
accessory.removeService(this.service!);
|
|
53
|
-
this.
|
|
53
|
+
this.errorLog(`Other: ${this.accessory.displayName} No Device Type Set, deviceType: ${device.other?.deviceType}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
logs() {
|
|
58
|
+
if (this.device.logging) {
|
|
59
|
+
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
60
|
+
} else if (this.platform.config.options?.logging) {
|
|
61
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
62
|
+
} else {
|
|
63
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
54
64
|
}
|
|
55
65
|
}
|
|
56
66
|
|
|
57
67
|
private ActiveSet(value: CharacteristicValue) {
|
|
58
|
-
this.
|
|
68
|
+
this.debugLog(`Other: ${this.accessory.displayName} On: ${value}`);
|
|
59
69
|
if (this.Active) {
|
|
60
70
|
this.pushOnChanges();
|
|
61
71
|
} else {
|
|
@@ -68,10 +78,10 @@ export class Others {
|
|
|
68
78
|
|
|
69
79
|
private updateHomeKitCharacteristics() {
|
|
70
80
|
if (this.Active === undefined) {
|
|
71
|
-
this.
|
|
81
|
+
this.debugLog(`Other: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
72
82
|
} else {
|
|
73
83
|
this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
74
|
-
this.
|
|
84
|
+
this.debugLog(`Other: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
75
85
|
}
|
|
76
86
|
}
|
|
77
87
|
|
|
@@ -98,13 +108,13 @@ export class Others {
|
|
|
98
108
|
await this.pushChanges(payload);
|
|
99
109
|
}
|
|
100
110
|
} else {
|
|
101
|
-
this.
|
|
111
|
+
this.errorLog(`Other: ${this.accessory.displayName} On Command not set, commandOn: ${this.device.other.commandOn}`);
|
|
102
112
|
}
|
|
103
113
|
} else {
|
|
104
|
-
this.
|
|
114
|
+
this.errorLog(`Other: ${this.accessory.displayName} On Command not set, other: ${this.device.other}`);
|
|
105
115
|
}
|
|
106
116
|
} else {
|
|
107
|
-
this.
|
|
117
|
+
this.errorLog(`Other: ${this.accessory.displayName} On Command not set`);
|
|
108
118
|
}
|
|
109
119
|
}
|
|
110
120
|
|
|
@@ -121,70 +131,105 @@ export class Others {
|
|
|
121
131
|
await this.pushChanges(payload);
|
|
122
132
|
}
|
|
123
133
|
} else {
|
|
124
|
-
this.
|
|
134
|
+
this.errorLog(`Other: ${this.accessory.displayName} Off Command not set, commandOff: ${this.device.other.commandOff}`);
|
|
125
135
|
}
|
|
126
136
|
} else {
|
|
127
|
-
this.
|
|
137
|
+
this.errorLog(`Other: ${this.accessory.displayName} Off Command not set, other: ${this.device.other}`);
|
|
128
138
|
}
|
|
129
139
|
} else {
|
|
130
|
-
this.
|
|
140
|
+
this.errorLog(`Other: ${this.accessory.displayName} Off Command not set.`);
|
|
131
141
|
}
|
|
132
142
|
}
|
|
133
143
|
|
|
134
144
|
public async pushChanges(payload: payload) {
|
|
135
145
|
try {
|
|
136
|
-
this.
|
|
146
|
+
this.infoLog(`Other: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
137
147
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
138
148
|
|
|
139
149
|
// Make the API request
|
|
140
150
|
const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
141
|
-
this.
|
|
151
|
+
this.debugLog(`Other: ${this.accessory.displayName} pushChanges: ${push.data}`);
|
|
142
152
|
this.statusCode(push);
|
|
143
153
|
this.updateHomeKitCharacteristics();
|
|
144
154
|
} catch (e: any) {
|
|
145
|
-
this.
|
|
146
|
-
if (this.
|
|
147
|
-
this.
|
|
155
|
+
this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
156
|
+
if (this.deviceLogging === 'debug') {
|
|
157
|
+
this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
148
158
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
149
159
|
}
|
|
150
|
-
if (this.
|
|
151
|
-
this.
|
|
160
|
+
if (this.platform.debugMode) {
|
|
161
|
+
this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
152
162
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
153
163
|
}
|
|
154
|
-
this.apiError(
|
|
164
|
+
this.apiError();
|
|
155
165
|
}
|
|
156
166
|
}
|
|
157
167
|
|
|
158
168
|
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
159
169
|
switch (push.data.statusCode) {
|
|
160
170
|
case 151:
|
|
161
|
-
this.
|
|
171
|
+
this.errorLog(`Other: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
162
172
|
break;
|
|
163
173
|
case 152:
|
|
164
|
-
this.
|
|
174
|
+
this.errorLog(`Other: ${this.accessory.displayName} Device not found.`);
|
|
165
175
|
break;
|
|
166
176
|
case 160:
|
|
167
|
-
this.
|
|
177
|
+
this.errorLog(`Other: ${this.accessory.displayName} Command is not supported.`);
|
|
168
178
|
break;
|
|
169
179
|
case 161:
|
|
170
|
-
this.
|
|
180
|
+
this.errorLog(`Other: ${this.accessory.displayName} Device is offline.`);
|
|
171
181
|
break;
|
|
172
182
|
case 171:
|
|
173
|
-
this.
|
|
183
|
+
this.errorLog(`Other: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
174
184
|
break;
|
|
175
185
|
case 190:
|
|
176
|
-
this.
|
|
186
|
+
this.errorLog(`Other: ${this.accessory.displayName} Device internal error due to device states not synchronized`
|
|
177
187
|
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
178
188
|
break;
|
|
179
189
|
case 100:
|
|
180
|
-
this.
|
|
190
|
+
this.debugLog(`Other: ${this.accessory.displayName} Command successfully sent.`);
|
|
181
191
|
break;
|
|
182
192
|
default:
|
|
183
|
-
this.
|
|
193
|
+
this.debugLog(`Other: ${this.accessory.displayName} Unknown statusCode.`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
public apiError() {
|
|
198
|
+
throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Logging for Device
|
|
203
|
+
*/
|
|
204
|
+
infoLog(...log: any[]) {
|
|
205
|
+
if (this.enablingDeviceLogging()) {
|
|
206
|
+
this.platform.log.info(String(...log));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
warnLog(...log: any[]) {
|
|
211
|
+
if (this.enablingDeviceLogging()) {
|
|
212
|
+
this.platform.log.warn(String(...log));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
errorLog(...log: any[]) {
|
|
217
|
+
if (this.enablingDeviceLogging()) {
|
|
218
|
+
this.platform.log.error(String(...log));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
debugLog(...log: any[]) {
|
|
223
|
+
if (this.enablingDeviceLogging()) {
|
|
224
|
+
if (this.deviceLogging === 'debug') {
|
|
225
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
226
|
+
} else {
|
|
227
|
+
this.platform.log.debug(String(...log));
|
|
228
|
+
}
|
|
184
229
|
}
|
|
185
230
|
}
|
|
186
231
|
|
|
187
|
-
|
|
188
|
-
this.
|
|
232
|
+
enablingDeviceLogging(): boolean {
|
|
233
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
189
234
|
}
|
|
190
235
|
}
|