@switchbot/homebridge-switchbot 3.5.0 → 3.5.1-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/.github/npm-version-script.cjs +81 -0
- package/config.schema.json +4 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +32 -63
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +31 -63
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +51 -111
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +38 -113
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +22 -49
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +53 -61
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +17 -1
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +112 -5
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +42 -95
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +7 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +52 -14
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +52 -99
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +25 -43
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +53 -115
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +33 -61
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +25 -43
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +24 -42
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +22 -40
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +29 -61
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +36 -77
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +21 -40
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +8 -25
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +6 -17
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +6 -17
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +6 -17
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +6 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +24 -0
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +6 -17
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +6 -17
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +6 -17
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +6 -17
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +6 -17
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +2 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/utils.d.ts +19 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +20 -1
- package/dist/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/device/blindtilt.ts +30 -63
- package/src/device/bot.ts +29 -63
- package/src/device/ceilinglight.ts +48 -111
- package/src/device/colorbulb.ts +37 -114
- package/src/device/contact.ts +20 -49
- package/src/device/curtain.ts +52 -62
- package/src/device/device.ts +124 -7
- package/src/device/fan.ts +40 -97
- package/src/device/hub.ts +53 -16
- package/src/device/humidifier.ts +49 -99
- package/src/device/iosensor.ts +23 -43
- package/src/device/lightstrip.ts +51 -116
- package/src/device/lock.ts +32 -62
- package/src/device/meter.ts +23 -43
- package/src/device/meterplus.ts +22 -42
- package/src/device/motion.ts +20 -40
- package/src/device/plug.ts +27 -61
- package/src/device/robotvacuumcleaner.ts +33 -78
- package/src/device/waterdetector.ts +20 -40
- package/src/irdevice/airconditioner.ts +8 -23
- package/src/irdevice/airpurifier.ts +6 -17
- package/src/irdevice/camera.ts +6 -17
- package/src/irdevice/fan.ts +6 -17
- package/src/irdevice/irdevice.ts +24 -0
- package/src/irdevice/light.ts +6 -17
- package/src/irdevice/other.ts +6 -17
- package/src/irdevice/tv.ts +6 -17
- package/src/irdevice/vacuumcleaner.ts +6 -17
- package/src/irdevice/waterheater.ts +6 -17
- package/src/settings.ts +2 -1
- package/src/utils.ts +20 -1
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
*
|
|
3
3
|
* airconditioners.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import { request } from 'undici';
|
|
6
|
-
import { Devices } from '../settings.js';
|
|
7
5
|
import { irdeviceBase } from './irdevice.js';
|
|
8
6
|
|
|
9
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
@@ -262,10 +260,8 @@ export class AirConditioner extends irdeviceBase {
|
|
|
262
260
|
|
|
263
261
|
if (this.HeaterCooler.Active === undefined) {
|
|
264
262
|
this.HeaterCooler.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
265
|
-
} else if (this.HeaterCooler.Active) {
|
|
266
|
-
this.HeaterCooler.Active;
|
|
267
263
|
} else {
|
|
268
|
-
this.HeaterCooler.Active = this.accessory.context.Active;
|
|
264
|
+
this.HeaterCooler.Active = this.HeaterCooler.Active ? this.HeaterCooler.Active : this.accessory.context.Active;
|
|
269
265
|
}
|
|
270
266
|
|
|
271
267
|
if (this.HeaterCooler.CurrentTemperature === undefined && this.accessory.context.CurrentTemperature === undefined) {
|
|
@@ -351,24 +347,15 @@ export class AirConditioner extends irdeviceBase {
|
|
|
351
347
|
if (this.device.connectionType === 'OpenAPI' && !this.disablePushDetail) {
|
|
352
348
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
353
349
|
try {
|
|
354
|
-
const { body, statusCode } = await
|
|
355
|
-
body: bodyChange,
|
|
356
|
-
method: 'POST',
|
|
357
|
-
headers: this.platform.generateHeaders(),
|
|
358
|
-
});
|
|
359
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
350
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
360
351
|
const deviceStatus: any = await body.json();
|
|
361
|
-
this.
|
|
362
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
352
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
363
353
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
364
|
-
this.
|
|
365
|
-
|
|
366
|
-
this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
367
|
-
+ ` request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
368
|
-
this.updateHomeKitCharacteristics();
|
|
354
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
355
|
+
await this.updateHomeKitCharacteristics();
|
|
369
356
|
} else {
|
|
370
|
-
this.statusCode(statusCode);
|
|
371
|
-
this.statusCode(deviceStatus.statusCode);
|
|
357
|
+
await this.statusCode(statusCode);
|
|
358
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
372
359
|
}
|
|
373
360
|
} catch (e: any) {
|
|
374
361
|
this.apiError(e);
|
|
@@ -520,10 +507,8 @@ export class AirConditioner extends irdeviceBase {
|
|
|
520
507
|
|
|
521
508
|
if (this.HeaterCooler.Active === undefined) {
|
|
522
509
|
this.HeaterCooler.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
523
|
-
} else if (this.HeaterCooler.Active) {
|
|
524
|
-
this.HeaterCooler.Active;
|
|
525
510
|
} else {
|
|
526
|
-
this.HeaterCooler.Active = this.accessory.context.Active;
|
|
511
|
+
this.HeaterCooler.Active = this.HeaterCooler.Active ? this.HeaterCooler.Active : this.accessory.context.Active;
|
|
527
512
|
}
|
|
528
513
|
|
|
529
514
|
if (this.HeaterCooler.CurrentTemperature === undefined && this.accessory.context.CurrentTemperature === undefined) {
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
*
|
|
3
3
|
* airpurifier.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import { request } from 'undici';
|
|
6
|
-
import { Devices } from '../settings.js';
|
|
7
5
|
import { irdeviceBase } from './irdevice.js';
|
|
8
6
|
|
|
9
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
@@ -226,24 +224,15 @@ export class AirPurifier extends irdeviceBase {
|
|
|
226
224
|
if (this.device.connectionType === 'OpenAPI') {
|
|
227
225
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
228
226
|
try {
|
|
229
|
-
const { body, statusCode } = await
|
|
230
|
-
body: bodyChange,
|
|
231
|
-
method: 'POST',
|
|
232
|
-
headers: this.platform.generateHeaders(),
|
|
233
|
-
});
|
|
234
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
227
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
235
228
|
const deviceStatus: any = await body.json();
|
|
236
|
-
this.
|
|
237
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
229
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
238
230
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
239
|
-
this.
|
|
240
|
-
|
|
241
|
-
this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
242
|
-
+ ` request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
243
|
-
this.updateHomeKitCharacteristics();
|
|
231
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
232
|
+
await this.updateHomeKitCharacteristics();
|
|
244
233
|
} else {
|
|
245
|
-
this.statusCode(statusCode);
|
|
246
|
-
this.statusCode(deviceStatus.statusCode);
|
|
234
|
+
await this.statusCode(statusCode);
|
|
235
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
247
236
|
}
|
|
248
237
|
} catch (e: any) {
|
|
249
238
|
this.apiError(e);
|
package/src/irdevice/camera.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
*
|
|
3
3
|
* camera.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import { request } from 'undici';
|
|
6
|
-
import { Devices } from '../settings.js';
|
|
7
5
|
import { irdeviceBase } from './irdevice.js';
|
|
8
6
|
|
|
9
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
@@ -104,24 +102,15 @@ export class Camera extends irdeviceBase {
|
|
|
104
102
|
if (this.device.connectionType === 'OpenAPI') {
|
|
105
103
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
106
104
|
try {
|
|
107
|
-
const { body, statusCode } = await
|
|
108
|
-
body: bodyChange,
|
|
109
|
-
method: 'POST',
|
|
110
|
-
headers: this.platform.generateHeaders(),
|
|
111
|
-
});
|
|
112
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
105
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
113
106
|
const deviceStatus: any = await body.json();
|
|
114
|
-
this.
|
|
115
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
107
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
116
108
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
117
|
-
this.
|
|
118
|
-
|
|
119
|
-
this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
120
|
-
+ ` request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
121
|
-
this.updateHomeKitCharacteristics();
|
|
109
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
110
|
+
await this.updateHomeKitCharacteristics();
|
|
122
111
|
} else {
|
|
123
|
-
this.statusCode(statusCode);
|
|
124
|
-
this.statusCode(deviceStatus.statusCode);
|
|
112
|
+
await this.statusCode(statusCode);
|
|
113
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
125
114
|
}
|
|
126
115
|
} catch (e: any) {
|
|
127
116
|
this.apiError(e);
|
package/src/irdevice/fan.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
*
|
|
3
3
|
* fan.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import { request } from 'undici';
|
|
6
|
-
import { Devices } from '../settings.js';
|
|
7
5
|
import { irdeviceBase } from './irdevice.js';
|
|
8
6
|
|
|
9
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
@@ -204,24 +202,15 @@ export class IRFan extends irdeviceBase {
|
|
|
204
202
|
if (this.device.connectionType === 'OpenAPI') {
|
|
205
203
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
206
204
|
try {
|
|
207
|
-
const { body, statusCode } = await
|
|
208
|
-
body: bodyChange,
|
|
209
|
-
method: 'POST',
|
|
210
|
-
headers: this.platform.generateHeaders(),
|
|
211
|
-
});
|
|
212
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
205
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
213
206
|
const deviceStatus: any = await body.json();
|
|
214
|
-
this.
|
|
215
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
207
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
216
208
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
217
|
-
this.
|
|
218
|
-
|
|
219
|
-
this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
220
|
-
+ ` request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
221
|
-
this.updateHomeKitCharacteristics();
|
|
209
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
210
|
+
await this.updateHomeKitCharacteristics();
|
|
222
211
|
} else {
|
|
223
|
-
this.statusCode(statusCode);
|
|
224
|
-
this.statusCode(deviceStatus.statusCode);
|
|
212
|
+
await this.statusCode(statusCode);
|
|
213
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
225
214
|
}
|
|
226
215
|
} catch (e: any) {
|
|
227
216
|
this.apiError(e);
|
package/src/irdevice/irdevice.ts
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
*
|
|
3
3
|
* device.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
+
import { request } from 'undici';
|
|
6
|
+
import { Devices } from '../settings.js';
|
|
7
|
+
|
|
5
8
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
6
9
|
import type { API, HAP, Logging, PlatformAccessory } from 'homebridge';
|
|
7
10
|
import type { SwitchBotPlatformConfig, irDevicesConfig, irdevice } from '../settings.js';
|
|
@@ -189,6 +192,27 @@ export abstract class irdeviceBase {
|
|
|
189
192
|
this.debugSuccessLog(`${device.remoteType}: ${accessory.displayName} deviceVersion: ${accessory.context.deviceVersion}`);
|
|
190
193
|
}
|
|
191
194
|
|
|
195
|
+
async pushChangeRequest(bodyChange: string): Promise<{ body: any; statusCode: any; }> {
|
|
196
|
+
return await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
197
|
+
body: bodyChange,
|
|
198
|
+
method: 'POST',
|
|
199
|
+
headers: this.platform.generateHeaders(),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async pushStatusCodes(statusCode: any, deviceStatus: any) {
|
|
204
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
205
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
206
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async successfulPushChange(statusCode: any, deviceStatus: any, bodyChange: any) {
|
|
210
|
+
this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode} & deviceStatus `
|
|
211
|
+
+ `StatusCode: ${deviceStatus.statusCode}`);
|
|
212
|
+
this.successLog(`${this.device.remoteType}: ${this.accessory.displayName} request to SwitchBot API,`
|
|
213
|
+
+ ` body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
214
|
+
}
|
|
215
|
+
|
|
192
216
|
async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
193
217
|
if (device.disablePushOn === undefined) {
|
|
194
218
|
this.disablePushOn = false;
|
package/src/irdevice/light.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
*
|
|
3
3
|
* light.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import { request } from 'undici';
|
|
6
|
-
import { Devices } from '../settings.js';
|
|
7
5
|
import { irdeviceBase } from './irdevice.js';
|
|
8
6
|
|
|
9
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
@@ -217,25 +215,16 @@ export class Light extends irdeviceBase {
|
|
|
217
215
|
if (this.device.connectionType === 'OpenAPI') {
|
|
218
216
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
219
217
|
try {
|
|
220
|
-
const { body, statusCode } = await
|
|
221
|
-
body: bodyChange,
|
|
222
|
-
method: 'POST',
|
|
223
|
-
headers: this.platform.generateHeaders(),
|
|
224
|
-
});
|
|
225
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
218
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
226
219
|
const deviceStatus: any = await body.json();
|
|
227
|
-
this.
|
|
228
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
220
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
229
221
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
230
|
-
this.
|
|
231
|
-
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
232
|
-
this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
233
|
-
+ ` request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
222
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
234
223
|
this.accessory.context.On = On;
|
|
235
|
-
this.updateHomeKitCharacteristics();
|
|
224
|
+
await this.updateHomeKitCharacteristics();
|
|
236
225
|
} else {
|
|
237
|
-
this.statusCode(statusCode);
|
|
238
|
-
this.statusCode(deviceStatus.statusCode);
|
|
226
|
+
await this.statusCode(statusCode);
|
|
227
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
239
228
|
}
|
|
240
229
|
} catch (e: any) {
|
|
241
230
|
this.apiError(e);
|
package/src/irdevice/other.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
*
|
|
3
3
|
* other.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import { request } from 'undici';
|
|
6
|
-
import { Devices } from '../settings.js';
|
|
7
5
|
import { irdeviceBase } from './irdevice.js';
|
|
8
6
|
|
|
9
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
@@ -535,24 +533,15 @@ export class Others extends irdeviceBase {
|
|
|
535
533
|
if (this.device.connectionType === 'OpenAPI') {
|
|
536
534
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
537
535
|
try {
|
|
538
|
-
const { body, statusCode } = await
|
|
539
|
-
body: bodyChange,
|
|
540
|
-
method: 'POST',
|
|
541
|
-
headers: this.platform.generateHeaders(),
|
|
542
|
-
});
|
|
543
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
536
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
544
537
|
const deviceStatus: any = await body.json();
|
|
545
|
-
this.
|
|
546
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
538
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
547
539
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
548
|
-
this.
|
|
549
|
-
|
|
550
|
-
this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
551
|
-
+ ` request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
552
|
-
this.updateHomeKitCharacteristics();
|
|
540
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
541
|
+
await this.updateHomeKitCharacteristics();
|
|
553
542
|
} else {
|
|
554
|
-
this.statusCode(statusCode);
|
|
555
|
-
this.statusCode(deviceStatus.statusCode);
|
|
543
|
+
await this.statusCode(statusCode);
|
|
544
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
556
545
|
}
|
|
557
546
|
} catch (e: any) {
|
|
558
547
|
this.apiError(e);
|
package/src/irdevice/tv.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
*
|
|
3
3
|
* tv.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import { request } from 'undici';
|
|
6
|
-
import { Devices } from '../settings.js';
|
|
7
5
|
import { irdeviceBase } from './irdevice.js';
|
|
8
6
|
|
|
9
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
@@ -367,24 +365,15 @@ export class TV extends irdeviceBase {
|
|
|
367
365
|
if (this.device.connectionType === 'OpenAPI') {
|
|
368
366
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
369
367
|
try {
|
|
370
|
-
const { body, statusCode } = await
|
|
371
|
-
body: bodyChange,
|
|
372
|
-
method: 'POST',
|
|
373
|
-
headers: this.platform.generateHeaders(),
|
|
374
|
-
});
|
|
375
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
368
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
376
369
|
const deviceStatus: any = await body.json();
|
|
377
|
-
this.
|
|
378
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
370
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
379
371
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
380
|
-
this.
|
|
381
|
-
|
|
382
|
-
this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
383
|
-
+ ` request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
384
|
-
this.updateHomeKitCharacteristics();
|
|
372
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
373
|
+
await this.updateHomeKitCharacteristics();
|
|
385
374
|
} else {
|
|
386
|
-
this.statusCode(statusCode);
|
|
387
|
-
this.statusCode(deviceStatus.statusCode);
|
|
375
|
+
await this.statusCode(statusCode);
|
|
376
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
388
377
|
}
|
|
389
378
|
} catch (e: any) {
|
|
390
379
|
this.apiError(e);
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
*
|
|
3
3
|
* vacuumcleaner.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import { request } from 'undici';
|
|
6
|
-
import { Devices } from '../settings.js';
|
|
7
5
|
import { irdeviceBase } from './irdevice.js';
|
|
8
6
|
|
|
9
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
@@ -101,24 +99,15 @@ export class VacuumCleaner extends irdeviceBase {
|
|
|
101
99
|
if (this.device.connectionType === 'OpenAPI') {
|
|
102
100
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
103
101
|
try {
|
|
104
|
-
const { body, statusCode } = await
|
|
105
|
-
body: bodyChange,
|
|
106
|
-
method: 'POST',
|
|
107
|
-
headers: this.platform.generateHeaders(),
|
|
108
|
-
});
|
|
109
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
102
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
110
103
|
const deviceStatus: any = await body.json();
|
|
111
|
-
this.
|
|
112
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
104
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
113
105
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
114
|
-
this.
|
|
115
|
-
|
|
116
|
-
this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
117
|
-
+ ` request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
118
|
-
this.updateHomeKitCharacteristics();
|
|
106
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
107
|
+
await this.updateHomeKitCharacteristics();
|
|
119
108
|
} else {
|
|
120
|
-
this.statusCode(statusCode);
|
|
121
|
-
this.statusCode(deviceStatus.statusCode);
|
|
109
|
+
await this.statusCode(statusCode);
|
|
110
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
122
111
|
}
|
|
123
112
|
} catch (e: any) {
|
|
124
113
|
this.apiError(e);
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
*
|
|
3
3
|
* waterheater.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import { request } from 'undici';
|
|
6
|
-
import { Devices } from '../settings.js';
|
|
7
5
|
import { irdeviceBase } from './irdevice.js';
|
|
8
6
|
|
|
9
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
@@ -103,24 +101,15 @@ export class WaterHeater extends irdeviceBase {
|
|
|
103
101
|
if (this.device.connectionType === 'OpenAPI') {
|
|
104
102
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
105
103
|
try {
|
|
106
|
-
const { body, statusCode } = await
|
|
107
|
-
body: bodyChange,
|
|
108
|
-
method: 'POST',
|
|
109
|
-
headers: this.platform.generateHeaders(),
|
|
110
|
-
});
|
|
111
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
104
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
112
105
|
const deviceStatus: any = await body.json();
|
|
113
|
-
this.
|
|
114
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
106
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
115
107
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
116
|
-
this.
|
|
117
|
-
|
|
118
|
-
this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
119
|
-
+ ` request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
120
|
-
this.updateHomeKitCharacteristics();
|
|
108
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
109
|
+
await this.updateHomeKitCharacteristics();
|
|
121
110
|
} else {
|
|
122
|
-
this.statusCode(statusCode);
|
|
123
|
-
this.statusCode(deviceStatus.statusCode);
|
|
111
|
+
await this.statusCode(statusCode);
|
|
112
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
124
113
|
}
|
|
125
114
|
} catch (e: any) {
|
|
126
115
|
this.apiError(e);
|
package/src/settings.ts
CHANGED
|
@@ -71,6 +71,7 @@ export interface devicesConfig extends device {
|
|
|
71
71
|
bleMac?: string;
|
|
72
72
|
model?: string;
|
|
73
73
|
bleModel?: string;
|
|
74
|
+
bleModelName?: string;
|
|
74
75
|
configDeviceType: string;
|
|
75
76
|
configDeviceName?: string;
|
|
76
77
|
deviceId: string;
|
|
@@ -425,7 +426,7 @@ export type serviceData = {
|
|
|
425
426
|
//Meter Temperature Levels
|
|
426
427
|
temperature?: temperature;
|
|
427
428
|
// Fahrenheit enabled for Meter
|
|
428
|
-
fahrenheit
|
|
429
|
+
fahrenheit?: boolean;
|
|
429
430
|
// Humidity level for Meter
|
|
430
431
|
humidity?: number;
|
|
431
432
|
//Motion Detected for Contact or Motion Sensors
|
package/src/utils.ts
CHANGED
|
@@ -51,6 +51,7 @@ export enum SwitchBotBLEModel {
|
|
|
51
51
|
Humidifier = 'e',
|
|
52
52
|
Meter = 'T',
|
|
53
53
|
MeterPlus = 'i',
|
|
54
|
+
Hub2 = 'v',
|
|
54
55
|
OutdoorMeter = 'w',
|
|
55
56
|
MotionSensor = 's',
|
|
56
57
|
ContactSensor = 'd',
|
|
@@ -59,13 +60,31 @@ export enum SwitchBotBLEModel {
|
|
|
59
60
|
PlugMiniUS = 'g',
|
|
60
61
|
PlugMiniJP = 'j',
|
|
61
62
|
Lock = 'o',
|
|
62
|
-
Remote = '',
|
|
63
63
|
CeilingLight = 'q', // Currently only available in Japan.
|
|
64
64
|
CeilingLightPro = 'n', // Currently only available in Japan.
|
|
65
65
|
BlindTilt = 'x',
|
|
66
66
|
Unknown = 'Unknown',
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
export enum SwitchBotBLEModelName {
|
|
70
|
+
Bot = 'WoHand',
|
|
71
|
+
Hub2 = 'WoHub2',
|
|
72
|
+
ColorBulb = 'WoBulb',
|
|
73
|
+
Curtain = 'WoCurtain',
|
|
74
|
+
Curtain3 = 'WoCurtain3',
|
|
75
|
+
Humidifier = 'WoHumi',
|
|
76
|
+
Meter = 'WoSensorTH',
|
|
77
|
+
Lock = 'WoSmartLock',
|
|
78
|
+
PlugMini = 'WoPlugMini',
|
|
79
|
+
StripLight = 'WoStrip',
|
|
80
|
+
MeterPlus = 'WoSensorTHPlus',
|
|
81
|
+
OutdoorMeter = 'WoIOSensorTH',
|
|
82
|
+
ContactSensor = 'WoContact',
|
|
83
|
+
MotionSensor = 'WoMotion',
|
|
84
|
+
BlindTilt = 'WoBlindTilt',
|
|
85
|
+
Unknown = 'Unknown',
|
|
86
|
+
}
|
|
87
|
+
|
|
69
88
|
export enum BlindTiltMappingMode {
|
|
70
89
|
OnlyUp = 'only_up',
|
|
71
90
|
OnlyDown = 'only_down',
|