@switchbot/homebridge-switchbot 3.5.0-beta.3 → 3.5.0-beta.30
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 +4 -1
- package/config.schema.json +147 -9
- package/dist/device/blindtilt.d.ts +21 -94
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +347 -756
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +25 -71
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +582 -759
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -67
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +209 -587
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -74
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +250 -632
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -65
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +204 -531
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -86
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +335 -786
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +59 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +646 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +51 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +499 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +15 -59
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +242 -596
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +10 -65
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +207 -571
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +174 -584
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -68
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +252 -568
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -62
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +210 -542
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -63
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +170 -577
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +13 -64
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +159 -577
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +136 -518
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +82 -452
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -62
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +140 -451
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +9 -70
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +121 -664
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -48
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +309 -419
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +7 -38
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +72 -304
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +6 -35
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +34 -278
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +6 -39
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +67 -311
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +40 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +509 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +6 -34
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +23 -272
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +18 -47
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +352 -546
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -39
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +82 -321
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +6 -35
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -284
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -35
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +42 -287
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +237 -94
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +40 -10
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +0 -552
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +77 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +638 -1
- package/dist/utils.js.map +1 -1
- package/package.json +16 -15
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +373 -782
- package/src/device/bot.ts +616 -844
- package/src/device/ceilinglight.ts +222 -607
- package/src/device/colorbulb.ts +264 -656
- package/src/device/contact.ts +229 -553
- package/src/device/curtain.ts +355 -810
- package/src/device/device.ts +673 -0
- package/src/device/fan.ts +548 -0
- package/src/device/hub.ts +268 -623
- package/src/device/humidifier.ts +237 -618
- package/src/device/iosensor.ts +200 -610
- package/src/device/lightstrip.ts +273 -596
- package/src/device/lock.ts +247 -582
- package/src/device/meter.ts +196 -601
- package/src/device/meterplus.ts +184 -602
- package/src/device/motion.ts +156 -541
- package/src/device/plug.ts +92 -480
- package/src/device/robotvacuumcleaner.ts +161 -477
- package/src/device/waterdetector.ts +139 -689
- package/src/index.ts +1 -1
- package/src/irdevice/airconditioner.ts +330 -446
- package/src/irdevice/airpurifier.ts +89 -321
- package/src/irdevice/camera.ts +42 -293
- package/src/irdevice/fan.ts +78 -327
- package/src/irdevice/irdevice.ts +526 -0
- package/src/irdevice/light.ts +32 -287
- package/src/irdevice/other.ts +396 -615
- package/src/irdevice/tv.ts +100 -339
- package/src/irdevice/vacuumcleaner.ts +49 -305
- package/src/irdevice/waterheater.ts +50 -310
- package/src/platform.ts +247 -102
- package/src/settings.ts +56 -565
- package/src/utils.ts +642 -1
package/dist/device/bot.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* bot.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
1
5
|
import { request } from 'undici';
|
|
2
|
-
import {
|
|
6
|
+
import { deviceBase } from './device.js';
|
|
3
7
|
import { interval, Subject } from 'rxjs';
|
|
4
8
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
5
9
|
import { Devices } from '../settings.js';
|
|
@@ -8,93 +12,51 @@ import { Devices } from '../settings.js';
|
|
|
8
12
|
* An instance of this class is created for each accessory your platform registers
|
|
9
13
|
* Each accessory may expose multiple services of different service types.
|
|
10
14
|
*/
|
|
11
|
-
export class Bot {
|
|
15
|
+
export class Bot extends deviceBase {
|
|
12
16
|
platform;
|
|
13
|
-
accessory;
|
|
14
|
-
device;
|
|
15
|
-
api;
|
|
16
|
-
log;
|
|
17
|
-
config;
|
|
18
|
-
hap;
|
|
19
17
|
// Services
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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;
|
|
18
|
+
Battery;
|
|
19
|
+
Switch;
|
|
20
|
+
GarageDoor;
|
|
21
|
+
Door;
|
|
22
|
+
Window;
|
|
23
|
+
WindowCovering;
|
|
24
|
+
Lock;
|
|
25
|
+
Faucet;
|
|
26
|
+
Fan;
|
|
27
|
+
StatefulProgrammableSwitch;
|
|
28
|
+
Outlet;
|
|
46
29
|
// Config
|
|
47
30
|
botMode;
|
|
48
31
|
allowPush;
|
|
49
32
|
doublePress;
|
|
50
|
-
scanDuration;
|
|
51
33
|
botDeviceType;
|
|
52
34
|
pushRatePress;
|
|
53
|
-
deviceLogging;
|
|
54
35
|
multiPressCount;
|
|
55
|
-
deviceRefreshRate;
|
|
56
36
|
// Updates
|
|
57
37
|
botUpdateInProgress;
|
|
58
38
|
doBotUpdate;
|
|
59
|
-
// Connection
|
|
60
|
-
OpenAPI;
|
|
61
|
-
BLE;
|
|
62
39
|
constructor(platform, accessory, device) {
|
|
40
|
+
super(platform, accessory, device);
|
|
63
41
|
this.platform = platform;
|
|
64
|
-
this.accessory = accessory;
|
|
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;
|
|
70
|
-
// Connection
|
|
71
|
-
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
72
|
-
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
73
42
|
// default placeholders
|
|
74
|
-
this.
|
|
75
|
-
this.deviceType(device);
|
|
76
|
-
this.scan(device);
|
|
77
|
-
this.refreshRate(device);
|
|
78
|
-
this.PressOrSwitch(device);
|
|
79
|
-
this.allowPushChanges(device);
|
|
80
|
-
this.deviceContext();
|
|
81
|
-
this.DoublePress(device);
|
|
82
|
-
this.deviceConfig(device);
|
|
83
|
-
this.multiPressCount = 0;
|
|
43
|
+
this.getBotConfigSettings(device);
|
|
84
44
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
85
45
|
this.doBotUpdate = new Subject();
|
|
86
46
|
this.botUpdateInProgress = false;
|
|
87
|
-
//
|
|
88
|
-
this.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
.
|
|
92
|
-
|
|
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);
|
|
47
|
+
// Initialize Battery property
|
|
48
|
+
this.Battery = {
|
|
49
|
+
Service: accessory.getService(this.hap.Service.Battery),
|
|
50
|
+
BatteryLevel: accessory.context.BatteryLevel || 100,
|
|
51
|
+
StatusLowBattery: accessory.context.StatusLowBattery || this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
52
|
+
};
|
|
96
53
|
// deviceType
|
|
97
54
|
if (this.botDeviceType === 'switch') {
|
|
55
|
+
// Initialize Switch property
|
|
56
|
+
this.Switch = {
|
|
57
|
+
Service: accessory.getService(this.hap.Service.Switch),
|
|
58
|
+
On: accessory.context.On || false,
|
|
59
|
+
};
|
|
98
60
|
this.removeFanService(accessory);
|
|
99
61
|
this.removeLockService(accessory);
|
|
100
62
|
this.removeDoorService(accessory);
|
|
@@ -106,16 +68,18 @@ export class Bot {
|
|
|
106
68
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
107
69
|
// Add switchService
|
|
108
70
|
const switchService = `${accessory.displayName} Switch`;
|
|
109
|
-
(this.
|
|
71
|
+
(this.Switch.Service = accessory.getService(this.hap.Service.Switch)
|
|
110
72
|
|| accessory.addService(this.hap.Service.Switch)), switchService;
|
|
111
73
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Switch`);
|
|
112
|
-
this.
|
|
113
|
-
|
|
114
|
-
this.switchService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
115
|
-
}
|
|
116
|
-
this.switchService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
74
|
+
this.Switch.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
75
|
+
this.Switch.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
117
76
|
}
|
|
118
77
|
else if (this.botDeviceType === 'garagedoor') {
|
|
78
|
+
// Initialize Switch property
|
|
79
|
+
this.GarageDoor = {
|
|
80
|
+
Service: accessory.getService(this.hap.Service.GarageDoorOpener),
|
|
81
|
+
On: accessory.context.On || false,
|
|
82
|
+
};
|
|
119
83
|
this.removeFanService(accessory);
|
|
120
84
|
this.removeLockService(accessory);
|
|
121
85
|
this.removeDoorService(accessory);
|
|
@@ -127,17 +91,19 @@ export class Bot {
|
|
|
127
91
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
128
92
|
// Add garageDoorService
|
|
129
93
|
const garageDoorService = `${accessory.displayName} Garage Door Opener`;
|
|
130
|
-
(this.
|
|
94
|
+
(this.GarageDoor.Service = accessory.getService(this.hap.Service.GarageDoorOpener)
|
|
131
95
|
|| accessory.addService(this.hap.Service.GarageDoorOpener)), garageDoorService;
|
|
132
96
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Garage Door Opener`);
|
|
133
|
-
this.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
this.garageDoorService.getCharacteristic(this.hap.Characteristic.TargetDoorState).onSet(this.OnSet.bind(this));
|
|
138
|
-
this.garageDoorService.setCharacteristic(this.hap.Characteristic.ObstructionDetected, false);
|
|
97
|
+
this.GarageDoor.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
98
|
+
this.GarageDoor.Service.getCharacteristic(this.hap.Characteristic.TargetDoorState).onSet(this.OnSet.bind(this));
|
|
99
|
+
this.GarageDoor.Service.setCharacteristic(this.hap.Characteristic.ObstructionDetected, false);
|
|
139
100
|
}
|
|
140
101
|
else if (this.botDeviceType === 'door') {
|
|
102
|
+
// Initialize Switch property
|
|
103
|
+
this.Door = {
|
|
104
|
+
Service: accessory.getService(this.hap.Service.Door),
|
|
105
|
+
On: accessory.context.On || false,
|
|
106
|
+
};
|
|
141
107
|
this.removeFanService(accessory);
|
|
142
108
|
this.removeLockService(accessory);
|
|
143
109
|
this.removeOutletService(accessory);
|
|
@@ -149,14 +115,11 @@ export class Bot {
|
|
|
149
115
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
150
116
|
// Add doorService
|
|
151
117
|
const doorService = `${accessory.displayName} Door`;
|
|
152
|
-
(this.
|
|
118
|
+
(this.Door.Service = accessory.getService(this.hap.Service.Door)
|
|
153
119
|
|| accessory.addService(this.hap.Service.Door)), doorService;
|
|
154
120
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Door`);
|
|
155
|
-
this.
|
|
156
|
-
|
|
157
|
-
this.doorService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
158
|
-
}
|
|
159
|
-
this.doorService
|
|
121
|
+
this.Door.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
122
|
+
this.Door.Service
|
|
160
123
|
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
161
124
|
.setProps({
|
|
162
125
|
validValues: [0, 100],
|
|
@@ -165,9 +128,14 @@ export class Bot {
|
|
|
165
128
|
minStep: 100,
|
|
166
129
|
})
|
|
167
130
|
.onSet(this.OnSet.bind(this));
|
|
168
|
-
this.
|
|
131
|
+
this.Door.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
169
132
|
}
|
|
170
133
|
else if (this.botDeviceType === 'window') {
|
|
134
|
+
// Initialize Switch property
|
|
135
|
+
this.Window = {
|
|
136
|
+
Service: accessory.getService(this.hap.Service.Window),
|
|
137
|
+
On: accessory.context.On || false,
|
|
138
|
+
};
|
|
171
139
|
this.removeFanService(accessory);
|
|
172
140
|
this.removeLockService(accessory);
|
|
173
141
|
this.removeDoorService(accessory);
|
|
@@ -179,14 +147,11 @@ export class Bot {
|
|
|
179
147
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
180
148
|
// Add windowService
|
|
181
149
|
const windowService = `${accessory.displayName} Window`;
|
|
182
|
-
(this.
|
|
150
|
+
(this.Window.Service = accessory.getService(this.hap.Service.Window)
|
|
183
151
|
|| accessory.addService(this.hap.Service.Window)), windowService;
|
|
184
152
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window`);
|
|
185
|
-
this.
|
|
186
|
-
|
|
187
|
-
this.windowService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
188
|
-
}
|
|
189
|
-
this.windowService
|
|
153
|
+
this.Window.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
154
|
+
this.Window.Service
|
|
190
155
|
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
191
156
|
.setProps({
|
|
192
157
|
validValues: [0, 100],
|
|
@@ -195,9 +160,14 @@ export class Bot {
|
|
|
195
160
|
minStep: 100,
|
|
196
161
|
})
|
|
197
162
|
.onSet(this.OnSet.bind(this));
|
|
198
|
-
this.
|
|
163
|
+
this.Window.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
199
164
|
}
|
|
200
165
|
else if (this.botDeviceType === 'windowcovering') {
|
|
166
|
+
// Initialize Switch property
|
|
167
|
+
this.WindowCovering = {
|
|
168
|
+
Service: accessory.getService(this.hap.Service.WindowCovering),
|
|
169
|
+
On: accessory.context.On || false,
|
|
170
|
+
};
|
|
201
171
|
this.removeFanService(accessory);
|
|
202
172
|
this.removeLockService(accessory);
|
|
203
173
|
this.removeDoorService(accessory);
|
|
@@ -209,14 +179,11 @@ export class Bot {
|
|
|
209
179
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
210
180
|
// Add windowCoveringService
|
|
211
181
|
const windowCoveringService = `${accessory.displayName} Window Covering`;
|
|
212
|
-
(this.
|
|
182
|
+
(this.WindowCovering.Service = accessory.getService(this.hap.Service.WindowCovering)
|
|
213
183
|
|| accessory.addService(this.hap.Service.WindowCovering)), windowCoveringService;
|
|
214
184
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window Covering`);
|
|
215
|
-
this.
|
|
216
|
-
|
|
217
|
-
this.windowCoveringService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
218
|
-
}
|
|
219
|
-
this.windowCoveringService
|
|
185
|
+
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
186
|
+
this.WindowCovering.Service
|
|
220
187
|
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
221
188
|
.setProps({
|
|
222
189
|
validValues: [0, 100],
|
|
@@ -225,9 +192,14 @@ export class Bot {
|
|
|
225
192
|
minStep: 100,
|
|
226
193
|
})
|
|
227
194
|
.onSet(this.OnSet.bind(this));
|
|
228
|
-
this.
|
|
195
|
+
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
229
196
|
}
|
|
230
197
|
else if (this.botDeviceType === 'lock') {
|
|
198
|
+
// Initialize Switch property
|
|
199
|
+
this.Lock = {
|
|
200
|
+
Service: accessory.getService(this.hap.Service.LockMechanism),
|
|
201
|
+
On: accessory.context.On || false,
|
|
202
|
+
};
|
|
231
203
|
this.removeFanService(accessory);
|
|
232
204
|
this.removeDoorService(accessory);
|
|
233
205
|
this.removeOutletService(accessory);
|
|
@@ -239,16 +211,18 @@ export class Bot {
|
|
|
239
211
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
240
212
|
// Add lockService
|
|
241
213
|
const lockService = `${accessory.displayName} Lock`;
|
|
242
|
-
(this.
|
|
214
|
+
(this.Lock.Service = accessory.getService(this.hap.Service.LockMechanism)
|
|
243
215
|
|| accessory.addService(this.hap.Service.LockMechanism)), lockService;
|
|
244
216
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Lock`);
|
|
245
|
-
this.
|
|
246
|
-
|
|
247
|
-
this.lockService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
248
|
-
}
|
|
249
|
-
this.lockService.getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.OnSet.bind(this));
|
|
217
|
+
this.Lock.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
218
|
+
this.Lock.Service.getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.OnSet.bind(this));
|
|
250
219
|
}
|
|
251
220
|
else if (this.botDeviceType === 'faucet') {
|
|
221
|
+
// Initialize Switch property
|
|
222
|
+
this.Faucet = {
|
|
223
|
+
Service: accessory.getService(this.hap.Service.Faucet),
|
|
224
|
+
On: accessory.context.On || false,
|
|
225
|
+
};
|
|
252
226
|
this.removeFanService(accessory);
|
|
253
227
|
this.removeLockService(accessory);
|
|
254
228
|
this.removeDoorService(accessory);
|
|
@@ -260,16 +234,18 @@ export class Bot {
|
|
|
260
234
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
261
235
|
// Add faucetService
|
|
262
236
|
const faucetService = `${accessory.displayName} Faucet`;
|
|
263
|
-
(this.
|
|
237
|
+
(this.Faucet.Service = accessory.getService(this.hap.Service.Faucet)
|
|
264
238
|
|| accessory.addService(this.hap.Service.Faucet)), faucetService;
|
|
265
239
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Faucet`);
|
|
266
|
-
this.
|
|
267
|
-
|
|
268
|
-
this.faucetService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
269
|
-
}
|
|
270
|
-
this.faucetService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this));
|
|
240
|
+
this.Faucet.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
241
|
+
this.Faucet.Service.getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this));
|
|
271
242
|
}
|
|
272
243
|
else if (this.botDeviceType === 'fan') {
|
|
244
|
+
// Initialize Switch property
|
|
245
|
+
this.Fan = {
|
|
246
|
+
Service: accessory.getService(this.hap.Service.Fanv2),
|
|
247
|
+
On: accessory.context.On || false,
|
|
248
|
+
};
|
|
273
249
|
this.removeLockService(accessory);
|
|
274
250
|
this.removeDoorService(accessory);
|
|
275
251
|
this.removeFaucetService(accessory);
|
|
@@ -281,16 +257,18 @@ export class Bot {
|
|
|
281
257
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
282
258
|
// Add fanService
|
|
283
259
|
const fanService = `${accessory.displayName} Fan`;
|
|
284
|
-
(this.
|
|
285
|
-
|| accessory.addService(this.hap.Service.
|
|
260
|
+
(this.Fan.Service = accessory.getService(this.hap.Service.Fanv2)
|
|
261
|
+
|| accessory.addService(this.hap.Service.Fanv2)), fanService;
|
|
286
262
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Fan`);
|
|
287
|
-
this.
|
|
288
|
-
|
|
289
|
-
this.fanService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
290
|
-
}
|
|
291
|
-
this.fanService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
263
|
+
this.Fan.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
264
|
+
this.Fan.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
292
265
|
}
|
|
293
266
|
else if (this.botDeviceType === 'stateful') {
|
|
267
|
+
// Initialize Switch property
|
|
268
|
+
this.StatefulProgrammableSwitch = {
|
|
269
|
+
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch),
|
|
270
|
+
On: accessory.context.On || false,
|
|
271
|
+
};
|
|
294
272
|
this.removeFanService(accessory);
|
|
295
273
|
this.removeLockService(accessory);
|
|
296
274
|
this.removeDoorService(accessory);
|
|
@@ -302,18 +280,20 @@ export class Bot {
|
|
|
302
280
|
this.removeWindowCoveringService(accessory);
|
|
303
281
|
// Add statefulProgrammableSwitchService
|
|
304
282
|
const statefulProgrammableSwitchService = `${accessory.displayName} Stateful Programmable Switch`;
|
|
305
|
-
(this.
|
|
283
|
+
(this.StatefulProgrammableSwitch.Service = accessory.getService(this.hap.Service.StatefulProgrammableSwitch) ||
|
|
306
284
|
accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), statefulProgrammableSwitchService;
|
|
307
285
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
|
|
308
|
-
this.
|
|
309
|
-
|
|
310
|
-
this.statefulProgrammableSwitchService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
311
|
-
}
|
|
312
|
-
this.statefulProgrammableSwitchService
|
|
286
|
+
this.StatefulProgrammableSwitch.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
287
|
+
this.StatefulProgrammableSwitch.Service
|
|
313
288
|
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
314
289
|
.onSet(this.OnSet.bind(this));
|
|
315
290
|
}
|
|
316
291
|
else {
|
|
292
|
+
// Initialize Switch property
|
|
293
|
+
this.Outlet = {
|
|
294
|
+
Service: accessory.getService(this.hap.Service.Outlet),
|
|
295
|
+
On: accessory.context.On || false,
|
|
296
|
+
};
|
|
317
297
|
this.removeFanService(accessory);
|
|
318
298
|
this.removeLockService(accessory);
|
|
319
299
|
this.removeDoorService(accessory);
|
|
@@ -325,24 +305,20 @@ export class Bot {
|
|
|
325
305
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
326
306
|
// Add outletService
|
|
327
307
|
const outletService = `${accessory.displayName} Outlet`;
|
|
328
|
-
(this.
|
|
308
|
+
(this.Outlet.Service = accessory.getService(this.hap.Service.Outlet)
|
|
329
309
|
|| accessory.addService(this.hap.Service.Outlet)), outletService;
|
|
330
310
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Outlet`);
|
|
331
|
-
this.
|
|
332
|
-
|
|
333
|
-
this.outletService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
334
|
-
}
|
|
335
|
-
this.outletService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
311
|
+
this.Outlet.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
312
|
+
this.Outlet.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
336
313
|
}
|
|
314
|
+
// Retrieve initial values and updateHomekit
|
|
315
|
+
this.refreshStatus();
|
|
337
316
|
// batteryService
|
|
338
317
|
const batteryService = `${accessory.displayName} Battery`;
|
|
339
|
-
(this.
|
|
318
|
+
(this.Battery.Service = this.accessory.getService(this.hap.Service.Battery)
|
|
340
319
|
|| accessory.addService(this.hap.Service.Battery)), batteryService;
|
|
341
|
-
this.
|
|
342
|
-
|
|
343
|
-
this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
344
|
-
}
|
|
345
|
-
this.batteryService.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
320
|
+
this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
321
|
+
this.Battery.Service.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
346
322
|
// Retrieve initial values and updateHomekit
|
|
347
323
|
this.updateHomeKitCharacteristics();
|
|
348
324
|
// Start an update interval
|
|
@@ -352,19 +328,21 @@ export class Bot {
|
|
|
352
328
|
await this.refreshStatus();
|
|
353
329
|
});
|
|
354
330
|
//regisiter webhook event handler
|
|
355
|
-
if (
|
|
356
|
-
this.
|
|
331
|
+
if (device.webhook) {
|
|
332
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
357
333
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
358
334
|
try {
|
|
359
335
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
360
336
|
const { power, battery, deviceMode } = context;
|
|
361
|
-
const {
|
|
337
|
+
const { botMode } = this;
|
|
338
|
+
const On = await this.getOn();
|
|
339
|
+
const { BatteryLevel } = this.Battery;
|
|
362
340
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
363
341
|
'(power, battery, deviceMode) = ' +
|
|
364
342
|
`Webhook:(${power}, ${battery}, ${deviceMode}), ` +
|
|
365
343
|
`current:(${On}, ${BatteryLevel}, ${botMode})`);
|
|
366
|
-
this.
|
|
367
|
-
this.BatteryLevel = battery;
|
|
344
|
+
await this.setOn(power);
|
|
345
|
+
this.Battery.BatteryLevel = battery;
|
|
368
346
|
this.botMode = deviceMode;
|
|
369
347
|
this.updateHomeKitCharacteristics();
|
|
370
348
|
}
|
|
@@ -402,80 +380,74 @@ export class Bot {
|
|
|
402
380
|
});
|
|
403
381
|
}
|
|
404
382
|
/**
|
|
405
|
-
* Parse the device status from the
|
|
383
|
+
* Parse the device status from the SwitchBotBLE API
|
|
406
384
|
*/
|
|
407
|
-
async
|
|
408
|
-
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
409
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
410
|
-
}
|
|
411
|
-
else if (this.BLE) {
|
|
412
|
-
await this.BLEparseStatus();
|
|
413
|
-
}
|
|
414
|
-
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
415
|
-
await this.openAPIparseStatus();
|
|
416
|
-
}
|
|
417
|
-
else {
|
|
418
|
-
await this.offlineOff();
|
|
419
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
async BLEparseStatus() {
|
|
385
|
+
async BLEparseStatus(serviceData) {
|
|
423
386
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
424
387
|
// BLEmode (true if Switch Mode) | (false if Press Mode)
|
|
425
|
-
if (
|
|
426
|
-
this.accessory.context.On = this.
|
|
427
|
-
if (this.
|
|
428
|
-
this.
|
|
388
|
+
if (serviceData.mode) {
|
|
389
|
+
this.accessory.context.On = await this.getOn();
|
|
390
|
+
if (this.getOn() === undefined) {
|
|
391
|
+
this.setOn(Boolean(serviceData.state));
|
|
429
392
|
}
|
|
430
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode
|
|
393
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode,`
|
|
394
|
+
+ ` mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
|
|
431
395
|
}
|
|
432
396
|
else {
|
|
433
|
-
this.
|
|
434
|
-
this.accessory.context.On = this.
|
|
435
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode
|
|
397
|
+
this.setOn(false);
|
|
398
|
+
this.accessory.context.On = await this.getOn();
|
|
399
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode,`
|
|
400
|
+
+ ` mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
|
|
436
401
|
}
|
|
437
|
-
this.BatteryLevel = Number(
|
|
438
|
-
if (this.BatteryLevel < 10) {
|
|
439
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
402
|
+
this.Battery.BatteryLevel = Number(serviceData.battery);
|
|
403
|
+
if (this.Battery.BatteryLevel < 10) {
|
|
404
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
440
405
|
}
|
|
441
406
|
else {
|
|
442
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
407
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
443
408
|
}
|
|
444
|
-
if (Number.isNaN(this.BatteryLevel)) {
|
|
445
|
-
this.BatteryLevel = 100;
|
|
409
|
+
if (Number.isNaN(this.Battery.BatteryLevel)) {
|
|
410
|
+
this.Battery.BatteryLevel = 100;
|
|
446
411
|
}
|
|
447
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
|
|
448
|
-
+ ` StatusLowBattery: ${this.StatusLowBattery}`);
|
|
412
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
413
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
449
414
|
}
|
|
450
|
-
|
|
415
|
+
/**
|
|
416
|
+
* Parse the device status from the SwitchBot OpenAPI
|
|
417
|
+
*/
|
|
418
|
+
async openAPIparseStatus(deviceStatus) {
|
|
451
419
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
452
420
|
if (this.botMode === 'press') {
|
|
453
|
-
this.
|
|
454
|
-
this.accessory.context.On = this.
|
|
421
|
+
this.setOn(false);
|
|
422
|
+
this.accessory.context.On = await this.getOn();
|
|
455
423
|
}
|
|
456
424
|
else {
|
|
457
|
-
this.accessory.context.On = this.
|
|
458
|
-
if (this.
|
|
459
|
-
this.
|
|
425
|
+
this.accessory.context.On = await this.getOn();
|
|
426
|
+
if (this.getOn() === undefined) {
|
|
427
|
+
this.setOn(false);
|
|
460
428
|
}
|
|
461
429
|
}
|
|
462
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
430
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.accessory.context.On}`);
|
|
463
431
|
// Battery
|
|
464
|
-
this.BatteryLevel = Number(
|
|
465
|
-
if (this.BatteryLevel < 10) {
|
|
466
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
432
|
+
this.Battery.BatteryLevel = Number(deviceStatus.body.battery);
|
|
433
|
+
if (this.Battery.BatteryLevel < 10) {
|
|
434
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
467
435
|
}
|
|
468
436
|
else {
|
|
469
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
437
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
470
438
|
}
|
|
471
|
-
if (Number.isNaN(this.BatteryLevel)) {
|
|
472
|
-
this.BatteryLevel = 100;
|
|
439
|
+
if (Number.isNaN(this.Battery.BatteryLevel)) {
|
|
440
|
+
this.Battery.BatteryLevel = 100;
|
|
473
441
|
}
|
|
474
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
|
|
475
|
-
+ ` StatusLowBattery: ${this.StatusLowBattery}`);
|
|
442
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
443
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
476
444
|
// FirmwareRevision
|
|
477
|
-
this.FirmwareRevision =
|
|
478
|
-
this.accessory
|
|
445
|
+
this.accessory.context.FirmwareRevision = deviceStatus.body.version;
|
|
446
|
+
this.accessory
|
|
447
|
+
.getService(this.hap.Service.AccessoryInformation)
|
|
448
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.accessory.context.FirmwareRevision)
|
|
449
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
450
|
+
.updateValue(this.accessory.context.FirmwareRevision);
|
|
479
451
|
}
|
|
480
452
|
/**
|
|
481
453
|
* Asks the SwitchBot API for the latest device information
|
|
@@ -509,99 +481,42 @@ export class Bot {
|
|
|
509
481
|
// Start to monitor advertisement packets
|
|
510
482
|
(async () => {
|
|
511
483
|
// Start to monitor advertisement packets
|
|
512
|
-
await switchbot.startScan({
|
|
513
|
-
model: 'H',
|
|
514
|
-
id: this.device.bleMac,
|
|
515
|
-
});
|
|
484
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
516
485
|
// Set an event handler
|
|
517
486
|
switchbot.onadvertisement = (ad) => {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
487
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
488
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
489
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
521
490
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
522
|
-
this.BLE_Mode = ad.serviceData.mode;
|
|
523
|
-
this.BLE_On = ad.serviceData.state;
|
|
524
|
-
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
525
491
|
}
|
|
526
492
|
else {
|
|
527
493
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
528
494
|
}
|
|
529
495
|
};
|
|
530
|
-
// Wait
|
|
496
|
+
// Wait 10 seconds
|
|
531
497
|
await switchbot.wait(this.scanDuration * 1000);
|
|
532
498
|
// Stop to monitor
|
|
533
499
|
await switchbot.stopScan();
|
|
534
500
|
// Update HomeKit
|
|
535
|
-
await this.BLEparseStatus();
|
|
501
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
536
502
|
await this.updateHomeKitCharacteristics();
|
|
537
503
|
})();
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
model: 'H',
|
|
542
|
-
id: this.device.bleMac,
|
|
543
|
-
})
|
|
544
|
-
.then(async () => {
|
|
545
|
-
// Set an event handler
|
|
546
|
-
switchbot.onadvertisement = async (ad: ad) => {
|
|
547
|
-
this.debugLog(
|
|
548
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
549
|
-
` BLE Address Found: ${ad.address}`,
|
|
550
|
-
);
|
|
551
|
-
this.BLE_Mode = ad.serviceData.mode;
|
|
552
|
-
this.BLE_On = ad.serviceData.state;
|
|
553
|
-
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
554
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
555
|
-
this.debugLog(
|
|
556
|
-
`${this.device.deviceType}: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ` +
|
|
557
|
-
`${ad.serviceData.modelName}, mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`,
|
|
558
|
-
);
|
|
559
|
-
|
|
560
|
-
if (ad.serviceData) {
|
|
561
|
-
this.BLE_IsConnected = true;
|
|
562
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
563
|
-
await this.stopScanning(switchbot);
|
|
564
|
-
} else {
|
|
565
|
-
this.BLE_IsConnected = false;
|
|
566
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
567
|
-
}
|
|
568
|
-
};
|
|
569
|
-
// Wait
|
|
570
|
-
return await sleep(this.scanDuration * 1000);
|
|
571
|
-
})
|
|
572
|
-
.then(async () => {
|
|
573
|
-
// Stop to monitor
|
|
574
|
-
await this.stopScanning(switchbot);
|
|
575
|
-
})
|
|
576
|
-
.catch(async (e: any) => {
|
|
577
|
-
this.apiError(e);
|
|
578
|
-
this.errorLog(
|
|
579
|
-
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
580
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
581
|
-
);
|
|
582
|
-
await this.BLERefreshConnection(switchbot);
|
|
583
|
-
});
|
|
584
|
-
} else {
|
|
585
|
-
await this.BLERefreshConnection(switchbot);
|
|
586
|
-
}*/
|
|
504
|
+
if (switchbot === undefined) {
|
|
505
|
+
await this.BLERefreshConnection(switchbot);
|
|
506
|
+
}
|
|
587
507
|
}
|
|
588
508
|
async openAPIRefreshStatus() {
|
|
589
509
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
590
510
|
try {
|
|
591
|
-
const { body, statusCode } = await
|
|
592
|
-
headers: this.platform.generateHeaders(),
|
|
593
|
-
});
|
|
511
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries, `${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
594
512
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
595
513
|
const deviceStatus = await body.json();
|
|
596
514
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
597
515
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
598
516
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
599
|
-
this.
|
|
517
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
600
518
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
601
|
-
this.
|
|
602
|
-
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
603
|
-
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
604
|
-
this.openAPIparseStatus();
|
|
519
|
+
this.openAPIparseStatus(deviceStatus);
|
|
605
520
|
this.updateHomeKitCharacteristics();
|
|
606
521
|
}
|
|
607
522
|
else {
|
|
@@ -646,8 +561,9 @@ export class Bot {
|
|
|
646
561
|
}
|
|
647
562
|
async BLEpushChanges() {
|
|
648
563
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
|
|
649
|
-
|
|
650
|
-
|
|
564
|
+
const On = await this.getOn();
|
|
565
|
+
if (On !== this.accessory.context.On || this.allowPush) {
|
|
566
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges On: ${On} OnCached: ${this.accessory.context.On}`);
|
|
651
567
|
const switchbot = await this.platform.connectBLE();
|
|
652
568
|
// Convert to BLE Address
|
|
653
569
|
this.device.bleMac = this.device
|
|
@@ -661,20 +577,22 @@ export class Bot {
|
|
|
661
577
|
switchbot
|
|
662
578
|
.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
663
579
|
.then(async (device_list) => {
|
|
664
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${
|
|
580
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${On}`);
|
|
665
581
|
return await device_list[0].press({ id: this.device.bleMac });
|
|
666
582
|
})
|
|
667
583
|
.then(() => {
|
|
668
584
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
669
|
-
this.
|
|
585
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
586
|
+
+ `On: ${On} sent over BLE, sent successfully`);
|
|
587
|
+
this.accessory.context.On = On;
|
|
670
588
|
setTimeout(() => {
|
|
671
589
|
if (this.botDeviceType === 'switch') {
|
|
672
|
-
this.
|
|
590
|
+
this.Switch.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
|
|
673
591
|
}
|
|
674
592
|
else {
|
|
675
|
-
this.
|
|
593
|
+
this.Outlet.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
|
|
676
594
|
}
|
|
677
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${
|
|
595
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${On}, Switch Timeout`);
|
|
678
596
|
}, 500);
|
|
679
597
|
})
|
|
680
598
|
.catch(async (e) => {
|
|
@@ -689,11 +607,11 @@ export class Bot {
|
|
|
689
607
|
switchbot
|
|
690
608
|
.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
691
609
|
.then(async (device_list) => {
|
|
692
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${
|
|
693
|
-
return await this.
|
|
694
|
-
max: this.
|
|
610
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${On}`);
|
|
611
|
+
return await this.retryBLE({
|
|
612
|
+
max: await this.maxRetryBLE(),
|
|
695
613
|
fn: async () => {
|
|
696
|
-
if (
|
|
614
|
+
if (On) {
|
|
697
615
|
return await device_list[0].turnOn({ id: this.device.bleMac });
|
|
698
616
|
}
|
|
699
617
|
else {
|
|
@@ -704,12 +622,12 @@ export class Bot {
|
|
|
704
622
|
})
|
|
705
623
|
.then(() => {
|
|
706
624
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
707
|
-
this.accessory.context.On =
|
|
625
|
+
this.accessory.context.On = On;
|
|
708
626
|
})
|
|
709
627
|
.catch(async (e) => {
|
|
710
628
|
this.apiError(e);
|
|
711
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
712
|
-
` Connection & botMode: ${this.botMode}, Error Message: ${JSON.stringify(e.message)}`);
|
|
629
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
630
|
+
+ ` Connection & botMode: ${this.botMode}, Error Message: ${JSON.stringify(e.message)}`);
|
|
713
631
|
await this.BLEPushConnection();
|
|
714
632
|
});
|
|
715
633
|
}
|
|
@@ -718,31 +636,32 @@ export class Bot {
|
|
|
718
636
|
}
|
|
719
637
|
}
|
|
720
638
|
else {
|
|
721
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges
|
|
639
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges, On: ${On}, OnCached: ${this.accessory.context.On}`);
|
|
722
640
|
}
|
|
723
641
|
}
|
|
724
642
|
async openAPIpushChanges() {
|
|
725
643
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
644
|
+
let On = await this.getOn();
|
|
726
645
|
if (this.multiPressCount > 0) {
|
|
727
646
|
this.debugLog(`${this.device.deviceType}: ${this.multiPressCount} request(s) queued.`);
|
|
728
|
-
|
|
647
|
+
On = true;
|
|
729
648
|
}
|
|
730
|
-
if (
|
|
649
|
+
if (On !== this.accessory.context.On || this.allowPush || this.multiPressCount > 0) {
|
|
731
650
|
let command = '';
|
|
732
|
-
if (this.botMode === 'switch' &&
|
|
651
|
+
if (this.botMode === 'switch' && On) {
|
|
733
652
|
command = 'turnOn';
|
|
734
|
-
|
|
735
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, Turning ${
|
|
653
|
+
On = true;
|
|
654
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, Turning ${On}`);
|
|
736
655
|
}
|
|
737
|
-
else if (this.botMode === 'switch' && !
|
|
656
|
+
else if (this.botMode === 'switch' && !On) {
|
|
738
657
|
command = 'turnOff';
|
|
739
|
-
|
|
740
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, Turning ${
|
|
658
|
+
On = false;
|
|
659
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, Turning ${On}`);
|
|
741
660
|
}
|
|
742
661
|
else if (this.botMode === 'press' || this.botMode === 'multipress') {
|
|
743
662
|
command = 'press';
|
|
744
663
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode`);
|
|
745
|
-
|
|
664
|
+
On = false;
|
|
746
665
|
}
|
|
747
666
|
else {
|
|
748
667
|
throw new Error(`${this.device.deviceType}: ${this.accessory.displayName} Device Parameters not set for this Bot.`);
|
|
@@ -765,8 +684,10 @@ export class Bot {
|
|
|
765
684
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
766
685
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
767
686
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
768
|
-
this.
|
|
687
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
769
688
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
689
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
690
|
+
+ `request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
|
|
770
691
|
}
|
|
771
692
|
else {
|
|
772
693
|
this.statusCode(statusCode);
|
|
@@ -776,21 +697,20 @@ export class Bot {
|
|
|
776
697
|
this.multiPressCount--;
|
|
777
698
|
if (this.multiPressCount > 0) {
|
|
778
699
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Multi Press Count: ${this.multiPressCount}`);
|
|
779
|
-
|
|
700
|
+
On = true;
|
|
780
701
|
this.openAPIpushChanges();
|
|
781
702
|
}
|
|
782
703
|
}
|
|
783
704
|
}
|
|
784
705
|
catch (e) {
|
|
785
706
|
this.apiError(e);
|
|
786
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
787
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
707
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
708
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
788
709
|
}
|
|
789
710
|
}
|
|
790
711
|
else {
|
|
791
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges
|
|
792
|
-
`On: ${this.On}
|
|
793
|
-
`OnCached: ${this.accessory.context.On}`);
|
|
712
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges,`
|
|
713
|
+
+ ` On: ${On}, OnCached: ${this.accessory.context.On}`);
|
|
794
714
|
}
|
|
795
715
|
}
|
|
796
716
|
/**
|
|
@@ -800,59 +720,101 @@ export class Bot {
|
|
|
800
720
|
if (this.botDeviceType === 'garagedoor') {
|
|
801
721
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetDoorState: ${value}`);
|
|
802
722
|
if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
|
|
803
|
-
this.
|
|
723
|
+
await this.setOn(false);
|
|
724
|
+
this.GarageDoor.On = false;
|
|
725
|
+
}
|
|
726
|
+
else {
|
|
727
|
+
await this.setOn(true);
|
|
728
|
+
this.GarageDoor.On = true;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
else if (this.botDeviceType === 'door') {
|
|
732
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
|
|
733
|
+
if (value === 0) {
|
|
734
|
+
await this.setOn(false);
|
|
735
|
+
this.Door.On = false;
|
|
736
|
+
}
|
|
737
|
+
else {
|
|
738
|
+
await this.setOn(true);
|
|
739
|
+
this.Door.On = true;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
else if (this.botDeviceType === 'window') {
|
|
743
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
|
|
744
|
+
if (value === 0) {
|
|
745
|
+
await this.setOn(false);
|
|
746
|
+
this.Window.On = false;
|
|
804
747
|
}
|
|
805
748
|
else {
|
|
806
|
-
this.
|
|
749
|
+
await this.setOn(true);
|
|
750
|
+
this.Window.On = true;
|
|
807
751
|
}
|
|
808
752
|
}
|
|
809
|
-
else if (this.botDeviceType === '
|
|
810
|
-
this.botDeviceType === 'window' ||
|
|
811
|
-
this.botDeviceType === 'windowcovering') {
|
|
753
|
+
else if (this.botDeviceType === 'windowcovering') {
|
|
812
754
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
|
|
813
755
|
if (value === 0) {
|
|
814
|
-
this.
|
|
756
|
+
await this.setOn(false);
|
|
757
|
+
this.WindowCovering.On = false;
|
|
815
758
|
}
|
|
816
759
|
else {
|
|
817
|
-
this.
|
|
760
|
+
await this.setOn(true);
|
|
761
|
+
this.WindowCovering.On = true;
|
|
818
762
|
}
|
|
819
763
|
}
|
|
820
764
|
else if (this.botDeviceType === 'lock') {
|
|
821
765
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set LockTargetState: ${value}`);
|
|
822
766
|
if (value === this.hap.Characteristic.LockTargetState.SECURED) {
|
|
823
|
-
this.
|
|
767
|
+
await this.setOn(false);
|
|
768
|
+
this.Lock.On = false;
|
|
824
769
|
}
|
|
825
770
|
else {
|
|
826
|
-
this.
|
|
771
|
+
await this.setOn(true);
|
|
772
|
+
this.Lock.On = true;
|
|
827
773
|
}
|
|
828
774
|
}
|
|
829
775
|
else if (this.botDeviceType === 'faucet') {
|
|
830
776
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
831
777
|
if (value === this.hap.Characteristic.Active.INACTIVE) {
|
|
832
|
-
this.
|
|
778
|
+
await this.setOn(false);
|
|
779
|
+
this.Faucet.On = false;
|
|
833
780
|
}
|
|
834
781
|
else {
|
|
835
|
-
this.
|
|
782
|
+
await this.setOn(true);
|
|
783
|
+
this.Faucet.On = true;
|
|
836
784
|
}
|
|
837
785
|
}
|
|
838
786
|
else if (this.botDeviceType === 'stateful') {
|
|
839
787
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ProgrammableSwitchOutputState: ${value}`);
|
|
840
788
|
if (value === 0) {
|
|
841
|
-
this.
|
|
789
|
+
await this.setOn(false);
|
|
790
|
+
this.StatefulProgrammableSwitch.On = false;
|
|
791
|
+
}
|
|
792
|
+
else {
|
|
793
|
+
await this.setOn(true);
|
|
794
|
+
this.StatefulProgrammableSwitch.On = true;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
else if (this.botDeviceType === 'switch') {
|
|
798
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ProgrammableSwitchOutputState: ${value}`);
|
|
799
|
+
if (value === 0) {
|
|
800
|
+
await this.setOn(false);
|
|
801
|
+
this.Switch.On = false;
|
|
842
802
|
}
|
|
843
803
|
else {
|
|
844
|
-
this.
|
|
804
|
+
await this.setOn(true);
|
|
805
|
+
this.Switch.On = true;
|
|
845
806
|
}
|
|
846
807
|
}
|
|
847
808
|
else {
|
|
848
809
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set On: ${value}`);
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
810
|
+
await this.setOn(Boolean(value));
|
|
811
|
+
this.Outlet.On = value;
|
|
812
|
+
}
|
|
813
|
+
if (this.device.bot?.mode === 'multipress') {
|
|
814
|
+
if (value === true) {
|
|
815
|
+
this.multiPressCount++;
|
|
816
|
+
this.debugLog(`${this.device.deviceType} set to Multi-Press. Multi-Press count: ${this.multiPressCount}`);
|
|
854
817
|
}
|
|
855
|
-
this.On = value;
|
|
856
818
|
}
|
|
857
819
|
this.doBotUpdate.next();
|
|
858
820
|
}
|
|
@@ -862,508 +824,360 @@ export class Bot {
|
|
|
862
824
|
async updateHomeKitCharacteristics() {
|
|
863
825
|
// State
|
|
864
826
|
if (this.botDeviceType === 'garagedoor') {
|
|
865
|
-
if (this.On === undefined) {
|
|
866
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
827
|
+
if (this.GarageDoor.On === undefined) {
|
|
828
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.GarageDoor.On}`);
|
|
867
829
|
}
|
|
868
830
|
else {
|
|
869
|
-
if (this.On) {
|
|
870
|
-
this.
|
|
871
|
-
this.
|
|
872
|
-
this.debugLog(`${this.device.deviceType}:
|
|
831
|
+
if (this.GarageDoor.On) {
|
|
832
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
|
|
833
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
|
|
834
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
835
|
+
+ ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
|
|
873
836
|
}
|
|
874
837
|
else {
|
|
875
|
-
this.
|
|
876
|
-
this.
|
|
877
|
-
this.debugLog(`${this.device.deviceType}:
|
|
838
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
|
|
839
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
|
|
840
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
|
|
841
|
+
+ ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
|
|
878
842
|
}
|
|
879
843
|
}
|
|
880
|
-
this.
|
|
844
|
+
await this.setOn(Boolean(this.GarageDoor.On));
|
|
845
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Garage Door On: ${this.GarageDoor.On}`);
|
|
881
846
|
}
|
|
882
847
|
else if (this.botDeviceType === 'door') {
|
|
883
|
-
if (this.On === undefined) {
|
|
884
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
848
|
+
if (this.Door.On === undefined) {
|
|
849
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Door.On}`);
|
|
885
850
|
}
|
|
886
851
|
else {
|
|
887
|
-
if (this.On) {
|
|
888
|
-
this.
|
|
889
|
-
this.
|
|
890
|
-
this.
|
|
891
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
852
|
+
if (this.Door.On) {
|
|
853
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
854
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
855
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
856
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
|
|
857
|
+
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.Door.On})`);
|
|
892
858
|
}
|
|
893
859
|
else {
|
|
894
|
-
this.
|
|
895
|
-
this.
|
|
896
|
-
this.
|
|
897
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
860
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
861
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
862
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
863
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
|
|
864
|
+
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.Door.On})`);
|
|
898
865
|
}
|
|
899
866
|
}
|
|
900
|
-
this.
|
|
867
|
+
await this.setOn(Boolean(this.Door.On));
|
|
868
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Door On: ${this.Door.On}`);
|
|
901
869
|
}
|
|
902
870
|
else if (this.botDeviceType === 'window') {
|
|
903
|
-
if (this.On === undefined) {
|
|
904
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
871
|
+
if (this.Window.On === undefined) {
|
|
872
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Window.On}`);
|
|
905
873
|
}
|
|
906
874
|
else {
|
|
907
|
-
if (this.On) {
|
|
908
|
-
this.
|
|
909
|
-
this.
|
|
910
|
-
this.
|
|
911
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
875
|
+
if (this.Window.On) {
|
|
876
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
877
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
878
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
879
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
|
|
880
|
+
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.Window.On})`);
|
|
912
881
|
}
|
|
913
882
|
else {
|
|
914
|
-
this.
|
|
915
|
-
this.
|
|
916
|
-
this.
|
|
917
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
883
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
884
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
885
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
886
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
|
|
887
|
+
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.Window.On})`);
|
|
918
888
|
}
|
|
919
889
|
}
|
|
920
|
-
this.
|
|
890
|
+
await this.setOn(Boolean(this.Window.On));
|
|
891
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Window On: ${this.Window.On}`);
|
|
921
892
|
}
|
|
922
893
|
else if (this.botDeviceType === 'windowcovering') {
|
|
923
|
-
if (this.On === undefined) {
|
|
924
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
894
|
+
if (this.WindowCovering.On === undefined) {
|
|
895
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.WindowCovering.On}`);
|
|
925
896
|
}
|
|
926
897
|
else {
|
|
927
|
-
if (this.On) {
|
|
928
|
-
this.
|
|
929
|
-
this.
|
|
930
|
-
this.
|
|
931
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
898
|
+
if (this.WindowCovering.On) {
|
|
899
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
900
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
901
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
902
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
|
|
903
|
+
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering.On})`);
|
|
932
904
|
}
|
|
933
905
|
else {
|
|
934
|
-
this.
|
|
935
|
-
this.
|
|
936
|
-
this.
|
|
937
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
906
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
907
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
908
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
909
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
|
|
910
|
+
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering.On})`);
|
|
938
911
|
}
|
|
939
912
|
}
|
|
940
|
-
this.
|
|
913
|
+
await this.setOn(Boolean(this.WindowCovering.On));
|
|
914
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Window Covering On: ${this.WindowCovering.On}`);
|
|
941
915
|
}
|
|
942
916
|
else if (this.botDeviceType === 'lock') {
|
|
943
|
-
if (this.On === undefined) {
|
|
944
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
917
|
+
if (this.Lock.On === undefined) {
|
|
918
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Lock.On}`);
|
|
945
919
|
}
|
|
946
920
|
else {
|
|
947
|
-
if (this.On) {
|
|
948
|
-
this.
|
|
949
|
-
this.
|
|
950
|
-
this.debugLog(`${this.device.deviceType}: `
|
|
951
|
-
|
|
921
|
+
if (this.Lock.On) {
|
|
922
|
+
this.Lock.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.UNSECURED);
|
|
923
|
+
this.Lock.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.UNSECURED);
|
|
924
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
|
|
925
|
+
+ ` LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.Lock.On})`);
|
|
952
926
|
}
|
|
953
927
|
else {
|
|
954
|
-
this.
|
|
955
|
-
this.
|
|
956
|
-
this.debugLog(`${this.device.deviceType}:
|
|
928
|
+
this.Lock.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
|
|
929
|
+
this.Lock.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED);
|
|
930
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
931
|
+
+ ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.Lock.On})`);
|
|
957
932
|
}
|
|
958
933
|
}
|
|
959
|
-
this.
|
|
934
|
+
await this.setOn(Boolean(this.Lock.On));
|
|
935
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Lock On: ${this.Lock.On}`);
|
|
960
936
|
}
|
|
961
937
|
else if (this.botDeviceType === 'faucet') {
|
|
962
|
-
if (this.On === undefined) {
|
|
963
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
938
|
+
if (this.Faucet.On === undefined) {
|
|
939
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Faucet.On}`);
|
|
964
940
|
}
|
|
965
941
|
else {
|
|
966
|
-
if (this.On) {
|
|
967
|
-
this.
|
|
968
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
|
|
942
|
+
if (this.Faucet.On) {
|
|
943
|
+
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
|
|
944
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet.On}`);
|
|
969
945
|
}
|
|
970
946
|
else {
|
|
971
|
-
this.
|
|
972
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
|
|
947
|
+
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
948
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet.On}`);
|
|
973
949
|
}
|
|
974
950
|
}
|
|
975
|
-
this.
|
|
951
|
+
await this.setOn(Boolean(this.Faucet.On));
|
|
952
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Faucet On: ${this.Faucet.On}`);
|
|
976
953
|
}
|
|
977
954
|
else if (this.botDeviceType === 'fan') {
|
|
978
|
-
if (this.On === undefined) {
|
|
979
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
955
|
+
if (this.Fan.On === undefined) {
|
|
956
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Fan.On}`);
|
|
980
957
|
}
|
|
981
958
|
else {
|
|
982
|
-
if (this.On) {
|
|
983
|
-
this.
|
|
984
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
959
|
+
if (this.Fan.On) {
|
|
960
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
|
|
961
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan.On}`);
|
|
985
962
|
}
|
|
986
963
|
else {
|
|
987
|
-
this.
|
|
988
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
964
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
|
|
965
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan.On}`);
|
|
989
966
|
}
|
|
990
967
|
}
|
|
991
|
-
this.
|
|
968
|
+
await this.setOn(Boolean(this.Fan.On));
|
|
969
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Fan On: ${this.Fan.On}`);
|
|
992
970
|
}
|
|
993
971
|
else if (this.botDeviceType === 'stateful') {
|
|
994
|
-
if (this.On === undefined) {
|
|
995
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
972
|
+
if (this.StatefulProgrammableSwitch.On === undefined) {
|
|
973
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.StatefulProgrammableSwitch.On}`);
|
|
996
974
|
}
|
|
997
975
|
else {
|
|
998
|
-
if (this.On) {
|
|
999
|
-
this.
|
|
1000
|
-
this.
|
|
1001
|
-
this.debugLog(`${this.device.deviceType}: `
|
|
1002
|
-
|
|
976
|
+
if (this.StatefulProgrammableSwitch.On) {
|
|
977
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
978
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
|
|
979
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
980
|
+
+ ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1 (${this.StatefulProgrammableSwitch.On})`);
|
|
1003
981
|
}
|
|
1004
982
|
else {
|
|
1005
|
-
this.
|
|
1006
|
-
this.
|
|
1007
|
-
this.debugLog(`${this.device.deviceType}: `
|
|
1008
|
-
|
|
983
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
984
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
|
|
985
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
986
|
+
+ ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0 (${this.StatefulProgrammableSwitch.On})`);
|
|
1009
987
|
}
|
|
1010
988
|
}
|
|
1011
|
-
this.
|
|
989
|
+
await this.setOn(Boolean(this.StatefulProgrammableSwitch.On));
|
|
990
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch.On}`);
|
|
1012
991
|
}
|
|
1013
992
|
else if (this.botDeviceType === 'switch') {
|
|
1014
|
-
if (this.On === undefined) {
|
|
1015
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
993
|
+
if (this.Switch.On === undefined) {
|
|
994
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Switch.On}`);
|
|
1016
995
|
}
|
|
1017
996
|
else {
|
|
1018
|
-
this.
|
|
1019
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
997
|
+
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
|
|
998
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Switch.On}`);
|
|
999
|
+
await this.setOn(Boolean(this.Switch.On));
|
|
1020
1000
|
}
|
|
1021
1001
|
}
|
|
1022
1002
|
else {
|
|
1023
|
-
if (this.On === undefined) {
|
|
1024
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
1003
|
+
if (this.Outlet.On === undefined) {
|
|
1004
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Outlet.On}`);
|
|
1025
1005
|
}
|
|
1026
1006
|
else {
|
|
1027
|
-
this.
|
|
1028
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
1007
|
+
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.Outlet.On);
|
|
1008
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Outlet.On}`);
|
|
1029
1009
|
}
|
|
1030
1010
|
}
|
|
1031
|
-
this.
|
|
1011
|
+
await this.setOn(Boolean(this.Outlet.On));
|
|
1012
|
+
this.accessory.context.On = await this.getOn();
|
|
1032
1013
|
// BatteryLevel
|
|
1033
|
-
if (this.BatteryLevel === undefined) {
|
|
1034
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
1014
|
+
if (this.Battery.BatteryLevel === undefined) {
|
|
1015
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
1035
1016
|
}
|
|
1036
1017
|
else {
|
|
1037
|
-
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
1038
|
-
this.
|
|
1039
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
1018
|
+
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
1019
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
1020
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
1040
1021
|
}
|
|
1041
1022
|
// StatusLowBattery
|
|
1042
|
-
if (this.StatusLowBattery === undefined) {
|
|
1043
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
1023
|
+
if (this.Battery.StatusLowBattery === undefined) {
|
|
1024
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1044
1025
|
}
|
|
1045
1026
|
else {
|
|
1046
|
-
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
1047
|
-
this.
|
|
1048
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
1027
|
+
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
1028
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
1029
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
1030
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1049
1031
|
}
|
|
1050
1032
|
}
|
|
1051
1033
|
async removeOutletService(accessory) {
|
|
1052
1034
|
// If outletService still present, then remove first
|
|
1053
|
-
this.
|
|
1054
|
-
if (this.
|
|
1035
|
+
this.Outlet.Service = this.accessory.getService(this.hap.Service.Outlet);
|
|
1036
|
+
if (this.Outlet?.Service) {
|
|
1055
1037
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Outlet Service`);
|
|
1056
1038
|
}
|
|
1057
|
-
accessory.removeService(this.
|
|
1039
|
+
accessory.removeService(this.Outlet.Service);
|
|
1058
1040
|
}
|
|
1059
1041
|
async removeGarageDoorService(accessory) {
|
|
1060
1042
|
// If garageDoorService still present, then remove first
|
|
1061
|
-
this.
|
|
1062
|
-
if (this.
|
|
1043
|
+
this.GarageDoor.Service = this.accessory.getService(this.hap.Service.GarageDoorOpener);
|
|
1044
|
+
if (this.GarageDoor?.Service) {
|
|
1063
1045
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Garage Door Service`);
|
|
1064
1046
|
}
|
|
1065
|
-
accessory.removeService(this.
|
|
1047
|
+
accessory.removeService(this.GarageDoor.Service);
|
|
1066
1048
|
}
|
|
1067
1049
|
async removeDoorService(accessory) {
|
|
1068
1050
|
// If doorService still present, then remove first
|
|
1069
|
-
this.
|
|
1070
|
-
if (this.
|
|
1051
|
+
this.Door.Service = this.accessory.getService(this.hap.Service.Door);
|
|
1052
|
+
if (this.Door?.Service) {
|
|
1071
1053
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Door Service`);
|
|
1072
1054
|
}
|
|
1073
|
-
accessory.removeService(this.
|
|
1055
|
+
accessory.removeService(this.Door.Service);
|
|
1074
1056
|
}
|
|
1075
1057
|
async removeLockService(accessory) {
|
|
1076
1058
|
// If lockService still present, then remove first
|
|
1077
|
-
this.
|
|
1078
|
-
if (this.
|
|
1059
|
+
this.Lock.Service = this.accessory.getService(this.hap.Service.LockMechanism);
|
|
1060
|
+
if (this.Lock?.Service) {
|
|
1079
1061
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Lock Service`);
|
|
1080
1062
|
}
|
|
1081
|
-
accessory.removeService(this.
|
|
1063
|
+
accessory.removeService(this.Lock.Service);
|
|
1082
1064
|
}
|
|
1083
1065
|
async removeFaucetService(accessory) {
|
|
1084
1066
|
// If faucetService still present, then remove first
|
|
1085
|
-
this.
|
|
1086
|
-
if (this.
|
|
1067
|
+
this.Faucet.Service = this.accessory.getService(this.hap.Service.Faucet);
|
|
1068
|
+
if (this.Faucet?.Service) {
|
|
1087
1069
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Faucet Service`);
|
|
1088
1070
|
}
|
|
1089
|
-
accessory.removeService(this.
|
|
1071
|
+
accessory.removeService(this.Faucet.Service);
|
|
1090
1072
|
}
|
|
1091
1073
|
async removeFanService(accessory) {
|
|
1092
1074
|
// If fanService still present, then remove first
|
|
1093
|
-
this.
|
|
1094
|
-
if (this.
|
|
1075
|
+
this.Fan.Service = this.accessory.getService(this.hap.Service.Fanv2);
|
|
1076
|
+
if (this.Fan?.Service) {
|
|
1095
1077
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Fan Service`);
|
|
1096
1078
|
}
|
|
1097
|
-
accessory.removeService(this.
|
|
1079
|
+
accessory.removeService(this.Fan.Service);
|
|
1098
1080
|
}
|
|
1099
1081
|
async removeWindowService(accessory) {
|
|
1100
1082
|
// If windowService still present, then remove first
|
|
1101
|
-
this.
|
|
1102
|
-
if (this.
|
|
1083
|
+
this.Window.Service = this.accessory.getService(this.hap.Service.Window);
|
|
1084
|
+
if (this.Window?.Service) {
|
|
1103
1085
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Window Service`);
|
|
1104
1086
|
}
|
|
1105
|
-
accessory.removeService(this.
|
|
1087
|
+
accessory.removeService(this.Window.Service);
|
|
1106
1088
|
}
|
|
1107
1089
|
async removeWindowCoveringService(accessory) {
|
|
1108
1090
|
// If windowCoveringService still present, then remove first
|
|
1109
|
-
this.
|
|
1110
|
-
if (this.
|
|
1091
|
+
this.WindowCovering.Service = this.accessory.getService(this.hap.Service.WindowCovering);
|
|
1092
|
+
if (this.WindowCovering?.Service) {
|
|
1111
1093
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Window Covering Service`);
|
|
1112
1094
|
}
|
|
1113
|
-
accessory.removeService(this.
|
|
1095
|
+
accessory.removeService(this.WindowCovering.Service);
|
|
1114
1096
|
}
|
|
1115
1097
|
async removeStatefulProgrammableSwitchService(accessory) {
|
|
1116
1098
|
// If statefulProgrammableSwitchService still present, then remove first
|
|
1117
|
-
this.
|
|
1118
|
-
if (this.
|
|
1099
|
+
this.StatefulProgrammableSwitch.Service = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch);
|
|
1100
|
+
if (this.StatefulProgrammableSwitch?.Service) {
|
|
1119
1101
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
|
|
1120
1102
|
}
|
|
1121
|
-
accessory.removeService(this.
|
|
1103
|
+
accessory.removeService(this.StatefulProgrammableSwitch.Service);
|
|
1122
1104
|
}
|
|
1123
1105
|
async removeSwitchService(accessory) {
|
|
1124
1106
|
// If switchService still present, then remove first
|
|
1125
|
-
this.
|
|
1126
|
-
if (this.
|
|
1107
|
+
this.Switch.Service = this.accessory.getService(this.hap.Service.Switch);
|
|
1108
|
+
if (this.Switch?.Service) {
|
|
1127
1109
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Switch Service`);
|
|
1128
1110
|
}
|
|
1129
|
-
accessory.removeService(this.
|
|
1111
|
+
accessory.removeService(this.Switch.Service);
|
|
1130
1112
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
this.
|
|
1135
|
-
}
|
|
1136
|
-
else {
|
|
1137
|
-
this.doublePress = 1;
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
async stopScanning(switchbot) {
|
|
1141
|
-
switchbot.stopScan();
|
|
1142
|
-
if (this.BLE_IsConnected) {
|
|
1143
|
-
await this.BLEparseStatus();
|
|
1144
|
-
await this.updateHomeKitCharacteristics();
|
|
1145
|
-
}
|
|
1146
|
-
else {
|
|
1147
|
-
await this.BLERefreshConnection(switchbot);
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
async getCustomBLEAddress(switchbot) {
|
|
1151
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
1152
|
-
(async () => {
|
|
1153
|
-
// Start to monitor advertisement packets
|
|
1154
|
-
await switchbot.startScan({
|
|
1155
|
-
model: 'H',
|
|
1156
|
-
});
|
|
1157
|
-
// Set an event handler
|
|
1158
|
-
switchbot.onadvertisement = (ad) => {
|
|
1159
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
1160
|
-
};
|
|
1161
|
-
await sleep(10000);
|
|
1162
|
-
// Stop to monitor
|
|
1163
|
-
switchbot.stopScan();
|
|
1164
|
-
})();
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
async BLEPushConnection() {
|
|
1168
|
-
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
1169
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
|
|
1170
|
-
await this.openAPIpushChanges();
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
async BLERefreshConnection(switchbot) {
|
|
1174
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
|
|
1175
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
1176
|
-
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
1177
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
|
|
1178
|
-
await this.openAPIRefreshStatus();
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
async retry({ max, fn }) {
|
|
1182
|
-
return fn().catch(async (e) => {
|
|
1183
|
-
if (max === 0) {
|
|
1184
|
-
throw e;
|
|
1185
|
-
}
|
|
1186
|
-
this.infoLog(e);
|
|
1187
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
|
|
1188
|
-
await sleep(1000);
|
|
1189
|
-
return this.retry({ max: max - 1, fn });
|
|
1190
|
-
});
|
|
1191
|
-
}
|
|
1192
|
-
maxRetry() {
|
|
1193
|
-
if (this.device.maxRetry) {
|
|
1194
|
-
return this.device.maxRetry;
|
|
1195
|
-
}
|
|
1196
|
-
else {
|
|
1197
|
-
return 5;
|
|
1113
|
+
async getOn() {
|
|
1114
|
+
let On;
|
|
1115
|
+
if (this.botDeviceType === 'garagedoor') {
|
|
1116
|
+
On = this.GarageDoor.On ? true : false;
|
|
1198
1117
|
}
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
if (!device.bot?.mode) {
|
|
1202
|
-
this.botMode = 'switch';
|
|
1203
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings,`);
|
|
1204
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} is defaulting to "${this.botMode}" mode, you may experience issues.`);
|
|
1118
|
+
else if (this.botDeviceType === 'door') {
|
|
1119
|
+
On = this.Door.On ? true : false;
|
|
1205
1120
|
}
|
|
1206
|
-
else if (
|
|
1207
|
-
this.
|
|
1208
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
|
|
1121
|
+
else if (this.botDeviceType === 'window') {
|
|
1122
|
+
On = this.Window.On ? true : false;
|
|
1209
1123
|
}
|
|
1210
|
-
else if (
|
|
1211
|
-
this.
|
|
1212
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
|
|
1124
|
+
else if (this.botDeviceType === 'windowcovering') {
|
|
1125
|
+
On = this.WindowCovering.On ? true : false;
|
|
1213
1126
|
}
|
|
1214
|
-
else if (
|
|
1215
|
-
this.
|
|
1216
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
|
|
1127
|
+
else if (this.botDeviceType === 'lock') {
|
|
1128
|
+
On = this.Lock.On ? true : false;
|
|
1217
1129
|
}
|
|
1218
|
-
else {
|
|
1219
|
-
|
|
1130
|
+
else if (this.botDeviceType === 'faucet') {
|
|
1131
|
+
On = this.Faucet.On ? true : false;
|
|
1220
1132
|
}
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
if (device.bot?.allowPush) {
|
|
1224
|
-
this.allowPush = true;
|
|
1133
|
+
else if (this.botDeviceType === 'fan') {
|
|
1134
|
+
On = this.Fan.On ? true : false;
|
|
1225
1135
|
}
|
|
1226
|
-
else {
|
|
1227
|
-
this.
|
|
1136
|
+
else if (this.botDeviceType === 'stateful') {
|
|
1137
|
+
On = this.StatefulProgrammableSwitch.On ? true : false;
|
|
1228
1138
|
}
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
async scan(device) {
|
|
1232
|
-
if (device.scanDuration) {
|
|
1233
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
1234
|
-
if (this.BLE) {
|
|
1235
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
1236
|
-
}
|
|
1139
|
+
else if (this.botDeviceType === 'switch') {
|
|
1140
|
+
On = this.Switch.On ? true : false;
|
|
1237
1141
|
}
|
|
1238
1142
|
else {
|
|
1239
|
-
|
|
1240
|
-
if (this.BLE) {
|
|
1241
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
async statusCode(statusCode) {
|
|
1246
|
-
switch (statusCode) {
|
|
1247
|
-
case 151:
|
|
1248
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
1249
|
-
break;
|
|
1250
|
-
case 152:
|
|
1251
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
1252
|
-
break;
|
|
1253
|
-
case 160:
|
|
1254
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
1255
|
-
break;
|
|
1256
|
-
case 161:
|
|
1257
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
1258
|
-
this.offlineOff();
|
|
1259
|
-
break;
|
|
1260
|
-
case 171:
|
|
1261
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
1262
|
-
`Hub: ${this.device.hubDeviceId}`);
|
|
1263
|
-
this.offlineOff();
|
|
1264
|
-
break;
|
|
1265
|
-
case 190:
|
|
1266
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
1267
|
-
` Or command format is invalid, statusCode: ${statusCode}`);
|
|
1268
|
-
break;
|
|
1269
|
-
case 100:
|
|
1270
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
1271
|
-
break;
|
|
1272
|
-
case 200:
|
|
1273
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
1274
|
-
break;
|
|
1275
|
-
case 400:
|
|
1276
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
1277
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
1278
|
-
break;
|
|
1279
|
-
case 401:
|
|
1280
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
1281
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
1282
|
-
break;
|
|
1283
|
-
case 403:
|
|
1284
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
1285
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
1286
|
-
break;
|
|
1287
|
-
case 404:
|
|
1288
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
1289
|
-
+ `statusCode: ${statusCode}`);
|
|
1290
|
-
break;
|
|
1291
|
-
case 406:
|
|
1292
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
1293
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
1294
|
-
break;
|
|
1295
|
-
case 415:
|
|
1296
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
1297
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
1298
|
-
break;
|
|
1299
|
-
case 422:
|
|
1300
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
|
|
1301
|
-
+ `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
1302
|
-
break;
|
|
1303
|
-
case 429:
|
|
1304
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
1305
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
1306
|
-
break;
|
|
1307
|
-
case 500:
|
|
1308
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
1309
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
1310
|
-
break;
|
|
1311
|
-
default:
|
|
1312
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
1313
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
1314
|
-
}
|
|
1315
|
-
}
|
|
1316
|
-
async offlineOff() {
|
|
1317
|
-
if (this.device.offline) {
|
|
1318
|
-
await this.deviceContext();
|
|
1319
|
-
await this.updateHomeKitCharacteristics();
|
|
1143
|
+
On = this.Outlet.On ? true : false;
|
|
1320
1144
|
}
|
|
1145
|
+
return On;
|
|
1321
1146
|
}
|
|
1322
|
-
async
|
|
1147
|
+
async setOn(On) {
|
|
1323
1148
|
if (this.botDeviceType === 'garagedoor') {
|
|
1324
|
-
this.
|
|
1325
|
-
this.garageDoorService?.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, e);
|
|
1326
|
-
this.garageDoorService?.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, e);
|
|
1149
|
+
this.GarageDoor.On = On;
|
|
1327
1150
|
}
|
|
1328
1151
|
else if (this.botDeviceType === 'door') {
|
|
1329
|
-
this.
|
|
1330
|
-
this.doorService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
1331
|
-
this.doorService?.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
1152
|
+
this.Door.On = On;
|
|
1332
1153
|
}
|
|
1333
1154
|
else if (this.botDeviceType === 'window') {
|
|
1334
|
-
this.
|
|
1335
|
-
this.windowService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
1336
|
-
this.windowService?.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
1155
|
+
this.Window.On = On;
|
|
1337
1156
|
}
|
|
1338
1157
|
else if (this.botDeviceType === 'windowcovering') {
|
|
1339
|
-
this.
|
|
1340
|
-
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
1341
|
-
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
1158
|
+
this.WindowCovering.On = On;
|
|
1342
1159
|
}
|
|
1343
1160
|
else if (this.botDeviceType === 'lock') {
|
|
1344
|
-
this.
|
|
1345
|
-
this.doorService?.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e);
|
|
1161
|
+
this.Lock.On = On;
|
|
1346
1162
|
}
|
|
1347
1163
|
else if (this.botDeviceType === 'faucet') {
|
|
1348
|
-
this.
|
|
1164
|
+
this.Faucet.On = On;
|
|
1349
1165
|
}
|
|
1350
1166
|
else if (this.botDeviceType === 'fan') {
|
|
1351
|
-
this.
|
|
1167
|
+
this.Fan.On = On;
|
|
1352
1168
|
}
|
|
1353
1169
|
else if (this.botDeviceType === 'stateful') {
|
|
1354
|
-
this.
|
|
1355
|
-
this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
1170
|
+
this.StatefulProgrammableSwitch.On = On;
|
|
1356
1171
|
}
|
|
1357
1172
|
else if (this.botDeviceType === 'switch') {
|
|
1358
|
-
this.
|
|
1173
|
+
this.Switch.On = On;
|
|
1359
1174
|
}
|
|
1360
1175
|
else {
|
|
1361
|
-
this.
|
|
1176
|
+
this.Outlet.On = On;
|
|
1362
1177
|
}
|
|
1363
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
1364
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
1365
1178
|
}
|
|
1366
|
-
async
|
|
1179
|
+
async getBotConfigSettings(device) {
|
|
1180
|
+
//Bot Device Type
|
|
1367
1181
|
if (!device.bot?.deviceType && this.accessory.context.deviceType) {
|
|
1368
1182
|
this.botDeviceType = this.accessory.context.deviceType;
|
|
1369
1183
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Type: ${this.botDeviceType}, from Accessory Cache.`);
|
|
@@ -1379,43 +1193,36 @@ export class Bot {
|
|
|
1379
1193
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} No Device Type Set, deviceType: ${this.device.bot?.deviceType}`);
|
|
1380
1194
|
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using default deviceType: ${this.botDeviceType}`);
|
|
1381
1195
|
}
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
this.
|
|
1386
|
-
this.
|
|
1387
|
-
}
|
|
1388
|
-
else {
|
|
1389
|
-
this.On = this.accessory.context.On;
|
|
1196
|
+
// Bot Mode
|
|
1197
|
+
if (!device.bot?.mode) {
|
|
1198
|
+
this.botMode = 'switch';
|
|
1199
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings,`);
|
|
1200
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} is defaulting to "${this.botMode}" mode, you may experience issues.`);
|
|
1390
1201
|
}
|
|
1391
|
-
if (
|
|
1392
|
-
this.
|
|
1202
|
+
else if (device.bot?.mode === 'switch') {
|
|
1203
|
+
this.botMode = 'switch';
|
|
1204
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
|
|
1393
1205
|
}
|
|
1394
|
-
else {
|
|
1395
|
-
this.
|
|
1206
|
+
else if (device.bot?.mode === 'press') {
|
|
1207
|
+
this.botMode = 'press';
|
|
1208
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
|
|
1396
1209
|
}
|
|
1397
|
-
if (
|
|
1398
|
-
this.
|
|
1399
|
-
this.
|
|
1210
|
+
else if (device.bot?.mode === 'multipress') {
|
|
1211
|
+
this.botMode = 'multipress';
|
|
1212
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
|
|
1400
1213
|
}
|
|
1401
1214
|
else {
|
|
1402
|
-
this.
|
|
1403
|
-
}
|
|
1404
|
-
if (this.FirmwareRevision === undefined) {
|
|
1405
|
-
this.FirmwareRevision = this.platform.version;
|
|
1406
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
1215
|
+
throw new Error(`${this.device.deviceType}: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
|
|
1407
1216
|
}
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
this.
|
|
1412
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1217
|
+
// Bot Double Press
|
|
1218
|
+
if (device.bot?.doublePress) {
|
|
1219
|
+
this.doublePress = device.bot?.doublePress;
|
|
1220
|
+
this.accessory.context.doublePress = this.doublePress;
|
|
1413
1221
|
}
|
|
1414
|
-
else
|
|
1415
|
-
this.
|
|
1416
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1222
|
+
else {
|
|
1223
|
+
this.doublePress = 1;
|
|
1417
1224
|
}
|
|
1418
|
-
//
|
|
1225
|
+
// Bot Press PushRate
|
|
1419
1226
|
if (device?.bot?.pushRatePress) {
|
|
1420
1227
|
this.pushRatePress = device?.bot?.pushRatePress;
|
|
1421
1228
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Bot pushRatePress: ${this.pushRatePress}`);
|
|
@@ -1424,102 +1231,118 @@ export class Bot {
|
|
|
1424
1231
|
this.pushRatePress = 15;
|
|
1425
1232
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default Bot pushRatePress: ${this.pushRatePress}`);
|
|
1426
1233
|
}
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
if (device.bot) {
|
|
1431
|
-
config = device.bot;
|
|
1432
|
-
}
|
|
1433
|
-
if (device.connectionType !== undefined) {
|
|
1434
|
-
config['connectionType'] = device.connectionType;
|
|
1435
|
-
}
|
|
1436
|
-
if (device.external !== undefined) {
|
|
1437
|
-
config['external'] = device.external;
|
|
1438
|
-
}
|
|
1439
|
-
if (device.logging !== undefined) {
|
|
1440
|
-
config['logging'] = device.logging;
|
|
1441
|
-
}
|
|
1442
|
-
if (device.refreshRate !== undefined) {
|
|
1443
|
-
config['refreshRate'] = device.refreshRate;
|
|
1444
|
-
}
|
|
1445
|
-
if (device.scanDuration !== undefined) {
|
|
1446
|
-
config['scanDuration'] = device.scanDuration;
|
|
1234
|
+
// Bot Allow Push
|
|
1235
|
+
if (device.bot?.allowPush) {
|
|
1236
|
+
this.allowPush = true;
|
|
1447
1237
|
}
|
|
1448
|
-
|
|
1449
|
-
|
|
1238
|
+
else {
|
|
1239
|
+
this.allowPush = false;
|
|
1450
1240
|
}
|
|
1451
|
-
|
|
1452
|
-
|
|
1241
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Allowing Push Changes: ${this.allowPush}`);
|
|
1242
|
+
// Bot Multi Press Count
|
|
1243
|
+
this.multiPressCount = 0;
|
|
1244
|
+
}
|
|
1245
|
+
async BLEPushConnection() {
|
|
1246
|
+
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
1247
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
|
|
1248
|
+
await this.openAPIpushChanges();
|
|
1453
1249
|
}
|
|
1454
|
-
|
|
1455
|
-
|
|
1250
|
+
}
|
|
1251
|
+
async BLERefreshConnection(switchbot) {
|
|
1252
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
|
|
1253
|
+
+ ` ${JSON.stringify(switchbot)}`);
|
|
1254
|
+
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
1255
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
|
|
1256
|
+
await this.openAPIRefreshStatus();
|
|
1456
1257
|
}
|
|
1457
|
-
|
|
1458
|
-
|
|
1258
|
+
}
|
|
1259
|
+
async offlineOff() {
|
|
1260
|
+
if (this.device.offline) {
|
|
1261
|
+
if (this.botDeviceType === 'garagedoor') {
|
|
1262
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
|
|
1263
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
|
|
1264
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, false);
|
|
1265
|
+
}
|
|
1266
|
+
else if (this.botDeviceType === 'door') {
|
|
1267
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
1268
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
1269
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
1270
|
+
}
|
|
1271
|
+
else if (this.botDeviceType === 'window') {
|
|
1272
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
1273
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
1274
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
1275
|
+
}
|
|
1276
|
+
else if (this.botDeviceType === 'windowcovering') {
|
|
1277
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
1278
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
1279
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
1280
|
+
}
|
|
1281
|
+
else if (this.botDeviceType === 'lock') {
|
|
1282
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
|
|
1283
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED);
|
|
1284
|
+
}
|
|
1285
|
+
else if (this.botDeviceType === 'faucet') {
|
|
1286
|
+
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
1287
|
+
}
|
|
1288
|
+
else if (this.botDeviceType === 'fan') {
|
|
1289
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, false);
|
|
1290
|
+
}
|
|
1291
|
+
else if (this.botDeviceType === 'stateful') {
|
|
1292
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
1293
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
|
|
1294
|
+
}
|
|
1295
|
+
else if (this.botDeviceType === 'switch') {
|
|
1296
|
+
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, false);
|
|
1297
|
+
}
|
|
1298
|
+
else {
|
|
1299
|
+
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, false);
|
|
1300
|
+
}
|
|
1459
1301
|
}
|
|
1460
1302
|
}
|
|
1461
|
-
async
|
|
1462
|
-
if (this.
|
|
1463
|
-
this.
|
|
1464
|
-
this.
|
|
1303
|
+
async apiError(e) {
|
|
1304
|
+
if (this.botDeviceType === 'garagedoor') {
|
|
1305
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, e);
|
|
1306
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, e);
|
|
1307
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, e);
|
|
1465
1308
|
}
|
|
1466
|
-
else if (
|
|
1467
|
-
this.
|
|
1468
|
-
this.
|
|
1309
|
+
else if (this.botDeviceType === 'door') {
|
|
1310
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
1311
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
1312
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
1469
1313
|
}
|
|
1470
|
-
else if (this.
|
|
1471
|
-
this.
|
|
1472
|
-
this.
|
|
1314
|
+
else if (this.botDeviceType === 'window') {
|
|
1315
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
1316
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
1317
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
1473
1318
|
}
|
|
1474
|
-
else {
|
|
1475
|
-
this.
|
|
1476
|
-
this.
|
|
1319
|
+
else if (this.botDeviceType === 'windowcovering') {
|
|
1320
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
1321
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
1322
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
1477
1323
|
}
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
*/
|
|
1482
|
-
infoLog(...log) {
|
|
1483
|
-
if (this.enablingDeviceLogging()) {
|
|
1484
|
-
this.platform.log.info(String(...log));
|
|
1324
|
+
else if (this.botDeviceType === 'lock') {
|
|
1325
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, e);
|
|
1326
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e);
|
|
1485
1327
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
if (this.enablingDeviceLogging()) {
|
|
1489
|
-
this.platform.log.warn(String(...log));
|
|
1328
|
+
else if (this.botDeviceType === 'faucet') {
|
|
1329
|
+
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
1490
1330
|
}
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
if (this.enablingDeviceLogging()) {
|
|
1494
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1495
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
1496
|
-
}
|
|
1331
|
+
else if (this.botDeviceType === 'fan') {
|
|
1332
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
1497
1333
|
}
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
this.platform.log.error(String(...log));
|
|
1334
|
+
else if (this.botDeviceType === 'stateful') {
|
|
1335
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
|
|
1336
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
1502
1337
|
}
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
if (this.enablingDeviceLogging()) {
|
|
1506
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1507
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
1508
|
-
}
|
|
1338
|
+
else if (this.botDeviceType === 'switch') {
|
|
1339
|
+
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
1509
1340
|
}
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
if (this.enablingDeviceLogging()) {
|
|
1513
|
-
if (this.deviceLogging === 'debug') {
|
|
1514
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
1515
|
-
}
|
|
1516
|
-
else {
|
|
1517
|
-
this.platform.log.debug(String(...log));
|
|
1518
|
-
}
|
|
1341
|
+
else {
|
|
1342
|
+
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
1519
1343
|
}
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
1344
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
1345
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
1523
1346
|
}
|
|
1524
1347
|
}
|
|
1525
1348
|
//# sourceMappingURL=bot.js.map
|