@switchbot/homebridge-switchbot 2.14.0 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/npm-version-script.cjs +81 -0
- package/.github/workflows/dependabot.yml +10 -11
- package/CHANGELOG.md +11 -2
- package/LICENSE +1 -1
- package/config.schema.json +1 -0
- package/dist/device/blindtilt.d.ts +9 -5
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +151 -91
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -5
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +234 -184
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -5
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +110 -64
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +9 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +121 -69
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +111 -66
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +9 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +164 -107
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +87 -51
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +9 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +133 -90
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +108 -66
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +9 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +110 -65
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -6
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +125 -84
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +102 -63
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +102 -63
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +95 -54
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -5
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +68 -40
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -5
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +86 -52
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/homebridge-ui/server.d.ts +2 -0
- package/dist/homebridge-ui/server.d.ts.map +1 -0
- package/dist/homebridge-ui/server.js +44 -0
- package/dist/homebridge-ui/server.js.map +1 -0
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -4
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +105 -71
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -4
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +78 -46
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +8 -4
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +41 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -4
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +62 -39
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +8 -4
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +67 -45
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +8 -4
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +176 -150
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -4
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +81 -62
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +8 -4
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -25
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +8 -4
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +48 -32
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +8 -9
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +147 -162
- package/dist/platform.js.map +1 -1
- package/dist/settings.js +7 -14
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -5
- package/dist/utils.js.map +1 -1
- package/package.json +28 -16
- package/src/device/blindtilt.ts +80 -69
- package/src/device/bot.ts +189 -178
- package/src/device/ceilinglight.ts +55 -42
- package/src/device/colorbulb.ts +51 -38
- package/src/device/contact.ts +69 -58
- package/src/device/curtain.ts +94 -83
- package/src/device/hub.ts +54 -43
- package/src/device/humidifier.ts +86 -75
- package/src/device/iosensor.ts +63 -52
- package/src/device/lightstrip.ts +54 -41
- package/src/device/lock.ts +89 -79
- package/src/device/meter.ts +59 -48
- package/src/device/meterplus.ts +63 -52
- package/src/device/motion.ts +56 -45
- package/src/device/plug.ts +36 -25
- package/src/device/robotvacuumcleaner.ts +47 -36
- package/src/homebridge-ui/public/index.html +240 -0
- package/src/homebridge-ui/server.ts +48 -0
- package/src/index.ts +10 -7
- package/src/irdevice/airconditioner.ts +70 -62
- package/src/irdevice/airpurifier.ts +47 -39
- package/src/irdevice/camera.ts +27 -19
- package/src/irdevice/fan.ts +41 -33
- package/src/irdevice/light.ts +47 -39
- package/src/irdevice/other.ts +163 -155
- package/src/irdevice/tv.ts +65 -57
- package/src/irdevice/vacuumcleaner.ts +27 -19
- package/src/irdevice/waterheater.ts +34 -26
- package/src/platform.ts +35 -21
- package/tsconfig.json +11 -13
- package/homebridge-ui/server.js +0 -50
- /package/{homebridge-ui → dist/homebridge-ui}/public/index.html +0 -0
package/src/device/bot.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { sleep } from '../utils';
|
|
|
3
3
|
import { interval, Subject } from 'rxjs';
|
|
4
4
|
import { SwitchBotPlatform } from '../platform';
|
|
5
5
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
|
-
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
7
|
-
import { device, devicesConfig, deviceStatus, ad, serviceData, Devices } from '../settings';
|
|
6
|
+
import { Service, PlatformAccessory, CharacteristicValue, API, Logging, HAP } from 'homebridge';
|
|
7
|
+
import { device, devicesConfig, deviceStatus, ad, serviceData, Devices, SwitchBotPlatformConfig } from '../settings';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Platform Accessory
|
|
@@ -12,6 +12,10 @@ import { device, devicesConfig, deviceStatus, ad, serviceData, Devices } from '.
|
|
|
12
12
|
* Each accessory may expose multiple services of different service types.
|
|
13
13
|
*/
|
|
14
14
|
export class Bot {
|
|
15
|
+
public readonly api: API;
|
|
16
|
+
public readonly log: Logging;
|
|
17
|
+
public readonly config!: SwitchBotPlatformConfig;
|
|
18
|
+
protected readonly hap: HAP;
|
|
15
19
|
// Services
|
|
16
20
|
fanService?: Service;
|
|
17
21
|
doorService?: Service;
|
|
@@ -60,16 +64,23 @@ export class Bot {
|
|
|
60
64
|
doBotUpdate!: Subject<void>;
|
|
61
65
|
|
|
62
66
|
// Connection
|
|
63
|
-
private readonly
|
|
64
|
-
private readonly
|
|
67
|
+
private readonly OpenAPI: boolean;
|
|
68
|
+
private readonly BLE: boolean;
|
|
65
69
|
|
|
66
70
|
constructor(
|
|
67
71
|
private readonly platform: SwitchBotPlatform,
|
|
68
72
|
private accessory: PlatformAccessory,
|
|
69
73
|
public device: device & devicesConfig,
|
|
70
74
|
) {
|
|
75
|
+
this.api = this.platform.api;
|
|
76
|
+
this.log = this.platform.log;
|
|
77
|
+
this.config = this.platform.config;
|
|
78
|
+
this.hap = this.api.hap;
|
|
79
|
+
// Connection
|
|
80
|
+
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
81
|
+
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
71
82
|
// default placeholders
|
|
72
|
-
this.
|
|
83
|
+
this.deviceLogs(device);
|
|
73
84
|
this.deviceType(device);
|
|
74
85
|
this.scan(device);
|
|
75
86
|
this.refreshRate(device);
|
|
@@ -77,7 +88,7 @@ export class Bot {
|
|
|
77
88
|
this.allowPushChanges(device);
|
|
78
89
|
this.context();
|
|
79
90
|
this.DoublePress(device);
|
|
80
|
-
this.
|
|
91
|
+
this.deviceConfig(device);
|
|
81
92
|
|
|
82
93
|
this.multiPressCount = 0;
|
|
83
94
|
|
|
@@ -90,11 +101,11 @@ export class Bot {
|
|
|
90
101
|
|
|
91
102
|
// set accessory information
|
|
92
103
|
accessory
|
|
93
|
-
.getService(this.
|
|
94
|
-
.setCharacteristic(this.
|
|
95
|
-
.setCharacteristic(this.
|
|
96
|
-
.setCharacteristic(this.
|
|
97
|
-
.setCharacteristic(this.
|
|
104
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
105
|
+
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
106
|
+
.setCharacteristic(this.hap.Characteristic.Model, 'SWITCHBOT-BOT-S1')
|
|
107
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
108
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
98
109
|
|
|
99
110
|
// deviceType
|
|
100
111
|
if (this.botDeviceType === 'switch') {
|
|
@@ -110,15 +121,15 @@ export class Bot {
|
|
|
110
121
|
|
|
111
122
|
// Add switchService
|
|
112
123
|
const switchService = `${accessory.displayName} Switch`;
|
|
113
|
-
(this.switchService = accessory.getService(this.
|
|
114
|
-
|| accessory.addService(this.
|
|
124
|
+
(this.switchService = accessory.getService(this.hap.Service.Switch)
|
|
125
|
+
|| accessory.addService(this.hap.Service.Switch)), switchService;
|
|
115
126
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Switch`);
|
|
116
127
|
|
|
117
|
-
this.switchService.setCharacteristic(this.
|
|
118
|
-
if (!this.switchService.testCharacteristic(this.
|
|
119
|
-
this.switchService.addCharacteristic(this.
|
|
128
|
+
this.switchService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
129
|
+
if (!this.switchService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
130
|
+
this.switchService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
120
131
|
}
|
|
121
|
-
this.switchService.getCharacteristic(this.
|
|
132
|
+
this.switchService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
122
133
|
} else if (this.botDeviceType === 'garagedoor') {
|
|
123
134
|
this.removeFanService(accessory);
|
|
124
135
|
this.removeLockService(accessory);
|
|
@@ -132,16 +143,16 @@ export class Bot {
|
|
|
132
143
|
|
|
133
144
|
// Add garageDoorService
|
|
134
145
|
const garageDoorService = `${accessory.displayName} Garage Door Opener`;
|
|
135
|
-
(this.garageDoorService = accessory.getService(this.
|
|
136
|
-
|| accessory.addService(this.
|
|
146
|
+
(this.garageDoorService = accessory.getService(this.hap.Service.GarageDoorOpener)
|
|
147
|
+
|| accessory.addService(this.hap.Service.GarageDoorOpener)), garageDoorService;
|
|
137
148
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Garage Door Opener`);
|
|
138
149
|
|
|
139
|
-
this.garageDoorService.setCharacteristic(this.
|
|
140
|
-
if (!this.garageDoorService.testCharacteristic(this.
|
|
141
|
-
this.garageDoorService.addCharacteristic(this.
|
|
150
|
+
this.garageDoorService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
151
|
+
if (!this.garageDoorService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
152
|
+
this.garageDoorService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
142
153
|
}
|
|
143
|
-
this.garageDoorService.getCharacteristic(this.
|
|
144
|
-
this.garageDoorService.setCharacteristic(this.
|
|
154
|
+
this.garageDoorService.getCharacteristic(this.hap.Characteristic.TargetDoorState).onSet(this.OnSet.bind(this));
|
|
155
|
+
this.garageDoorService.setCharacteristic(this.hap.Characteristic.ObstructionDetected, false);
|
|
145
156
|
} else if (this.botDeviceType === 'door') {
|
|
146
157
|
this.removeFanService(accessory);
|
|
147
158
|
this.removeLockService(accessory);
|
|
@@ -155,16 +166,16 @@ export class Bot {
|
|
|
155
166
|
|
|
156
167
|
// Add doorService
|
|
157
168
|
const doorService = `${accessory.displayName} Door`;
|
|
158
|
-
(this.doorService = accessory.getService(this.
|
|
159
|
-
|| accessory.addService(this.
|
|
169
|
+
(this.doorService = accessory.getService(this.hap.Service.Door)
|
|
170
|
+
|| accessory.addService(this.hap.Service.Door)), doorService;
|
|
160
171
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Door`);
|
|
161
172
|
|
|
162
|
-
this.doorService.setCharacteristic(this.
|
|
163
|
-
if (!this.doorService.testCharacteristic(this.
|
|
164
|
-
this.doorService.addCharacteristic(this.
|
|
173
|
+
this.doorService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
174
|
+
if (!this.doorService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
175
|
+
this.doorService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
165
176
|
}
|
|
166
177
|
this.doorService
|
|
167
|
-
.getCharacteristic(this.
|
|
178
|
+
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
168
179
|
.setProps({
|
|
169
180
|
validValues: [0, 100],
|
|
170
181
|
minValue: 0,
|
|
@@ -172,7 +183,7 @@ export class Bot {
|
|
|
172
183
|
minStep: 100,
|
|
173
184
|
})
|
|
174
185
|
.onSet(this.OnSet.bind(this));
|
|
175
|
-
this.doorService.setCharacteristic(this.
|
|
186
|
+
this.doorService.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
176
187
|
} else if (this.botDeviceType === 'window') {
|
|
177
188
|
this.removeFanService(accessory);
|
|
178
189
|
this.removeLockService(accessory);
|
|
@@ -186,16 +197,16 @@ export class Bot {
|
|
|
186
197
|
|
|
187
198
|
// Add windowService
|
|
188
199
|
const windowService = `${accessory.displayName} Window`;
|
|
189
|
-
(this.windowService = accessory.getService(this.
|
|
190
|
-
|| accessory.addService(this.
|
|
200
|
+
(this.windowService = accessory.getService(this.hap.Service.Window)
|
|
201
|
+
|| accessory.addService(this.hap.Service.Window)), windowService;
|
|
191
202
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window`);
|
|
192
203
|
|
|
193
|
-
this.windowService.setCharacteristic(this.
|
|
194
|
-
if (!this.windowService.testCharacteristic(this.
|
|
195
|
-
this.windowService.addCharacteristic(this.
|
|
204
|
+
this.windowService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
205
|
+
if (!this.windowService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
206
|
+
this.windowService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
196
207
|
}
|
|
197
208
|
this.windowService
|
|
198
|
-
.getCharacteristic(this.
|
|
209
|
+
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
199
210
|
.setProps({
|
|
200
211
|
validValues: [0, 100],
|
|
201
212
|
minValue: 0,
|
|
@@ -203,7 +214,7 @@ export class Bot {
|
|
|
203
214
|
minStep: 100,
|
|
204
215
|
})
|
|
205
216
|
.onSet(this.OnSet.bind(this));
|
|
206
|
-
this.windowService.setCharacteristic(this.
|
|
217
|
+
this.windowService.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
207
218
|
} else if (this.botDeviceType === 'windowcovering') {
|
|
208
219
|
this.removeFanService(accessory);
|
|
209
220
|
this.removeLockService(accessory);
|
|
@@ -217,16 +228,16 @@ export class Bot {
|
|
|
217
228
|
|
|
218
229
|
// Add windowCoveringService
|
|
219
230
|
const windowCoveringService = `${accessory.displayName} Window Covering`;
|
|
220
|
-
(this.windowCoveringService = accessory.getService(this.
|
|
221
|
-
|| accessory.addService(this.
|
|
231
|
+
(this.windowCoveringService = accessory.getService(this.hap.Service.WindowCovering)
|
|
232
|
+
|| accessory.addService(this.hap.Service.WindowCovering)), windowCoveringService;
|
|
222
233
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window Covering`);
|
|
223
234
|
|
|
224
|
-
this.windowCoveringService.setCharacteristic(this.
|
|
225
|
-
if (!this.windowCoveringService.testCharacteristic(this.
|
|
226
|
-
this.windowCoveringService.addCharacteristic(this.
|
|
235
|
+
this.windowCoveringService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
236
|
+
if (!this.windowCoveringService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
237
|
+
this.windowCoveringService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
227
238
|
}
|
|
228
239
|
this.windowCoveringService
|
|
229
|
-
.getCharacteristic(this.
|
|
240
|
+
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
230
241
|
.setProps({
|
|
231
242
|
validValues: [0, 100],
|
|
232
243
|
minValue: 0,
|
|
@@ -234,7 +245,7 @@ export class Bot {
|
|
|
234
245
|
minStep: 100,
|
|
235
246
|
})
|
|
236
247
|
.onSet(this.OnSet.bind(this));
|
|
237
|
-
this.windowCoveringService.setCharacteristic(this.
|
|
248
|
+
this.windowCoveringService.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
238
249
|
} else if (this.botDeviceType === 'lock') {
|
|
239
250
|
this.removeFanService(accessory);
|
|
240
251
|
this.removeDoorService(accessory);
|
|
@@ -248,15 +259,15 @@ export class Bot {
|
|
|
248
259
|
|
|
249
260
|
// Add lockService
|
|
250
261
|
const lockService = `${accessory.displayName} Lock`;
|
|
251
|
-
(this.lockService = accessory.getService(this.
|
|
252
|
-
|| accessory.addService(this.
|
|
262
|
+
(this.lockService = accessory.getService(this.hap.Service.LockMechanism)
|
|
263
|
+
|| accessory.addService(this.hap.Service.LockMechanism)), lockService;
|
|
253
264
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Lock`);
|
|
254
265
|
|
|
255
|
-
this.lockService.setCharacteristic(this.
|
|
256
|
-
if (!this.lockService.testCharacteristic(this.
|
|
257
|
-
this.lockService.addCharacteristic(this.
|
|
266
|
+
this.lockService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
267
|
+
if (!this.lockService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
268
|
+
this.lockService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
258
269
|
}
|
|
259
|
-
this.lockService.getCharacteristic(this.
|
|
270
|
+
this.lockService.getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.OnSet.bind(this));
|
|
260
271
|
} else if (this.botDeviceType === 'faucet') {
|
|
261
272
|
this.removeFanService(accessory);
|
|
262
273
|
this.removeLockService(accessory);
|
|
@@ -270,15 +281,15 @@ export class Bot {
|
|
|
270
281
|
|
|
271
282
|
// Add faucetService
|
|
272
283
|
const faucetService = `${accessory.displayName} Faucet`;
|
|
273
|
-
(this.faucetService = accessory.getService(this.
|
|
274
|
-
|| accessory.addService(this.
|
|
284
|
+
(this.faucetService = accessory.getService(this.hap.Service.Faucet)
|
|
285
|
+
|| accessory.addService(this.hap.Service.Faucet)), faucetService;
|
|
275
286
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Faucet`);
|
|
276
287
|
|
|
277
|
-
this.faucetService.setCharacteristic(this.
|
|
278
|
-
if (!this.faucetService.testCharacteristic(this.
|
|
279
|
-
this.faucetService.addCharacteristic(this.
|
|
288
|
+
this.faucetService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
289
|
+
if (!this.faucetService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
290
|
+
this.faucetService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
280
291
|
}
|
|
281
|
-
this.faucetService.getCharacteristic(this.
|
|
292
|
+
this.faucetService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this));
|
|
282
293
|
} else if (this.botDeviceType === 'fan') {
|
|
283
294
|
this.removeLockService(accessory);
|
|
284
295
|
this.removeDoorService(accessory);
|
|
@@ -292,15 +303,15 @@ export class Bot {
|
|
|
292
303
|
|
|
293
304
|
// Add fanService
|
|
294
305
|
const fanService = `${accessory.displayName} Fan`;
|
|
295
|
-
(this.fanService = accessory.getService(this.
|
|
296
|
-
|| accessory.addService(this.
|
|
306
|
+
(this.fanService = accessory.getService(this.hap.Service.Fan)
|
|
307
|
+
|| accessory.addService(this.hap.Service.Fan)), fanService;
|
|
297
308
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Fan`);
|
|
298
309
|
|
|
299
|
-
this.fanService.setCharacteristic(this.
|
|
300
|
-
if (!this.fanService.testCharacteristic(this.
|
|
301
|
-
this.fanService.addCharacteristic(this.
|
|
310
|
+
this.fanService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
311
|
+
if (!this.fanService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
312
|
+
this.fanService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
302
313
|
}
|
|
303
|
-
this.fanService.getCharacteristic(this.
|
|
314
|
+
this.fanService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
304
315
|
} else if (this.botDeviceType === 'stateful') {
|
|
305
316
|
this.removeFanService(accessory);
|
|
306
317
|
this.removeLockService(accessory);
|
|
@@ -314,16 +325,16 @@ export class Bot {
|
|
|
314
325
|
|
|
315
326
|
// Add statefulProgrammableSwitchService
|
|
316
327
|
const statefulProgrammableSwitchService = `${accessory.displayName} Stateful Programmable Switch`;
|
|
317
|
-
(this.statefulProgrammableSwitchService = accessory.getService(this.
|
|
318
|
-
accessory.addService(this.
|
|
328
|
+
(this.statefulProgrammableSwitchService = accessory.getService(this.hap.Service.StatefulProgrammableSwitch) ||
|
|
329
|
+
accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), statefulProgrammableSwitchService;
|
|
319
330
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
|
|
320
331
|
|
|
321
|
-
this.statefulProgrammableSwitchService.setCharacteristic(this.
|
|
322
|
-
if (!this.statefulProgrammableSwitchService.testCharacteristic(this.
|
|
323
|
-
this.statefulProgrammableSwitchService.addCharacteristic(this.
|
|
332
|
+
this.statefulProgrammableSwitchService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
333
|
+
if (!this.statefulProgrammableSwitchService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
334
|
+
this.statefulProgrammableSwitchService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
324
335
|
}
|
|
325
336
|
this.statefulProgrammableSwitchService
|
|
326
|
-
.getCharacteristic(this.
|
|
337
|
+
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
327
338
|
.onSet(this.OnSet.bind(this));
|
|
328
339
|
} else {
|
|
329
340
|
this.removeFanService(accessory);
|
|
@@ -338,27 +349,27 @@ export class Bot {
|
|
|
338
349
|
|
|
339
350
|
// Add outletService
|
|
340
351
|
const outletService = `${accessory.displayName} Outlet`;
|
|
341
|
-
(this.outletService = accessory.getService(this.
|
|
342
|
-
|| accessory.addService(this.
|
|
352
|
+
(this.outletService = accessory.getService(this.hap.Service.Outlet)
|
|
353
|
+
|| accessory.addService(this.hap.Service.Outlet)), outletService;
|
|
343
354
|
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Outlet`);
|
|
344
355
|
|
|
345
|
-
this.outletService.setCharacteristic(this.
|
|
346
|
-
if (!this.outletService.testCharacteristic(this.
|
|
347
|
-
this.outletService.addCharacteristic(this.
|
|
356
|
+
this.outletService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
357
|
+
if (!this.outletService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
358
|
+
this.outletService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
348
359
|
}
|
|
349
|
-
this.outletService.getCharacteristic(this.
|
|
360
|
+
this.outletService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
350
361
|
}
|
|
351
362
|
|
|
352
363
|
// batteryService
|
|
353
364
|
const batteryService = `${accessory.displayName} Battery`;
|
|
354
|
-
(this.batteryService = this.accessory.getService(this.
|
|
355
|
-
|| accessory.addService(this.
|
|
365
|
+
(this.batteryService = this.accessory.getService(this.hap.Service.Battery)
|
|
366
|
+
|| accessory.addService(this.hap.Service.Battery)), batteryService;
|
|
356
367
|
|
|
357
|
-
this.batteryService.setCharacteristic(this.
|
|
358
|
-
if (!this.batteryService.testCharacteristic(this.
|
|
359
|
-
this.batteryService.addCharacteristic(this.
|
|
368
|
+
this.batteryService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
369
|
+
if (!this.batteryService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
370
|
+
this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
360
371
|
}
|
|
361
|
-
this.batteryService.setCharacteristic(this.
|
|
372
|
+
this.batteryService.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
362
373
|
|
|
363
374
|
// Retrieve initial values and updateHomekit
|
|
364
375
|
this.updateHomeKitCharacteristics();
|
|
@@ -379,16 +390,16 @@ export class Bot {
|
|
|
379
390
|
const { power, battery, deviceMode } = context;
|
|
380
391
|
const { On, BatteryLevel, botMode } = this;
|
|
381
392
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
393
|
+
'(power, battery, deviceMode) = ' +
|
|
394
|
+
`Webhook:(${power}, ${battery}, ${deviceMode}), ` +
|
|
395
|
+
`current:(${On}, ${BatteryLevel}, ${botMode})`);
|
|
385
396
|
this.On = power;
|
|
386
397
|
this.BatteryLevel = battery;
|
|
387
398
|
this.botMode = deviceMode;
|
|
388
399
|
this.updateHomeKitCharacteristics();
|
|
389
400
|
} catch (e: any) {
|
|
390
401
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
391
|
-
|
|
402
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
392
403
|
}
|
|
393
404
|
};
|
|
394
405
|
}
|
|
@@ -459,9 +470,9 @@ export class Bot {
|
|
|
459
470
|
|
|
460
471
|
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
461
472
|
if (this.BatteryLevel < 10) {
|
|
462
|
-
this.StatusLowBattery = this.
|
|
473
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
463
474
|
} else {
|
|
464
|
-
this.StatusLowBattery = this.
|
|
475
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
465
476
|
}
|
|
466
477
|
if (Number.isNaN(this.BatteryLevel)) {
|
|
467
478
|
this.BatteryLevel = 100;
|
|
@@ -486,9 +497,9 @@ export class Bot {
|
|
|
486
497
|
// Battery
|
|
487
498
|
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
488
499
|
if (this.BatteryLevel < 10) {
|
|
489
|
-
this.StatusLowBattery = this.
|
|
500
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
490
501
|
} else {
|
|
491
|
-
this.StatusLowBattery = this.
|
|
502
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
492
503
|
}
|
|
493
504
|
if (Number.isNaN(this.BatteryLevel)) {
|
|
494
505
|
this.BatteryLevel = 100;
|
|
@@ -670,9 +681,9 @@ export class Bot {
|
|
|
670
681
|
this.accessory.context.On = this.On;
|
|
671
682
|
setTimeout(() => {
|
|
672
683
|
if (this.botDeviceType === 'switch') {
|
|
673
|
-
this.switchService?.getCharacteristic(this.
|
|
684
|
+
this.switchService?.getCharacteristic(this.hap.Characteristic.On).updateValue(this.On);
|
|
674
685
|
} else {
|
|
675
|
-
this.outletService?.getCharacteristic(this.
|
|
686
|
+
this.outletService?.getCharacteristic(this.hap.Characteristic.On).updateValue(this.On);
|
|
676
687
|
}
|
|
677
688
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
|
|
678
689
|
}, 500);
|
|
@@ -803,7 +814,7 @@ export class Bot {
|
|
|
803
814
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
804
815
|
if (this.botDeviceType === 'garagedoor') {
|
|
805
816
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetDoorState: ${value}`);
|
|
806
|
-
if (value === this.
|
|
817
|
+
if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
|
|
807
818
|
this.On = false;
|
|
808
819
|
} else {
|
|
809
820
|
this.On = true;
|
|
@@ -821,14 +832,14 @@ export class Bot {
|
|
|
821
832
|
}
|
|
822
833
|
} else if (this.botDeviceType === 'lock') {
|
|
823
834
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set LockTargetState: ${value}`);
|
|
824
|
-
if (value === this.
|
|
835
|
+
if (value === this.hap.Characteristic.LockTargetState.SECURED) {
|
|
825
836
|
this.On = false;
|
|
826
837
|
} else {
|
|
827
838
|
this.On = true;
|
|
828
839
|
}
|
|
829
840
|
} else if (this.botDeviceType === 'faucet') {
|
|
830
841
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
831
|
-
if (value === this.
|
|
842
|
+
if (value === this.hap.Characteristic.Active.INACTIVE) {
|
|
832
843
|
this.On = false;
|
|
833
844
|
} else {
|
|
834
845
|
this.On = true;
|
|
@@ -864,24 +875,24 @@ export class Bot {
|
|
|
864
875
|
} else {
|
|
865
876
|
if (this.On) {
|
|
866
877
|
this.garageDoorService?.updateCharacteristic(
|
|
867
|
-
this.
|
|
868
|
-
this.
|
|
878
|
+
this.hap.Characteristic.TargetDoorState,
|
|
879
|
+
this.hap.Characteristic.TargetDoorState.OPEN,
|
|
869
880
|
);
|
|
870
881
|
this.garageDoorService?.updateCharacteristic(
|
|
871
|
-
this.
|
|
872
|
-
this.
|
|
882
|
+
this.hap.Characteristic.CurrentDoorState,
|
|
883
|
+
this.hap.Characteristic.CurrentDoorState.OPEN,
|
|
873
884
|
);
|
|
874
885
|
this.debugLog(
|
|
875
886
|
`${this.device.deviceType}: ` + `${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`,
|
|
876
887
|
);
|
|
877
888
|
} else {
|
|
878
889
|
this.garageDoorService?.updateCharacteristic(
|
|
879
|
-
this.
|
|
880
|
-
this.
|
|
890
|
+
this.hap.Characteristic.TargetDoorState,
|
|
891
|
+
this.hap.Characteristic.TargetDoorState.CLOSED,
|
|
881
892
|
);
|
|
882
893
|
this.garageDoorService?.updateCharacteristic(
|
|
883
|
-
this.
|
|
884
|
-
this.
|
|
894
|
+
this.hap.Characteristic.CurrentDoorState,
|
|
895
|
+
this.hap.Characteristic.CurrentDoorState.CLOSED,
|
|
885
896
|
);
|
|
886
897
|
this.debugLog(
|
|
887
898
|
`${this.device.deviceType}: ` + `${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`,
|
|
@@ -894,14 +905,14 @@ export class Bot {
|
|
|
894
905
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
895
906
|
} else {
|
|
896
907
|
if (this.On) {
|
|
897
|
-
this.doorService?.updateCharacteristic(this.
|
|
898
|
-
this.doorService?.updateCharacteristic(this.
|
|
899
|
-
this.doorService?.updateCharacteristic(this.
|
|
908
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
909
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
910
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
900
911
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
|
|
901
912
|
} else {
|
|
902
|
-
this.doorService?.updateCharacteristic(this.
|
|
903
|
-
this.doorService?.updateCharacteristic(this.
|
|
904
|
-
this.doorService?.updateCharacteristic(this.
|
|
913
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
914
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
915
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
905
916
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
|
|
906
917
|
}
|
|
907
918
|
}
|
|
@@ -911,14 +922,14 @@ export class Bot {
|
|
|
911
922
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
912
923
|
} else {
|
|
913
924
|
if (this.On) {
|
|
914
|
-
this.windowService?.updateCharacteristic(this.
|
|
915
|
-
this.windowService?.updateCharacteristic(this.
|
|
916
|
-
this.windowService?.updateCharacteristic(this.
|
|
925
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
926
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
927
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
917
928
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
|
|
918
929
|
} else {
|
|
919
|
-
this.windowService?.updateCharacteristic(this.
|
|
920
|
-
this.windowService?.updateCharacteristic(this.
|
|
921
|
-
this.windowService?.updateCharacteristic(this.
|
|
930
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
931
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
932
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
922
933
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
|
|
923
934
|
}
|
|
924
935
|
}
|
|
@@ -928,19 +939,19 @@ export class Bot {
|
|
|
928
939
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
929
940
|
} else {
|
|
930
941
|
if (this.On) {
|
|
931
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
932
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
942
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
943
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
933
944
|
this.windowCoveringService?.updateCharacteristic(
|
|
934
|
-
this.
|
|
935
|
-
this.
|
|
945
|
+
this.hap.Characteristic.PositionState,
|
|
946
|
+
this.hap.Characteristic.PositionState.STOPPED,
|
|
936
947
|
);
|
|
937
948
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
|
|
938
949
|
} else {
|
|
939
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
940
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
950
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
951
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
941
952
|
this.windowCoveringService?.updateCharacteristic(
|
|
942
|
-
this.
|
|
943
|
-
this.
|
|
953
|
+
this.hap.Characteristic.PositionState,
|
|
954
|
+
this.hap.Characteristic.PositionState.STOPPED,
|
|
944
955
|
);
|
|
945
956
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
|
|
946
957
|
}
|
|
@@ -952,22 +963,22 @@ export class Bot {
|
|
|
952
963
|
} else {
|
|
953
964
|
if (this.On) {
|
|
954
965
|
this.lockService?.updateCharacteristic(
|
|
955
|
-
this.
|
|
956
|
-
this.
|
|
966
|
+
this.hap.Characteristic.LockTargetState,
|
|
967
|
+
this.hap.Characteristic.LockTargetState.UNSECURED,
|
|
957
968
|
);
|
|
958
969
|
this.lockService?.updateCharacteristic(
|
|
959
|
-
this.
|
|
960
|
-
this.
|
|
970
|
+
this.hap.Characteristic.LockCurrentState,
|
|
971
|
+
this.hap.Characteristic.LockCurrentState.UNSECURED,
|
|
961
972
|
);
|
|
962
973
|
this.debugLog(
|
|
963
974
|
`${this.device.deviceType}: ` +
|
|
964
975
|
`${this.accessory.displayName} updateCharacteristic LockTargetState: UNSECURED, LockCurrentState: UNSECURED`,
|
|
965
976
|
);
|
|
966
977
|
} else {
|
|
967
|
-
this.lockService?.updateCharacteristic(this.
|
|
978
|
+
this.lockService?.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
|
|
968
979
|
this.lockService?.updateCharacteristic(
|
|
969
|
-
this.
|
|
970
|
-
this.
|
|
980
|
+
this.hap.Characteristic.LockCurrentState,
|
|
981
|
+
this.hap.Characteristic.LockCurrentState.SECURED,
|
|
971
982
|
);
|
|
972
983
|
this.debugLog(
|
|
973
984
|
`${this.device.deviceType}: ` + `${this.accessory.displayName} updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED`,
|
|
@@ -980,10 +991,10 @@ export class Bot {
|
|
|
980
991
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
981
992
|
} else {
|
|
982
993
|
if (this.On) {
|
|
983
|
-
this.faucetService?.updateCharacteristic(this.
|
|
994
|
+
this.faucetService?.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
|
|
984
995
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
|
|
985
996
|
} else {
|
|
986
|
-
this.faucetService?.updateCharacteristic(this.
|
|
997
|
+
this.faucetService?.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
987
998
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
|
|
988
999
|
}
|
|
989
1000
|
}
|
|
@@ -993,10 +1004,10 @@ export class Bot {
|
|
|
993
1004
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
994
1005
|
} else {
|
|
995
1006
|
if (this.On) {
|
|
996
|
-
this.fanService?.updateCharacteristic(this.
|
|
1007
|
+
this.fanService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
997
1008
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
998
1009
|
} else {
|
|
999
|
-
this.fanService?.updateCharacteristic(this.
|
|
1010
|
+
this.fanService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
1000
1011
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
1001
1012
|
}
|
|
1002
1013
|
}
|
|
@@ -1007,20 +1018,20 @@ export class Bot {
|
|
|
1007
1018
|
} else {
|
|
1008
1019
|
if (this.On) {
|
|
1009
1020
|
this.statefulProgrammableSwitchService?.updateCharacteristic(
|
|
1010
|
-
this.
|
|
1011
|
-
this.
|
|
1021
|
+
this.hap.Characteristic.ProgrammableSwitchEvent,
|
|
1022
|
+
this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
|
|
1012
1023
|
);
|
|
1013
|
-
this.statefulProgrammableSwitchService?.updateCharacteristic(this.
|
|
1024
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
|
|
1014
1025
|
this.debugLog(
|
|
1015
1026
|
`${this.device.deviceType}: ` +
|
|
1016
1027
|
`${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1`,
|
|
1017
1028
|
);
|
|
1018
1029
|
} else {
|
|
1019
1030
|
this.statefulProgrammableSwitchService?.updateCharacteristic(
|
|
1020
|
-
this.
|
|
1021
|
-
this.
|
|
1031
|
+
this.hap.Characteristic.ProgrammableSwitchEvent,
|
|
1032
|
+
this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
|
|
1022
1033
|
);
|
|
1023
|
-
this.statefulProgrammableSwitchService?.updateCharacteristic(this.
|
|
1034
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
|
|
1024
1035
|
this.debugLog(
|
|
1025
1036
|
`${this.device.deviceType}: ` +
|
|
1026
1037
|
`${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0`,
|
|
@@ -1032,14 +1043,14 @@ export class Bot {
|
|
|
1032
1043
|
if (this.On === undefined) {
|
|
1033
1044
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
1034
1045
|
} else {
|
|
1035
|
-
this.switchService?.updateCharacteristic(this.
|
|
1046
|
+
this.switchService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
1036
1047
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
1037
1048
|
}
|
|
1038
1049
|
} else {
|
|
1039
1050
|
if (this.On === undefined) {
|
|
1040
1051
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
1041
1052
|
} else {
|
|
1042
|
-
this.outletService?.updateCharacteristic(this.
|
|
1053
|
+
this.outletService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
1043
1054
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
1044
1055
|
}
|
|
1045
1056
|
}
|
|
@@ -1049,7 +1060,7 @@ export class Bot {
|
|
|
1049
1060
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
1050
1061
|
} else {
|
|
1051
1062
|
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
1052
|
-
this.batteryService?.updateCharacteristic(this.
|
|
1063
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
1053
1064
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
1054
1065
|
}
|
|
1055
1066
|
// StatusLowBattery
|
|
@@ -1057,14 +1068,14 @@ export class Bot {
|
|
|
1057
1068
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
1058
1069
|
} else {
|
|
1059
1070
|
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
1060
|
-
this.batteryService?.updateCharacteristic(this.
|
|
1071
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
1061
1072
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
1062
1073
|
}
|
|
1063
1074
|
}
|
|
1064
1075
|
|
|
1065
1076
|
async removeOutletService(accessory: PlatformAccessory): Promise<void> {
|
|
1066
1077
|
// If outletService still pressent, then remove first
|
|
1067
|
-
this.outletService = this.accessory.getService(this.
|
|
1078
|
+
this.outletService = this.accessory.getService(this.hap.Service.Outlet);
|
|
1068
1079
|
if (this.outletService) {
|
|
1069
1080
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Outlet Service`);
|
|
1070
1081
|
}
|
|
@@ -1073,7 +1084,7 @@ export class Bot {
|
|
|
1073
1084
|
|
|
1074
1085
|
async removeGarageDoorService(accessory: PlatformAccessory): Promise<void> {
|
|
1075
1086
|
// If garageDoorService still pressent, then remove first
|
|
1076
|
-
this.garageDoorService = this.accessory.getService(this.
|
|
1087
|
+
this.garageDoorService = this.accessory.getService(this.hap.Service.GarageDoorOpener);
|
|
1077
1088
|
if (this.garageDoorService) {
|
|
1078
1089
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Garage Door Service`);
|
|
1079
1090
|
}
|
|
@@ -1082,7 +1093,7 @@ export class Bot {
|
|
|
1082
1093
|
|
|
1083
1094
|
async removeDoorService(accessory: PlatformAccessory): Promise<void> {
|
|
1084
1095
|
// If doorService still pressent, then remove first
|
|
1085
|
-
this.doorService = this.accessory.getService(this.
|
|
1096
|
+
this.doorService = this.accessory.getService(this.hap.Service.Door);
|
|
1086
1097
|
if (this.doorService) {
|
|
1087
1098
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Door Service`);
|
|
1088
1099
|
}
|
|
@@ -1091,7 +1102,7 @@ export class Bot {
|
|
|
1091
1102
|
|
|
1092
1103
|
async removeLockService(accessory: PlatformAccessory): Promise<void> {
|
|
1093
1104
|
// If lockService still pressent, then remove first
|
|
1094
|
-
this.lockService = this.accessory.getService(this.
|
|
1105
|
+
this.lockService = this.accessory.getService(this.hap.Service.LockMechanism);
|
|
1095
1106
|
if (this.lockService) {
|
|
1096
1107
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Lock Service`);
|
|
1097
1108
|
}
|
|
@@ -1100,7 +1111,7 @@ export class Bot {
|
|
|
1100
1111
|
|
|
1101
1112
|
async removeFaucetService(accessory: PlatformAccessory): Promise<void> {
|
|
1102
1113
|
// If faucetService still pressent, then remove first
|
|
1103
|
-
this.faucetService = this.accessory.getService(this.
|
|
1114
|
+
this.faucetService = this.accessory.getService(this.hap.Service.Faucet);
|
|
1104
1115
|
if (this.faucetService) {
|
|
1105
1116
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Faucet Service`);
|
|
1106
1117
|
}
|
|
@@ -1109,7 +1120,7 @@ export class Bot {
|
|
|
1109
1120
|
|
|
1110
1121
|
async removeFanService(accessory: PlatformAccessory): Promise<void> {
|
|
1111
1122
|
// If fanService still pressent, then remove first
|
|
1112
|
-
this.fanService = this.accessory.getService(this.
|
|
1123
|
+
this.fanService = this.accessory.getService(this.hap.Service.Fan);
|
|
1113
1124
|
if (this.fanService) {
|
|
1114
1125
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Fan Service`);
|
|
1115
1126
|
}
|
|
@@ -1118,7 +1129,7 @@ export class Bot {
|
|
|
1118
1129
|
|
|
1119
1130
|
async removeWindowService(accessory: PlatformAccessory): Promise<void> {
|
|
1120
1131
|
// If windowService still pressent, then remove first
|
|
1121
|
-
this.windowService = this.accessory.getService(this.
|
|
1132
|
+
this.windowService = this.accessory.getService(this.hap.Service.Window);
|
|
1122
1133
|
if (this.windowService) {
|
|
1123
1134
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Window Service`);
|
|
1124
1135
|
}
|
|
@@ -1127,7 +1138,7 @@ export class Bot {
|
|
|
1127
1138
|
|
|
1128
1139
|
async removeWindowCoveringService(accessory: PlatformAccessory): Promise<void> {
|
|
1129
1140
|
// If windowCoveringService still pressent, then remove first
|
|
1130
|
-
this.windowCoveringService = this.accessory.getService(this.
|
|
1141
|
+
this.windowCoveringService = this.accessory.getService(this.hap.Service.WindowCovering);
|
|
1131
1142
|
if (this.windowCoveringService) {
|
|
1132
1143
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Window Covering Service`);
|
|
1133
1144
|
}
|
|
@@ -1136,7 +1147,7 @@ export class Bot {
|
|
|
1136
1147
|
|
|
1137
1148
|
async removeStatefulProgrammableSwitchService(accessory: PlatformAccessory): Promise<void> {
|
|
1138
1149
|
// If statefulProgrammableSwitchService still pressent, then remove first
|
|
1139
|
-
this.statefulProgrammableSwitchService = this.accessory.getService(this.
|
|
1150
|
+
this.statefulProgrammableSwitchService = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch);
|
|
1140
1151
|
if (this.statefulProgrammableSwitchService) {
|
|
1141
1152
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
|
|
1142
1153
|
}
|
|
@@ -1145,7 +1156,7 @@ export class Bot {
|
|
|
1145
1156
|
|
|
1146
1157
|
async removeSwitchService(accessory: PlatformAccessory): Promise<void> {
|
|
1147
1158
|
// If switchService still pressent, then remove first
|
|
1148
|
-
this.switchService = this.accessory.getService(this.
|
|
1159
|
+
this.switchService = this.accessory.getService(this.hap.Service.Switch);
|
|
1149
1160
|
if (this.switchService) {
|
|
1150
1161
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Switch Service`);
|
|
1151
1162
|
}
|
|
@@ -1317,38 +1328,38 @@ export class Bot {
|
|
|
1317
1328
|
|
|
1318
1329
|
async apiError(e: any): Promise<void> {
|
|
1319
1330
|
if (this.botDeviceType === 'garagedoor') {
|
|
1320
|
-
this.garageDoorService?.updateCharacteristic(this.
|
|
1321
|
-
this.garageDoorService?.updateCharacteristic(this.
|
|
1322
|
-
this.garageDoorService?.updateCharacteristic(this.
|
|
1331
|
+
this.garageDoorService?.updateCharacteristic(this.hap.Characteristic.TargetDoorState, e);
|
|
1332
|
+
this.garageDoorService?.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, e);
|
|
1333
|
+
this.garageDoorService?.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, e);
|
|
1323
1334
|
} else if (this.botDeviceType === 'door') {
|
|
1324
|
-
this.doorService?.updateCharacteristic(this.
|
|
1325
|
-
this.doorService?.updateCharacteristic(this.
|
|
1326
|
-
this.doorService?.updateCharacteristic(this.
|
|
1335
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
1336
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
1337
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
1327
1338
|
} else if (this.botDeviceType === 'window') {
|
|
1328
|
-
this.windowService?.updateCharacteristic(this.
|
|
1329
|
-
this.windowService?.updateCharacteristic(this.
|
|
1330
|
-
this.windowService?.updateCharacteristic(this.
|
|
1339
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
1340
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
1341
|
+
this.windowService?.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
1331
1342
|
} else if (this.botDeviceType === 'windowcovering') {
|
|
1332
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
1333
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
1334
|
-
this.windowCoveringService?.updateCharacteristic(this.
|
|
1343
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
1344
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
1345
|
+
this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
1335
1346
|
} else if (this.botDeviceType === 'lock') {
|
|
1336
|
-
this.doorService?.updateCharacteristic(this.
|
|
1337
|
-
this.doorService?.updateCharacteristic(this.
|
|
1347
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.LockTargetState, e);
|
|
1348
|
+
this.doorService?.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e);
|
|
1338
1349
|
} else if (this.botDeviceType === 'faucet') {
|
|
1339
|
-
this.faucetService?.updateCharacteristic(this.
|
|
1350
|
+
this.faucetService?.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
1340
1351
|
} else if (this.botDeviceType === 'fan') {
|
|
1341
|
-
this.fanService?.updateCharacteristic(this.
|
|
1352
|
+
this.fanService?.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
1342
1353
|
} else if (this.botDeviceType === 'stateful') {
|
|
1343
|
-
this.statefulProgrammableSwitchService?.updateCharacteristic(this.
|
|
1344
|
-
this.statefulProgrammableSwitchService?.updateCharacteristic(this.
|
|
1354
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
|
|
1355
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
1345
1356
|
} else if (this.botDeviceType === 'switch') {
|
|
1346
|
-
this.switchService?.updateCharacteristic(this.
|
|
1357
|
+
this.switchService?.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
1347
1358
|
} else {
|
|
1348
|
-
this.outletService?.updateCharacteristic(this.
|
|
1359
|
+
this.outletService?.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
1349
1360
|
}
|
|
1350
|
-
this.batteryService?.updateCharacteristic(this.
|
|
1351
|
-
this.batteryService?.updateCharacteristic(this.
|
|
1361
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
1362
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
1352
1363
|
}
|
|
1353
1364
|
|
|
1354
1365
|
async deviceType(device: device & devicesConfig): Promise<void> {
|
|
@@ -1380,7 +1391,7 @@ export class Bot {
|
|
|
1380
1391
|
this.BatteryLevel = this.accessory.context.BatteryLevel;
|
|
1381
1392
|
}
|
|
1382
1393
|
if (this.StatusLowBattery === undefined) {
|
|
1383
|
-
this.StatusLowBattery = this.
|
|
1394
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
1384
1395
|
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
1385
1396
|
} else {
|
|
1386
1397
|
this.StatusLowBattery = this.accessory.context.StatusLowBattery;
|
|
@@ -1409,7 +1420,7 @@ export class Bot {
|
|
|
1409
1420
|
}
|
|
1410
1421
|
}
|
|
1411
1422
|
|
|
1412
|
-
async
|
|
1423
|
+
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
1413
1424
|
let config = {};
|
|
1414
1425
|
if (device.bot) {
|
|
1415
1426
|
config = device.bot;
|
|
@@ -1440,7 +1451,7 @@ export class Bot {
|
|
|
1440
1451
|
}
|
|
1441
1452
|
}
|
|
1442
1453
|
|
|
1443
|
-
async
|
|
1454
|
+
async deviceLogs(device: device & devicesConfig): Promise<void> {
|
|
1444
1455
|
if (this.platform.debugMode) {
|
|
1445
1456
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
1446
1457
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|