@switchbot/homebridge-switchbot 1.15.0 → 1.15.1-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/config.schema.json +12 -5
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +10 -10
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +15 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +140 -13
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +12 -9
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +13 -9
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +9 -8
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +2 -1
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +29 -18
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +6 -5
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +6 -5
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +7 -7
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +5 -5
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +7 -11
- package/dist/device/striplight.js.map +1 -1
- package/dist/platform.d.ts +7 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +75 -13
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +3 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +81 -79
- package/src/device/bot.ts +10 -10
- package/src/device/colorbulb.ts +169 -18
- package/src/device/contact.ts +13 -10
- package/src/device/curtain.ts +13 -9
- package/src/device/humidifier.ts +9 -8
- package/src/device/lock.ts +4 -3
- package/src/device/meter.ts +46 -36
- package/src/device/meterplus.ts +6 -5
- package/src/device/motion.ts +6 -5
- package/src/device/plug.ts +13 -13
- package/src/device/striplight.ts +8 -14
- package/src/platform.ts +81 -13
- package/src/settings.ts +3 -1
package/src/device/humidifier.ts
CHANGED
|
@@ -80,7 +80,8 @@ export class Humidifier {
|
|
|
80
80
|
.setCharacteristic(this.platform.Characteristic.Model, 'W0801800')
|
|
81
81
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
82
82
|
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
83
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
83
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
84
|
+
.updateValue(this.FirmwareRevision(accessory, device));
|
|
84
85
|
|
|
85
86
|
// get the service if it exists, otherwise create a new service
|
|
86
87
|
// you can create multiple services for each accessory
|
|
@@ -214,7 +215,7 @@ export class Humidifier {
|
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
async openAPIparseStatus(): Promise<void> {
|
|
217
|
-
if (this.platform.config.credentials?.
|
|
218
|
+
if (this.platform.config.credentials?.token) {
|
|
218
219
|
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
219
220
|
// Current Relative Humidity
|
|
220
221
|
this.CurrentRelativeHumidity = this.humidity!;
|
|
@@ -346,7 +347,7 @@ export class Humidifier {
|
|
|
346
347
|
`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
347
348
|
);
|
|
348
349
|
}
|
|
349
|
-
if (this.platform.config.credentials?.
|
|
350
|
+
if (this.platform.config.credentials?.token) {
|
|
350
351
|
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
351
352
|
await this.openAPIRefreshStatus();
|
|
352
353
|
}
|
|
@@ -377,14 +378,14 @@ export class Humidifier {
|
|
|
377
378
|
|
|
378
379
|
async BLEconnection(switchbot: any): Promise<void> {
|
|
379
380
|
this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
380
|
-
if (this.platform.config.credentials?.
|
|
381
|
+
if (this.platform.config.credentials?.token) {
|
|
381
382
|
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
382
383
|
await this.openAPIRefreshStatus();
|
|
383
384
|
}
|
|
384
385
|
}
|
|
385
386
|
|
|
386
387
|
async openAPIRefreshStatus(): Promise<void> {
|
|
387
|
-
if (this.platform.config.credentials?.
|
|
388
|
+
if (this.platform.config.credentials?.token) {
|
|
388
389
|
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
389
390
|
try {
|
|
390
391
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
@@ -456,7 +457,7 @@ export class Humidifier {
|
|
|
456
457
|
`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
457
458
|
);
|
|
458
459
|
}
|
|
459
|
-
if (this.platform.config.credentials?.
|
|
460
|
+
if (this.platform.config.credentials?.token) {
|
|
460
461
|
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
461
462
|
await this.openAPIpushChanges();
|
|
462
463
|
}
|
|
@@ -464,7 +465,7 @@ export class Humidifier {
|
|
|
464
465
|
});
|
|
465
466
|
} else {
|
|
466
467
|
this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
467
|
-
if (this.platform.config.credentials?.
|
|
468
|
+
if (this.platform.config.credentials?.token) {
|
|
468
469
|
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
469
470
|
await this.openAPIpushChanges();
|
|
470
471
|
}
|
|
@@ -472,7 +473,7 @@ export class Humidifier {
|
|
|
472
473
|
}
|
|
473
474
|
|
|
474
475
|
async openAPIpushChanges(): Promise<void> {
|
|
475
|
-
if (this.platform.config.credentials?.
|
|
476
|
+
if (this.platform.config.credentials?.token) {
|
|
476
477
|
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
477
478
|
if (
|
|
478
479
|
this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
package/src/device/lock.ts
CHANGED
|
@@ -56,7 +56,8 @@ export class Lock {
|
|
|
56
56
|
.setCharacteristic(this.platform.Characteristic.Model, 'W1601700')
|
|
57
57
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
58
58
|
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
59
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
59
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
60
|
+
.updateValue(this.FirmwareRevision(accessory, device));
|
|
60
61
|
|
|
61
62
|
// get the LockMechanism service if it exists, otherwise create a new LockMechanism service
|
|
62
63
|
// you can create multiple services for each accessory
|
|
@@ -187,7 +188,7 @@ export class Lock {
|
|
|
187
188
|
|
|
188
189
|
this.infoLog(
|
|
189
190
|
`Lock: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
190
|
-
|
|
191
|
+
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
191
192
|
);
|
|
192
193
|
|
|
193
194
|
// Make the API request
|
|
@@ -254,7 +255,7 @@ export class Lock {
|
|
|
254
255
|
case 190:
|
|
255
256
|
this.errorLog(
|
|
256
257
|
`Lock: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
257
|
-
|
|
258
|
+
` Or command: ${JSON.stringify(push.data)} format is invalid`,
|
|
258
259
|
);
|
|
259
260
|
break;
|
|
260
261
|
case 100:
|
package/src/device/meter.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceSta
|
|
|
6
6
|
import { Context } from 'vm';
|
|
7
7
|
import { MqttClient } from 'mqtt';
|
|
8
8
|
import { connectAsync } from 'async-mqtt';
|
|
9
|
-
import { hostname } from
|
|
9
|
+
import { hostname } from 'os';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Platform Accessory
|
|
@@ -56,7 +56,7 @@ export class Meter {
|
|
|
56
56
|
|
|
57
57
|
//MQTT stuff
|
|
58
58
|
mqttClient: MqttClient | null = null;
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
// EVE history service handler
|
|
61
61
|
historyService: any;
|
|
62
62
|
|
|
@@ -93,7 +93,8 @@ export class Meter {
|
|
|
93
93
|
.setCharacteristic(this.platform.Characteristic.Model, 'METERTH-S1')
|
|
94
94
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
95
95
|
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
96
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
96
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
97
|
+
.updateValue(this.FirmwareRevision(accessory, device));
|
|
97
98
|
|
|
98
99
|
// Temperature Sensor Service
|
|
99
100
|
if (device.meter?.hide_temperature) {
|
|
@@ -182,7 +183,10 @@ export class Meter {
|
|
|
182
183
|
* 'homebridge-switchbot/meter/xx:xx:xx:xx:xx:xx'
|
|
183
184
|
*/
|
|
184
185
|
mqttPublish(message: any) {
|
|
185
|
-
const mac = this.device.deviceId
|
|
186
|
+
const mac = this.device.deviceId
|
|
187
|
+
?.toLowerCase()
|
|
188
|
+
.match(/[\s\S]{1,2}/g)
|
|
189
|
+
?.join(':');
|
|
186
190
|
const options = this.device.mqttPubOptions || {};
|
|
187
191
|
this.mqttClient?.publish(`homebridge-switchbot/meter/${mac}`, `${message}`, options);
|
|
188
192
|
this.debugLog(`Meter: ${this.accessory.displayName} MQTT message: ${message} options:${JSON.stringify(options)}`);
|
|
@@ -194,14 +198,14 @@ export class Meter {
|
|
|
194
198
|
async setupMqtt(device: device & devicesConfig): Promise<void> {
|
|
195
199
|
if (device.mqttURL) {
|
|
196
200
|
try {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
this.mqttClient = await connectAsync(device.mqttURL, device.mqttOptions || {});
|
|
202
|
+
this.debugLog(`Meter: ${this.accessory.displayName} MQTT connection has been established successfully.`);
|
|
203
|
+
this.mqttClient.on('error', (e: Error) => {
|
|
204
|
+
this.errorLog(`Meter: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
|
|
205
|
+
});
|
|
202
206
|
} catch (e) {
|
|
203
|
-
|
|
204
|
-
|
|
207
|
+
this.mqttClient = null;
|
|
208
|
+
this.errorLog(`Meter: ${this.accessory.displayName} Failed to establish MQTT connection. ${e}`);
|
|
205
209
|
}
|
|
206
210
|
}
|
|
207
211
|
}
|
|
@@ -210,15 +214,19 @@ export class Meter {
|
|
|
210
214
|
* Setup EVE history graph feature if enabled.
|
|
211
215
|
*/
|
|
212
216
|
async setupHistoryService(device: device & devicesConfig): Promise<void> {
|
|
213
|
-
const mac = this.device
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
217
|
+
const mac = this.device
|
|
218
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
219
|
+
.join(':')
|
|
220
|
+
.toLowerCase();
|
|
221
|
+
this.historyService = device.history
|
|
222
|
+
? new this.platform.fakegatoAPI('room', this.accessory, {
|
|
223
|
+
log: this.platform.log,
|
|
224
|
+
storage: 'fs',
|
|
225
|
+
filename: `${hostname().split('.')[0]}_${mac}_persist.json`,
|
|
226
|
+
})
|
|
227
|
+
: null;
|
|
220
228
|
}
|
|
221
|
-
|
|
229
|
+
|
|
222
230
|
/**
|
|
223
231
|
* Parse the device status from the SwitchBot api
|
|
224
232
|
*/
|
|
@@ -240,7 +248,7 @@ export class Meter {
|
|
|
240
248
|
} else {
|
|
241
249
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
242
250
|
}
|
|
243
|
-
|
|
251
|
+
this.debugLog(`Meter: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
244
252
|
|
|
245
253
|
// Humidity
|
|
246
254
|
if (!this.device.meter?.hide_humidity) {
|
|
@@ -260,7 +268,7 @@ export class Meter {
|
|
|
260
268
|
if (this.device.ble) {
|
|
261
269
|
this.SwitchToOpenAPI = false;
|
|
262
270
|
}
|
|
263
|
-
if (this.platform.config.credentials?.
|
|
271
|
+
if (this.platform.config.credentials?.token) {
|
|
264
272
|
this.debugLog(`Meter: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
265
273
|
// Current Relative Humidity
|
|
266
274
|
if (!this.device.meter?.hide_humidity) {
|
|
@@ -314,12 +322,13 @@ export class Meter {
|
|
|
314
322
|
this.infoLog(`Meter: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
|
|
315
323
|
this.infoLog(`Meter: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
|
|
316
324
|
}
|
|
317
|
-
|
|
325
|
+
if (ad.serviceData.humidity! > 0) {
|
|
326
|
+
// reject unreliable data
|
|
318
327
|
this.serviceData = ad.serviceData;
|
|
319
328
|
this.temperature = ad.serviceData.temperature!.c;
|
|
320
329
|
this.humidity = ad.serviceData.humidity;
|
|
321
330
|
this.battery = ad.serviceData.battery;
|
|
322
|
-
|
|
331
|
+
}
|
|
323
332
|
this.debugLog(`Meter: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
324
333
|
this.debugLog(
|
|
325
334
|
`Meter: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
|
|
@@ -355,7 +364,7 @@ export class Meter {
|
|
|
355
364
|
`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
356
365
|
);
|
|
357
366
|
}
|
|
358
|
-
if (this.platform.config.credentials?.
|
|
367
|
+
if (this.platform.config.credentials?.token) {
|
|
359
368
|
this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
360
369
|
this.SwitchToOpenAPI = true;
|
|
361
370
|
this.openAPIRefreshStatus();
|
|
@@ -387,7 +396,7 @@ export class Meter {
|
|
|
387
396
|
|
|
388
397
|
async BLEconnection(switchbot: any): Promise<void> {
|
|
389
398
|
this.errorLog(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
390
|
-
if (this.platform.config.credentials?.
|
|
399
|
+
if (this.platform.config.credentials?.token) {
|
|
391
400
|
this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
392
401
|
this.SwitchToOpenAPI = true;
|
|
393
402
|
await this.openAPIRefreshStatus();
|
|
@@ -395,7 +404,7 @@ export class Meter {
|
|
|
395
404
|
}
|
|
396
405
|
|
|
397
406
|
async openAPIRefreshStatus(): Promise<void> {
|
|
398
|
-
if (this.platform.config.credentials?.
|
|
407
|
+
if (this.platform.config.credentials?.token) {
|
|
399
408
|
this.debugLog(`Meter: ${this.accessory.displayName} OpenAPI RefreshStatus`);
|
|
400
409
|
try {
|
|
401
410
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
@@ -420,16 +429,16 @@ export class Meter {
|
|
|
420
429
|
* Updates the status for each of the HomeKit Characteristics
|
|
421
430
|
*/
|
|
422
431
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
423
|
-
|
|
424
|
-
|
|
432
|
+
const mqttmessage: string[] = [];
|
|
433
|
+
const entry = { time: Math.round(new Date().valueOf() / 1000) };
|
|
425
434
|
if (!this.device.meter?.hide_humidity) {
|
|
426
435
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
427
436
|
this.debugLog(`Meter: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
428
437
|
} else {
|
|
429
438
|
this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
430
439
|
this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
431
|
-
|
|
432
|
-
|
|
440
|
+
mqttmessage.push(`"humidity": ${this.CurrentRelativeHumidity}`);
|
|
441
|
+
entry['humidity'] = this.CurrentRelativeHumidity;
|
|
433
442
|
}
|
|
434
443
|
}
|
|
435
444
|
if (!this.device.meter?.hide_temperature) {
|
|
@@ -438,8 +447,8 @@ export class Meter {
|
|
|
438
447
|
} else {
|
|
439
448
|
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
440
449
|
this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
441
|
-
|
|
442
|
-
|
|
450
|
+
mqttmessage.push(`"temperature": ${this.CurrentTemperature}`);
|
|
451
|
+
entry['temp'] = this.CurrentTemperature;
|
|
443
452
|
}
|
|
444
453
|
}
|
|
445
454
|
if (this.device.ble) {
|
|
@@ -448,18 +457,19 @@ export class Meter {
|
|
|
448
457
|
} else {
|
|
449
458
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
450
459
|
this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
451
|
-
|
|
460
|
+
mqttmessage.push(`"battery": ${this.BatteryLevel}`);
|
|
452
461
|
}
|
|
453
462
|
if (this.StatusLowBattery === undefined) {
|
|
454
463
|
this.debugLog(`Meter: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
455
464
|
} else {
|
|
456
465
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
457
466
|
this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
458
|
-
|
|
467
|
+
mqttmessage.push(`"lowBattery": ${this.StatusLowBattery}`);
|
|
459
468
|
}
|
|
460
469
|
}
|
|
461
|
-
this.mqttPublish(`{${mqttmessage.join(',')}}`)
|
|
462
|
-
if (this.CurrentRelativeHumidity > 0) {
|
|
470
|
+
this.mqttPublish(`{${mqttmessage.join(',')}}`);
|
|
471
|
+
if (this.CurrentRelativeHumidity > 0) {
|
|
472
|
+
// reject unreliable data
|
|
463
473
|
this.historyService?.addEntry(entry);
|
|
464
474
|
}
|
|
465
475
|
}
|
package/src/device/meterplus.ts
CHANGED
|
@@ -82,7 +82,8 @@ export class MeterPlus {
|
|
|
82
82
|
.setCharacteristic(this.platform.Characteristic.Model, this.model(device))
|
|
83
83
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
84
84
|
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
85
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
85
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
86
|
+
.updateValue(this.FirmwareRevision(accessory, device));
|
|
86
87
|
|
|
87
88
|
// Temperature Sensor Service
|
|
88
89
|
if (device.meter?.hide_temperature) {
|
|
@@ -207,7 +208,7 @@ export class MeterPlus {
|
|
|
207
208
|
if (this.device.ble) {
|
|
208
209
|
this.SwitchToOpenAPI = false;
|
|
209
210
|
}
|
|
210
|
-
if (this.platform.config.credentials?.
|
|
211
|
+
if (this.platform.config.credentials?.token) {
|
|
211
212
|
this.debugLog(`Meter Plus: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
212
213
|
// Current Relative Humidity
|
|
213
214
|
if (!this.device.meter?.hide_humidity) {
|
|
@@ -300,7 +301,7 @@ export class MeterPlus {
|
|
|
300
301
|
`Meter Plus: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
301
302
|
);
|
|
302
303
|
}
|
|
303
|
-
if (this.platform.config.credentials?.
|
|
304
|
+
if (this.platform.config.credentials?.token) {
|
|
304
305
|
this.warnLog(`Meter Plus: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
305
306
|
this.SwitchToOpenAPI = true;
|
|
306
307
|
this.openAPIRefreshStatus();
|
|
@@ -332,7 +333,7 @@ export class MeterPlus {
|
|
|
332
333
|
|
|
333
334
|
async BLEconnection(switchbot: any): Promise<void> {
|
|
334
335
|
this.errorLog(`Meter Plus: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
335
|
-
if (this.platform.config.credentials?.
|
|
336
|
+
if (this.platform.config.credentials?.token) {
|
|
336
337
|
this.warnLog(`Meter Plus: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
337
338
|
this.SwitchToOpenAPI = true;
|
|
338
339
|
await this.openAPIRefreshStatus();
|
|
@@ -340,7 +341,7 @@ export class MeterPlus {
|
|
|
340
341
|
}
|
|
341
342
|
|
|
342
343
|
async openAPIRefreshStatus(): Promise<void> {
|
|
343
|
-
if (this.platform.config.credentials?.
|
|
344
|
+
if (this.platform.config.credentials?.token) {
|
|
344
345
|
this.debugLog(`Meter Plus: ${this.accessory.displayName} OpenAPI RefreshStatus`);
|
|
345
346
|
try {
|
|
346
347
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
package/src/device/motion.ts
CHANGED
|
@@ -70,7 +70,8 @@ export class Motion {
|
|
|
70
70
|
.setCharacteristic(this.platform.Characteristic.Model, 'W1101500')
|
|
71
71
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
72
72
|
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
73
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
73
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
74
|
+
.updateValue(this.FirmwareRevision(accessory, device));
|
|
74
75
|
|
|
75
76
|
// get the Battery service if it exists, otherwise create a new Motion service
|
|
76
77
|
// you can create multiple services for each accessory
|
|
@@ -180,7 +181,7 @@ export class Motion {
|
|
|
180
181
|
if (this.device.ble) {
|
|
181
182
|
this.SwitchToOpenAPI = false;
|
|
182
183
|
}
|
|
183
|
-
if (this.platform.config.credentials?.
|
|
184
|
+
if (this.platform.config.credentials?.token) {
|
|
184
185
|
this.debugLog(`Motion Sensor: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
185
186
|
// Motion State
|
|
186
187
|
this.MotionDetected = this.moveDetected!;
|
|
@@ -282,7 +283,7 @@ export class Motion {
|
|
|
282
283
|
` Error Message: ${JSON.stringify(e.message)}`,
|
|
283
284
|
);
|
|
284
285
|
}
|
|
285
|
-
if (this.platform.config.credentials?.
|
|
286
|
+
if (this.platform.config.credentials?.token) {
|
|
286
287
|
this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
287
288
|
this.SwitchToOpenAPI = true;
|
|
288
289
|
await this.openAPIRefreshStatus();
|
|
@@ -314,7 +315,7 @@ export class Motion {
|
|
|
314
315
|
|
|
315
316
|
async BLEconnection(switchbot: any): Promise<void> {
|
|
316
317
|
this.errorLog(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
317
|
-
if (this.platform.config.credentials?.
|
|
318
|
+
if (this.platform.config.credentials?.token) {
|
|
318
319
|
this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
319
320
|
this.SwitchToOpenAPI = true;
|
|
320
321
|
await this.openAPIRefreshStatus();
|
|
@@ -322,7 +323,7 @@ export class Motion {
|
|
|
322
323
|
}
|
|
323
324
|
|
|
324
325
|
async openAPIRefreshStatus(): Promise<void> {
|
|
325
|
-
if (this.platform.config.credentials?.
|
|
326
|
+
if (this.platform.config.credentials?.token) {
|
|
326
327
|
this.debugLog(`Motion Sensor: ${this.accessory.displayName} OpenAPI RefreshStatus`);
|
|
327
328
|
try {
|
|
328
329
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
package/src/device/plug.ts
CHANGED
|
@@ -21,9 +21,16 @@ export class Plug {
|
|
|
21
21
|
// BLE Others
|
|
22
22
|
connected?: boolean;
|
|
23
23
|
switchbot!: switchbot;
|
|
24
|
+
address!: ad['address'];
|
|
24
25
|
SwitchToOpenAPI?: boolean;
|
|
25
26
|
serviceData!: serviceData;
|
|
26
|
-
|
|
27
|
+
state: serviceData['state'];
|
|
28
|
+
delay: serviceData['delay'];
|
|
29
|
+
timer: serviceData['timer'];
|
|
30
|
+
wifiRssi: serviceData['wifiRssi'];
|
|
31
|
+
overload: serviceData['overload'];
|
|
32
|
+
syncUtcTime: serviceData['syncUtcTime'];
|
|
33
|
+
currentPower: serviceData['currentPower'];
|
|
27
34
|
|
|
28
35
|
// Config
|
|
29
36
|
scanDuration!: number;
|
|
@@ -33,13 +40,6 @@ export class Plug {
|
|
|
33
40
|
// Updates
|
|
34
41
|
plugUpdateInProgress!: boolean;
|
|
35
42
|
doPlugUpdate!: Subject<void>;
|
|
36
|
-
state: serviceData['state'];
|
|
37
|
-
delay: serviceData['delay'];
|
|
38
|
-
timer: serviceData['timer'];
|
|
39
|
-
syncUtcTime: serviceData['syncUtcTime'];
|
|
40
|
-
wifiRssi: serviceData['wifiRssi'];
|
|
41
|
-
overload: serviceData['overload'];
|
|
42
|
-
currentPower: serviceData['currentPower'];
|
|
43
43
|
|
|
44
44
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
45
45
|
// default placeholders
|
|
@@ -232,7 +232,7 @@ export class Plug {
|
|
|
232
232
|
`Plug: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
233
233
|
);
|
|
234
234
|
}
|
|
235
|
-
if (this.platform.config.credentials?.
|
|
235
|
+
if (this.platform.config.credentials?.token) {
|
|
236
236
|
this.warnLog(`Plug: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
237
237
|
this.SwitchToOpenAPI = true;
|
|
238
238
|
await this.openAPIRefreshStatus();
|
|
@@ -271,8 +271,8 @@ export class Plug {
|
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
async BLEconnection(switchbot: any): Promise<void> {
|
|
274
|
-
this.errorLog(`Plug: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-
|
|
275
|
-
if (this.platform.config.credentials?.
|
|
274
|
+
this.errorLog(`Plug: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
275
|
+
if (this.platform.config.credentials?.token) {
|
|
276
276
|
this.warnLog(`Plug: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
277
277
|
this.SwitchToOpenAPI = true;
|
|
278
278
|
await this.openAPIRefreshStatus();
|
|
@@ -350,7 +350,7 @@ export class Plug {
|
|
|
350
350
|
if (this.platform.debugMode) {
|
|
351
351
|
this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
352
352
|
}
|
|
353
|
-
if (this.platform.config.credentials?.
|
|
353
|
+
if (this.platform.config.credentials?.token) {
|
|
354
354
|
this.warnLog(`Plug: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
355
355
|
await this.openAPIpushChanges();
|
|
356
356
|
}
|
|
@@ -374,7 +374,7 @@ export class Plug {
|
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
async openAPIpushChanges() {
|
|
377
|
-
if (this.platform.config.credentials?.
|
|
377
|
+
if (this.platform.config.credentials?.token) {
|
|
378
378
|
if (this.On !== this.OnCached) {
|
|
379
379
|
this.debugLog(`Plug: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
380
380
|
const payload = {
|
package/src/device/striplight.ts
CHANGED
|
@@ -81,7 +81,8 @@ export class StripLight {
|
|
|
81
81
|
.setCharacteristic(this.platform.Characteristic.Model, 'W1701100')
|
|
82
82
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
83
83
|
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
84
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
84
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
85
|
+
.updateValue(this.FirmwareRevision(accessory, device));
|
|
85
86
|
|
|
86
87
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
87
88
|
// you can create multiple services for each accessory
|
|
@@ -195,9 +196,7 @@ export class StripLight {
|
|
|
195
196
|
this.debugLog(`Strip Light: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
196
197
|
|
|
197
198
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
198
|
-
this.debugLog(
|
|
199
|
-
`Strip Light: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`,
|
|
200
|
-
);
|
|
199
|
+
this.debugLog(`Strip Light: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
|
|
201
200
|
|
|
202
201
|
// Hue
|
|
203
202
|
this.Hue = hue;
|
|
@@ -223,8 +222,7 @@ export class StripLight {
|
|
|
223
222
|
this.errorLog(`Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
224
223
|
if (this.deviceLogging.includes('debug')) {
|
|
225
224
|
this.errorLog(
|
|
226
|
-
`Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
227
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
225
|
+
`Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
228
226
|
);
|
|
229
227
|
}
|
|
230
228
|
this.apiError(e);
|
|
@@ -281,8 +279,7 @@ export class StripLight {
|
|
|
281
279
|
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
282
280
|
if (this.deviceLogging.includes('debug')) {
|
|
283
281
|
this.errorLog(
|
|
284
|
-
`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
285
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
282
|
+
`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
286
283
|
);
|
|
287
284
|
}
|
|
288
285
|
this.apiError(e);
|
|
@@ -325,8 +322,7 @@ export class StripLight {
|
|
|
325
322
|
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
326
323
|
if (this.deviceLogging.includes('debug')) {
|
|
327
324
|
this.errorLog(
|
|
328
|
-
`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
329
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
325
|
+
`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
330
326
|
);
|
|
331
327
|
}
|
|
332
328
|
this.apiError(e);
|
|
@@ -354,16 +350,14 @@ export class StripLight {
|
|
|
354
350
|
this.BrightnessCached = this.Brightness;
|
|
355
351
|
} else {
|
|
356
352
|
this.debugLog(
|
|
357
|
-
`Strip Light: ${this.accessory.displayName} No Changes.` +
|
|
358
|
-
`Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`,
|
|
353
|
+
`Strip Light: ${this.accessory.displayName} No Changes.` + `Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`,
|
|
359
354
|
);
|
|
360
355
|
}
|
|
361
356
|
} catch (e: any) {
|
|
362
357
|
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
363
358
|
if (this.deviceLogging.includes('debug')) {
|
|
364
359
|
this.errorLog(
|
|
365
|
-
`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
366
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
360
|
+
`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
367
361
|
);
|
|
368
362
|
}
|
|
369
363
|
this.apiError(e);
|