@switchbot/homebridge-switchbot 1.8.2 → 1.8.3-beta.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/.eslintrc +1 -1
- package/.vscode/extensions.json +5 -0
- package/.vscode/settings.json +15 -0
- package/dist/devices/bots.d.ts +34 -35
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +241 -184
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +50 -50
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +145 -131
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +27 -29
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +138 -115
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +29 -31
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +211 -176
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +33 -33
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +214 -189
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +30 -31
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +124 -100
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +25 -26
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +120 -102
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +23 -23
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +81 -63
- package/dist/devices/plugs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -3
- package/dist/index.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +6 -6
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +105 -79
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +5 -5
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +56 -42
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +5 -5
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +31 -27
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +5 -5
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +45 -38
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +5 -5
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +37 -33
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +5 -5
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +34 -29
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +5 -5
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +91 -76
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +5 -5
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +31 -27
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +5 -5
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +31 -27
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +12 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +241 -172
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +4 -4
- package/dist/settings.js.map +1 -1
- package/package.json +72 -71
- package/src/devices/bots.ts +927 -442
- package/src/devices/colorbulb.ts +473 -246
- package/src/devices/contact.ts +381 -208
- package/src/devices/curtains.ts +613 -321
- package/src/devices/humidifiers.ts +594 -323
- package/src/devices/meters.ts +331 -186
- package/src/devices/motion.ts +327 -184
- package/src/devices/plugs.ts +175 -107
- package/src/index.ts +5 -5
- package/src/irdevices/airconditioners.ts +360 -149
- package/src/irdevices/airpurifiers.ts +178 -80
- package/src/irdevices/cameras.ts +109 -51
- package/src/irdevices/fans.ts +174 -77
- package/src/irdevices/lights.ts +110 -57
- package/src/irdevices/others.ts +137 -62
- package/src/irdevices/tvs.ts +249 -124
- package/src/irdevices/vacuumcleaners.ts +112 -52
- package/src/irdevices/waterheaters.ts +115 -53
- package/src/platform.ts +768 -357
- package/src/settings.ts +17 -23
package/src/irdevices/lights.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AxiosResponse } from
|
|
2
|
-
import { SwitchBotPlatform } from
|
|
3
|
-
import { irDevicesConfig, DeviceURL, irdevice, payload } from
|
|
4
|
-
import { CharacteristicValue, PlatformAccessory, Service } from
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
import { SwitchBotPlatform } from "../platform";
|
|
3
|
+
import { irDevicesConfig, DeviceURL, irdevice, payload } from "../settings";
|
|
4
|
+
import { CharacteristicValue, PlatformAccessory, Service } from "homebridge";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -36,15 +36,19 @@ export class Light {
|
|
|
36
36
|
// set accessory information
|
|
37
37
|
accessory
|
|
38
38
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
39
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer,
|
|
39
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
|
|
40
40
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
41
|
-
.setCharacteristic(
|
|
41
|
+
.setCharacteristic(
|
|
42
|
+
this.platform.Characteristic.SerialNumber,
|
|
43
|
+
device.deviceId!,
|
|
44
|
+
);
|
|
42
45
|
|
|
43
46
|
// get the Television service if it exists, otherwise create a new Television service
|
|
44
47
|
// you can create multiple services for each accessory
|
|
45
48
|
(this.service =
|
|
46
49
|
accessory.getService(this.platform.Service.Lightbulb) ||
|
|
47
|
-
accessory.addService(this.platform.Service.Lightbulb)),
|
|
50
|
+
accessory.addService(this.platform.Service.Lightbulb)),
|
|
51
|
+
`${accessory.displayName} Light Bulb`;
|
|
48
52
|
|
|
49
53
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
50
54
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -52,10 +56,15 @@ export class Light {
|
|
|
52
56
|
|
|
53
57
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
54
58
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
55
|
-
this.service.setCharacteristic(
|
|
59
|
+
this.service.setCharacteristic(
|
|
60
|
+
this.platform.Characteristic.Name,
|
|
61
|
+
accessory.displayName,
|
|
62
|
+
);
|
|
56
63
|
|
|
57
64
|
// handle on / off events using the On characteristic
|
|
58
|
-
this.service
|
|
65
|
+
this.service
|
|
66
|
+
.getCharacteristic(this.platform.Characteristic.On)
|
|
67
|
+
.onSet(this.OnSet.bind(this));
|
|
59
68
|
|
|
60
69
|
// handle Brightness events using the Brightness characteristic
|
|
61
70
|
/* this.service
|
|
@@ -87,8 +96,13 @@ export class Light {
|
|
|
87
96
|
if (this.On === undefined) {
|
|
88
97
|
this.debugLog(`Light: ${this.accessory.displayName} On: ${this.On}`);
|
|
89
98
|
} else {
|
|
90
|
-
this.service?.updateCharacteristic(
|
|
91
|
-
|
|
99
|
+
this.service?.updateCharacteristic(
|
|
100
|
+
this.platform.Characteristic.On,
|
|
101
|
+
this.On,
|
|
102
|
+
);
|
|
103
|
+
this.debugLog(
|
|
104
|
+
`Light: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
|
|
105
|
+
);
|
|
92
106
|
}
|
|
93
107
|
}
|
|
94
108
|
|
|
@@ -105,9 +119,9 @@ export class Light {
|
|
|
105
119
|
async pushLightOnChanges() {
|
|
106
120
|
if (this.On) {
|
|
107
121
|
const payload = {
|
|
108
|
-
commandType:
|
|
109
|
-
parameter:
|
|
110
|
-
command:
|
|
122
|
+
commandType: "command",
|
|
123
|
+
parameter: "default",
|
|
124
|
+
command: "turnOn",
|
|
111
125
|
} as payload;
|
|
112
126
|
await this.pushChanges(payload);
|
|
113
127
|
}
|
|
@@ -116,9 +130,9 @@ export class Light {
|
|
|
116
130
|
async pushLightOffChanges() {
|
|
117
131
|
if (!this.On) {
|
|
118
132
|
const payload = {
|
|
119
|
-
commandType:
|
|
120
|
-
parameter:
|
|
121
|
-
command:
|
|
133
|
+
commandType: "command",
|
|
134
|
+
parameter: "default",
|
|
135
|
+
command: "turnOff",
|
|
122
136
|
} as payload;
|
|
123
137
|
await this.pushChanges(payload);
|
|
124
138
|
}
|
|
@@ -126,75 +140,103 @@ export class Light {
|
|
|
126
140
|
|
|
127
141
|
async pushLightBrightnessUpChanges() {
|
|
128
142
|
const payload = {
|
|
129
|
-
commandType:
|
|
130
|
-
parameter:
|
|
131
|
-
command:
|
|
143
|
+
commandType: "command",
|
|
144
|
+
parameter: "default",
|
|
145
|
+
command: "brightnessUp",
|
|
132
146
|
} as payload;
|
|
133
147
|
await this.pushChanges(payload);
|
|
134
148
|
}
|
|
135
149
|
|
|
136
150
|
async pushLightBrightnessDownChanges() {
|
|
137
151
|
const payload = {
|
|
138
|
-
commandType:
|
|
139
|
-
parameter:
|
|
140
|
-
command:
|
|
152
|
+
commandType: "command",
|
|
153
|
+
parameter: "default",
|
|
154
|
+
command: "brightnessDown",
|
|
141
155
|
} as payload;
|
|
142
156
|
await this.pushChanges(payload);
|
|
143
157
|
}
|
|
144
158
|
|
|
145
159
|
public async pushChanges(payload: payload) {
|
|
146
160
|
try {
|
|
147
|
-
this.infoLog(
|
|
148
|
-
|
|
161
|
+
this.infoLog(
|
|
162
|
+
`Light: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
163
|
+
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
164
|
+
);
|
|
149
165
|
|
|
150
166
|
// Make the API request
|
|
151
|
-
const push = await this.platform.axios.post(
|
|
152
|
-
|
|
167
|
+
const push = await this.platform.axios.post(
|
|
168
|
+
`${DeviceURL}/${this.device.deviceId}/commands`,
|
|
169
|
+
payload,
|
|
170
|
+
);
|
|
171
|
+
this.debugLog(
|
|
172
|
+
`Light: ${this.accessory.displayName} pushChanges: ${push.data}`,
|
|
173
|
+
);
|
|
153
174
|
this.statusCode(push);
|
|
154
175
|
this.OnCached = this.On;
|
|
155
176
|
this.accessory.context.On = this.OnCached;
|
|
156
177
|
this.updateHomeKitCharacteristics();
|
|
157
178
|
} catch (e: any) {
|
|
158
|
-
this.errorLog(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
179
|
+
this.errorLog(
|
|
180
|
+
`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
|
|
181
|
+
);
|
|
182
|
+
if (this.deviceLogging === "debug") {
|
|
183
|
+
this.errorLog(
|
|
184
|
+
`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
185
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
186
|
+
);
|
|
162
187
|
}
|
|
163
188
|
if (this.platform.debugMode) {
|
|
164
|
-
this.errorLog(
|
|
165
|
-
|
|
189
|
+
this.errorLog(
|
|
190
|
+
`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
191
|
+
` Error: ${JSON.stringify(e)}`,
|
|
192
|
+
);
|
|
166
193
|
}
|
|
167
194
|
this.apiError(e);
|
|
168
195
|
}
|
|
169
196
|
}
|
|
170
197
|
|
|
171
|
-
|
|
172
|
-
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
198
|
+
private statusCode(push: AxiosResponse<{ statusCode: number }>) {
|
|
173
199
|
switch (push.data.statusCode) {
|
|
174
200
|
case 151:
|
|
175
|
-
this.errorLog(
|
|
201
|
+
this.errorLog(
|
|
202
|
+
`Light: ${this.accessory.displayName} Command not supported by this device type.`,
|
|
203
|
+
);
|
|
176
204
|
break;
|
|
177
205
|
case 152:
|
|
178
206
|
this.errorLog(`Light: ${this.accessory.displayName} Device not found.`);
|
|
179
207
|
break;
|
|
180
208
|
case 160:
|
|
181
|
-
this.errorLog(
|
|
209
|
+
this.errorLog(
|
|
210
|
+
`Light: ${this.accessory.displayName} Command is not supported.`,
|
|
211
|
+
);
|
|
182
212
|
break;
|
|
183
213
|
case 161:
|
|
184
|
-
this.errorLog(
|
|
214
|
+
this.errorLog(
|
|
215
|
+
`Light: ${this.accessory.displayName} Device is offline.`,
|
|
216
|
+
);
|
|
185
217
|
break;
|
|
186
218
|
case 171:
|
|
187
|
-
this.errorLog(
|
|
219
|
+
this.errorLog(
|
|
220
|
+
`Light: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
|
|
221
|
+
);
|
|
188
222
|
break;
|
|
189
223
|
case 190:
|
|
190
|
-
this.errorLog(
|
|
191
|
-
|
|
224
|
+
this.errorLog(
|
|
225
|
+
`Light: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
|
|
226
|
+
` with server, Or command: ${JSON.stringify(
|
|
227
|
+
push.data,
|
|
228
|
+
)} format is invalid`,
|
|
229
|
+
);
|
|
192
230
|
break;
|
|
193
231
|
case 100:
|
|
194
|
-
this.debugLog(
|
|
232
|
+
this.debugLog(
|
|
233
|
+
`Light: ${this.accessory.displayName} Command successfully sent.`,
|
|
234
|
+
);
|
|
195
235
|
break;
|
|
196
236
|
default:
|
|
197
|
-
this.debugLog(
|
|
237
|
+
this.debugLog(
|
|
238
|
+
`Light: ${this.accessory.displayName} Unknown statusCode.`,
|
|
239
|
+
);
|
|
198
240
|
}
|
|
199
241
|
}
|
|
200
242
|
|
|
@@ -209,32 +251,43 @@ export class Light {
|
|
|
209
251
|
config = device.irlight;
|
|
210
252
|
}
|
|
211
253
|
if (device.logging !== undefined) {
|
|
212
|
-
config[
|
|
254
|
+
config["logging"] = device.logging;
|
|
213
255
|
}
|
|
214
256
|
if (Object.entries(config).length !== 0) {
|
|
215
|
-
this.warnLog(
|
|
257
|
+
this.warnLog(
|
|
258
|
+
`Light: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`,
|
|
259
|
+
);
|
|
216
260
|
}
|
|
217
261
|
}
|
|
218
262
|
|
|
219
263
|
logs(device: irdevice & irDevicesConfig) {
|
|
220
264
|
if (this.platform.debugMode) {
|
|
221
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
222
|
-
this.debugLog(
|
|
265
|
+
this.deviceLogging = this.accessory.context.logging = "debugMode";
|
|
266
|
+
this.debugLog(
|
|
267
|
+
`Light: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
|
|
268
|
+
);
|
|
223
269
|
} else if (device.logging) {
|
|
224
270
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
225
|
-
this.debugLog(
|
|
271
|
+
this.debugLog(
|
|
272
|
+
`Light: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
|
|
273
|
+
);
|
|
226
274
|
} else if (this.platform.config.options?.logging) {
|
|
227
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
228
|
-
|
|
275
|
+
this.deviceLogging = this.accessory.context.logging =
|
|
276
|
+
this.platform.config.options?.logging;
|
|
277
|
+
this.debugLog(
|
|
278
|
+
`Light: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
|
|
279
|
+
);
|
|
229
280
|
} else {
|
|
230
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
231
|
-
this.debugLog(
|
|
281
|
+
this.deviceLogging = this.accessory.context.logging = "standard";
|
|
282
|
+
this.debugLog(
|
|
283
|
+
`Light: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
|
|
284
|
+
);
|
|
232
285
|
}
|
|
233
286
|
}
|
|
234
287
|
|
|
235
288
|
/**
|
|
236
|
-
|
|
237
|
-
|
|
289
|
+
* Logging for Device
|
|
290
|
+
*/
|
|
238
291
|
infoLog(...log: any[]) {
|
|
239
292
|
if (this.enablingDeviceLogging()) {
|
|
240
293
|
this.platform.log.info(String(...log));
|
|
@@ -255,8 +308,8 @@ export class Light {
|
|
|
255
308
|
|
|
256
309
|
debugLog(...log: any[]) {
|
|
257
310
|
if (this.enablingDeviceLogging()) {
|
|
258
|
-
if (this.deviceLogging ===
|
|
259
|
-
this.platform.log.info(
|
|
311
|
+
if (this.deviceLogging === "debug") {
|
|
312
|
+
this.platform.log.info("[DEBUG]", String(...log));
|
|
260
313
|
} else {
|
|
261
314
|
this.platform.log.debug(String(...log));
|
|
262
315
|
}
|
|
@@ -264,6 +317,6 @@ export class Light {
|
|
|
264
317
|
}
|
|
265
318
|
|
|
266
319
|
enablingDeviceLogging(): boolean {
|
|
267
|
-
return this.deviceLogging
|
|
320
|
+
return this.deviceLogging.includes("debug") || this.deviceLogging === "standard";
|
|
268
321
|
}
|
|
269
322
|
}
|
package/src/irdevices/others.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AxiosResponse } from
|
|
2
|
-
import { SwitchBotPlatform } from
|
|
3
|
-
import { irDevicesConfig, DeviceURL, irdevice, payload } from
|
|
4
|
-
import { CharacteristicValue, PlatformAccessory, Service } from
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
import { SwitchBotPlatform } from "../platform";
|
|
3
|
+
import { irDevicesConfig, DeviceURL, irdevice, payload } from "../settings";
|
|
4
|
+
import { CharacteristicValue, PlatformAccessory, Service } from "homebridge";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -38,31 +38,44 @@ export class Others {
|
|
|
38
38
|
// set accessory information
|
|
39
39
|
accessory
|
|
40
40
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
41
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer,
|
|
41
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
|
|
42
42
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
43
|
-
.setCharacteristic(
|
|
43
|
+
.setCharacteristic(
|
|
44
|
+
this.platform.Characteristic.SerialNumber,
|
|
45
|
+
device.deviceId!,
|
|
46
|
+
);
|
|
44
47
|
|
|
45
48
|
// get the Television service if it exists, otherwise create a new Television service
|
|
46
49
|
// you can create multiple services for each accessory
|
|
47
|
-
if (this.otherDeviceType !==
|
|
50
|
+
if (this.otherDeviceType !== "Fan") {
|
|
48
51
|
this.debugLog(`Other: ${accessory.displayName} Removing Fanv2 Service`);
|
|
49
52
|
|
|
50
53
|
if (this.otherDeviceType === undefined) {
|
|
51
|
-
this.errorLog(
|
|
54
|
+
this.errorLog(
|
|
55
|
+
`Other: ${this.accessory.displayName} No Device Type Set, deviceType: ${device.other?.deviceType}`,
|
|
56
|
+
);
|
|
52
57
|
}
|
|
53
58
|
this.service = this.accessory.getService(this.platform.Service.Fanv2);
|
|
54
59
|
accessory.removeService(this.service!);
|
|
55
|
-
} else if (!this.service && this.otherDeviceType ===
|
|
60
|
+
} else if (!this.service && this.otherDeviceType === "Fan") {
|
|
56
61
|
this.debugLog(`Other: ${accessory.displayName} Add Fanv2 Service`);
|
|
57
62
|
(this.service =
|
|
58
63
|
this.accessory.getService(this.platform.Service.Fanv2) ||
|
|
59
|
-
this.accessory.addService(this.platform.Service.Fanv2)),
|
|
64
|
+
this.accessory.addService(this.platform.Service.Fanv2)),
|
|
65
|
+
`${accessory.displayName} Fan`;
|
|
60
66
|
|
|
61
|
-
this.service.setCharacteristic(
|
|
67
|
+
this.service.setCharacteristic(
|
|
68
|
+
this.platform.Characteristic.Name,
|
|
69
|
+
`${accessory.displayName} Fan`,
|
|
70
|
+
);
|
|
62
71
|
|
|
63
|
-
this.service
|
|
72
|
+
this.service
|
|
73
|
+
.getCharacteristic(this.platform.Characteristic.Active)
|
|
74
|
+
.onSet(this.ActiveSet.bind(this));
|
|
64
75
|
} else {
|
|
65
|
-
this.debugLog(
|
|
76
|
+
this.debugLog(
|
|
77
|
+
`Other: ${accessory.displayName} Fanv2 Service Not Added, deviceType: ${device.other?.deviceType}`,
|
|
78
|
+
);
|
|
66
79
|
}
|
|
67
80
|
}
|
|
68
81
|
|
|
@@ -80,10 +93,17 @@ export class Others {
|
|
|
80
93
|
|
|
81
94
|
private updateHomeKitCharacteristics() {
|
|
82
95
|
if (this.Active === undefined) {
|
|
83
|
-
this.debugLog(
|
|
96
|
+
this.debugLog(
|
|
97
|
+
`Other: ${this.accessory.displayName} Active: ${this.Active}`,
|
|
98
|
+
);
|
|
84
99
|
} else {
|
|
85
|
-
this.service?.updateCharacteristic(
|
|
86
|
-
|
|
100
|
+
this.service?.updateCharacteristic(
|
|
101
|
+
this.platform.Characteristic.Active,
|
|
102
|
+
this.Active,
|
|
103
|
+
);
|
|
104
|
+
this.debugLog(
|
|
105
|
+
`Other: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`,
|
|
106
|
+
);
|
|
87
107
|
}
|
|
88
108
|
}
|
|
89
109
|
|
|
@@ -103,17 +123,21 @@ export class Others {
|
|
|
103
123
|
if (this.device.other.commandOn) {
|
|
104
124
|
if (this.Active) {
|
|
105
125
|
const payload = {
|
|
106
|
-
commandType:
|
|
107
|
-
parameter:
|
|
126
|
+
commandType: "customize",
|
|
127
|
+
parameter: "default",
|
|
108
128
|
command: `${this.device.other.commandOn}`,
|
|
109
129
|
} as payload;
|
|
110
130
|
await this.pushChanges(payload);
|
|
111
131
|
}
|
|
112
132
|
} else {
|
|
113
|
-
this.errorLog(
|
|
133
|
+
this.errorLog(
|
|
134
|
+
`Other: ${this.accessory.displayName} On Command not set, commandOn: ${this.device.other.commandOn}`,
|
|
135
|
+
);
|
|
114
136
|
}
|
|
115
137
|
} else {
|
|
116
|
-
this.errorLog(
|
|
138
|
+
this.errorLog(
|
|
139
|
+
`Other: ${this.accessory.displayName} On Command not set, other: ${this.device.other}`,
|
|
140
|
+
);
|
|
117
141
|
}
|
|
118
142
|
} else {
|
|
119
143
|
this.errorLog(`Other: ${this.accessory.displayName} On Command not set`);
|
|
@@ -126,73 +150,108 @@ export class Others {
|
|
|
126
150
|
if (this.device.other.commandOff) {
|
|
127
151
|
if (!this.Active) {
|
|
128
152
|
const payload = {
|
|
129
|
-
commandType:
|
|
130
|
-
parameter:
|
|
153
|
+
commandType: "customize",
|
|
154
|
+
parameter: "default",
|
|
131
155
|
command: `${this.device.other.commandOff}`,
|
|
132
156
|
} as payload;
|
|
133
157
|
await this.pushChanges(payload);
|
|
134
158
|
}
|
|
135
159
|
} else {
|
|
136
|
-
this.errorLog(
|
|
160
|
+
this.errorLog(
|
|
161
|
+
`Other: ${this.accessory.displayName} Off Command not set, commandOff: ${this.device.other.commandOff}`,
|
|
162
|
+
);
|
|
137
163
|
}
|
|
138
164
|
} else {
|
|
139
|
-
this.errorLog(
|
|
165
|
+
this.errorLog(
|
|
166
|
+
`Other: ${this.accessory.displayName} Off Command not set, other: ${this.device.other}`,
|
|
167
|
+
);
|
|
140
168
|
}
|
|
141
169
|
} else {
|
|
142
|
-
this.errorLog(
|
|
170
|
+
this.errorLog(
|
|
171
|
+
`Other: ${this.accessory.displayName} Off Command not set.`,
|
|
172
|
+
);
|
|
143
173
|
}
|
|
144
174
|
}
|
|
145
175
|
|
|
146
176
|
public async pushChanges(payload: payload) {
|
|
147
177
|
try {
|
|
148
|
-
this.infoLog(
|
|
149
|
-
|
|
178
|
+
this.infoLog(
|
|
179
|
+
`Other: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
180
|
+
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
181
|
+
);
|
|
150
182
|
|
|
151
183
|
// Make the API request
|
|
152
|
-
const push = await this.platform.axios.post(
|
|
153
|
-
|
|
184
|
+
const push = await this.platform.axios.post(
|
|
185
|
+
`${DeviceURL}/${this.device.deviceId}/commands`,
|
|
186
|
+
payload,
|
|
187
|
+
);
|
|
188
|
+
this.debugLog(
|
|
189
|
+
`Other: ${this.accessory.displayName} pushChanges: ${push.data}`,
|
|
190
|
+
);
|
|
154
191
|
this.statusCode(push);
|
|
155
192
|
this.updateHomeKitCharacteristics();
|
|
156
193
|
} catch (e: any) {
|
|
157
|
-
this.errorLog(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
194
|
+
this.errorLog(
|
|
195
|
+
`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
|
|
196
|
+
);
|
|
197
|
+
if (this.deviceLogging === "debug") {
|
|
198
|
+
this.errorLog(
|
|
199
|
+
`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
200
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
201
|
+
);
|
|
161
202
|
}
|
|
162
203
|
if (this.platform.debugMode) {
|
|
163
|
-
this.errorLog(
|
|
164
|
-
|
|
204
|
+
this.errorLog(
|
|
205
|
+
`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
206
|
+
` Error: ${JSON.stringify(e)}`,
|
|
207
|
+
);
|
|
165
208
|
}
|
|
166
209
|
this.apiError(e);
|
|
167
210
|
}
|
|
168
211
|
}
|
|
169
212
|
|
|
170
|
-
private statusCode(push: AxiosResponse<{ statusCode: number
|
|
213
|
+
private statusCode(push: AxiosResponse<{ statusCode: number }>) {
|
|
171
214
|
switch (push.data.statusCode) {
|
|
172
215
|
case 151:
|
|
173
|
-
this.errorLog(
|
|
216
|
+
this.errorLog(
|
|
217
|
+
`Other: ${this.accessory.displayName} Command not supported by this device type.`,
|
|
218
|
+
);
|
|
174
219
|
break;
|
|
175
220
|
case 152:
|
|
176
221
|
this.errorLog(`Other: ${this.accessory.displayName} Device not found.`);
|
|
177
222
|
break;
|
|
178
223
|
case 160:
|
|
179
|
-
this.errorLog(
|
|
224
|
+
this.errorLog(
|
|
225
|
+
`Other: ${this.accessory.displayName} Command is not supported.`,
|
|
226
|
+
);
|
|
180
227
|
break;
|
|
181
228
|
case 161:
|
|
182
|
-
this.errorLog(
|
|
229
|
+
this.errorLog(
|
|
230
|
+
`Other: ${this.accessory.displayName} Device is offline.`,
|
|
231
|
+
);
|
|
183
232
|
break;
|
|
184
233
|
case 171:
|
|
185
|
-
this.errorLog(
|
|
234
|
+
this.errorLog(
|
|
235
|
+
`Other: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
|
|
236
|
+
);
|
|
186
237
|
break;
|
|
187
238
|
case 190:
|
|
188
|
-
this.errorLog(
|
|
189
|
-
|
|
239
|
+
this.errorLog(
|
|
240
|
+
`Other: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
|
|
241
|
+
` with server, Or command: ${JSON.stringify(
|
|
242
|
+
push.data,
|
|
243
|
+
)} format is invalid`,
|
|
244
|
+
);
|
|
190
245
|
break;
|
|
191
246
|
case 100:
|
|
192
|
-
this.debugLog(
|
|
247
|
+
this.debugLog(
|
|
248
|
+
`Other: ${this.accessory.displayName} Command successfully sent.`,
|
|
249
|
+
);
|
|
193
250
|
break;
|
|
194
251
|
default:
|
|
195
|
-
this.debugLog(
|
|
252
|
+
this.debugLog(
|
|
253
|
+
`Other: ${this.accessory.displayName} Unknown statusCode.`,
|
|
254
|
+
);
|
|
196
255
|
}
|
|
197
256
|
}
|
|
198
257
|
|
|
@@ -203,12 +262,17 @@ export class Others {
|
|
|
203
262
|
|
|
204
263
|
deviceType(device: irdevice & irDevicesConfig) {
|
|
205
264
|
if (device.other?.deviceType) {
|
|
206
|
-
this.otherDeviceType = this.accessory.context.deviceType =
|
|
207
|
-
|
|
208
|
-
|
|
265
|
+
this.otherDeviceType = this.accessory.context.deviceType =
|
|
266
|
+
device.other.deviceType;
|
|
267
|
+
if (this.deviceLogging === "debug" || this.deviceLogging === "standard") {
|
|
268
|
+
this.warnLog(
|
|
269
|
+
`Other: ${this.accessory.displayName} Using Device Type: ${this.otherDeviceType}`,
|
|
270
|
+
);
|
|
209
271
|
}
|
|
210
272
|
} else {
|
|
211
|
-
this.errorLog(
|
|
273
|
+
this.errorLog(
|
|
274
|
+
`Other: ${this.accessory.displayName} No Device Type Set, deviceType: ${this.device.other?.deviceType}`,
|
|
275
|
+
);
|
|
212
276
|
}
|
|
213
277
|
}
|
|
214
278
|
|
|
@@ -218,32 +282,43 @@ export class Others {
|
|
|
218
282
|
config = device.other;
|
|
219
283
|
}
|
|
220
284
|
if (device.logging !== undefined) {
|
|
221
|
-
config[
|
|
285
|
+
config["logging"] = device.logging;
|
|
222
286
|
}
|
|
223
287
|
if (Object.entries(config).length !== 0) {
|
|
224
|
-
this.warnLog(
|
|
288
|
+
this.warnLog(
|
|
289
|
+
`Other: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`,
|
|
290
|
+
);
|
|
225
291
|
}
|
|
226
292
|
}
|
|
227
293
|
|
|
228
294
|
logs(device: irdevice & irDevicesConfig) {
|
|
229
295
|
if (this.platform.debugMode) {
|
|
230
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
231
|
-
this.debugLog(
|
|
296
|
+
this.deviceLogging = this.accessory.context.logging = "debugMode";
|
|
297
|
+
this.debugLog(
|
|
298
|
+
`Other: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
|
|
299
|
+
);
|
|
232
300
|
} else if (device.logging) {
|
|
233
301
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
234
|
-
this.debugLog(
|
|
302
|
+
this.debugLog(
|
|
303
|
+
`Other: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
|
|
304
|
+
);
|
|
235
305
|
} else if (this.platform.config.options?.logging) {
|
|
236
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
237
|
-
|
|
306
|
+
this.deviceLogging = this.accessory.context.logging =
|
|
307
|
+
this.platform.config.options?.logging;
|
|
308
|
+
this.debugLog(
|
|
309
|
+
`Other: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
|
|
310
|
+
);
|
|
238
311
|
} else {
|
|
239
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
240
|
-
this.debugLog(
|
|
312
|
+
this.deviceLogging = this.accessory.context.logging = "standard";
|
|
313
|
+
this.debugLog(
|
|
314
|
+
`Other: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
|
|
315
|
+
);
|
|
241
316
|
}
|
|
242
317
|
}
|
|
243
318
|
|
|
244
319
|
/**
|
|
245
|
-
|
|
246
|
-
|
|
320
|
+
* Logging for Device
|
|
321
|
+
*/
|
|
247
322
|
infoLog(...log: any[]) {
|
|
248
323
|
if (this.enablingDeviceLogging()) {
|
|
249
324
|
this.platform.log.info(String(...log));
|
|
@@ -264,8 +339,8 @@ export class Others {
|
|
|
264
339
|
|
|
265
340
|
debugLog(...log: any[]) {
|
|
266
341
|
if (this.enablingDeviceLogging()) {
|
|
267
|
-
if (this.deviceLogging ===
|
|
268
|
-
this.platform.log.info(
|
|
342
|
+
if (this.deviceLogging === "debug") {
|
|
343
|
+
this.platform.log.info("[DEBUG]", String(...log));
|
|
269
344
|
} else {
|
|
270
345
|
this.platform.log.debug(String(...log));
|
|
271
346
|
}
|
|
@@ -273,6 +348,6 @@ export class Others {
|
|
|
273
348
|
}
|
|
274
349
|
|
|
275
350
|
enablingDeviceLogging(): boolean {
|
|
276
|
-
return this.deviceLogging
|
|
351
|
+
return this.deviceLogging.includes("debug") || this.deviceLogging === "standard";
|
|
277
352
|
}
|
|
278
353
|
}
|