@switchbot/homebridge-switchbot 3.7.1-beta.9 → 3.8.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/CHANGELOG.md +8 -2
- package/README.md +14 -0
- package/assets/security-privacy-bluetooth.png +0 -0
- package/config.schema.json +76 -1
- package/dist/device/blindtilt.d.ts +18 -8
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +108 -70
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -9
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +133 -160
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -13
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +38 -73
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +12 -12
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +41 -79
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +5 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +20 -42
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +15 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +127 -81
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +18 -18
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +33 -36
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +8 -8
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +43 -75
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +5 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +18 -39
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +5 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +38 -78
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +5 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +21 -40
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +6 -6
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +34 -73
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +9 -9
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +37 -52
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +21 -39
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +5 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +21 -38
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +5 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +14 -32
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +12 -12
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +16 -25
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -11
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +42 -56
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +5 -5
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +47 -44
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/server.js +2 -2
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -8
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +61 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +10 -10
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +22 -42
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +9 -9
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +15 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -8
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +21 -40
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +11 -11
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +14 -22
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +9 -9
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +24 -47
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +9 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +40 -83
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +9 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +29 -54
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +5 -5
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +11 -21
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +5 -5
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +11 -22
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +20 -19
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +466 -710
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +5 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +9 -9
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicelist.d.ts +6 -6
- package/dist/types/devicelist.d.ts.map +1 -1
- package/dist/types/deviceresponse.d.ts +4 -4
- package/dist/types/deviceresponse.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts +2 -2
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/dist/types/devicewebhookstatus.d.ts +5 -5
- package/dist/types/devicewebhookstatus.d.ts.map +1 -1
- package/dist/types/irdevicelist.d.ts +4 -4
- package/dist/types/irdevicelist.d.ts.map +1 -1
- package/dist/types/pushbody.d.ts +2 -2
- package/dist/types/pushbody.d.ts.map +1 -1
- package/dist/utils.d.ts +4 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +9 -13
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +48 -93
- package/package.json +61 -54
- package/src/device/blindtilt.ts +509 -460
- package/src/device/bot.ts +696 -718
- package/src/device/ceilinglight.ts +331 -364
- package/src/device/colorbulb.ts +412 -448
- package/src/device/contact.ts +200 -221
- package/src/device/curtain.ts +506 -444
- package/src/device/device.ts +206 -208
- package/src/device/fan.ts +307 -340
- package/src/device/hub.ts +184 -209
- package/src/device/humidifier.ts +297 -342
- package/src/device/iosensor.ts +182 -204
- package/src/device/lightstrip.ts +362 -399
- package/src/device/lock.ts +262 -276
- package/src/device/meter.ts +183 -205
- package/src/device/meterplus.ts +183 -204
- package/src/device/motion.ts +169 -185
- package/src/device/plug.ts +174 -177
- package/src/device/robotvacuumcleaner.ts +256 -269
- package/src/device/waterdetector.ts +185 -185
- package/src/homebridge-ui/server.ts +16 -15
- package/src/index.ts +5 -6
- package/src/irdevice/airconditioner.ts +277 -326
- package/src/irdevice/airpurifier.ts +124 -143
- package/src/irdevice/camera.ts +58 -64
- package/src/irdevice/fan.ts +106 -123
- package/src/irdevice/irdevice.ts +116 -119
- package/src/irdevice/light.ts +119 -143
- package/src/irdevice/other.ts +417 -461
- package/src/irdevice/tv.ts +155 -177
- package/src/irdevice/vacuumcleaner.ts +54 -60
- package/src/irdevice/waterheater.ts +56 -63
- package/src/platform.ts +1462 -1678
- package/src/settings.ts +173 -170
- package/src/types/bledevicestatus.ts +252 -256
- package/src/types/devicelist.ts +79 -79
- package/src/types/deviceresponse.ts +12 -13
- package/src/types/devicestatus.ts +124 -124
- package/src/types/devicewebhookstatus.ts +126 -131
- package/src/types/irdevicelist.ts +10 -10
- package/src/types/pushbody.ts +5 -5
- package/src/utils.ts +64 -65
- package/tsconfig.json +10 -9
- package/.github/npm-version-script.cjs +0 -81
package/dist/device/bot.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
-
*
|
|
3
|
-
* bot.ts: @switchbot/homebridge-switchbot.
|
|
4
|
-
*/
|
|
5
|
-
import { deviceBase } from './device.js';
|
|
6
1
|
/*
|
|
7
2
|
* For Testing Locally:
|
|
8
3
|
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
9
4
|
*/
|
|
10
5
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
11
|
-
import {
|
|
6
|
+
import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs';
|
|
7
|
+
import { deviceBase } from './device.js';
|
|
12
8
|
/**
|
|
13
9
|
* Platform Accessory
|
|
14
10
|
* An instance of this class is created for each accessory your platform registers
|
|
@@ -31,7 +27,7 @@ export class Bot extends deviceBase {
|
|
|
31
27
|
On;
|
|
32
28
|
// OpenAPI
|
|
33
29
|
deviceStatus;
|
|
34
|
-
//Webhook
|
|
30
|
+
// Webhook
|
|
35
31
|
webhookContext;
|
|
36
32
|
// BLE
|
|
37
33
|
serviceData;
|
|
@@ -63,10 +59,7 @@ export class Bot extends deviceBase {
|
|
|
63
59
|
};
|
|
64
60
|
accessory.context.Battery = this.Battery;
|
|
65
61
|
// Initialize Battery Characteristics
|
|
66
|
-
this.Battery.Service
|
|
67
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
|
|
68
|
-
.setCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery)
|
|
69
|
-
.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
62
|
+
this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name).setCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery).setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
70
63
|
// deviceType
|
|
71
64
|
if (this.botDeviceType === 'switch') {
|
|
72
65
|
// Set category
|
|
@@ -80,10 +73,7 @@ export class Bot extends deviceBase {
|
|
|
80
73
|
accessory.context.Switch = this.Switch;
|
|
81
74
|
this.debugLog('Displaying as Switch');
|
|
82
75
|
// Initialize Switch Characteristics
|
|
83
|
-
this.Switch.Service
|
|
84
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
|
|
85
|
-
.getCharacteristic(this.hap.Characteristic.On)
|
|
86
|
-
.onSet(this.OnSet.bind(this));
|
|
76
|
+
this.Switch.Service.setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name).getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
87
77
|
// Remove other services
|
|
88
78
|
this.removeFanService(accessory);
|
|
89
79
|
this.removeLockService(accessory);
|
|
@@ -107,17 +97,12 @@ export class Bot extends deviceBase {
|
|
|
107
97
|
accessory.context.GarageDoor = this.GarageDoor;
|
|
108
98
|
this.debugLog('Displaying as Garage Door Opener');
|
|
109
99
|
// Initialize GarageDoor Characteristics
|
|
110
|
-
this.GarageDoor.Service
|
|
111
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.GarageDoor.Name)
|
|
112
|
-
.setCharacteristic(this.hap.Characteristic.ObstructionDetected, false)
|
|
113
|
-
.getCharacteristic(this.hap.Characteristic.TargetDoorState)
|
|
114
|
-
.setProps({
|
|
100
|
+
this.GarageDoor.Service.setCharacteristic(this.hap.Characteristic.Name, this.GarageDoor.Name).setCharacteristic(this.hap.Characteristic.ObstructionDetected, false).getCharacteristic(this.hap.Characteristic.TargetDoorState).setProps({
|
|
115
101
|
validValues: [0, 100],
|
|
116
102
|
minValue: 0,
|
|
117
103
|
maxValue: 100,
|
|
118
104
|
minStep: 100,
|
|
119
|
-
})
|
|
120
|
-
.onSet(this.OnSet.bind(this));
|
|
105
|
+
}).onSet(this.OnSet.bind(this));
|
|
121
106
|
// Remove other services
|
|
122
107
|
this.removeFanService(accessory);
|
|
123
108
|
this.removeLockService(accessory);
|
|
@@ -141,16 +126,12 @@ export class Bot extends deviceBase {
|
|
|
141
126
|
accessory.context.Door = this.Door;
|
|
142
127
|
this.debugLog('Displaying as Door');
|
|
143
128
|
// Initialize Door Characteristics
|
|
144
|
-
this.Door.Service
|
|
145
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.Door.Name)
|
|
146
|
-
.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
147
|
-
.getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
|
|
129
|
+
this.Door.Service.setCharacteristic(this.hap.Characteristic.Name, this.Door.Name).setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED).getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
|
|
148
130
|
validValues: [0, 100],
|
|
149
131
|
minValue: 0,
|
|
150
132
|
maxValue: 100,
|
|
151
133
|
minStep: 100,
|
|
152
|
-
})
|
|
153
|
-
.onSet(this.OnSet.bind(this));
|
|
134
|
+
}).onSet(this.OnSet.bind(this));
|
|
154
135
|
// Remove other services
|
|
155
136
|
this.removeFanService(accessory);
|
|
156
137
|
this.removeLockService(accessory);
|
|
@@ -174,16 +155,12 @@ export class Bot extends deviceBase {
|
|
|
174
155
|
accessory.context.Window = this.Window;
|
|
175
156
|
this.debugLog('Displaying as Window');
|
|
176
157
|
// Initialize Window Characteristics
|
|
177
|
-
this.Window.Service
|
|
178
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.Window.Name)
|
|
179
|
-
.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
180
|
-
.getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
|
|
158
|
+
this.Window.Service.setCharacteristic(this.hap.Characteristic.Name, this.Window.Name).setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED).getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
|
|
181
159
|
validValues: [0, 100],
|
|
182
160
|
minValue: 0,
|
|
183
161
|
maxValue: 100,
|
|
184
162
|
minStep: 100,
|
|
185
|
-
})
|
|
186
|
-
.onSet(this.OnSet.bind(this));
|
|
163
|
+
}).onSet(this.OnSet.bind(this));
|
|
187
164
|
// Remove other services
|
|
188
165
|
this.removeFanService(accessory);
|
|
189
166
|
this.removeLockService(accessory);
|
|
@@ -207,17 +184,12 @@ export class Bot extends deviceBase {
|
|
|
207
184
|
accessory.context.WindowCovering = this.WindowCovering;
|
|
208
185
|
this.debugLog('Displaying as Window Covering');
|
|
209
186
|
// Initialize WindowCovering Characteristics
|
|
210
|
-
this.WindowCovering.Service
|
|
211
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name)
|
|
212
|
-
.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
213
|
-
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
214
|
-
.setProps({
|
|
187
|
+
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name).setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED).getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
|
|
215
188
|
validValues: [0, 100],
|
|
216
189
|
minValue: 0,
|
|
217
190
|
maxValue: 100,
|
|
218
191
|
minStep: 100,
|
|
219
|
-
})
|
|
220
|
-
.onSet(this.OnSet.bind(this));
|
|
192
|
+
}).onSet(this.OnSet.bind(this));
|
|
221
193
|
// Remove other services
|
|
222
194
|
this.removeFanService(accessory);
|
|
223
195
|
this.removeLockService(accessory);
|
|
@@ -241,11 +213,7 @@ export class Bot extends deviceBase {
|
|
|
241
213
|
accessory.context.LockMechanism = this.LockMechanism;
|
|
242
214
|
this.debugLog('Displaying as Lock');
|
|
243
215
|
// Initialize Lock Characteristics
|
|
244
|
-
this.LockMechanism.Service
|
|
245
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name)
|
|
246
|
-
.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
247
|
-
.getCharacteristic(this.hap.Characteristic.LockTargetState)
|
|
248
|
-
.onSet(this.OnSet.bind(this));
|
|
216
|
+
this.LockMechanism.Service.setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name).setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED).getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.OnSet.bind(this));
|
|
249
217
|
// Remove other services
|
|
250
218
|
this.removeFanService(accessory);
|
|
251
219
|
this.removeDoorService(accessory);
|
|
@@ -269,10 +237,7 @@ export class Bot extends deviceBase {
|
|
|
269
237
|
accessory.context.Faucet = this.Faucet;
|
|
270
238
|
this.debugLog('Displaying as Faucet');
|
|
271
239
|
// Initialize Faucet Characteristics
|
|
272
|
-
this.Faucet.Service
|
|
273
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.Faucet.Name)
|
|
274
|
-
.getCharacteristic(this.hap.Characteristic.Active)
|
|
275
|
-
.onSet(this.OnSet.bind(this));
|
|
240
|
+
this.Faucet.Service.setCharacteristic(this.hap.Characteristic.Name, this.Faucet.Name).getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this));
|
|
276
241
|
// Remove other services
|
|
277
242
|
this.removeFanService(accessory);
|
|
278
243
|
this.removeLockService(accessory);
|
|
@@ -296,10 +261,7 @@ export class Bot extends deviceBase {
|
|
|
296
261
|
accessory.context.Fan = this.Fan;
|
|
297
262
|
this.debugLog('Displaying as Fan');
|
|
298
263
|
// Initialize Fan Characteristics
|
|
299
|
-
this.Fan.Service
|
|
300
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name)
|
|
301
|
-
.getCharacteristic(this.hap.Characteristic.Active)
|
|
302
|
-
.onSet(this.OnSet.bind(this));
|
|
264
|
+
this.Fan.Service.setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name).getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this));
|
|
303
265
|
// Remove other services
|
|
304
266
|
this.removeLockService(accessory);
|
|
305
267
|
this.removeDoorService(accessory);
|
|
@@ -318,16 +280,12 @@ export class Bot extends deviceBase {
|
|
|
318
280
|
accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {};
|
|
319
281
|
this.StatefulProgrammableSwitch = {
|
|
320
282
|
Name: accessory.displayName,
|
|
321
|
-
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
322
|
-
?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch),
|
|
283
|
+
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch),
|
|
323
284
|
};
|
|
324
285
|
accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch;
|
|
325
286
|
this.debugLog('Displaying as Stateful Programmable Switch');
|
|
326
287
|
// Initialize StatefulProgrammableSwitch Characteristics
|
|
327
|
-
this.StatefulProgrammableSwitch.Service
|
|
328
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.StatefulProgrammableSwitch.Name)
|
|
329
|
-
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
330
|
-
.onSet(this.OnSet.bind(this));
|
|
288
|
+
this.StatefulProgrammableSwitch.Service.setCharacteristic(this.hap.Characteristic.Name, this.StatefulProgrammableSwitch.Name).getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState).onSet(this.OnSet.bind(this));
|
|
331
289
|
// Remove other services
|
|
332
290
|
this.removeFanService(accessory);
|
|
333
291
|
this.removeLockService(accessory);
|
|
@@ -351,10 +309,7 @@ export class Bot extends deviceBase {
|
|
|
351
309
|
accessory.context.Outlet = this.Outlet;
|
|
352
310
|
this.debugLog('Displaying as Outlet');
|
|
353
311
|
// Initialize Outlet Characteristics
|
|
354
|
-
this.Outlet.Service
|
|
355
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.Outlet.Name)
|
|
356
|
-
.getCharacteristic(this.hap.Characteristic.On)
|
|
357
|
-
.onSet(this.OnSet.bind(this));
|
|
312
|
+
this.Outlet.Service.setCharacteristic(this.hap.Characteristic.Name, this.Outlet.Name).getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
358
313
|
// Remove other services
|
|
359
314
|
this.removeFanService(accessory);
|
|
360
315
|
this.removeLockService(accessory);
|
|
@@ -377,7 +332,7 @@ export class Bot extends deviceBase {
|
|
|
377
332
|
catch (e) {
|
|
378
333
|
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
|
|
379
334
|
}
|
|
380
|
-
//regisiter webhook event handler if enabled
|
|
335
|
+
// regisiter webhook event handler if enabled
|
|
381
336
|
try {
|
|
382
337
|
this.debugLog('Registering Webhook Event Handler');
|
|
383
338
|
this.registerWebhook();
|
|
@@ -385,7 +340,7 @@ export class Bot extends deviceBase {
|
|
|
385
340
|
catch (e) {
|
|
386
341
|
this.errorLog(`failed to registerWebhook, Error: ${e}`);
|
|
387
342
|
}
|
|
388
|
-
//regisiter platform BLE event handler if enabled
|
|
343
|
+
// regisiter platform BLE event handler if enabled
|
|
389
344
|
try {
|
|
390
345
|
this.debugLog('Registering Platform BLE Event Handler');
|
|
391
346
|
this.registerPlatformBLE();
|
|
@@ -430,8 +385,7 @@ export class Bot extends deviceBase {
|
|
|
430
385
|
*/
|
|
431
386
|
async BLEparseStatus() {
|
|
432
387
|
await this.debugLog('BLEparseStatus');
|
|
433
|
-
await this.debugLog(`(power, battery, deviceMode) = BLE:(${this.serviceData.state}, ${this.serviceData.battery}, ${this.serviceData.mode})
|
|
434
|
-
+ ` current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
388
|
+
await this.debugLog(`(power, battery, deviceMode) = BLE:(${this.serviceData.state}, ${this.serviceData.battery}, ${this.serviceData.mode}), current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
435
389
|
// BLEmode (true if Switch Mode) | (false if Press Mode)
|
|
436
390
|
this.On = this.serviceData.mode ? this.serviceData.state : false;
|
|
437
391
|
const mode = this.serviceData.mode ? 'Switch' : 'Press';
|
|
@@ -442,7 +396,8 @@ export class Bot extends deviceBase {
|
|
|
442
396
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
443
397
|
// StatusLowBattery
|
|
444
398
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
445
|
-
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
399
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
400
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
446
401
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
447
402
|
}
|
|
448
403
|
/**
|
|
@@ -450,10 +405,9 @@ export class Bot extends deviceBase {
|
|
|
450
405
|
*/
|
|
451
406
|
async openAPIparseStatus() {
|
|
452
407
|
await this.debugLog('openAPIparseStatus');
|
|
453
|
-
await this.debugLog(`(power, battery, deviceMode) = API:(${this.deviceStatus.power}, ${this.deviceStatus.battery}, ${this.botMode})
|
|
454
|
-
+ ` current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
408
|
+
await this.debugLog(`(power, battery, deviceMode) = API:(${this.deviceStatus.power}, ${this.deviceStatus.battery}, ${this.botMode}), current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
455
409
|
// On
|
|
456
|
-
this.On = this.botMode === 'press' ? false : this.deviceStatus.power === 'on'
|
|
410
|
+
this.On = this.botMode === 'press' ? false : this.deviceStatus.power === 'on';
|
|
457
411
|
this.accessory.context.On = this.On;
|
|
458
412
|
await this.debugLog(`On: ${this.accessory.context.On}`);
|
|
459
413
|
// Battery Level
|
|
@@ -461,7 +415,8 @@ export class Bot extends deviceBase {
|
|
|
461
415
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
462
416
|
// StatusLowBattery
|
|
463
417
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
464
|
-
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
418
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
419
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
465
420
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
466
421
|
// Firmware Version
|
|
467
422
|
if (this.deviceStatus.version) {
|
|
@@ -480,17 +435,17 @@ export class Bot extends deviceBase {
|
|
|
480
435
|
}
|
|
481
436
|
async parseStatusWebhook() {
|
|
482
437
|
await this.debugLog('parseStatusWebhook');
|
|
483
|
-
await this.debugLog(`(power, battery, deviceMode) = Webhook:(${this.webhookContext.power}, ${this.webhookContext.battery}
|
|
484
|
-
+ ` ${this.webhookContext.deviceMode}), current:(${this.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
438
|
+
await this.debugLog(`(power, battery, deviceMode) = Webhook:(${this.webhookContext.power}, ${this.webhookContext.battery}, ${this.webhookContext.deviceMode}), current:(${this.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
485
439
|
// On
|
|
486
|
-
this.On = this.webhookContext.power === 'on'
|
|
440
|
+
this.On = this.webhookContext.power === 'on';
|
|
487
441
|
await this.debugLog(`On: ${this.On}`);
|
|
488
442
|
// BatteryLevel
|
|
489
443
|
this.Battery.BatteryLevel = this.webhookContext.battery;
|
|
490
444
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
491
445
|
// StatusLowBattery
|
|
492
446
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
493
|
-
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
447
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
448
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
494
449
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
495
450
|
// Mode
|
|
496
451
|
this.botMode = this.webhookContext.deviceMode;
|
|
@@ -566,7 +521,6 @@ export class Bot extends deviceBase {
|
|
|
566
521
|
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
567
522
|
const deviceStatus = await body.json();
|
|
568
523
|
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
569
|
-
;
|
|
570
524
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
571
525
|
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
572
526
|
this.deviceStatus = deviceStatus.body;
|
|
@@ -604,10 +558,10 @@ export class Bot extends deviceBase {
|
|
|
604
558
|
}
|
|
605
559
|
/**
|
|
606
560
|
* Pushes the requested changes to the SwitchBot API
|
|
607
|
-
* deviceType
|
|
608
|
-
* Bot
|
|
609
|
-
* Bot
|
|
610
|
-
* Bot
|
|
561
|
+
* deviceType commandType Command command parameter Description
|
|
562
|
+
* Bot "command" "turnOff" "default" = set to OFF state
|
|
563
|
+
* Bot "command" "turnOn" "default" = set to ON state
|
|
564
|
+
* Bot "command" "press" "default" = trigger press
|
|
611
565
|
*/
|
|
612
566
|
async pushChanges() {
|
|
613
567
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
@@ -637,7 +591,7 @@ export class Bot extends deviceBase {
|
|
|
637
591
|
await this.debugLog(`BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
|
|
638
592
|
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
639
593
|
await this.convertBLEAddress();
|
|
640
|
-
//if (switchbot !== false) {
|
|
594
|
+
// if (switchbot !== false) {
|
|
641
595
|
await this.debugLog(`Bot Mode: ${this.botMode}`);
|
|
642
596
|
if (this.botMode === 'press') {
|
|
643
597
|
switchbot
|
|
@@ -755,63 +709,71 @@ export class Bot extends deviceBase {
|
|
|
755
709
|
* Handle requests to set the "On" characteristic
|
|
756
710
|
*/
|
|
757
711
|
async OnSet(value) {
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
712
|
+
this.On = this.accessory.context.On ?? false;
|
|
713
|
+
this.accessory.context.On = this.On;
|
|
714
|
+
const deviceTypeActions = {
|
|
715
|
+
switch: async () => {
|
|
716
|
+
if (this.Switch) {
|
|
717
|
+
await this.debugLog(`Set On: ${value}`);
|
|
718
|
+
this.On = value !== false;
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
garagedoor: async () => {
|
|
722
|
+
if (this.GarageDoor) {
|
|
723
|
+
await this.debugLog(`Set TargetDoorState: ${value}`);
|
|
724
|
+
this.On = value !== this.hap.Characteristic.TargetDoorState.CLOSED;
|
|
725
|
+
}
|
|
726
|
+
},
|
|
727
|
+
door: async () => {
|
|
728
|
+
if (this.Door) {
|
|
729
|
+
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
730
|
+
this.On = value !== 0;
|
|
731
|
+
}
|
|
732
|
+
},
|
|
733
|
+
window: async () => {
|
|
734
|
+
if (this.Window) {
|
|
735
|
+
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
736
|
+
this.On = value !== 0;
|
|
737
|
+
}
|
|
738
|
+
},
|
|
739
|
+
windowcovering: async () => {
|
|
740
|
+
if (this.WindowCovering) {
|
|
741
|
+
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
742
|
+
this.On = value !== 0;
|
|
743
|
+
}
|
|
744
|
+
},
|
|
745
|
+
lock: async () => {
|
|
746
|
+
if (this.LockMechanism) {
|
|
747
|
+
await this.debugLog(`Set LockTargetState: ${value}`);
|
|
748
|
+
this.On = value !== this.hap.Characteristic.LockTargetState.SECURED;
|
|
749
|
+
}
|
|
750
|
+
},
|
|
751
|
+
faucet: async () => {
|
|
752
|
+
if (this.Faucet) {
|
|
753
|
+
await this.debugLog(`Set Active: ${value}`);
|
|
754
|
+
this.On = value !== this.hap.Characteristic.Active.INACTIVE;
|
|
755
|
+
}
|
|
756
|
+
},
|
|
757
|
+
stateful: async () => {
|
|
758
|
+
if (this.StatefulProgrammableSwitch) {
|
|
759
|
+
await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
|
|
760
|
+
this.On = value !== 0;
|
|
761
|
+
}
|
|
762
|
+
},
|
|
763
|
+
default: async () => {
|
|
764
|
+
if (this.Outlet) {
|
|
765
|
+
await this.debugLog(`Set On: ${value}`);
|
|
766
|
+
this.On = value !== false;
|
|
767
|
+
}
|
|
768
|
+
if (this.device.bot?.mode === 'multipress' && this.On) {
|
|
809
769
|
this.multiPressCount++;
|
|
810
|
-
this.debugLog(`
|
|
770
|
+
await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
|
|
811
771
|
}
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
|
|
772
|
+
},
|
|
773
|
+
};
|
|
774
|
+
const action = deviceTypeActions[this.botDeviceType] || deviceTypeActions.default;
|
|
775
|
+
await action();
|
|
776
|
+
this.accessory.context.On = this.On;
|
|
815
777
|
this.doBotUpdate.next();
|
|
816
778
|
}
|
|
817
779
|
/**
|
|
@@ -1117,39 +1079,50 @@ export class Bot extends deviceBase {
|
|
|
1117
1079
|
accessory.removeService(this.Switch.Service);
|
|
1118
1080
|
}
|
|
1119
1081
|
async getBotConfigSettings(device) {
|
|
1120
|
-
//Bot Device Type
|
|
1121
|
-
this.botDeviceType =
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
: device.bot?.deviceType
|
|
1125
|
-
: `No Device Type Set, deviceType: ${this.device.bot?.deviceType}, Using default deviceType: ${this.botDeviceType}`;
|
|
1082
|
+
// Bot Device Type
|
|
1083
|
+
this.botDeviceType = device.bot?.deviceType ?? 'outlet';
|
|
1084
|
+
const botDeviceType = device.bot?.deviceType
|
|
1085
|
+
? `Using Device Type: ${this.botDeviceType}`
|
|
1086
|
+
: `No Device Type Set, deviceType: ${this.device.bot?.deviceType}, Using default deviceType: ${this.botDeviceType}`;
|
|
1126
1087
|
await this.debugWarnLog(botDeviceType);
|
|
1127
1088
|
this.accessory.context.botDeviceType = this.botDeviceType;
|
|
1128
1089
|
// Bot Mode
|
|
1129
|
-
this.botMode =
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1090
|
+
this.botMode = device.bot?.mode ?? 'switch';
|
|
1091
|
+
if (!device.bot?.mode) {
|
|
1092
|
+
this.botMode = 'switch';
|
|
1093
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings, defaulting to "${this.botMode}" mode. You may experience issues.`);
|
|
1094
|
+
}
|
|
1095
|
+
else if (['switch', 'press', 'multipress'].includes(device.bot.mode)) {
|
|
1096
|
+
this.botMode = device.bot.mode;
|
|
1097
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
|
|
1098
|
+
}
|
|
1099
|
+
else {
|
|
1100
|
+
throw new Error(`${this.device.deviceType}: ${this.accessory.displayName} Invalid Bot Mode: ${device.bot.mode}`);
|
|
1101
|
+
}
|
|
1102
|
+
const botModeLog = device.bot?.mode
|
|
1103
|
+
? `Using Bot Mode: ${this.botMode}`
|
|
1104
|
+
: `No Bot Mode Set, Using default Bot Mode: ${this.botMode}`;
|
|
1105
|
+
await this.debugWarnLog(botModeLog);
|
|
1133
1106
|
this.accessory.context.botMode = this.botMode;
|
|
1134
1107
|
// Bot Double Press
|
|
1135
|
-
this.doublePress =
|
|
1136
|
-
const doublePress =
|
|
1137
|
-
|
|
1138
|
-
|
|
1108
|
+
this.doublePress = device.bot?.doublePress ?? 1;
|
|
1109
|
+
const doublePress = device.bot?.doublePress
|
|
1110
|
+
? `Using Double Press: ${this.doublePress}`
|
|
1111
|
+
: `No Double Press Set, Using default Double Press: ${this.doublePress}`;
|
|
1139
1112
|
await this.debugWarnLog(doublePress);
|
|
1140
1113
|
this.accessory.context.doublePress = this.doublePress;
|
|
1141
1114
|
// Bot Press PushRate
|
|
1142
|
-
this.pushRatePress =
|
|
1143
|
-
const pushRatePress =
|
|
1144
|
-
|
|
1145
|
-
|
|
1115
|
+
this.pushRatePress = device.bot?.pushRatePress ?? 15;
|
|
1116
|
+
const pushRatePress = device.bot?.pushRatePress
|
|
1117
|
+
? `Using Bot Push Rate Press: ${this.pushRatePress}`
|
|
1118
|
+
: `No Push Rate Press Set, Using default Push Rate Press: ${this.pushRatePress}`;
|
|
1146
1119
|
await this.debugWarnLog(pushRatePress);
|
|
1147
1120
|
this.accessory.context.pushRatePress = this.pushRatePress;
|
|
1148
1121
|
// Bot Allow Push
|
|
1149
|
-
this.allowPush =
|
|
1150
|
-
const allowPush =
|
|
1151
|
-
|
|
1152
|
-
|
|
1122
|
+
this.allowPush = device.bot?.allowPush ?? false;
|
|
1123
|
+
const allowPush = device.bot?.allowPush
|
|
1124
|
+
? `Using Allow Push: ${this.allowPush}`
|
|
1125
|
+
: `No Allow Push Set, Using default Allow Push: ${this.allowPush}`;
|
|
1153
1126
|
await this.debugWarnLog(allowPush);
|
|
1154
1127
|
this.accessory.context.allowPush = this.allowPush;
|
|
1155
1128
|
// Bot Multi Press Count
|