@switchbot/homebridge-switchbot 2.8.0-beta.0 → 2.8.0-beta.10
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/.prettierrc +1 -1
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +10 -0
- package/config.schema.json +8 -0
- package/dist/device/blindtilt.d.ts +1 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +58 -65
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +52 -55
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -0
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +68 -68
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +76 -75
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +2 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +67 -59
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +81 -94
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +197 -30
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +58 -62
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -0
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +28 -26
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -0
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +68 -67
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +2 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +51 -47
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +75 -74
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +4 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +74 -74
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +2 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +66 -54
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +39 -39
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -0
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +74 -53
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +64 -66
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +32 -34
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +20 -23
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -2
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +30 -32
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +26 -29
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +22 -23
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -2
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +47 -50
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +20 -23
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +22 -23
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +46 -44
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/device/blindtilt.ts +114 -78
- package/src/device/bot.ts +102 -63
- package/src/device/ceilinglight.ts +113 -73
- package/src/device/colorbulb.ts +144 -87
- package/src/device/contact.ts +98 -63
- package/src/device/curtain.ts +160 -134
- package/src/device/hub.ts +228 -39
- package/src/device/humidifier.ts +136 -85
- package/src/device/iosensor.ts +52 -32
- package/src/device/lightstrip.ts +118 -72
- package/src/device/lock.ts +85 -50
- package/src/device/meter.ts +104 -80
- package/src/device/meterplus.ts +103 -80
- package/src/device/motion.ts +95 -59
- package/src/device/plug.ts +70 -44
- package/src/device/robotvacuumcleaner.ts +107 -56
- package/src/irdevice/airconditioner.ts +116 -86
- package/src/irdevice/airpurifier.ts +60 -39
- package/src/irdevice/camera.ts +40 -28
- package/src/irdevice/fan.ts +52 -38
- package/src/irdevice/light.ts +48 -34
- package/src/irdevice/other.ts +44 -28
- package/src/irdevice/tv.ts +70 -56
- package/src/irdevice/vacuumcleaner.ts +40 -28
- package/src/irdevice/waterheater.ts +48 -32
- package/src/platform.ts +87 -56
- package/src/settings.ts +41 -40
- package/src/utils.ts +1 -1
package/src/irdevice/other.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
1
2
|
import { request } from 'undici';
|
|
2
3
|
import { SwitchBotPlatform } from '../platform';
|
|
3
|
-
import { irDevicesConfig, irdevice
|
|
4
|
-
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
4
|
+
import { Devices, irDevicesConfig, irdevice } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -21,14 +21,18 @@ export class Others {
|
|
|
21
21
|
deviceLogging!: string;
|
|
22
22
|
otherDeviceType?: string;
|
|
23
23
|
|
|
24
|
-
constructor(
|
|
24
|
+
constructor(
|
|
25
|
+
private readonly platform: SwitchBotPlatform,
|
|
26
|
+
private accessory: PlatformAccessory,
|
|
27
|
+
public device: irdevice & irDevicesConfig,
|
|
28
|
+
) {
|
|
25
29
|
// default placeholders
|
|
26
30
|
this.logs(device);
|
|
27
31
|
this.deviceType(device);
|
|
28
|
-
this.config(device);
|
|
29
32
|
this.context();
|
|
30
33
|
this.disablePushOnChanges({ device });
|
|
31
34
|
this.disablePushOffChanges({ device });
|
|
35
|
+
this.config(device);
|
|
32
36
|
|
|
33
37
|
// set accessory information
|
|
34
38
|
accessory
|
|
@@ -87,16 +91,18 @@ export class Others {
|
|
|
87
91
|
* Other - "command" "channelSub" "default" = previous channel
|
|
88
92
|
*/
|
|
89
93
|
async pushOnChanges(): Promise<void> {
|
|
90
|
-
this.debugLog(
|
|
91
|
-
|
|
94
|
+
this.debugLog(
|
|
95
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges Active: ${this.Active},` +
|
|
96
|
+
` disablePushOn: ${this.disablePushOn}, customize: ${this.device.customize}, customOn: ${this.device.customOn}`,
|
|
97
|
+
);
|
|
92
98
|
if (this.device.customize) {
|
|
93
99
|
if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
94
100
|
const commandType: string = await this.commandType();
|
|
95
101
|
const command: string = await this.commandOn();
|
|
96
102
|
const bodyChange = JSON.stringify({
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
command: command,
|
|
104
|
+
parameter: 'default',
|
|
105
|
+
commandType: commandType,
|
|
100
106
|
});
|
|
101
107
|
await this.pushChanges(bodyChange);
|
|
102
108
|
}
|
|
@@ -106,16 +112,18 @@ export class Others {
|
|
|
106
112
|
}
|
|
107
113
|
|
|
108
114
|
async pushOffChanges(): Promise<void> {
|
|
109
|
-
this.debugLog(
|
|
110
|
-
|
|
115
|
+
this.debugLog(
|
|
116
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges Active: ${this.Active},` +
|
|
117
|
+
` disablePushOff: ${this.disablePushOff}, customize: ${this.device.customize}, customOff: ${this.device.customOff}`,
|
|
118
|
+
);
|
|
111
119
|
if (this.device.customize) {
|
|
112
120
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
113
121
|
const commandType: string = await this.commandType();
|
|
114
122
|
const command: string = await this.commandOff();
|
|
115
123
|
const bodyChange = JSON.stringify({
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
124
|
+
command: command,
|
|
125
|
+
parameter: 'default',
|
|
126
|
+
commandType: commandType,
|
|
119
127
|
});
|
|
120
128
|
await this.pushChanges(bodyChange);
|
|
121
129
|
}
|
|
@@ -127,7 +135,7 @@ export class Others {
|
|
|
127
135
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
128
136
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
|
|
129
137
|
if (this.device.connectionType === 'OpenAPI') {
|
|
130
|
-
this.
|
|
138
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
131
139
|
try {
|
|
132
140
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
133
141
|
body: bodyChange,
|
|
@@ -141,13 +149,16 @@ export class Others {
|
|
|
141
149
|
this.updateHomeKitCharacteristics();
|
|
142
150
|
} catch (e: any) {
|
|
143
151
|
this.apiError(e);
|
|
144
|
-
this.errorLog(
|
|
145
|
-
|
|
152
|
+
this.errorLog(
|
|
153
|
+
`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}` +
|
|
154
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
146
155
|
);
|
|
147
156
|
}
|
|
148
157
|
} else {
|
|
149
|
-
this.warnLog(
|
|
150
|
-
|
|
158
|
+
this.warnLog(
|
|
159
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` +
|
|
160
|
+
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
161
|
+
);
|
|
151
162
|
}
|
|
152
163
|
}
|
|
153
164
|
|
|
@@ -161,7 +172,7 @@ export class Others {
|
|
|
161
172
|
}
|
|
162
173
|
}
|
|
163
174
|
|
|
164
|
-
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig
|
|
175
|
+
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
165
176
|
if (device.disablePushOn === undefined) {
|
|
166
177
|
this.disablePushOn = false;
|
|
167
178
|
} else {
|
|
@@ -169,7 +180,7 @@ export class Others {
|
|
|
169
180
|
}
|
|
170
181
|
}
|
|
171
182
|
|
|
172
|
-
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig
|
|
183
|
+
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
173
184
|
if (device.disablePushOff === undefined) {
|
|
174
185
|
this.disablePushOff = false;
|
|
175
186
|
} else {
|
|
@@ -222,8 +233,10 @@ export class Others {
|
|
|
222
233
|
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
223
234
|
break;
|
|
224
235
|
case 171:
|
|
225
|
-
this.errorLog(
|
|
226
|
-
|
|
236
|
+
this.errorLog(
|
|
237
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
238
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
239
|
+
);
|
|
227
240
|
break;
|
|
228
241
|
case 190:
|
|
229
242
|
this.errorLog(
|
|
@@ -238,8 +251,10 @@ export class Others {
|
|
|
238
251
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
239
252
|
break;
|
|
240
253
|
default:
|
|
241
|
-
this.infoLog(
|
|
242
|
-
|
|
254
|
+
this.infoLog(
|
|
255
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
256
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
257
|
+
);
|
|
243
258
|
}
|
|
244
259
|
}
|
|
245
260
|
|
|
@@ -261,8 +276,9 @@ export class Others {
|
|
|
261
276
|
|
|
262
277
|
FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
|
|
263
278
|
let FirmwareRevision: string;
|
|
264
|
-
this.debugLog(
|
|
265
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
279
|
+
this.debugLog(
|
|
280
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
281
|
+
);
|
|
266
282
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
267
283
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
268
284
|
if (accessory.context.FirmwareRevision) {
|
|
@@ -313,7 +329,7 @@ export class Others {
|
|
|
313
329
|
config['disablePushOff'] = device.disablePushOff;
|
|
314
330
|
}
|
|
315
331
|
if (Object.entries(config).length !== 0) {
|
|
316
|
-
this.
|
|
332
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
317
333
|
}
|
|
318
334
|
}
|
|
319
335
|
|
package/src/irdevice/tv.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
1
2
|
import { request } from 'undici';
|
|
2
3
|
import { SwitchBotPlatform } from '../platform';
|
|
3
|
-
import {
|
|
4
|
-
import { irdevice, irDevicesConfig, Devices } from '../settings';
|
|
4
|
+
import { Devices, irDevicesConfig, irdevice } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -26,14 +26,18 @@ export class TV {
|
|
|
26
26
|
disablePushDetail?: boolean;
|
|
27
27
|
deviceLogging!: string;
|
|
28
28
|
|
|
29
|
-
constructor(
|
|
29
|
+
constructor(
|
|
30
|
+
private readonly platform: SwitchBotPlatform,
|
|
31
|
+
private accessory: PlatformAccessory,
|
|
32
|
+
public device: irdevice & irDevicesConfig,
|
|
33
|
+
) {
|
|
30
34
|
// default placeholders
|
|
31
35
|
this.logs(device);
|
|
32
|
-
this.config(device);
|
|
33
36
|
this.context();
|
|
34
37
|
this.disablePushOnChanges({ device });
|
|
35
38
|
this.disablePushOffChanges({ device });
|
|
36
39
|
this.disablePushDetailChanges({ device });
|
|
40
|
+
this.config(device);
|
|
37
41
|
|
|
38
42
|
// set accessory information
|
|
39
43
|
accessory
|
|
@@ -222,30 +226,32 @@ export class TV {
|
|
|
222
226
|
* TV "command" "channelSub" "default" previous channel
|
|
223
227
|
*/
|
|
224
228
|
async pushTvOnChanges(): Promise<void> {
|
|
225
|
-
this.debugLog(
|
|
226
|
-
+ ` disablePushOn: ${this.disablePushOn}
|
|
229
|
+
this.debugLog(
|
|
230
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushTvOnChanges Active: ${this.Active},` + ` disablePushOn: ${this.disablePushOn}`,
|
|
231
|
+
);
|
|
227
232
|
if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
228
233
|
const commandType: string = await this.commandType();
|
|
229
234
|
const command: string = await this.commandOn();
|
|
230
235
|
const bodyChange = JSON.stringify({
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
236
|
+
command: command,
|
|
237
|
+
parameter: 'default',
|
|
238
|
+
commandType: commandType,
|
|
234
239
|
});
|
|
235
240
|
await this.pushTVChanges(bodyChange);
|
|
236
241
|
}
|
|
237
242
|
}
|
|
238
243
|
|
|
239
244
|
async pushTvOffChanges(): Promise<void> {
|
|
240
|
-
this.debugLog(
|
|
241
|
-
+ ` disablePushOff: ${this.disablePushOff}
|
|
245
|
+
this.debugLog(
|
|
246
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushTvOffChanges Active: ${this.Active},` + ` disablePushOff: ${this.disablePushOff}`,
|
|
247
|
+
);
|
|
242
248
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
243
249
|
const commandType: string = await this.commandType();
|
|
244
250
|
const command: string = await this.commandOff();
|
|
245
251
|
const bodyChange = JSON.stringify({
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
252
|
+
command: command,
|
|
253
|
+
parameter: 'default',
|
|
254
|
+
commandType: commandType,
|
|
249
255
|
});
|
|
250
256
|
await this.pushTVChanges(bodyChange);
|
|
251
257
|
}
|
|
@@ -255,9 +261,9 @@ export class TV {
|
|
|
255
261
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOkChanges disablePushDetail: ${this.disablePushDetail}`);
|
|
256
262
|
if (!this.disablePushDetail) {
|
|
257
263
|
const bodyChange = JSON.stringify({
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
264
|
+
command: 'Ok',
|
|
265
|
+
parameter: 'default',
|
|
266
|
+
commandType: 'command',
|
|
261
267
|
});
|
|
262
268
|
await this.pushTVChanges(bodyChange);
|
|
263
269
|
}
|
|
@@ -267,9 +273,9 @@ export class TV {
|
|
|
267
273
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushBackChanges disablePushDetail: ${this.disablePushDetail}`);
|
|
268
274
|
if (!this.disablePushDetail) {
|
|
269
275
|
const bodyChange = JSON.stringify({
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
276
|
+
command: 'Back',
|
|
277
|
+
parameter: 'default',
|
|
278
|
+
commandType: 'command',
|
|
273
279
|
});
|
|
274
280
|
await this.pushTVChanges(bodyChange);
|
|
275
281
|
}
|
|
@@ -279,9 +285,9 @@ export class TV {
|
|
|
279
285
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushMenuChanges disablePushDetail: ${this.disablePushDetail}`);
|
|
280
286
|
if (!this.disablePushDetail) {
|
|
281
287
|
const bodyChange = JSON.stringify({
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
288
|
+
command: 'Menu',
|
|
289
|
+
parameter: 'default',
|
|
290
|
+
commandType: 'command',
|
|
285
291
|
});
|
|
286
292
|
await this.pushTVChanges(bodyChange);
|
|
287
293
|
}
|
|
@@ -291,9 +297,9 @@ export class TV {
|
|
|
291
297
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushUpChanges disablePushDetail: ${this.disablePushDetail}`);
|
|
292
298
|
if (!this.disablePushDetail) {
|
|
293
299
|
const bodyChange = JSON.stringify({
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
300
|
+
command: 'Up',
|
|
301
|
+
parameter: 'default',
|
|
302
|
+
commandType: 'command',
|
|
297
303
|
});
|
|
298
304
|
await this.pushTVChanges(bodyChange);
|
|
299
305
|
}
|
|
@@ -303,9 +309,9 @@ export class TV {
|
|
|
303
309
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushDownChanges disablePushDetail: ${this.disablePushDetail}`);
|
|
304
310
|
if (!this.disablePushDetail) {
|
|
305
311
|
const bodyChange = JSON.stringify({
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
312
|
+
command: 'Down',
|
|
313
|
+
parameter: 'default',
|
|
314
|
+
commandType: 'command',
|
|
309
315
|
});
|
|
310
316
|
await this.pushTVChanges(bodyChange);
|
|
311
317
|
}
|
|
@@ -315,9 +321,9 @@ export class TV {
|
|
|
315
321
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushRightChanges disablePushDetail: ${this.disablePushDetail}`);
|
|
316
322
|
if (!this.disablePushDetail) {
|
|
317
323
|
const bodyChange = JSON.stringify({
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
324
|
+
command: 'Right',
|
|
325
|
+
parameter: 'default',
|
|
326
|
+
commandType: 'command',
|
|
321
327
|
});
|
|
322
328
|
await this.pushTVChanges(bodyChange);
|
|
323
329
|
}
|
|
@@ -327,9 +333,9 @@ export class TV {
|
|
|
327
333
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLeftChanges disablePushDetail: ${this.disablePushDetail}`);
|
|
328
334
|
if (!this.disablePushDetail) {
|
|
329
335
|
const bodyChange = JSON.stringify({
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
336
|
+
command: 'Left',
|
|
337
|
+
parameter: 'default',
|
|
338
|
+
commandType: 'command',
|
|
333
339
|
});
|
|
334
340
|
await this.pushTVChanges(bodyChange);
|
|
335
341
|
}
|
|
@@ -339,9 +345,9 @@ export class TV {
|
|
|
339
345
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushVolumeUpChanges disablePushDetail: ${this.disablePushDetail}`);
|
|
340
346
|
if (!this.disablePushDetail) {
|
|
341
347
|
const bodyChange = JSON.stringify({
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
348
|
+
command: 'volumeAdd',
|
|
349
|
+
parameter: 'default',
|
|
350
|
+
commandType: 'command',
|
|
345
351
|
});
|
|
346
352
|
await this.pushTVChanges(bodyChange);
|
|
347
353
|
}
|
|
@@ -351,9 +357,9 @@ export class TV {
|
|
|
351
357
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushVolumeDownChanges disablePushDetail: ${this.disablePushDetail}`);
|
|
352
358
|
if (!this.disablePushDetail) {
|
|
353
359
|
const bodyChange = JSON.stringify({
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
360
|
+
command: 'volumeSub',
|
|
361
|
+
parameter: 'default',
|
|
362
|
+
commandType: 'command',
|
|
357
363
|
});
|
|
358
364
|
await this.pushTVChanges(bodyChange);
|
|
359
365
|
}
|
|
@@ -362,7 +368,7 @@ export class TV {
|
|
|
362
368
|
async pushTVChanges(bodyChange: any): Promise<void> {
|
|
363
369
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushTVChanges`);
|
|
364
370
|
if (this.device.connectionType === 'OpenAPI') {
|
|
365
|
-
this.
|
|
371
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
366
372
|
try {
|
|
367
373
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
368
374
|
body: bodyChange,
|
|
@@ -376,13 +382,16 @@ export class TV {
|
|
|
376
382
|
this.updateHomeKitCharacteristics();
|
|
377
383
|
} catch (e: any) {
|
|
378
384
|
this.apiError(e);
|
|
379
|
-
this.errorLog(
|
|
380
|
-
|
|
385
|
+
this.errorLog(
|
|
386
|
+
`${this.device.remoteType}: ${this.accessory.displayName} failed pushTVChanges with ${this.device.connectionType}` +
|
|
387
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
381
388
|
);
|
|
382
389
|
}
|
|
383
390
|
} else {
|
|
384
|
-
this.warnLog(
|
|
385
|
-
|
|
391
|
+
this.warnLog(
|
|
392
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` +
|
|
393
|
+
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
394
|
+
);
|
|
386
395
|
}
|
|
387
396
|
}
|
|
388
397
|
|
|
@@ -403,7 +412,7 @@ export class TV {
|
|
|
403
412
|
}
|
|
404
413
|
}
|
|
405
414
|
|
|
406
|
-
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig
|
|
415
|
+
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
407
416
|
if (device.disablePushOn === undefined) {
|
|
408
417
|
this.disablePushOn = false;
|
|
409
418
|
} else {
|
|
@@ -411,7 +420,7 @@ export class TV {
|
|
|
411
420
|
}
|
|
412
421
|
}
|
|
413
422
|
|
|
414
|
-
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig
|
|
423
|
+
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
415
424
|
if (device.disablePushOff === undefined) {
|
|
416
425
|
this.disablePushOff = false;
|
|
417
426
|
} else {
|
|
@@ -419,7 +428,7 @@ export class TV {
|
|
|
419
428
|
}
|
|
420
429
|
}
|
|
421
430
|
|
|
422
|
-
async disablePushDetailChanges({ device }: { device: irdevice & irDevicesConfig
|
|
431
|
+
async disablePushDetailChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
423
432
|
if (device.disablePushDetail === undefined) {
|
|
424
433
|
this.disablePushDetail = false;
|
|
425
434
|
} else {
|
|
@@ -472,8 +481,10 @@ export class TV {
|
|
|
472
481
|
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
473
482
|
break;
|
|
474
483
|
case 171:
|
|
475
|
-
this.errorLog(
|
|
476
|
-
|
|
484
|
+
this.errorLog(
|
|
485
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
486
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
487
|
+
);
|
|
477
488
|
break;
|
|
478
489
|
case 190:
|
|
479
490
|
this.errorLog(
|
|
@@ -488,8 +499,10 @@ export class TV {
|
|
|
488
499
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
489
500
|
break;
|
|
490
501
|
default:
|
|
491
|
-
this.infoLog(
|
|
492
|
-
|
|
502
|
+
this.infoLog(
|
|
503
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
504
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
505
|
+
);
|
|
493
506
|
}
|
|
494
507
|
}
|
|
495
508
|
|
|
@@ -500,8 +513,9 @@ export class TV {
|
|
|
500
513
|
|
|
501
514
|
FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
|
|
502
515
|
let FirmwareRevision: string;
|
|
503
|
-
this.debugLog(
|
|
504
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
516
|
+
this.debugLog(
|
|
517
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
518
|
+
);
|
|
505
519
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
506
520
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
507
521
|
if (accessory.context.FirmwareRevision) {
|
|
@@ -560,7 +574,7 @@ export class TV {
|
|
|
560
574
|
config['disablePushDetail'] = device.disablePushDetail;
|
|
561
575
|
}
|
|
562
576
|
if (Object.entries(config).length !== 0) {
|
|
563
|
-
this.
|
|
577
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
564
578
|
}
|
|
565
579
|
}
|
|
566
580
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
1
2
|
import { request } from 'undici';
|
|
2
3
|
import { SwitchBotPlatform } from '../platform';
|
|
3
|
-
import { irDevicesConfig, irdevice
|
|
4
|
-
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
4
|
+
import { Devices, irDevicesConfig, irdevice } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -20,13 +20,17 @@ export class VacuumCleaner {
|
|
|
20
20
|
disablePushOff?: boolean;
|
|
21
21
|
deviceLogging!: string;
|
|
22
22
|
|
|
23
|
-
constructor(
|
|
23
|
+
constructor(
|
|
24
|
+
private readonly platform: SwitchBotPlatform,
|
|
25
|
+
private accessory: PlatformAccessory,
|
|
26
|
+
public device: irdevice & irDevicesConfig,
|
|
27
|
+
) {
|
|
24
28
|
// default placeholders
|
|
25
29
|
this.logs(device);
|
|
26
|
-
this.config(device);
|
|
27
30
|
this.context();
|
|
28
31
|
this.disablePushOnChanges({ device });
|
|
29
32
|
this.disablePushOffChanges({ device });
|
|
33
|
+
this.config(device);
|
|
30
34
|
|
|
31
35
|
// set accessory information
|
|
32
36
|
accessory
|
|
@@ -76,30 +80,30 @@ export class VacuumCleaner {
|
|
|
76
80
|
* Vacuum Cleaner "command" "turnOn" "default" set to ON state
|
|
77
81
|
*/
|
|
78
82
|
async pushOnChanges(): Promise<void> {
|
|
79
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${this.On},`
|
|
80
|
-
+ ` disablePushOn: ${this.disablePushOn}`);
|
|
83
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${this.On},` + ` disablePushOn: ${this.disablePushOn}`);
|
|
81
84
|
if (this.On && !this.disablePushOn) {
|
|
82
85
|
const commandType: string = await this.commandType();
|
|
83
86
|
const command: string = await this.commandOn();
|
|
84
87
|
const bodyChange = JSON.stringify({
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
command: command,
|
|
89
|
+
parameter: 'default',
|
|
90
|
+
commandType: commandType,
|
|
88
91
|
});
|
|
89
92
|
await this.pushChanges(bodyChange);
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
async pushOffChanges(): Promise<void> {
|
|
94
|
-
this.debugLog(
|
|
95
|
-
+ ` disablePushOff: ${this.disablePushOff}
|
|
97
|
+
this.debugLog(
|
|
98
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges On: ${this.On},` + ` disablePushOff: ${this.disablePushOff}`,
|
|
99
|
+
);
|
|
96
100
|
if (!this.On && !this.disablePushOff) {
|
|
97
101
|
const commandType: string = await this.commandType();
|
|
98
102
|
const command: string = await this.commandOff();
|
|
99
103
|
const bodyChange = JSON.stringify({
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
command: command,
|
|
105
|
+
parameter: 'default',
|
|
106
|
+
commandType: commandType,
|
|
103
107
|
});
|
|
104
108
|
await this.pushChanges(bodyChange);
|
|
105
109
|
}
|
|
@@ -108,7 +112,7 @@ export class VacuumCleaner {
|
|
|
108
112
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
109
113
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
|
|
110
114
|
if (this.device.connectionType === 'OpenAPI') {
|
|
111
|
-
this.
|
|
115
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
112
116
|
try {
|
|
113
117
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
114
118
|
body: bodyChange,
|
|
@@ -122,13 +126,16 @@ export class VacuumCleaner {
|
|
|
122
126
|
this.updateHomeKitCharacteristics();
|
|
123
127
|
} catch (e: any) {
|
|
124
128
|
this.apiError(e);
|
|
125
|
-
this.errorLog(
|
|
126
|
-
|
|
129
|
+
this.errorLog(
|
|
130
|
+
`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}` +
|
|
131
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
127
132
|
);
|
|
128
133
|
}
|
|
129
134
|
} else {
|
|
130
|
-
this.warnLog(
|
|
131
|
-
|
|
135
|
+
this.warnLog(
|
|
136
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` +
|
|
137
|
+
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
138
|
+
);
|
|
132
139
|
}
|
|
133
140
|
}
|
|
134
141
|
|
|
@@ -142,7 +149,7 @@ export class VacuumCleaner {
|
|
|
142
149
|
}
|
|
143
150
|
}
|
|
144
151
|
|
|
145
|
-
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig
|
|
152
|
+
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
146
153
|
if (device.disablePushOn === undefined) {
|
|
147
154
|
this.disablePushOn = false;
|
|
148
155
|
} else {
|
|
@@ -150,7 +157,7 @@ export class VacuumCleaner {
|
|
|
150
157
|
}
|
|
151
158
|
}
|
|
152
159
|
|
|
153
|
-
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig
|
|
160
|
+
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
154
161
|
if (device.disablePushOff === undefined) {
|
|
155
162
|
this.disablePushOff = false;
|
|
156
163
|
} else {
|
|
@@ -203,8 +210,10 @@ export class VacuumCleaner {
|
|
|
203
210
|
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
204
211
|
break;
|
|
205
212
|
case 171:
|
|
206
|
-
this.errorLog(
|
|
207
|
-
|
|
213
|
+
this.errorLog(
|
|
214
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
215
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
216
|
+
);
|
|
208
217
|
break;
|
|
209
218
|
case 190:
|
|
210
219
|
this.errorLog(
|
|
@@ -219,8 +228,10 @@ export class VacuumCleaner {
|
|
|
219
228
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
220
229
|
break;
|
|
221
230
|
default:
|
|
222
|
-
this.infoLog(
|
|
223
|
-
|
|
231
|
+
this.infoLog(
|
|
232
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
233
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
234
|
+
);
|
|
224
235
|
}
|
|
225
236
|
}
|
|
226
237
|
|
|
@@ -230,8 +241,9 @@ export class VacuumCleaner {
|
|
|
230
241
|
|
|
231
242
|
FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
|
|
232
243
|
let FirmwareRevision: string;
|
|
233
|
-
this.debugLog(
|
|
234
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
244
|
+
this.debugLog(
|
|
245
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
246
|
+
);
|
|
235
247
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
236
248
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
237
249
|
if (accessory.context.FirmwareRevision) {
|
|
@@ -282,7 +294,7 @@ export class VacuumCleaner {
|
|
|
282
294
|
config['disablePushOff'] = device.disablePushOff;
|
|
283
295
|
}
|
|
284
296
|
if (Object.entries(config).length !== 0) {
|
|
285
|
-
this.
|
|
297
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
286
298
|
}
|
|
287
299
|
}
|
|
288
300
|
|