@switchbot/homebridge-switchbot 1.12.9-beta.9 → 1.13.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/workflows/codeql-analysis.yml +3 -3
- package/.github/workflows/dependabot.yml +17 -0
- package/.github/workflows/nodejs-beta.yml +0 -3
- package/.github/workflows/nodejs.yml +0 -3
- package/CHANGELOG.md +3 -1
- package/config.schema.json +1 -1
- package/dist/device/bot.d.ts +3 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +18 -2
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +3 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +18 -2
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +3 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +18 -2
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +6 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +57 -2
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +3 -0
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +18 -2
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +3 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +18 -2
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -0
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +82 -7
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +3 -0
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +18 -2
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +3 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +18 -2
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +3 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +18 -2
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +3 -0
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +18 -2
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/other.js +3 -3
- package/dist/irdevice/other.js.map +1 -1
- package/dist/platform.d.ts +1 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +43 -40
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +5 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +78 -76
- package/src/device/bot.ts +18 -2
- package/src/device/colorbulb.ts +18 -2
- package/src/device/contact.ts +18 -2
- package/src/device/curtain.ts +60 -2
- package/src/device/humidifier.ts +18 -2
- package/src/device/lock.ts +18 -2
- package/src/device/meter.ts +90 -7
- package/src/device/meterplus.ts +18 -2
- package/src/device/motion.ts +18 -2
- package/src/device/plug.ts +18 -2
- package/src/device/striplight.ts +18 -2
- package/src/irdevice/other.ts +3 -3
- package/src/platform.ts +46 -40
- package/src/settings.ts +5 -0
package/package.json
CHANGED
|
@@ -1,80 +1,82 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
"displayName": "Homebridge SwitchBot",
|
|
3
|
+
"name": "@switchbot/homebridge-switchbot",
|
|
4
|
+
"version": "1.13.0",
|
|
5
|
+
"description": "The [Homebridge](https://homebridge.io) SwitchBot plugin allows you to access your [SwitchBot](https://www.switch-bot.com) device(s) from HomeKit.",
|
|
6
|
+
"author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git://github.com/OpenWonderLabs/homebridge-switchbot.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/OpenWonderLabs/homebridge-switchbot/issues"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"homebridge": "^1.4.1",
|
|
17
|
+
"node": "^14.19.1 || ^16.15.0 || ^18.1.0"
|
|
18
|
+
},
|
|
19
|
+
"main": "dist/index.js",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"check": "npm install && npm outdated",
|
|
22
|
+
"update": "ncu -u && npm update && npm install",
|
|
23
|
+
"lint": "eslint src/**.ts",
|
|
24
|
+
"watch": "npm run build && npm link && nodemon",
|
|
25
|
+
"build": "rimraf ./dist && tsc",
|
|
26
|
+
"prepublishOnly": "npm run lint && npm run build",
|
|
27
|
+
"postpublish": "npm run clean",
|
|
28
|
+
"clean": "rimraf ./dist",
|
|
29
|
+
"test": "eslint src/**.ts"
|
|
30
|
+
},
|
|
31
|
+
"funding": [
|
|
32
|
+
{
|
|
33
|
+
"type": "Paypal",
|
|
34
|
+
"url": "https://paypal.me/donavanbecker"
|
|
11
35
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"engines": {
|
|
16
|
-
"homebridge": "^1.4.0",
|
|
17
|
-
"node": "^14.19.0 || ^16.14.0"
|
|
18
|
-
},
|
|
19
|
-
"main": "dist/index.js",
|
|
20
|
-
"scripts": {
|
|
21
|
-
"check": "npm install && npm outdated",
|
|
22
|
-
"update": "ncu -u && npm update && npm install",
|
|
23
|
-
"lint": "eslint src/**.ts",
|
|
24
|
-
"watch": "npm run build && npm link && nodemon",
|
|
25
|
-
"build": "rimraf ./dist && tsc",
|
|
26
|
-
"prepublishOnly": "npm run lint && npm run build",
|
|
27
|
-
"postpublish": "npm run clean",
|
|
28
|
-
"clean": "rimraf ./dist",
|
|
29
|
-
"test": "eslint src/**.ts"
|
|
30
|
-
},
|
|
31
|
-
"funding": [
|
|
32
|
-
{
|
|
33
|
-
"type": "Paypal",
|
|
34
|
-
"url": "https://paypal.me/donavanbecker"
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"type": "GitHub",
|
|
38
|
-
"url": "https://github.com/sponsors/donavanbecker"
|
|
39
|
-
}
|
|
40
|
-
],
|
|
41
|
-
"publishConfig": {
|
|
42
|
-
"access": "public"
|
|
43
|
-
},
|
|
44
|
-
"keywords": [
|
|
45
|
-
"homebridge-plugin",
|
|
46
|
-
"switchbot",
|
|
47
|
-
"humidifier",
|
|
48
|
-
"humidity",
|
|
49
|
-
"temperature",
|
|
50
|
-
"bot",
|
|
51
|
-
"curtains",
|
|
52
|
-
"windows",
|
|
53
|
-
"ble",
|
|
54
|
-
"ir"
|
|
55
|
-
],
|
|
56
|
-
"dependencies": {
|
|
57
|
-
"@homebridge/plugin-ui-utils": "^0.0.19",
|
|
58
|
-
"axios": "^0.26.1",
|
|
59
|
-
"rxjs": "^7.5.5"
|
|
60
|
-
},
|
|
61
|
-
"devDependencies": {
|
|
62
|
-
"@types/node": "^17.0.23",
|
|
63
|
-
"@typescript-eslint/eslint-plugin": "^5.17.0",
|
|
64
|
-
"@typescript-eslint/parser": "^5.17.0",
|
|
65
|
-
"eslint": "^8.12.0",
|
|
66
|
-
"eslint-config-prettier": "8.5.0",
|
|
67
|
-
"eslint-plugin-prettier": "4.0.0",
|
|
68
|
-
"homebridge": "^1.4.0",
|
|
69
|
-
"nodemon": "^2.0.15",
|
|
70
|
-
"npm-check-updates": "^12.5.7",
|
|
71
|
-
"prettier": "2.6.2",
|
|
72
|
-
"rimraf": "^3.0.2",
|
|
73
|
-
"ts-node": "^10.7.0",
|
|
74
|
-
"typescript": "^4.6.3",
|
|
75
|
-
"typescript-axios-wb": "^1.0.3"
|
|
76
|
-
},
|
|
77
|
-
"optionalDependencies": {
|
|
78
|
-
"node-switchbot": "^1.2.0"
|
|
36
|
+
{
|
|
37
|
+
"type": "GitHub",
|
|
38
|
+
"url": "https://github.com/sponsors/donavanbecker"
|
|
79
39
|
}
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"homebridge-plugin",
|
|
46
|
+
"switchbot",
|
|
47
|
+
"humidifier",
|
|
48
|
+
"humidity",
|
|
49
|
+
"temperature",
|
|
50
|
+
"bot",
|
|
51
|
+
"curtains",
|
|
52
|
+
"windows",
|
|
53
|
+
"ble",
|
|
54
|
+
"ir"
|
|
55
|
+
],
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@homebridge/plugin-ui-utils": "^0.0.19",
|
|
58
|
+
"axios": "^0.27.2",
|
|
59
|
+
"rxjs": "^7.5.5",
|
|
60
|
+
"async-mqtt": "^2.6.2",
|
|
61
|
+
"fakegato-history": "^0.6.3"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@types/node": "^17.0.31",
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "^5.22.0",
|
|
66
|
+
"@typescript-eslint/parser": "^5.22.0",
|
|
67
|
+
"eslint": "^8.14.0",
|
|
68
|
+
"eslint-config-prettier": "8.5.0",
|
|
69
|
+
"eslint-plugin-prettier": "4.0.0",
|
|
70
|
+
"homebridge": "^1.4.1",
|
|
71
|
+
"nodemon": "^2.0.16",
|
|
72
|
+
"npm-check-updates": "^12.5.11",
|
|
73
|
+
"prettier": "2.6.2",
|
|
74
|
+
"rimraf": "^3.0.2",
|
|
75
|
+
"ts-node": "^10.7.0",
|
|
76
|
+
"typescript": "^4.6.4",
|
|
77
|
+
"typescript-axios-wb": "^1.0.3"
|
|
78
|
+
},
|
|
79
|
+
"optionalDependencies": {
|
|
80
|
+
"node-switchbot": "^1.2.0"
|
|
81
|
+
}
|
|
80
82
|
}
|
package/src/device/bot.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { SwitchBotPlatform } from '../platform';
|
|
|
4
4
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
5
5
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
6
6
|
import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse, payload, deviceStatus } from '../settings';
|
|
7
|
+
import { Context } from 'vm';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Platform Accessory
|
|
@@ -94,8 +95,8 @@ export class Bot {
|
|
|
94
95
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
95
96
|
.setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-BOT-S1')
|
|
96
97
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
97
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision,
|
|
98
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(accessory
|
|
98
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
99
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
|
|
99
100
|
|
|
100
101
|
// get the service if it exists, otherwise create a new service
|
|
101
102
|
// you can create multiple services for each accessory
|
|
@@ -1157,6 +1158,21 @@ export class Bot {
|
|
|
1157
1158
|
}
|
|
1158
1159
|
}
|
|
1159
1160
|
|
|
1161
|
+
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
1162
|
+
let FirmwareRevision: string;
|
|
1163
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
1164
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
1165
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
1166
|
+
if (accessory.context.FirmwareRevision) {
|
|
1167
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
1168
|
+
} else if (device.firmware) {
|
|
1169
|
+
FirmwareRevision = device.firmware;
|
|
1170
|
+
} else {
|
|
1171
|
+
FirmwareRevision = this.platform.version;
|
|
1172
|
+
}
|
|
1173
|
+
return FirmwareRevision;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1160
1176
|
async PressOrSwitch(device: device & devicesConfig): Promise<void> {
|
|
1161
1177
|
if (!device.bot?.mode) {
|
|
1162
1178
|
this.botMode = 'switch';
|
package/src/device/colorbulb.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { SwitchBotPlatform } from '../platform';
|
|
|
4
4
|
import { debounceTime, skipWhile, tap } from 'rxjs/operators';
|
|
5
5
|
import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
6
6
|
import { DeviceURL, device, devicesConfig, switchbot, deviceStatusResponse, payload, hs2rgb, rgb2hs, m2hs, deviceStatus } from '../settings';
|
|
7
|
+
import { Context } from 'vm';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Platform Accessory
|
|
@@ -84,8 +85,8 @@ export class ColorBulb {
|
|
|
84
85
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
85
86
|
.setCharacteristic(this.platform.Characteristic.Model, 'W1401400')
|
|
86
87
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
87
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision,
|
|
88
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(accessory
|
|
88
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
89
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
|
|
89
90
|
|
|
90
91
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
91
92
|
// you can create multiple services for each accessory
|
|
@@ -673,6 +674,21 @@ export class ColorBulb {
|
|
|
673
674
|
}
|
|
674
675
|
}
|
|
675
676
|
|
|
677
|
+
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
678
|
+
let FirmwareRevision: string;
|
|
679
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
680
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
681
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
682
|
+
if (accessory.context.FirmwareRevision) {
|
|
683
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
684
|
+
} else if (device.firmware) {
|
|
685
|
+
FirmwareRevision = device.firmware;
|
|
686
|
+
} else {
|
|
687
|
+
FirmwareRevision = this.platform.version;
|
|
688
|
+
}
|
|
689
|
+
return FirmwareRevision;
|
|
690
|
+
}
|
|
691
|
+
|
|
676
692
|
async adaptiveLighting(device: device & devicesConfig): Promise<void> {
|
|
677
693
|
if (device.colorbulb?.adaptiveLightingShift) {
|
|
678
694
|
this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
|
package/src/device/contact.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { skipWhile } from 'rxjs/operators';
|
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
4
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
5
5
|
import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, deviceStatus, ad } from '../settings';
|
|
6
|
+
import { Context } from 'vm';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Platform Accessory
|
|
@@ -72,8 +73,8 @@ export class Contact {
|
|
|
72
73
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
73
74
|
.setCharacteristic(this.platform.Characteristic.Model, 'W1201500')
|
|
74
75
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
75
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision,
|
|
76
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(accessory
|
|
76
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
77
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
|
|
77
78
|
|
|
78
79
|
// get the Contact service if it exists, otherwise create a new Contact service
|
|
79
80
|
// you can create multiple services for each accessory
|
|
@@ -511,6 +512,21 @@ export class Contact {
|
|
|
511
512
|
}
|
|
512
513
|
}
|
|
513
514
|
|
|
515
|
+
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
516
|
+
let FirmwareRevision: string;
|
|
517
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
518
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
519
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
520
|
+
if (accessory.context.FirmwareRevision) {
|
|
521
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
522
|
+
} else if (device.firmware) {
|
|
523
|
+
FirmwareRevision = device.firmware;
|
|
524
|
+
} else {
|
|
525
|
+
FirmwareRevision = this.platform.version;
|
|
526
|
+
}
|
|
527
|
+
return FirmwareRevision;
|
|
528
|
+
}
|
|
529
|
+
|
|
514
530
|
minLux(): number {
|
|
515
531
|
if (this.device.contact?.set_minLux) {
|
|
516
532
|
this.set_minLux = this.device.contact!.set_minLux!;
|
package/src/device/curtain.ts
CHANGED
|
@@ -4,6 +4,9 @@ import { SwitchBotPlatform } from '../platform';
|
|
|
4
4
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
5
5
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
6
6
|
import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, payload, deviceStatus, ad } from '../settings';
|
|
7
|
+
import { Context } from 'vm';
|
|
8
|
+
import { MqttClient } from 'mqtt';
|
|
9
|
+
import { connectAsync } from 'async-mqtt';
|
|
7
10
|
|
|
8
11
|
export class Curtain {
|
|
9
12
|
// Services
|
|
@@ -58,12 +61,16 @@ export class Curtain {
|
|
|
58
61
|
curtainUpdateInProgress!: boolean;
|
|
59
62
|
doCurtainUpdate!: Subject<void>;
|
|
60
63
|
|
|
64
|
+
//MQTT stuff
|
|
65
|
+
mqttClient: MqttClient | null = null;
|
|
66
|
+
|
|
61
67
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
62
68
|
// default placeholders
|
|
63
69
|
this.logs(device);
|
|
64
70
|
this.refreshRate(device);
|
|
65
71
|
this.scan(device);
|
|
66
72
|
this.config(device);
|
|
73
|
+
this.setupMqtt(device);
|
|
67
74
|
this.CurrentPosition = 0;
|
|
68
75
|
this.TargetPosition = 0;
|
|
69
76
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
@@ -82,8 +89,8 @@ export class Curtain {
|
|
|
82
89
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
83
90
|
.setCharacteristic(this.platform.Characteristic.Model, 'W0701600')
|
|
84
91
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
|
|
85
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision,
|
|
86
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(accessory
|
|
92
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
93
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
|
|
87
94
|
|
|
88
95
|
// get the WindowCovering service if it exists, otherwise create a new WindowCovering service
|
|
89
96
|
// you can create multiple services for each accessory
|
|
@@ -200,6 +207,35 @@ export class Curtain {
|
|
|
200
207
|
});
|
|
201
208
|
}
|
|
202
209
|
|
|
210
|
+
/*
|
|
211
|
+
* Publish MQTT message for topics of
|
|
212
|
+
* 'homebridge-switchbot/curtain/xx:xx:xx:xx:xx:xx'
|
|
213
|
+
*/
|
|
214
|
+
mqttPublish(topic: string, message: any) {
|
|
215
|
+
const mac = this.device.deviceId?.toLowerCase().match(/[\s\S]{1,2}/g)?.join(':');
|
|
216
|
+
const options = this.device.mqttPubOptions || {};
|
|
217
|
+
this.mqttClient?.publish(`homebridge-switchbot/curtain/${mac}/${topic}`, `${message}`, options);
|
|
218
|
+
this.debugLog(`Meter: ${this.accessory.displayName} MQTT message: ${topic}/${message} options:${JSON.stringify(options)}`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/*
|
|
222
|
+
* Setup MQTT hadler if URL is specifed.
|
|
223
|
+
*/
|
|
224
|
+
async setupMqtt(device: device & devicesConfig): Promise<void> {
|
|
225
|
+
if (device.mqttURL) {
|
|
226
|
+
try {
|
|
227
|
+
this.mqttClient = await connectAsync(device.mqttURL, device.mqttOptions || {});
|
|
228
|
+
this.debugLog(`Meter: ${this.accessory.displayName} MQTT connection has been established successfully.`)
|
|
229
|
+
this.mqttClient.on('error', (e: Error) => {
|
|
230
|
+
this.errorLog(`Meter: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`)
|
|
231
|
+
});
|
|
232
|
+
} catch (e) {
|
|
233
|
+
this.mqttClient = null;
|
|
234
|
+
this.errorLog(`Meter: ${this.accessory.displayName} Failed to establish MQTT connection. ${e}`)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
203
239
|
/**
|
|
204
240
|
* Parse the device status from the SwitchBot api
|
|
205
241
|
*/
|
|
@@ -655,18 +691,21 @@ export class Curtain {
|
|
|
655
691
|
} else {
|
|
656
692
|
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.CurrentPosition, Number(this.CurrentPosition));
|
|
657
693
|
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic CurrentPosition: ${this.CurrentPosition}`);
|
|
694
|
+
this.mqttPublish('CurrentPosition', this.CurrentPosition);
|
|
658
695
|
}
|
|
659
696
|
if (this.PositionState === undefined) {
|
|
660
697
|
this.debugLog(`Curtain: ${this.accessory.displayName} PositionState: ${this.PositionState}`);
|
|
661
698
|
} else {
|
|
662
699
|
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.PositionState, Number(this.PositionState));
|
|
663
700
|
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic PositionState: ${this.PositionState}`);
|
|
701
|
+
this.mqttPublish('PositionState', this.PositionState);
|
|
664
702
|
}
|
|
665
703
|
if (this.TargetPosition === undefined || Number.isNaN(this.TargetPosition)) {
|
|
666
704
|
this.debugLog(`Curtain: ${this.accessory.displayName} TargetPosition: ${this.TargetPosition}`);
|
|
667
705
|
} else {
|
|
668
706
|
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.TargetPosition, Number(this.TargetPosition));
|
|
669
707
|
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`);
|
|
708
|
+
this.mqttPublish('TargetPosition', this.TargetPosition);
|
|
670
709
|
}
|
|
671
710
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
672
711
|
if (this.CurrentAmbientLightLevel === undefined || Number.isNaN(this.CurrentAmbientLightLevel)) {
|
|
@@ -674,6 +713,7 @@ export class Curtain {
|
|
|
674
713
|
} else {
|
|
675
714
|
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
676
715
|
this.debugLog(`Curtain: ${this.accessory.displayName}` + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
716
|
+
this.mqttPublish('CurrentAmbientLightLevel', this.CurrentAmbientLightLevel);
|
|
677
717
|
}
|
|
678
718
|
}
|
|
679
719
|
if (this.device.ble) {
|
|
@@ -682,12 +722,14 @@ export class Curtain {
|
|
|
682
722
|
} else {
|
|
683
723
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
684
724
|
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
725
|
+
this.mqttPublish('BatteryLevel', this.BatteryLevel);
|
|
685
726
|
}
|
|
686
727
|
if (this.StatusLowBattery === undefined) {
|
|
687
728
|
this.debugLog(`Curtain: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
688
729
|
} else {
|
|
689
730
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
690
731
|
this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
732
|
+
this.mqttPublish('StatusLowBattery', this.StatusLowBattery);
|
|
691
733
|
}
|
|
692
734
|
}
|
|
693
735
|
}
|
|
@@ -744,6 +786,7 @@ export class Curtain {
|
|
|
744
786
|
this.debugLog(`Curtain: ${this.accessory.displayName} TargetPosition: ${value}`);
|
|
745
787
|
|
|
746
788
|
this.TargetPosition = value;
|
|
789
|
+
this.mqttPublish('TargetPosition', this.TargetPosition);
|
|
747
790
|
|
|
748
791
|
await this.setMinMax();
|
|
749
792
|
if (value > this.CurrentPosition) {
|
|
@@ -871,6 +914,21 @@ export class Curtain {
|
|
|
871
914
|
}
|
|
872
915
|
}
|
|
873
916
|
|
|
917
|
+
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
918
|
+
let FirmwareRevision: string;
|
|
919
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
920
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
921
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
922
|
+
if (accessory.context.FirmwareRevision) {
|
|
923
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
924
|
+
} else if (device.firmware) {
|
|
925
|
+
FirmwareRevision = device.firmware;
|
|
926
|
+
} else {
|
|
927
|
+
FirmwareRevision = this.platform.version;
|
|
928
|
+
}
|
|
929
|
+
return FirmwareRevision;
|
|
930
|
+
}
|
|
931
|
+
|
|
874
932
|
minStep(device: device & devicesConfig): number {
|
|
875
933
|
if (device.curtain?.set_minStep) {
|
|
876
934
|
this.set_minStep = device.curtain?.set_minStep;
|
package/src/device/humidifier.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { SwitchBotPlatform } from '../platform';
|
|
|
4
4
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
5
5
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
6
6
|
import { DeviceURL, device, devicesConfig, serviceData, ad, deviceStatusResponse, payload, deviceStatus } from '../settings';
|
|
7
|
+
import { Context } from 'vm';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Platform Accessory
|
|
@@ -78,8 +79,8 @@ export class Humidifier {
|
|
|
78
79
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
79
80
|
.setCharacteristic(this.platform.Characteristic.Model, 'W0801800')
|
|
80
81
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
81
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision,
|
|
82
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(accessory
|
|
82
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
83
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
|
|
83
84
|
|
|
84
85
|
// get the service if it exists, otherwise create a new service
|
|
85
86
|
// you can create multiple services for each accessory
|
|
@@ -813,6 +814,21 @@ export class Humidifier {
|
|
|
813
814
|
}
|
|
814
815
|
}
|
|
815
816
|
|
|
817
|
+
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
818
|
+
let FirmwareRevision: string;
|
|
819
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
820
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
821
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
822
|
+
if (accessory.context.FirmwareRevision) {
|
|
823
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
824
|
+
} else if (device.firmware) {
|
|
825
|
+
FirmwareRevision = device.firmware;
|
|
826
|
+
} else {
|
|
827
|
+
FirmwareRevision = this.platform.version;
|
|
828
|
+
}
|
|
829
|
+
return FirmwareRevision;
|
|
830
|
+
}
|
|
831
|
+
|
|
816
832
|
minStep(): number {
|
|
817
833
|
if (this.device.humidifier?.set_minStep) {
|
|
818
834
|
this.set_minStep = this.device.humidifier?.set_minStep;
|
package/src/device/lock.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { SwitchBotPlatform } from '../platform';
|
|
|
4
4
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
5
5
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
6
6
|
import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload, deviceStatus } from '../settings';
|
|
7
|
+
import { Context } from 'vm';
|
|
7
8
|
|
|
8
9
|
export class Lock {
|
|
9
10
|
// Services
|
|
@@ -55,8 +56,8 @@ export class Lock {
|
|
|
55
56
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
56
57
|
.setCharacteristic(this.platform.Characteristic.Model, 'W1601700')
|
|
57
58
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
58
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision,
|
|
59
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(accessory
|
|
59
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
60
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).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
|
|
@@ -340,6 +341,21 @@ export class Lock {
|
|
|
340
341
|
}
|
|
341
342
|
}
|
|
342
343
|
|
|
344
|
+
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
345
|
+
let FirmwareRevision: string;
|
|
346
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
347
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
348
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
349
|
+
if (accessory.context.FirmwareRevision) {
|
|
350
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
351
|
+
} else if (device.firmware) {
|
|
352
|
+
FirmwareRevision = device.firmware;
|
|
353
|
+
} else {
|
|
354
|
+
FirmwareRevision = this.platform.version;
|
|
355
|
+
}
|
|
356
|
+
return FirmwareRevision;
|
|
357
|
+
}
|
|
358
|
+
|
|
343
359
|
/**
|
|
344
360
|
* Logging for Device
|
|
345
361
|
*/
|