@switchbot/homebridge-switchbot 2.14.0 → 3.0.0-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/.github/workflows/dependabot.yml +10 -11
- package/CHANGELOG.md +11 -2
- package/LICENSE +1 -1
- package/config.schema.json +1 -0
- package/dist/device/blindtilt.d.ts +9 -5
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +151 -91
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -5
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +234 -184
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -5
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +110 -64
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +9 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +121 -69
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +111 -66
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +9 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +164 -107
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +87 -51
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +9 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +133 -90
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +108 -66
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +9 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +110 -65
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -6
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +125 -84
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +102 -63
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +102 -63
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +95 -54
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -5
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +68 -40
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -5
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +86 -52
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/homebridge-ui/server.d.ts +2 -0
- package/dist/homebridge-ui/server.d.ts.map +1 -0
- package/dist/homebridge-ui/server.js +44 -0
- package/dist/homebridge-ui/server.js.map +1 -0
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -4
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +105 -71
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -4
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +78 -46
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +8 -4
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +41 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -4
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +62 -39
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +8 -4
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +67 -45
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +8 -4
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +176 -150
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -4
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +81 -62
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +8 -4
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -25
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +8 -4
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +48 -32
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +8 -9
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +147 -162
- package/dist/platform.js.map +1 -1
- package/dist/settings.js +7 -14
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -5
- package/dist/utils.js.map +1 -1
- package/package.json +28 -16
- package/src/device/blindtilt.ts +80 -69
- package/src/device/bot.ts +189 -178
- package/src/device/ceilinglight.ts +55 -42
- package/src/device/colorbulb.ts +51 -38
- package/src/device/contact.ts +69 -58
- package/src/device/curtain.ts +94 -83
- package/src/device/hub.ts +54 -43
- package/src/device/humidifier.ts +86 -75
- package/src/device/iosensor.ts +63 -52
- package/src/device/lightstrip.ts +54 -41
- package/src/device/lock.ts +89 -79
- package/src/device/meter.ts +59 -48
- package/src/device/meterplus.ts +63 -52
- package/src/device/motion.ts +56 -45
- package/src/device/plug.ts +36 -25
- package/src/device/robotvacuumcleaner.ts +47 -36
- package/src/homebridge-ui/public/index.html +240 -0
- package/src/homebridge-ui/server.ts +48 -0
- package/src/index.ts +10 -7
- package/src/irdevice/airconditioner.ts +70 -62
- package/src/irdevice/airpurifier.ts +47 -39
- package/src/irdevice/camera.ts +27 -19
- package/src/irdevice/fan.ts +41 -33
- package/src/irdevice/light.ts +47 -39
- package/src/irdevice/other.ts +163 -155
- package/src/irdevice/tv.ts +65 -57
- package/src/irdevice/vacuumcleaner.ts +27 -19
- package/src/irdevice/waterheater.ts +34 -26
- package/src/platform.ts +35 -21
- package/tsconfig.json +11 -13
- package/homebridge-ui/server.js +0 -50
- /package/{homebridge-ui → dist/homebridge-ui}/public/index.html +0 -0
package/dist/device/bot.js
CHANGED
|
@@ -1,26 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const rxjs_1 = require("rxjs");
|
|
7
|
-
const operators_1 = require("rxjs/operators");
|
|
8
|
-
const settings_1 = require("../settings");
|
|
1
|
+
import { request } from 'undici';
|
|
2
|
+
import { sleep } from '../utils';
|
|
3
|
+
import { interval, Subject } from 'rxjs';
|
|
4
|
+
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
5
|
+
import { Devices } from '../settings';
|
|
9
6
|
/**
|
|
10
7
|
* Platform Accessory
|
|
11
8
|
* An instance of this class is created for each accessory your platform registers
|
|
12
9
|
* Each accessory may expose multiple services of different service types.
|
|
13
10
|
*/
|
|
14
|
-
class Bot {
|
|
11
|
+
export class Bot {
|
|
12
|
+
platform;
|
|
13
|
+
accessory;
|
|
14
|
+
device;
|
|
15
|
+
api;
|
|
16
|
+
log;
|
|
17
|
+
config;
|
|
18
|
+
hap;
|
|
19
|
+
// Services
|
|
20
|
+
fanService;
|
|
21
|
+
doorService;
|
|
22
|
+
lockService;
|
|
23
|
+
faucetService;
|
|
24
|
+
windowService;
|
|
25
|
+
switchService;
|
|
26
|
+
outletService;
|
|
27
|
+
batteryService;
|
|
28
|
+
garageDoorService;
|
|
29
|
+
windowCoveringService;
|
|
30
|
+
statefulProgrammableSwitchService;
|
|
31
|
+
// Characteristic Values
|
|
32
|
+
On;
|
|
33
|
+
BatteryLevel;
|
|
34
|
+
FirmwareRevision;
|
|
35
|
+
StatusLowBattery;
|
|
36
|
+
// OpenAPI Status
|
|
37
|
+
OpenAPI_On;
|
|
38
|
+
OpenAPI_BatteryLevel;
|
|
39
|
+
OpenAPI_FirmwareRevision;
|
|
40
|
+
// BLE Status
|
|
41
|
+
BLE_On;
|
|
42
|
+
BLE_Mode;
|
|
43
|
+
BLE_BatteryLevel;
|
|
44
|
+
//BLE Others
|
|
45
|
+
BLE_IsConnected;
|
|
46
|
+
// Config
|
|
47
|
+
botMode;
|
|
48
|
+
allowPush;
|
|
49
|
+
doublePress;
|
|
50
|
+
scanDuration;
|
|
51
|
+
botDeviceType;
|
|
52
|
+
pushRatePress;
|
|
53
|
+
deviceLogging;
|
|
54
|
+
multiPressCount;
|
|
55
|
+
deviceRefreshRate;
|
|
56
|
+
// Updates
|
|
57
|
+
botUpdateInProgress;
|
|
58
|
+
doBotUpdate;
|
|
59
|
+
// Connection
|
|
60
|
+
OpenAPI;
|
|
61
|
+
BLE;
|
|
15
62
|
constructor(platform, accessory, device) {
|
|
16
63
|
this.platform = platform;
|
|
17
64
|
this.accessory = accessory;
|
|
18
65
|
this.device = device;
|
|
66
|
+
this.api = this.platform.api;
|
|
67
|
+
this.log = this.platform.log;
|
|
68
|
+
this.config = this.platform.config;
|
|
69
|
+
this.hap = this.api.hap;
|
|
19
70
|
// Connection
|
|
20
71
|
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
21
72
|
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
22
73
|
// default placeholders
|
|
23
|
-
this.
|
|
74
|
+
this.deviceLogs(device);
|
|
24
75
|
this.deviceType(device);
|
|
25
76
|
this.scan(device);
|
|
26
77
|
this.refreshRate(device);
|
|
@@ -28,20 +79,20 @@ class Bot {
|
|
|
28
79
|
this.allowPushChanges(device);
|
|
29
80
|
this.context();
|
|
30
81
|
this.DoublePress(device);
|
|
31
|
-
this.
|
|
82
|
+
this.deviceConfig(device);
|
|
32
83
|
this.multiPressCount = 0;
|
|
33
84
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
34
|
-
this.doBotUpdate = new
|
|
85
|
+
this.doBotUpdate = new Subject();
|
|
35
86
|
this.botUpdateInProgress = false;
|
|
36
87
|
// Retrieve initial values and updateHomekit
|
|
37
88
|
this.refreshStatus();
|
|
38
89
|
// set accessory information
|
|
39
90
|
accessory
|
|
40
|
-
.getService(this.
|
|
41
|
-
.setCharacteristic(this.
|
|
42
|
-
.setCharacteristic(this.
|
|
43
|
-
.setCharacteristic(this.
|
|
44
|
-
.setCharacteristic(this.
|
|
91
|
+
.getService(this.hap.Service.AccessoryInformation)
|
|
92
|
+
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
93
|
+
.setCharacteristic(this.hap.Characteristic.Model, 'SWITCHBOT-BOT-S1')
|
|
94
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
95
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
45
96
|
// deviceType
|
|
46
97
|
if (this.botDeviceType === 'switch') {
|
|
47
98
|
this.removeFanService(accessory);
|
|
@@ -55,14 +106,14 @@ class Bot {
|
|
|
55
106
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
56
107
|
// Add switchService
|
|
57
108
|
const switchService = `${accessory.displayName} Switch`;
|
|
58
|
-
(this.switchService = accessory.getService(this.
|
|
59
|
-
|| accessory.addService(this.
|
|
109
|
+
(this.switchService = accessory.getService(this.hap.Service.Switch)
|
|
110
|
+
|| accessory.addService(this.hap.Service.Switch)), switchService;
|
|
60
111
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Switch`);
|
|
61
|
-
this.switchService.setCharacteristic(this.
|
|
62
|
-
if (!this.switchService.testCharacteristic(this.
|
|
63
|
-
this.switchService.addCharacteristic(this.
|
|
112
|
+
this.switchService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
113
|
+
if (!this.switchService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
114
|
+
this.switchService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
64
115
|
}
|
|
65
|
-
this.switchService.getCharacteristic(this.
|
|
116
|
+
this.switchService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
66
117
|
}
|
|
67
118
|
else if (this.botDeviceType === 'garagedoor') {
|
|
68
119
|
this.removeFanService(accessory);
|
|
@@ -76,15 +127,15 @@ class Bot {
|
|
|
76
127
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
77
128
|
// Add garageDoorService
|
|
78
129
|
const garageDoorService = `${accessory.displayName} Garage Door Opener`;
|
|
79
|
-
(this.garageDoorService = accessory.getService(this.
|
|
80
|
-
|| accessory.addService(this.
|
|
130
|
+
(this.garageDoorService = accessory.getService(this.hap.Service.GarageDoorOpener)
|
|
131
|
+
|| accessory.addService(this.hap.Service.GarageDoorOpener)), garageDoorService;
|
|
81
132
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Garage Door Opener`);
|
|
82
|
-
this.garageDoorService.setCharacteristic(this.
|
|
83
|
-
if (!this.garageDoorService.testCharacteristic(this.
|
|
84
|
-
this.garageDoorService.addCharacteristic(this.
|
|
133
|
+
this.garageDoorService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
134
|
+
if (!this.garageDoorService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
135
|
+
this.garageDoorService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
85
136
|
}
|
|
86
|
-
this.garageDoorService.getCharacteristic(this.
|
|
87
|
-
this.garageDoorService.setCharacteristic(this.
|
|
137
|
+
this.garageDoorService.getCharacteristic(this.hap.Characteristic.TargetDoorState).onSet(this.OnSet.bind(this));
|
|
138
|
+
this.garageDoorService.setCharacteristic(this.hap.Characteristic.ObstructionDetected, false);
|
|
88
139
|
}
|
|
89
140
|
else if (this.botDeviceType === 'door') {
|
|
90
141
|
this.removeFanService(accessory);
|
|
@@ -98,15 +149,15 @@ class Bot {
|
|
|
98
149
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
99
150
|
// Add doorService
|
|
100
151
|
const doorService = `${accessory.displayName} Door`;
|
|
101
|
-
(this.doorService = accessory.getService(this.
|
|
102
|
-
|| accessory.addService(this.
|
|
152
|
+
(this.doorService = accessory.getService(this.hap.Service.Door)
|
|
153
|
+
|| accessory.addService(this.hap.Service.Door)), doorService;
|
|
103
154
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Door`);
|
|
104
|
-
this.doorService.setCharacteristic(this.
|
|
105
|
-
if (!this.doorService.testCharacteristic(this.
|
|
106
|
-
this.doorService.addCharacteristic(this.
|
|
155
|
+
this.doorService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
156
|
+
if (!this.doorService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
157
|
+
this.doorService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
107
158
|
}
|
|
108
159
|
this.doorService
|
|
109
|
-
.getCharacteristic(this.
|
|
160
|
+
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
110
161
|
.setProps({
|
|
111
162
|
validValues: [0, 100],
|
|
112
163
|
minValue: 0,
|
|
@@ -114,7 +165,7 @@ class Bot {
|
|
|
114
165
|
minStep: 100,
|
|
115
166
|
})
|
|
116
167
|
.onSet(this.OnSet.bind(this));
|
|
117
|
-
this.doorService.setCharacteristic(this.
|
|
168
|
+
this.doorService.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
118
169
|
}
|
|
119
170
|
else if (this.botDeviceType === 'window') {
|
|
120
171
|
this.removeFanService(accessory);
|
|
@@ -128,15 +179,15 @@ class Bot {
|
|
|
128
179
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
129
180
|
// Add windowService
|
|
130
181
|
const windowService = `${accessory.displayName} Window`;
|
|
131
|
-
(this.windowService = accessory.getService(this.
|
|
132
|
-
|| accessory.addService(this.
|
|
182
|
+
(this.windowService = accessory.getService(this.hap.Service.Window)
|
|
183
|
+
|| accessory.addService(this.hap.Service.Window)), windowService;
|
|
133
184
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window`);
|
|
134
|
-
this.windowService.setCharacteristic(this.
|
|
135
|
-
if (!this.windowService.testCharacteristic(this.
|
|
136
|
-
this.windowService.addCharacteristic(this.
|
|
185
|
+
this.windowService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
186
|
+
if (!this.windowService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
187
|
+
this.windowService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
137
188
|
}
|
|
138
189
|
this.windowService
|
|
139
|
-
.getCharacteristic(this.
|
|
190
|
+
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
140
191
|
.setProps({
|
|
141
192
|
validValues: [0, 100],
|
|
142
193
|
minValue: 0,
|
|
@@ -144,7 +195,7 @@ class Bot {
|
|
|
144
195
|
minStep: 100,
|
|
145
196
|
})
|
|
146
197
|
.onSet(this.OnSet.bind(this));
|
|
147
|
-
this.windowService.setCharacteristic(this.
|
|
198
|
+
this.windowService.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
148
199
|
}
|
|
149
200
|
else if (this.botDeviceType === 'windowcovering') {
|
|
150
201
|
this.removeFanService(accessory);
|
|
@@ -158,15 +209,15 @@ class Bot {
|
|
|
158
209
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
159
210
|
// Add windowCoveringService
|
|
160
211
|
const windowCoveringService = `${accessory.displayName} Window Covering`;
|
|
161
|
-
(this.windowCoveringService = accessory.getService(this.
|
|
162
|
-
|| accessory.addService(this.
|
|
212
|
+
(this.windowCoveringService = accessory.getService(this.hap.Service.WindowCovering)
|
|
213
|
+
|| accessory.addService(this.hap.Service.WindowCovering)), windowCoveringService;
|
|
163
214
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window Covering`);
|
|
164
|
-
this.windowCoveringService.setCharacteristic(this.
|
|
165
|
-
if (!this.windowCoveringService.testCharacteristic(this.
|
|
166
|
-
this.windowCoveringService.addCharacteristic(this.
|
|
215
|
+
this.windowCoveringService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
216
|
+
if (!this.windowCoveringService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
217
|
+
this.windowCoveringService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
167
218
|
}
|
|
168
219
|
this.windowCoveringService
|
|
169
|
-
.getCharacteristic(this.
|
|
220
|
+
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
170
221
|
.setProps({
|
|
171
222
|
validValues: [0, 100],
|
|
172
223
|
minValue: 0,
|
|
@@ -174,7 +225,7 @@ class Bot {
|
|
|
174
225
|
minStep: 100,
|
|
175
226
|
})
|
|
176
227
|
.onSet(this.OnSet.bind(this));
|
|
177
|
-
this.windowCoveringService.setCharacteristic(this.
|
|
228
|
+
this.windowCoveringService.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
178
229
|
}
|
|
179
230
|
else if (this.botDeviceType === 'lock') {
|
|
180
231
|
this.removeFanService(accessory);
|
|
@@ -188,14 +239,14 @@ class Bot {
|
|
|
188
239
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
189
240
|
// Add lockService
|
|
190
241
|
const lockService = `${accessory.displayName} Lock`;
|
|
191
|
-
(this.lockService = accessory.getService(this.
|
|
192
|
-
|| accessory.addService(this.
|
|
242
|
+
(this.lockService = accessory.getService(this.hap.Service.LockMechanism)
|
|
243
|
+
|| accessory.addService(this.hap.Service.LockMechanism)), lockService;
|
|
193
244
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Lock`);
|
|
194
|
-
this.lockService.setCharacteristic(this.
|
|
195
|
-
if (!this.lockService.testCharacteristic(this.
|
|
196
|
-
this.lockService.addCharacteristic(this.
|
|
245
|
+
this.lockService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
246
|
+
if (!this.lockService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
247
|
+
this.lockService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
197
248
|
}
|
|
198
|
-
this.lockService.getCharacteristic(this.
|
|
249
|
+
this.lockService.getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.OnSet.bind(this));
|
|
199
250
|
}
|
|
200
251
|
else if (this.botDeviceType === 'faucet') {
|
|
201
252
|
this.removeFanService(accessory);
|
|
@@ -209,14 +260,14 @@ class Bot {
|
|
|
209
260
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
210
261
|
// Add faucetService
|
|
211
262
|
const faucetService = `${accessory.displayName} Faucet`;
|
|
212
|
-
(this.faucetService = accessory.getService(this.
|
|
213
|
-
|| accessory.addService(this.
|
|
263
|
+
(this.faucetService = accessory.getService(this.hap.Service.Faucet)
|
|
264
|
+
|| accessory.addService(this.hap.Service.Faucet)), faucetService;
|
|
214
265
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Faucet`);
|
|
215
|
-
this.faucetService.setCharacteristic(this.
|
|
216
|
-
if (!this.faucetService.testCharacteristic(this.
|
|
217
|
-
this.faucetService.addCharacteristic(this.
|
|
266
|
+
this.faucetService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
267
|
+
if (!this.faucetService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
268
|
+
this.faucetService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
218
269
|
}
|
|
219
|
-
this.faucetService.getCharacteristic(this.
|
|
270
|
+
this.faucetService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this));
|
|
220
271
|
}
|
|
221
272
|
else if (this.botDeviceType === 'fan') {
|
|
222
273
|
this.removeLockService(accessory);
|
|
@@ -230,14 +281,14 @@ class Bot {
|
|
|
230
281
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
231
282
|
// Add fanService
|
|
232
283
|
const fanService = `${accessory.displayName} Fan`;
|
|
233
|
-
(this.fanService = accessory.getService(this.
|
|
234
|
-
|| accessory.addService(this.
|
|
284
|
+
(this.fanService = accessory.getService(this.hap.Service.Fan)
|
|
285
|
+
|| accessory.addService(this.hap.Service.Fan)), fanService;
|
|
235
286
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Fan`);
|
|
236
|
-
this.fanService.setCharacteristic(this.
|
|
237
|
-
if (!this.fanService.testCharacteristic(this.
|
|
238
|
-
this.fanService.addCharacteristic(this.
|
|
287
|
+
this.fanService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
288
|
+
if (!this.fanService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
289
|
+
this.fanService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
239
290
|
}
|
|
240
|
-
this.fanService.getCharacteristic(this.
|
|
291
|
+
this.fanService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
241
292
|
}
|
|
242
293
|
else if (this.botDeviceType === 'stateful') {
|
|
243
294
|
this.removeFanService(accessory);
|
|
@@ -251,15 +302,15 @@ class Bot {
|
|
|
251
302
|
this.removeWindowCoveringService(accessory);
|
|
252
303
|
// Add statefulProgrammableSwitchService
|
|
253
304
|
const statefulProgrammableSwitchService = `${accessory.displayName} Stateful Programmable Switch`;
|
|
254
|
-
(this.statefulProgrammableSwitchService = accessory.getService(this.
|
|
255
|
-
accessory.addService(this.
|
|
305
|
+
(this.statefulProgrammableSwitchService = accessory.getService(this.hap.Service.StatefulProgrammableSwitch) ||
|
|
306
|
+
accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), statefulProgrammableSwitchService;
|
|
256
307
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
|
|
257
|
-
this.statefulProgrammableSwitchService.setCharacteristic(this.
|
|
258
|
-
if (!this.statefulProgrammableSwitchService.testCharacteristic(this.
|
|
259
|
-
this.statefulProgrammableSwitchService.addCharacteristic(this.
|
|
308
|
+
this.statefulProgrammableSwitchService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
309
|
+
if (!this.statefulProgrammableSwitchService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
310
|
+
this.statefulProgrammableSwitchService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
260
311
|
}
|
|
261
312
|
this.statefulProgrammableSwitchService
|
|
262
|
-
.getCharacteristic(this.
|
|
313
|
+
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
263
314
|
.onSet(this.OnSet.bind(this));
|
|
264
315
|
}
|
|
265
316
|
else {
|
|
@@ -274,29 +325,29 @@ class Bot {
|
|
|
274
325
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
275
326
|
// Add outletService
|
|
276
327
|
const outletService = `${accessory.displayName} Outlet`;
|
|
277
|
-
(this.outletService = accessory.getService(this.
|
|
278
|
-
|| accessory.addService(this.
|
|
328
|
+
(this.outletService = accessory.getService(this.hap.Service.Outlet)
|
|
329
|
+
|| accessory.addService(this.hap.Service.Outlet)), outletService;
|
|
279
330
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Outlet`);
|
|
280
|
-
this.outletService.setCharacteristic(this.
|
|
281
|
-
if (!this.outletService.testCharacteristic(this.
|
|
282
|
-
this.outletService.addCharacteristic(this.
|
|
331
|
+
this.outletService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
332
|
+
if (!this.outletService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
333
|
+
this.outletService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
283
334
|
}
|
|
284
|
-
this.outletService.getCharacteristic(this.
|
|
335
|
+
this.outletService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
285
336
|
}
|
|
286
337
|
// batteryService
|
|
287
338
|
const batteryService = `${accessory.displayName} Battery`;
|
|
288
|
-
(this.batteryService = this.accessory.getService(this.
|
|
289
|
-
|| accessory.addService(this.
|
|
290
|
-
this.batteryService.setCharacteristic(this.
|
|
291
|
-
if (!this.batteryService.testCharacteristic(this.
|
|
292
|
-
this.batteryService.addCharacteristic(this.
|
|
339
|
+
(this.batteryService = this.accessory.getService(this.hap.Service.Battery)
|
|
340
|
+
|| accessory.addService(this.hap.Service.Battery)), batteryService;
|
|
341
|
+
this.batteryService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
342
|
+
if (!this.batteryService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
343
|
+
this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
293
344
|
}
|
|
294
|
-
this.batteryService.setCharacteristic(this.
|
|
345
|
+
this.batteryService.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
295
346
|
// Retrieve initial values and updateHomekit
|
|
296
347
|
this.updateHomeKitCharacteristics();
|
|
297
348
|
// Start an update interval
|
|
298
|
-
|
|
299
|
-
.pipe(
|
|
349
|
+
interval(this.deviceRefreshRate * 1000)
|
|
350
|
+
.pipe(skipWhile(() => this.botUpdateInProgress))
|
|
300
351
|
.subscribe(async () => {
|
|
301
352
|
await this.refreshStatus();
|
|
302
353
|
});
|
|
@@ -326,14 +377,14 @@ class Bot {
|
|
|
326
377
|
// Watch for Bot change events
|
|
327
378
|
// We put in a debounce of 1000ms so we don't make duplicate calls
|
|
328
379
|
this.doBotUpdate
|
|
329
|
-
.pipe(
|
|
380
|
+
.pipe(tap(() => {
|
|
330
381
|
this.botUpdateInProgress = true;
|
|
331
|
-
}),
|
|
382
|
+
}), debounceTime(this.platform.config.options.pushRate * 1000))
|
|
332
383
|
.subscribe(async () => {
|
|
333
384
|
try {
|
|
334
385
|
if (this.doublePress > 1) {
|
|
335
|
-
|
|
336
|
-
.pipe(
|
|
386
|
+
interval(this.pushRatePress * 1000)
|
|
387
|
+
.pipe(take(this.doublePress))
|
|
337
388
|
.subscribe(async () => {
|
|
338
389
|
await this.pushChanges();
|
|
339
390
|
});
|
|
@@ -385,10 +436,10 @@ class Bot {
|
|
|
385
436
|
}
|
|
386
437
|
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
387
438
|
if (this.BatteryLevel < 10) {
|
|
388
|
-
this.StatusLowBattery = this.
|
|
439
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
389
440
|
}
|
|
390
441
|
else {
|
|
391
|
-
this.StatusLowBattery = this.
|
|
442
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
392
443
|
}
|
|
393
444
|
if (Number.isNaN(this.BatteryLevel)) {
|
|
394
445
|
this.BatteryLevel = 100;
|
|
@@ -412,10 +463,10 @@ class Bot {
|
|
|
412
463
|
// Battery
|
|
413
464
|
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
414
465
|
if (this.BatteryLevel < 10) {
|
|
415
|
-
this.StatusLowBattery = this.
|
|
466
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
416
467
|
}
|
|
417
468
|
else {
|
|
418
|
-
this.StatusLowBattery = this.
|
|
469
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
419
470
|
}
|
|
420
471
|
if (Number.isNaN(this.BatteryLevel)) {
|
|
421
472
|
this.BatteryLevel = 100;
|
|
@@ -484,7 +535,7 @@ class Bot {
|
|
|
484
535
|
}
|
|
485
536
|
};
|
|
486
537
|
// Wait
|
|
487
|
-
return await
|
|
538
|
+
return await sleep(this.scanDuration * 1000);
|
|
488
539
|
})
|
|
489
540
|
.then(async () => {
|
|
490
541
|
// Stop to monitor
|
|
@@ -504,7 +555,7 @@ class Bot {
|
|
|
504
555
|
async openAPIRefreshStatus() {
|
|
505
556
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
506
557
|
try {
|
|
507
|
-
const { body, statusCode, headers } = await
|
|
558
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
508
559
|
headers: this.platform.generateHeaders(),
|
|
509
560
|
});
|
|
510
561
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
@@ -556,9 +607,9 @@ class Bot {
|
|
|
556
607
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
557
608
|
}
|
|
558
609
|
// Refresh the status from the API
|
|
559
|
-
|
|
560
|
-
.pipe(
|
|
561
|
-
.pipe(
|
|
610
|
+
interval(15000)
|
|
611
|
+
.pipe(skipWhile(() => this.botUpdateInProgress))
|
|
612
|
+
.pipe(take(1))
|
|
562
613
|
.subscribe(async () => {
|
|
563
614
|
await this.refreshStatus();
|
|
564
615
|
});
|
|
@@ -588,10 +639,10 @@ class Bot {
|
|
|
588
639
|
this.accessory.context.On = this.On;
|
|
589
640
|
setTimeout(() => {
|
|
590
641
|
if (this.botDeviceType === 'switch') {
|
|
591
|
-
this.switchService?.getCharacteristic(this.
|
|
642
|
+
this.switchService?.getCharacteristic(this.hap.Characteristic.On).updateValue(this.On);
|
|
592
643
|
}
|
|
593
644
|
else {
|
|
594
|
-
this.outletService?.getCharacteristic(this.
|
|
645
|
+
this.outletService?.getCharacteristic(this.hap.Characteristic.On).updateValue(this.On);
|
|
595
646
|
}
|
|
596
647
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
|
|
597
648
|
}, 500);
|
|
@@ -673,7 +724,7 @@ class Bot {
|
|
|
673
724
|
});
|
|
674
725
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
675
726
|
try {
|
|
676
|
-
const { body, statusCode, headers } = await
|
|
727
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
677
728
|
body: bodyChange,
|
|
678
729
|
method: 'POST',
|
|
679
730
|
headers: this.platform.generateHeaders(),
|
|
@@ -720,7 +771,7 @@ class Bot {
|
|
|
720
771
|
async OnSet(value) {
|
|
721
772
|
if (this.botDeviceType === 'garagedoor') {
|
|
722
773
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetDoorState: ${value}`);
|
|
723
|
-
if (value === this.
|
|
774
|
+
if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
|
|
724
775
|
this.On = false;
|
|
725
776
|
}
|
|
726
777
|
else {
|
|
@@ -740,7 +791,7 @@ class Bot {
|
|
|
740
791
|
}
|
|
741
792
|
else if (this.botDeviceType === 'lock') {
|
|
742
793
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set LockTargetState: ${value}`);
|
|
743
|
-
if (value === this.
|
|
794
|
+
if (value === this.hap.Characteristic.LockTargetState.SECURED) {
|
|
744
795
|
this.On = false;
|
|
745
796
|
}
|
|
746
797
|
else {
|
|
@@ -749,7 +800,7 @@ class Bot {
|
|
|
749
800
|
}
|
|
750
801
|
else if (this.botDeviceType === 'faucet') {
|
|
751
802
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
752
|
-
if (value === this.
|
|
803
|
+
if (value === this.hap.Characteristic.Active.INACTIVE) {
|
|
753
804
|
this.On = false;
|
|
754
805
|
}
|
|
755
806
|
else {
|
|
@@ -788,13 +839,13 @@ class Bot {
|
|
|
788
839
|
}
|
|
789
840
|
else {
|
|
790
841
|
if (this.On) {
|
|
791
|
-
this.garageDoorService?.updateCharacteristic(this.
|
|
792
|
-
this.garageDoorService?.updateCharacteristic(this.
|
|
842
|
+
this.garageDoorService?.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
|
|
843
|
+
this.garageDoorService?.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
|
|
793
844
|
this.debugLog(`${this.device.deviceType}: ` + `${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`);
|
|
794
845
|
}
|
|
795
846
|
else {
|
|
796
|
-
this.garageDoorService?.updateCharacteristic(this.
|
|
797
|
-
this.garageDoorService?.updateCharacteristic(this.
|
|
847
|
+
this.garageDoorService?.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
|
|
848
|
+
this.garageDoorService?.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
|
|
798
849
|
this.debugLog(`${this.device.deviceType}: ` + `${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`);
|
|
799
850
|
}
|
|
800
851
|
}
|
|
@@ -806,15 +857,15 @@ class Bot {
|
|
|
806
857
|
}
|
|
807
858
|
else {
|
|
808
859
|
if (this.On) {
|
|
809
|
-
this.doorService?.updateCharacteristic(this.
|
|
810
|
-
this.doorService?.updateCharacteristic(this.
|
|
811
|
-
this.doorService?.updateCharacteristic(this.
|
|
860
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
861
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
862
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
812
863
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
|
|
813
864
|
}
|
|
814
865
|
else {
|
|
815
|
-
this.doorService?.updateCharacteristic(this.
|
|
816
|
-
this.doorService?.updateCharacteristic(this.
|
|
817
|
-
this.doorService?.updateCharacteristic(this.
|
|
866
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
867
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
868
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
818
869
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
|
|
819
870
|
}
|
|
820
871
|
}
|
|
@@ -826,15 +877,15 @@ class Bot {
|
|
|
826
877
|
}
|
|
827
878
|
else {
|
|
828
879
|
if (this.On) {
|
|
829
|
-
this.windowService?.updateCharacteristic(this.
|
|
830
|
-
this.windowService?.updateCharacteristic(this.
|
|
831
|
-
this.windowService?.updateCharacteristic(this.
|
|
880
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
881
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
882
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
832
883
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
|
|
833
884
|
}
|
|
834
885
|
else {
|
|
835
|
-
this.windowService?.updateCharacteristic(this.
|
|
836
|
-
this.windowService?.updateCharacteristic(this.
|
|
837
|
-
this.windowService?.updateCharacteristic(this.
|
|
886
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
887
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
888
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
838
889
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
|
|
839
890
|
}
|
|
840
891
|
}
|
|
@@ -846,15 +897,15 @@ class Bot {
|
|
|
846
897
|
}
|
|
847
898
|
else {
|
|
848
899
|
if (this.On) {
|
|
849
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
850
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
851
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
900
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
901
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
902
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
852
903
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
|
|
853
904
|
}
|
|
854
905
|
else {
|
|
855
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
856
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
857
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
906
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
907
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
908
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
858
909
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
|
|
859
910
|
}
|
|
860
911
|
}
|
|
@@ -866,14 +917,14 @@ class Bot {
|
|
|
866
917
|
}
|
|
867
918
|
else {
|
|
868
919
|
if (this.On) {
|
|
869
|
-
this.lockService?.updateCharacteristic(this.
|
|
870
|
-
this.lockService?.updateCharacteristic(this.
|
|
920
|
+
this.lockService?.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.UNSECURED);
|
|
921
|
+
this.lockService?.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.UNSECURED);
|
|
871
922
|
this.debugLog(`${this.device.deviceType}: ` +
|
|
872
923
|
`${this.accessory.displayName} updateCharacteristic LockTargetState: UNSECURED, LockCurrentState: UNSECURED`);
|
|
873
924
|
}
|
|
874
925
|
else {
|
|
875
|
-
this.lockService?.updateCharacteristic(this.
|
|
876
|
-
this.lockService?.updateCharacteristic(this.
|
|
926
|
+
this.lockService?.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
|
|
927
|
+
this.lockService?.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED);
|
|
877
928
|
this.debugLog(`${this.device.deviceType}: ` + `${this.accessory.displayName} updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED`);
|
|
878
929
|
}
|
|
879
930
|
}
|
|
@@ -885,11 +936,11 @@ class Bot {
|
|
|
885
936
|
}
|
|
886
937
|
else {
|
|
887
938
|
if (this.On) {
|
|
888
|
-
this.faucetService?.updateCharacteristic(this.
|
|
939
|
+
this.faucetService?.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
|
|
889
940
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
|
|
890
941
|
}
|
|
891
942
|
else {
|
|
892
|
-
this.faucetService?.updateCharacteristic(this.
|
|
943
|
+
this.faucetService?.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
893
944
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
|
|
894
945
|
}
|
|
895
946
|
}
|
|
@@ -901,11 +952,11 @@ class Bot {
|
|
|
901
952
|
}
|
|
902
953
|
else {
|
|
903
954
|
if (this.On) {
|
|
904
|
-
this.fanService?.updateCharacteristic(this.
|
|
955
|
+
this.fanService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
905
956
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
906
957
|
}
|
|
907
958
|
else {
|
|
908
|
-
this.fanService?.updateCharacteristic(this.
|
|
959
|
+
this.fanService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
909
960
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
910
961
|
}
|
|
911
962
|
}
|
|
@@ -917,14 +968,14 @@ class Bot {
|
|
|
917
968
|
}
|
|
918
969
|
else {
|
|
919
970
|
if (this.On) {
|
|
920
|
-
this.statefulProgrammableSwitchService?.updateCharacteristic(this.
|
|
921
|
-
this.statefulProgrammableSwitchService?.updateCharacteristic(this.
|
|
971
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
972
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
|
|
922
973
|
this.debugLog(`${this.device.deviceType}: ` +
|
|
923
974
|
`${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1`);
|
|
924
975
|
}
|
|
925
976
|
else {
|
|
926
|
-
this.statefulProgrammableSwitchService?.updateCharacteristic(this.
|
|
927
|
-
this.statefulProgrammableSwitchService?.updateCharacteristic(this.
|
|
977
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
978
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
|
|
928
979
|
this.debugLog(`${this.device.deviceType}: ` +
|
|
929
980
|
`${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0`);
|
|
930
981
|
}
|
|
@@ -936,7 +987,7 @@ class Bot {
|
|
|
936
987
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
937
988
|
}
|
|
938
989
|
else {
|
|
939
|
-
this.switchService?.updateCharacteristic(this.
|
|
990
|
+
this.switchService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
940
991
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
941
992
|
}
|
|
942
993
|
}
|
|
@@ -945,7 +996,7 @@ class Bot {
|
|
|
945
996
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
946
997
|
}
|
|
947
998
|
else {
|
|
948
|
-
this.outletService?.updateCharacteristic(this.
|
|
999
|
+
this.outletService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
949
1000
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
950
1001
|
}
|
|
951
1002
|
}
|
|
@@ -956,7 +1007,7 @@ class Bot {
|
|
|
956
1007
|
}
|
|
957
1008
|
else {
|
|
958
1009
|
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
959
|
-
this.batteryService?.updateCharacteristic(this.
|
|
1010
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
960
1011
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
961
1012
|
}
|
|
962
1013
|
// StatusLowBattery
|
|
@@ -965,13 +1016,13 @@ class Bot {
|
|
|
965
1016
|
}
|
|
966
1017
|
else {
|
|
967
1018
|
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
968
|
-
this.batteryService?.updateCharacteristic(this.
|
|
1019
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
969
1020
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
970
1021
|
}
|
|
971
1022
|
}
|
|
972
1023
|
async removeOutletService(accessory) {
|
|
973
1024
|
// If outletService still pressent, then remove first
|
|
974
|
-
this.outletService = this.accessory.getService(this.
|
|
1025
|
+
this.outletService = this.accessory.getService(this.hap.Service.Outlet);
|
|
975
1026
|
if (this.outletService) {
|
|
976
1027
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Outlet Service`);
|
|
977
1028
|
}
|
|
@@ -979,7 +1030,7 @@ class Bot {
|
|
|
979
1030
|
}
|
|
980
1031
|
async removeGarageDoorService(accessory) {
|
|
981
1032
|
// If garageDoorService still pressent, then remove first
|
|
982
|
-
this.garageDoorService = this.accessory.getService(this.
|
|
1033
|
+
this.garageDoorService = this.accessory.getService(this.hap.Service.GarageDoorOpener);
|
|
983
1034
|
if (this.garageDoorService) {
|
|
984
1035
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Garage Door Service`);
|
|
985
1036
|
}
|
|
@@ -987,7 +1038,7 @@ class Bot {
|
|
|
987
1038
|
}
|
|
988
1039
|
async removeDoorService(accessory) {
|
|
989
1040
|
// If doorService still pressent, then remove first
|
|
990
|
-
this.doorService = this.accessory.getService(this.
|
|
1041
|
+
this.doorService = this.accessory.getService(this.hap.Service.Door);
|
|
991
1042
|
if (this.doorService) {
|
|
992
1043
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Door Service`);
|
|
993
1044
|
}
|
|
@@ -995,7 +1046,7 @@ class Bot {
|
|
|
995
1046
|
}
|
|
996
1047
|
async removeLockService(accessory) {
|
|
997
1048
|
// If lockService still pressent, then remove first
|
|
998
|
-
this.lockService = this.accessory.getService(this.
|
|
1049
|
+
this.lockService = this.accessory.getService(this.hap.Service.LockMechanism);
|
|
999
1050
|
if (this.lockService) {
|
|
1000
1051
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Lock Service`);
|
|
1001
1052
|
}
|
|
@@ -1003,7 +1054,7 @@ class Bot {
|
|
|
1003
1054
|
}
|
|
1004
1055
|
async removeFaucetService(accessory) {
|
|
1005
1056
|
// If faucetService still pressent, then remove first
|
|
1006
|
-
this.faucetService = this.accessory.getService(this.
|
|
1057
|
+
this.faucetService = this.accessory.getService(this.hap.Service.Faucet);
|
|
1007
1058
|
if (this.faucetService) {
|
|
1008
1059
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Faucet Service`);
|
|
1009
1060
|
}
|
|
@@ -1011,7 +1062,7 @@ class Bot {
|
|
|
1011
1062
|
}
|
|
1012
1063
|
async removeFanService(accessory) {
|
|
1013
1064
|
// If fanService still pressent, then remove first
|
|
1014
|
-
this.fanService = this.accessory.getService(this.
|
|
1065
|
+
this.fanService = this.accessory.getService(this.hap.Service.Fan);
|
|
1015
1066
|
if (this.fanService) {
|
|
1016
1067
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Fan Service`);
|
|
1017
1068
|
}
|
|
@@ -1019,7 +1070,7 @@ class Bot {
|
|
|
1019
1070
|
}
|
|
1020
1071
|
async removeWindowService(accessory) {
|
|
1021
1072
|
// If windowService still pressent, then remove first
|
|
1022
|
-
this.windowService = this.accessory.getService(this.
|
|
1073
|
+
this.windowService = this.accessory.getService(this.hap.Service.Window);
|
|
1023
1074
|
if (this.windowService) {
|
|
1024
1075
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Window Service`);
|
|
1025
1076
|
}
|
|
@@ -1027,7 +1078,7 @@ class Bot {
|
|
|
1027
1078
|
}
|
|
1028
1079
|
async removeWindowCoveringService(accessory) {
|
|
1029
1080
|
// If windowCoveringService still pressent, then remove first
|
|
1030
|
-
this.windowCoveringService = this.accessory.getService(this.
|
|
1081
|
+
this.windowCoveringService = this.accessory.getService(this.hap.Service.WindowCovering);
|
|
1031
1082
|
if (this.windowCoveringService) {
|
|
1032
1083
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Window Covering Service`);
|
|
1033
1084
|
}
|
|
@@ -1035,7 +1086,7 @@ class Bot {
|
|
|
1035
1086
|
}
|
|
1036
1087
|
async removeStatefulProgrammableSwitchService(accessory) {
|
|
1037
1088
|
// If statefulProgrammableSwitchService still pressent, then remove first
|
|
1038
|
-
this.statefulProgrammableSwitchService = this.accessory.getService(this.
|
|
1089
|
+
this.statefulProgrammableSwitchService = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch);
|
|
1039
1090
|
if (this.statefulProgrammableSwitchService) {
|
|
1040
1091
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
|
|
1041
1092
|
}
|
|
@@ -1043,7 +1094,7 @@ class Bot {
|
|
|
1043
1094
|
}
|
|
1044
1095
|
async removeSwitchService(accessory) {
|
|
1045
1096
|
// If switchService still pressent, then remove first
|
|
1046
|
-
this.switchService = this.accessory.getService(this.
|
|
1097
|
+
this.switchService = this.accessory.getService(this.hap.Service.Switch);
|
|
1047
1098
|
if (this.switchService) {
|
|
1048
1099
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Switch Service`);
|
|
1049
1100
|
}
|
|
@@ -1079,7 +1130,7 @@ class Bot {
|
|
|
1079
1130
|
switchbot.onadvertisement = (ad) => {
|
|
1080
1131
|
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
1081
1132
|
};
|
|
1082
|
-
await
|
|
1133
|
+
await sleep(10000);
|
|
1083
1134
|
// Stop to monitor
|
|
1084
1135
|
await switchbot.stopScan();
|
|
1085
1136
|
})();
|
|
@@ -1105,7 +1156,7 @@ class Bot {
|
|
|
1105
1156
|
}
|
|
1106
1157
|
this.infoLog(e);
|
|
1107
1158
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
|
|
1108
|
-
await
|
|
1159
|
+
await sleep(1000);
|
|
1109
1160
|
return this.retry({ max: max - 1, fn });
|
|
1110
1161
|
});
|
|
1111
1162
|
}
|
|
@@ -1205,47 +1256,47 @@ class Bot {
|
|
|
1205
1256
|
}
|
|
1206
1257
|
async apiError(e) {
|
|
1207
1258
|
if (this.botDeviceType === 'garagedoor') {
|
|
1208
|
-
this.garageDoorService?.updateCharacteristic(this.
|
|
1209
|
-
this.garageDoorService?.updateCharacteristic(this.
|
|
1210
|
-
this.garageDoorService?.updateCharacteristic(this.
|
|
1259
|
+
this.garageDoorService?.updateCharacteristic(this.hap.Characteristic.TargetDoorState, e);
|
|
1260
|
+
this.garageDoorService?.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, e);
|
|
1261
|
+
this.garageDoorService?.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, e);
|
|
1211
1262
|
}
|
|
1212
1263
|
else if (this.botDeviceType === 'door') {
|
|
1213
|
-
this.doorService?.updateCharacteristic(this.
|
|
1214
|
-
this.doorService?.updateCharacteristic(this.
|
|
1215
|
-
this.doorService?.updateCharacteristic(this.
|
|
1264
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
1265
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
1266
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
1216
1267
|
}
|
|
1217
1268
|
else if (this.botDeviceType === 'window') {
|
|
1218
|
-
this.windowService?.updateCharacteristic(this.
|
|
1219
|
-
this.windowService?.updateCharacteristic(this.
|
|
1220
|
-
this.windowService?.updateCharacteristic(this.
|
|
1269
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
1270
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
1271
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
1221
1272
|
}
|
|
1222
1273
|
else if (this.botDeviceType === 'windowcovering') {
|
|
1223
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
1224
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
1225
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
1274
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
1275
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
1276
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
1226
1277
|
}
|
|
1227
1278
|
else if (this.botDeviceType === 'lock') {
|
|
1228
|
-
this.doorService?.updateCharacteristic(this.
|
|
1229
|
-
this.doorService?.updateCharacteristic(this.
|
|
1279
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.LockTargetState, e);
|
|
1280
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e);
|
|
1230
1281
|
}
|
|
1231
1282
|
else if (this.botDeviceType === 'faucet') {
|
|
1232
|
-
this.faucetService?.updateCharacteristic(this.
|
|
1283
|
+
this.faucetService?.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
1233
1284
|
}
|
|
1234
1285
|
else if (this.botDeviceType === 'fan') {
|
|
1235
|
-
this.fanService?.updateCharacteristic(this.
|
|
1286
|
+
this.fanService?.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
1236
1287
|
}
|
|
1237
1288
|
else if (this.botDeviceType === 'stateful') {
|
|
1238
|
-
this.statefulProgrammableSwitchService?.updateCharacteristic(this.
|
|
1239
|
-
this.statefulProgrammableSwitchService?.updateCharacteristic(this.
|
|
1289
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
|
|
1290
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
1240
1291
|
}
|
|
1241
1292
|
else if (this.botDeviceType === 'switch') {
|
|
1242
|
-
this.switchService?.updateCharacteristic(this.
|
|
1293
|
+
this.switchService?.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
1243
1294
|
}
|
|
1244
1295
|
else {
|
|
1245
|
-
this.outletService?.updateCharacteristic(this.
|
|
1296
|
+
this.outletService?.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
1246
1297
|
}
|
|
1247
|
-
this.batteryService?.updateCharacteristic(this.
|
|
1248
|
-
this.batteryService?.updateCharacteristic(this.
|
|
1298
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
1299
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
1249
1300
|
}
|
|
1250
1301
|
async deviceType(device) {
|
|
1251
1302
|
if (!device.bot?.deviceType && this.accessory.context.deviceType) {
|
|
@@ -1279,7 +1330,7 @@ class Bot {
|
|
|
1279
1330
|
this.BatteryLevel = this.accessory.context.BatteryLevel;
|
|
1280
1331
|
}
|
|
1281
1332
|
if (this.StatusLowBattery === undefined) {
|
|
1282
|
-
this.StatusLowBattery = this.
|
|
1333
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
1283
1334
|
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
1284
1335
|
}
|
|
1285
1336
|
else {
|
|
@@ -1309,7 +1360,7 @@ class Bot {
|
|
|
1309
1360
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default Bot pushRatePress: ${this.pushRatePress}`);
|
|
1310
1361
|
}
|
|
1311
1362
|
}
|
|
1312
|
-
async
|
|
1363
|
+
async deviceConfig(device) {
|
|
1313
1364
|
let config = {};
|
|
1314
1365
|
if (device.bot) {
|
|
1315
1366
|
config = device.bot;
|
|
@@ -1339,7 +1390,7 @@ class Bot {
|
|
|
1339
1390
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1340
1391
|
}
|
|
1341
1392
|
}
|
|
1342
|
-
async
|
|
1393
|
+
async deviceLogs(device) {
|
|
1343
1394
|
if (this.platform.debugMode) {
|
|
1344
1395
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
1345
1396
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -1403,5 +1454,4 @@ class Bot {
|
|
|
1403
1454
|
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
1404
1455
|
}
|
|
1405
1456
|
}
|
|
1406
|
-
exports.Bot = Bot;
|
|
1407
1457
|
//# sourceMappingURL=bot.js.map
|