@switchbot/homebridge-switchbot 2.7.1 → 2.8.0-beta.1
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/.github/npm-version-script.js +81 -0
- 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.map +1 -1
- package/dist/device/blindtilt.js +49 -59
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +44 -50
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +60 -63
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +68 -70
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +22 -25
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +50 -58
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +6 -0
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +168 -26
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +49 -56
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +18 -20
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +59 -61
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +40 -41
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +3 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +65 -68
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +18 -20
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +20 -23
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +30 -33
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +48 -51
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +57 -61
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +29 -31
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +17 -20
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +27 -29
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +23 -26
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +19 -20
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +44 -47
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +17 -20
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +19 -20
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +44 -43
- 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 +1 -1
- package/src/device/blindtilt.ts +106 -72
- package/src/device/bot.ts +94 -58
- package/src/device/ceilinglight.ts +102 -68
- package/src/device/colorbulb.ts +134 -82
- package/src/device/contact.ts +54 -33
- package/src/device/curtain.ts +130 -101
- package/src/device/hub.ts +198 -35
- package/src/device/humidifier.ts +128 -80
- package/src/device/iosensor.ts +43 -27
- package/src/device/lightstrip.ts +108 -67
- package/src/device/lock.ts +73 -45
- package/src/device/meter.ts +94 -75
- package/src/device/meterplus.ts +43 -27
- package/src/device/motion.ts +50 -32
- package/src/device/plug.ts +62 -39
- package/src/device/robotvacuumcleaner.ts +78 -54
- package/src/irdevice/airconditioner.ts +111 -83
- package/src/irdevice/airpurifier.ts +55 -34
- package/src/irdevice/camera.ts +35 -23
- package/src/irdevice/fan.ts +47 -33
- package/src/irdevice/light.ts +43 -29
- package/src/irdevice/other.ts +39 -23
- package/src/irdevice/tv.ts +65 -51
- package/src/irdevice/vacuumcleaner.ts +35 -23
- package/src/irdevice/waterheater.ts +43 -27
- package/src/platform.ts +85 -55
- package/src/settings.ts +41 -40
- package/src/utils.ts +1 -1
package/src/device/plug.ts
CHANGED
|
@@ -41,10 +41,14 @@ export class Plug {
|
|
|
41
41
|
doPlugUpdate!: Subject<void>;
|
|
42
42
|
|
|
43
43
|
// Connection
|
|
44
|
-
private readonly BLE =
|
|
45
|
-
private readonly OpenAPI =
|
|
46
|
-
|
|
47
|
-
constructor(
|
|
44
|
+
private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
45
|
+
private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
46
|
+
|
|
47
|
+
constructor(
|
|
48
|
+
private readonly platform: SwitchBotPlatform,
|
|
49
|
+
private accessory: PlatformAccessory,
|
|
50
|
+
public device: device & devicesConfig,
|
|
51
|
+
) {
|
|
48
52
|
// default placeholders
|
|
49
53
|
this.logs(device);
|
|
50
54
|
this.scan(device);
|
|
@@ -114,8 +118,10 @@ export class Plug {
|
|
|
114
118
|
await this.pushChanges();
|
|
115
119
|
} catch (e: any) {
|
|
116
120
|
this.apiError(e);
|
|
117
|
-
this.errorLog(
|
|
118
|
-
|
|
121
|
+
this.errorLog(
|
|
122
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
|
|
123
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
124
|
+
);
|
|
119
125
|
}
|
|
120
126
|
this.plugUpdateInProgress = false;
|
|
121
127
|
});
|
|
@@ -133,8 +139,9 @@ export class Plug {
|
|
|
133
139
|
await this.openAPIparseStatus();
|
|
134
140
|
} else {
|
|
135
141
|
await this.offlineOff();
|
|
136
|
-
this.debugWarnLog(
|
|
137
|
-
+ ` ${this.device.connectionType}, parseStatus will not happen
|
|
142
|
+
this.debugWarnLog(
|
|
143
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
144
|
+
);
|
|
138
145
|
}
|
|
139
146
|
}
|
|
140
147
|
|
|
@@ -175,8 +182,10 @@ export class Plug {
|
|
|
175
182
|
await this.openAPIRefreshStatus();
|
|
176
183
|
} else {
|
|
177
184
|
await this.offlineOff();
|
|
178
|
-
this.debugWarnLog(
|
|
179
|
-
|
|
185
|
+
this.debugWarnLog(
|
|
186
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
|
|
187
|
+
` ${this.device.connectionType}, refreshStatus will not happen.`,
|
|
188
|
+
);
|
|
180
189
|
}
|
|
181
190
|
}
|
|
182
191
|
|
|
@@ -201,8 +210,10 @@ export class Plug {
|
|
|
201
210
|
// Set an event hander
|
|
202
211
|
switchbot.onadvertisement = async (ad: any) => {
|
|
203
212
|
this.address = ad.address;
|
|
204
|
-
this.debugLog(
|
|
205
|
-
|
|
213
|
+
this.debugLog(
|
|
214
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
215
|
+
` BLE Address Found: ${this.address}`,
|
|
216
|
+
);
|
|
206
217
|
this.serviceData = ad.serviceData;
|
|
207
218
|
this.state = ad.serviceData.state;
|
|
208
219
|
this.delay = ad.serviceData.delay;
|
|
@@ -236,8 +247,10 @@ export class Plug {
|
|
|
236
247
|
})
|
|
237
248
|
.catch(async (e: any) => {
|
|
238
249
|
this.apiError(e);
|
|
239
|
-
this.errorLog(
|
|
240
|
-
|
|
250
|
+
this.errorLog(
|
|
251
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
252
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
253
|
+
);
|
|
241
254
|
await this.BLERefreshConnection(switchbot);
|
|
242
255
|
});
|
|
243
256
|
} else {
|
|
@@ -255,17 +268,16 @@ export class Plug {
|
|
|
255
268
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
256
269
|
this.statusCode(statusCode);
|
|
257
270
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
258
|
-
this.debugLog(
|
|
259
|
-
`${this.device.deviceType}: ${this.accessory.displayName
|
|
260
|
-
} refreshStatus: ${JSON.stringify(deviceStatus)}`,
|
|
261
|
-
);
|
|
271
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
262
272
|
this.power = deviceStatus.body.power;
|
|
263
273
|
this.openAPIparseStatus();
|
|
264
274
|
this.updateHomeKitCharacteristics();
|
|
265
275
|
} catch (e: any) {
|
|
266
276
|
this.apiError(e);
|
|
267
|
-
this.errorLog(
|
|
268
|
-
|
|
277
|
+
this.errorLog(
|
|
278
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
|
|
279
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
280
|
+
);
|
|
269
281
|
}
|
|
270
282
|
}
|
|
271
283
|
|
|
@@ -288,8 +300,9 @@ export class Plug {
|
|
|
288
300
|
await this.openAPIpushChanges();
|
|
289
301
|
} else {
|
|
290
302
|
await this.offlineOff();
|
|
291
|
-
this.debugWarnLog(
|
|
292
|
-
+ ` ${this.device.connectionType}, pushChanges will not happen
|
|
303
|
+
this.debugWarnLog(
|
|
304
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
|
|
305
|
+
);
|
|
293
306
|
}
|
|
294
307
|
// Refresh the status from the API
|
|
295
308
|
interval(15000)
|
|
@@ -335,14 +348,15 @@ export class Plug {
|
|
|
335
348
|
})
|
|
336
349
|
.catch(async (e: any) => {
|
|
337
350
|
this.apiError(e);
|
|
338
|
-
this.errorLog(
|
|
339
|
-
|
|
351
|
+
this.errorLog(
|
|
352
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
|
|
353
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
354
|
+
);
|
|
340
355
|
await this.BLEPushConnection();
|
|
341
356
|
});
|
|
342
357
|
} else {
|
|
343
358
|
this.debugLog(
|
|
344
|
-
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
|
|
345
|
-
+ `OnCached: ${this.accessory.context.On}`,
|
|
359
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, ` + `OnCached: ${this.accessory.context.On}`,
|
|
346
360
|
);
|
|
347
361
|
}
|
|
348
362
|
}
|
|
@@ -357,9 +371,9 @@ export class Plug {
|
|
|
357
371
|
command = 'turnOff';
|
|
358
372
|
}
|
|
359
373
|
const bodyChange = JSON.stringify({
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
374
|
+
command: `${command}`,
|
|
375
|
+
parameter: 'default',
|
|
376
|
+
commandType: 'command',
|
|
363
377
|
});
|
|
364
378
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
365
379
|
try {
|
|
@@ -374,13 +388,17 @@ export class Plug {
|
|
|
374
388
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
375
389
|
} catch (e: any) {
|
|
376
390
|
this.apiError(e);
|
|
377
|
-
this.errorLog(
|
|
378
|
-
|
|
391
|
+
this.errorLog(
|
|
392
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
|
|
393
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
379
394
|
);
|
|
380
395
|
}
|
|
381
396
|
} else {
|
|
382
|
-
this.debugLog(
|
|
383
|
-
|
|
397
|
+
this.debugLog(
|
|
398
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` +
|
|
399
|
+
`On: ${this.On}, ` +
|
|
400
|
+
`OnCached: ${this.accessory.context.On}`,
|
|
401
|
+
);
|
|
384
402
|
}
|
|
385
403
|
}
|
|
386
404
|
|
|
@@ -521,8 +539,10 @@ export class Plug {
|
|
|
521
539
|
this.offlineOff();
|
|
522
540
|
break;
|
|
523
541
|
case 171:
|
|
524
|
-
this.errorLog(
|
|
525
|
-
|
|
542
|
+
this.errorLog(
|
|
543
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
544
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
545
|
+
);
|
|
526
546
|
this.offlineOff();
|
|
527
547
|
break;
|
|
528
548
|
case 190:
|
|
@@ -538,8 +558,10 @@ export class Plug {
|
|
|
538
558
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
539
559
|
break;
|
|
540
560
|
default:
|
|
541
|
-
this.infoLog(
|
|
542
|
-
|
|
561
|
+
this.infoLog(
|
|
562
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
563
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
564
|
+
);
|
|
543
565
|
}
|
|
544
566
|
}
|
|
545
567
|
|
|
@@ -556,8 +578,9 @@ export class Plug {
|
|
|
556
578
|
|
|
557
579
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
558
580
|
let FirmwareRevision: string;
|
|
559
|
-
this.debugLog(
|
|
560
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
581
|
+
this.debugLog(
|
|
582
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
583
|
+
);
|
|
561
584
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
562
585
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
563
586
|
if (accessory.context.FirmwareRevision) {
|
|
@@ -39,10 +39,14 @@ export class RobotVacuumCleaner {
|
|
|
39
39
|
doRobotVacuumCleanerUpdate!: Subject<void>;
|
|
40
40
|
|
|
41
41
|
// Connection
|
|
42
|
-
private readonly BLE =
|
|
43
|
-
private readonly OpenAPI =
|
|
44
|
-
|
|
45
|
-
constructor(
|
|
42
|
+
private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
43
|
+
private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
44
|
+
|
|
45
|
+
constructor(
|
|
46
|
+
private readonly platform: SwitchBotPlatform,
|
|
47
|
+
private accessory: PlatformAccessory,
|
|
48
|
+
public device: device & devicesConfig,
|
|
49
|
+
) {
|
|
46
50
|
// default placeholders
|
|
47
51
|
this.logs(device);
|
|
48
52
|
this.scan(device);
|
|
@@ -127,13 +131,15 @@ export class RobotVacuumCleaner {
|
|
|
127
131
|
if (this.On !== this.accessory.context.On) {
|
|
128
132
|
await this.pushChanges();
|
|
129
133
|
}
|
|
130
|
-
if (this.On &&
|
|
134
|
+
if (this.On && this.Brightness !== this.accessory.context.Brightness) {
|
|
131
135
|
await this.openAPIpushBrightnessChanges();
|
|
132
136
|
}
|
|
133
137
|
} catch (e: any) {
|
|
134
138
|
this.apiError(e);
|
|
135
|
-
this.errorLog(
|
|
136
|
-
|
|
139
|
+
this.errorLog(
|
|
140
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
|
|
141
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
142
|
+
);
|
|
137
143
|
}
|
|
138
144
|
this.robotVacuumCleanerUpdateInProgress = false;
|
|
139
145
|
});
|
|
@@ -145,14 +151,15 @@ export class RobotVacuumCleaner {
|
|
|
145
151
|
async parseStatus(): Promise<void> {
|
|
146
152
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
147
153
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
148
|
-
}
|
|
154
|
+
} /*if (this.BLE) {
|
|
149
155
|
await this.BLEparseStatus();
|
|
150
|
-
} else*/if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
156
|
+
} else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
151
157
|
await this.openAPIparseStatus();
|
|
152
158
|
} else {
|
|
153
159
|
await this.offlineOff();
|
|
154
|
-
this.debugWarnLog(
|
|
155
|
-
|
|
160
|
+
this.debugWarnLog(
|
|
161
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
162
|
+
);
|
|
156
163
|
}
|
|
157
164
|
}
|
|
158
165
|
|
|
@@ -187,14 +194,16 @@ export class RobotVacuumCleaner {
|
|
|
187
194
|
async refreshStatus(): Promise<void> {
|
|
188
195
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
189
196
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
190
|
-
}
|
|
197
|
+
} /*if (this.BLE) {
|
|
191
198
|
await this.BLERefreshStatus();
|
|
192
|
-
} else*/if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
199
|
+
} else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
193
200
|
await this.openAPIRefreshStatus();
|
|
194
201
|
} else {
|
|
195
202
|
await this.offlineOff();
|
|
196
|
-
this.debugWarnLog(
|
|
197
|
-
|
|
203
|
+
this.debugWarnLog(
|
|
204
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
|
|
205
|
+
` ${this.device.connectionType}, refreshStatus will not happen.`,
|
|
206
|
+
);
|
|
198
207
|
}
|
|
199
208
|
}
|
|
200
209
|
|
|
@@ -219,8 +228,10 @@ export class RobotVacuumCleaner {
|
|
|
219
228
|
// Set an event hander
|
|
220
229
|
switchbot.onadvertisement = async (ad: any) => {
|
|
221
230
|
this.address = ad.address;
|
|
222
|
-
this.debugLog(
|
|
223
|
-
|
|
231
|
+
this.debugLog(
|
|
232
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
233
|
+
` BLE Address Found: ${this.address}`,
|
|
234
|
+
);
|
|
224
235
|
this.serviceData = ad.serviceData;
|
|
225
236
|
this.state = ad.serviceData.state;
|
|
226
237
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
@@ -248,8 +259,10 @@ export class RobotVacuumCleaner {
|
|
|
248
259
|
})
|
|
249
260
|
.catch(async (e: any) => {
|
|
250
261
|
this.apiError(e);
|
|
251
|
-
this.errorLog(
|
|
252
|
-
|
|
262
|
+
this.errorLog(
|
|
263
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
264
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
265
|
+
);
|
|
253
266
|
await this.BLERefreshConnection(switchbot);
|
|
254
267
|
});
|
|
255
268
|
} else {
|
|
@@ -267,17 +280,16 @@ export class RobotVacuumCleaner {
|
|
|
267
280
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
268
281
|
this.statusCode(statusCode);
|
|
269
282
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
270
|
-
this.debugLog(
|
|
271
|
-
`${this.device.deviceType}: ${this.accessory.displayName
|
|
272
|
-
} refreshStatus: ${JSON.stringify(deviceStatus)}`,
|
|
273
|
-
);
|
|
283
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
274
284
|
this.power = deviceStatus.body.power;
|
|
275
285
|
this.openAPIparseStatus();
|
|
276
286
|
this.updateHomeKitCharacteristics();
|
|
277
287
|
} catch (e: any) {
|
|
278
288
|
this.apiError(e);
|
|
279
|
-
this.errorLog(
|
|
280
|
-
|
|
289
|
+
this.errorLog(
|
|
290
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
|
|
291
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
292
|
+
);
|
|
281
293
|
}
|
|
282
294
|
}
|
|
283
295
|
|
|
@@ -293,14 +305,15 @@ export class RobotVacuumCleaner {
|
|
|
293
305
|
async pushChanges(): Promise<void> {
|
|
294
306
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
295
307
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
296
|
-
}
|
|
308
|
+
} /* if (this.BLE) {
|
|
297
309
|
await this.BLEpushChanges();
|
|
298
|
-
} else*/if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
310
|
+
} else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
299
311
|
await this.openAPIpushChanges();
|
|
300
312
|
} else {
|
|
301
313
|
await this.offlineOff();
|
|
302
|
-
this.debugWarnLog(
|
|
303
|
-
|
|
314
|
+
this.debugWarnLog(
|
|
315
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
|
|
316
|
+
);
|
|
304
317
|
}
|
|
305
318
|
// Refresh the status from the API
|
|
306
319
|
interval(15000)
|
|
@@ -346,14 +359,15 @@ export class RobotVacuumCleaner {
|
|
|
346
359
|
})
|
|
347
360
|
.catch(async (e: any) => {
|
|
348
361
|
this.apiError(e);
|
|
349
|
-
this.errorLog(
|
|
350
|
-
|
|
362
|
+
this.errorLog(
|
|
363
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
|
|
364
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
365
|
+
);
|
|
351
366
|
await this.BLEPushConnection();
|
|
352
367
|
});
|
|
353
368
|
} else {
|
|
354
369
|
this.debugLog(
|
|
355
|
-
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
|
|
356
|
-
+ `OnCached: ${this.accessory.context.On}`,
|
|
370
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, ` + `OnCached: ${this.accessory.context.On}`,
|
|
357
371
|
);
|
|
358
372
|
}
|
|
359
373
|
}
|
|
@@ -368,9 +382,9 @@ export class RobotVacuumCleaner {
|
|
|
368
382
|
command = 'turnOff';
|
|
369
383
|
}
|
|
370
384
|
const bodyChange = JSON.stringify({
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
385
|
+
command: `${command}`,
|
|
386
|
+
parameter: 'default',
|
|
387
|
+
commandType: 'command',
|
|
374
388
|
});
|
|
375
389
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
376
390
|
try {
|
|
@@ -385,13 +399,17 @@ export class RobotVacuumCleaner {
|
|
|
385
399
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
386
400
|
} catch (e: any) {
|
|
387
401
|
this.apiError(e);
|
|
388
|
-
this.errorLog(
|
|
389
|
-
|
|
402
|
+
this.errorLog(
|
|
403
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
|
|
404
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
390
405
|
);
|
|
391
406
|
}
|
|
392
407
|
} else {
|
|
393
|
-
this.debugLog(
|
|
394
|
-
|
|
408
|
+
this.debugLog(
|
|
409
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` +
|
|
410
|
+
`On: ${this.On}, ` +
|
|
411
|
+
`OnCached: ${this.accessory.context.On}`,
|
|
412
|
+
);
|
|
395
413
|
}
|
|
396
414
|
}
|
|
397
415
|
|
|
@@ -410,8 +428,9 @@ export class RobotVacuumCleaner {
|
|
|
410
428
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
411
429
|
} catch (e: any) {
|
|
412
430
|
this.apiError(e);
|
|
413
|
-
this.errorLog(
|
|
414
|
-
|
|
431
|
+
this.errorLog(
|
|
432
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
|
|
433
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
415
434
|
);
|
|
416
435
|
}
|
|
417
436
|
}
|
|
@@ -427,9 +446,9 @@ export class RobotVacuumCleaner {
|
|
|
427
446
|
parameter = 'default';
|
|
428
447
|
}
|
|
429
448
|
const body = JSON.stringify({
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
449
|
+
command: `${command}`,
|
|
450
|
+
parameter: `${parameter}`,
|
|
451
|
+
commandType: 'command',
|
|
433
452
|
});
|
|
434
453
|
return body;
|
|
435
454
|
}
|
|
@@ -454,9 +473,9 @@ export class RobotVacuumCleaner {
|
|
|
454
473
|
parameter = 'default';
|
|
455
474
|
}
|
|
456
475
|
const body = JSON.stringify({
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
476
|
+
command: `${command}`,
|
|
477
|
+
parameter: `${parameter}`,
|
|
478
|
+
commandType: 'command',
|
|
460
479
|
});
|
|
461
480
|
return body;
|
|
462
481
|
}
|
|
@@ -635,8 +654,10 @@ export class RobotVacuumCleaner {
|
|
|
635
654
|
this.offlineOff();
|
|
636
655
|
break;
|
|
637
656
|
case 171:
|
|
638
|
-
this.errorLog(
|
|
639
|
-
|
|
657
|
+
this.errorLog(
|
|
658
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
659
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
660
|
+
);
|
|
640
661
|
this.offlineOff();
|
|
641
662
|
break;
|
|
642
663
|
case 190:
|
|
@@ -652,8 +673,10 @@ export class RobotVacuumCleaner {
|
|
|
652
673
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
653
674
|
break;
|
|
654
675
|
default:
|
|
655
|
-
this.infoLog(
|
|
656
|
-
|
|
676
|
+
this.infoLog(
|
|
677
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
678
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
679
|
+
);
|
|
657
680
|
}
|
|
658
681
|
}
|
|
659
682
|
|
|
@@ -670,8 +693,9 @@ export class RobotVacuumCleaner {
|
|
|
670
693
|
|
|
671
694
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
672
695
|
let FirmwareRevision: string;
|
|
673
|
-
this.debugLog(
|
|
674
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
696
|
+
this.debugLog(
|
|
697
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
698
|
+
);
|
|
675
699
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
676
700
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
677
701
|
if (accessory.context.FirmwareRevision) {
|