@switchbot/homebridge-switchbot 3.6.1-beta.0 → 3.6.1-beta.2
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 +11 -0
- package/config.schema.json +11 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +36 -18
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -2
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +186 -396
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +36 -19
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +36 -19
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +36 -19
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +37 -18
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.js +2 -2
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +36 -19
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +36 -17
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +36 -17
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +36 -17
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +36 -17
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +37 -18
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +36 -17
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +36 -17
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +36 -17
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +37 -18
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +36 -17
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +36 -17
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -0
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +186 -228
- package/dist/irdevice/other.js.map +1 -1
- package/dist/platform.d.ts +4 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +32 -0
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +3 -3
- package/src/device/blindtilt.ts +33 -18
- package/src/device/bot.ts +179 -406
- package/src/device/ceilinglight.ts +33 -20
- package/src/device/colorbulb.ts +33 -20
- package/src/device/contact.ts +33 -20
- package/src/device/curtain.ts +34 -18
- package/src/device/device.ts +2 -2
- package/src/device/fan.ts +33 -20
- package/src/device/hub.ts +33 -17
- package/src/device/humidifier.ts +33 -17
- package/src/device/iosensor.ts +33 -17
- package/src/device/lightstrip.ts +33 -17
- package/src/device/lock.ts +34 -18
- package/src/device/meter.ts +33 -17
- package/src/device/meterplus.ts +33 -17
- package/src/device/motion.ts +33 -17
- package/src/device/plug.ts +34 -18
- package/src/device/robotvacuumcleaner.ts +33 -17
- package/src/device/waterdetector.ts +33 -17
- package/src/irdevice/other.ts +214 -283
- package/src/platform.ts +30 -0
- package/src/settings.ts +1 -0
package/src/device/bot.ts
CHANGED
|
@@ -31,63 +31,55 @@ export class Bot extends deviceBase {
|
|
|
31
31
|
private Switch?: {
|
|
32
32
|
Name: CharacteristicValue;
|
|
33
33
|
Service: Service;
|
|
34
|
-
On: CharacteristicValue;
|
|
35
34
|
};
|
|
36
35
|
|
|
37
36
|
private GarageDoor?: {
|
|
38
37
|
Name: CharacteristicValue;
|
|
39
38
|
Service: Service;
|
|
40
|
-
On: CharacteristicValue;
|
|
41
39
|
};
|
|
42
40
|
|
|
43
41
|
private Door?: {
|
|
44
42
|
Name: CharacteristicValue;
|
|
45
43
|
Service: Service;
|
|
46
|
-
On: CharacteristicValue;
|
|
47
44
|
};
|
|
48
45
|
|
|
49
46
|
private Window?: {
|
|
50
47
|
Name: CharacteristicValue;
|
|
51
48
|
Service: Service;
|
|
52
|
-
On: CharacteristicValue;
|
|
53
49
|
};
|
|
54
50
|
|
|
55
51
|
private WindowCovering?: {
|
|
56
52
|
Name: CharacteristicValue;
|
|
57
53
|
Service: Service;
|
|
58
|
-
On: CharacteristicValue;
|
|
59
54
|
};
|
|
60
55
|
|
|
61
56
|
private LockMechanism?: {
|
|
62
57
|
Name: CharacteristicValue;
|
|
63
58
|
Service: Service;
|
|
64
|
-
On: CharacteristicValue;
|
|
65
59
|
};
|
|
66
60
|
|
|
67
61
|
private Faucet?: {
|
|
68
62
|
Name: CharacteristicValue;
|
|
69
63
|
Service: Service;
|
|
70
|
-
On: CharacteristicValue;
|
|
71
64
|
};
|
|
72
65
|
|
|
73
66
|
private Fan?: {
|
|
74
67
|
Name: CharacteristicValue;
|
|
75
68
|
Service: Service;
|
|
76
|
-
On: CharacteristicValue;
|
|
77
69
|
};
|
|
78
70
|
|
|
79
71
|
private StatefulProgrammableSwitch?: {
|
|
80
72
|
Name: CharacteristicValue;
|
|
81
73
|
Service: Service;
|
|
82
|
-
On: CharacteristicValue;
|
|
83
74
|
};
|
|
84
75
|
|
|
85
76
|
private Outlet?: {
|
|
86
77
|
Name: CharacteristicValue;
|
|
87
78
|
Service: Service;
|
|
88
|
-
On: CharacteristicValue;
|
|
89
79
|
};
|
|
90
80
|
|
|
81
|
+
On!: boolean;
|
|
82
|
+
|
|
91
83
|
// OpenAPI
|
|
92
84
|
deviceStatus!: botStatus;
|
|
93
85
|
|
|
@@ -132,7 +124,6 @@ export class Bot extends deviceBase {
|
|
|
132
124
|
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
133
125
|
};
|
|
134
126
|
accessory.context.Battery = this.Battery as object;
|
|
135
|
-
|
|
136
127
|
// Initialize Battery Characteristics
|
|
137
128
|
this.Battery.Service
|
|
138
129
|
.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
|
|
@@ -142,28 +133,20 @@ export class Bot extends deviceBase {
|
|
|
142
133
|
// deviceType
|
|
143
134
|
if (this.botDeviceType === 'switch') {
|
|
144
135
|
// Set category
|
|
145
|
-
accessory.category = this.hap.Categories.SWITCH
|
|
146
|
-
;
|
|
136
|
+
accessory.category = this.hap.Categories.SWITCH;
|
|
147
137
|
// Initialize Switch Service
|
|
148
138
|
accessory.context.Switch = accessory.context.Switch ?? {};
|
|
149
139
|
this.Switch = {
|
|
150
140
|
Name: accessory.context.Switch.Name ?? accessory.displayName,
|
|
151
141
|
Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
|
|
152
|
-
On: accessory.context.On ?? false,
|
|
153
142
|
};
|
|
154
143
|
accessory.context.Switch = this.Switch as object;
|
|
155
144
|
this.debugLog('Displaying as Switch');
|
|
156
|
-
|
|
157
145
|
// Initialize Switch Characteristics
|
|
158
146
|
this.Switch.Service
|
|
159
147
|
.setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
|
|
160
|
-
.setCharacteristic(this.hap.Characteristic.On, this.Switch.On)
|
|
161
148
|
.getCharacteristic(this.hap.Characteristic.On)
|
|
162
|
-
.onGet(() => {
|
|
163
|
-
return this.Switch!.On;
|
|
164
|
-
})
|
|
165
149
|
.onSet(this.OnSet.bind(this));
|
|
166
|
-
|
|
167
150
|
// Remove other services
|
|
168
151
|
this.removeFanService(accessory);
|
|
169
152
|
this.removeLockService(accessory);
|
|
@@ -177,32 +160,26 @@ export class Bot extends deviceBase {
|
|
|
177
160
|
} else if (this.botDeviceType === 'garagedoor') {
|
|
178
161
|
// Set category
|
|
179
162
|
accessory.category = this.hap.Categories.GARAGE_DOOR_OPENER;
|
|
180
|
-
|
|
181
163
|
// Initialize GarageDoor Service
|
|
182
164
|
accessory.context.GarageDoor = accessory.context.GarageDoor ?? {};
|
|
183
165
|
this.GarageDoor = {
|
|
184
166
|
Name: accessory.context.GarageDoor.Name ?? accessory.displayName,
|
|
185
167
|
Service: accessory.getService(this.hap.Service.GarageDoorOpener) ?? accessory.addService(this.hap.Service.GarageDoorOpener) as Service,
|
|
186
|
-
On: accessory.context.On ?? false,
|
|
187
168
|
};
|
|
188
169
|
accessory.context.GarageDoor = this.GarageDoor as object;
|
|
189
170
|
this.debugLog('Displaying as Garage Door Opener');
|
|
190
|
-
|
|
191
171
|
// Initialize GarageDoor Characteristics
|
|
192
172
|
this.GarageDoor.Service
|
|
193
173
|
.setCharacteristic(this.hap.Characteristic.Name, this.GarageDoor.Name)
|
|
194
174
|
.setCharacteristic(this.hap.Characteristic.ObstructionDetected, false)
|
|
195
|
-
.getCharacteristic(this.hap.Characteristic.TargetDoorState)
|
|
175
|
+
.getCharacteristic(this.hap.Characteristic.TargetDoorState)
|
|
176
|
+
.setProps({
|
|
196
177
|
validValues: [0, 100],
|
|
197
178
|
minValue: 0,
|
|
198
179
|
maxValue: 100,
|
|
199
180
|
minStep: 100,
|
|
200
181
|
})
|
|
201
|
-
.onGet(() => {
|
|
202
|
-
return this.GarageDoor!.On;
|
|
203
|
-
})
|
|
204
182
|
.onSet(this.OnSet.bind(this));
|
|
205
|
-
|
|
206
183
|
// Remove other services
|
|
207
184
|
this.removeFanService(accessory);
|
|
208
185
|
this.removeLockService(accessory);
|
|
@@ -216,17 +193,14 @@ export class Bot extends deviceBase {
|
|
|
216
193
|
} else if (this.botDeviceType === 'door') {
|
|
217
194
|
// Set category
|
|
218
195
|
accessory.category = this.hap.Categories.DOOR;
|
|
219
|
-
|
|
220
196
|
// Initialize Door Service
|
|
221
197
|
accessory.context.Door = accessory.context.Door ?? {};
|
|
222
198
|
this.Door = {
|
|
223
199
|
Name: accessory.context.Door.Name ?? accessory.displayName,
|
|
224
200
|
Service: accessory.getService(this.hap.Service.Door) ?? accessory.addService(this.hap.Service.Door) as Service,
|
|
225
|
-
On: accessory.context.On ?? false,
|
|
226
201
|
};
|
|
227
202
|
accessory.context.Door = this.Door as object;
|
|
228
203
|
this.debugLog('Displaying as Door');
|
|
229
|
-
|
|
230
204
|
// Initialize Door Characteristics
|
|
231
205
|
this.Door.Service
|
|
232
206
|
.setCharacteristic(this.hap.Characteristic.Name, this.Door.Name)
|
|
@@ -237,11 +211,7 @@ export class Bot extends deviceBase {
|
|
|
237
211
|
maxValue: 100,
|
|
238
212
|
minStep: 100,
|
|
239
213
|
})
|
|
240
|
-
.onGet(() => {
|
|
241
|
-
return this.Door!.On;
|
|
242
|
-
})
|
|
243
214
|
.onSet(this.OnSet.bind(this));
|
|
244
|
-
|
|
245
215
|
// Remove other services
|
|
246
216
|
this.removeFanService(accessory);
|
|
247
217
|
this.removeLockService(accessory);
|
|
@@ -255,17 +225,14 @@ export class Bot extends deviceBase {
|
|
|
255
225
|
} else if (this.botDeviceType === 'window') {
|
|
256
226
|
// Set category
|
|
257
227
|
accessory.category = this.hap.Categories.WINDOW;
|
|
258
|
-
|
|
259
228
|
// Initialize Window Service
|
|
260
229
|
accessory.context.Window = accessory.context.Window ?? {};
|
|
261
230
|
this.Window = {
|
|
262
231
|
Name: accessory.context.Window.Name ?? accessory.displayName,
|
|
263
232
|
Service: accessory.getService(this.hap.Service.Window) ?? accessory.addService(this.hap.Service.Window) as Service,
|
|
264
|
-
On: accessory.context.On ?? false,
|
|
265
233
|
};
|
|
266
234
|
accessory.context.Window = this.Window as object;
|
|
267
235
|
this.debugLog('Displaying as Window');
|
|
268
|
-
|
|
269
236
|
// Initialize Window Characteristics
|
|
270
237
|
this.Window.Service
|
|
271
238
|
.setCharacteristic(this.hap.Characteristic.Name, this.Window.Name)
|
|
@@ -276,11 +243,7 @@ export class Bot extends deviceBase {
|
|
|
276
243
|
maxValue: 100,
|
|
277
244
|
minStep: 100,
|
|
278
245
|
})
|
|
279
|
-
.onGet(() => {
|
|
280
|
-
return this.Window!.On;
|
|
281
|
-
})
|
|
282
246
|
.onSet(this.OnSet.bind(this));
|
|
283
|
-
|
|
284
247
|
// Remove other services
|
|
285
248
|
this.removeFanService(accessory);
|
|
286
249
|
this.removeLockService(accessory);
|
|
@@ -294,32 +257,26 @@ export class Bot extends deviceBase {
|
|
|
294
257
|
} else if (this.botDeviceType === 'windowcovering') {
|
|
295
258
|
// Set category
|
|
296
259
|
accessory.category = this.hap.Categories.WINDOW_COVERING;
|
|
297
|
-
|
|
298
260
|
// Initialize WindowCovering Service
|
|
299
261
|
accessory.context.WindowCovering = accessory.context.WindowCovering ?? {};
|
|
300
262
|
this.WindowCovering = {
|
|
301
263
|
Name: accessory.context.WindowCovering.Name ?? accessory.displayName,
|
|
302
264
|
Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering) as Service,
|
|
303
|
-
On: accessory.context.On ?? false,
|
|
304
265
|
};
|
|
305
266
|
accessory.context.WindowCovering = this.WindowCovering as object;
|
|
306
267
|
this.debugLog('Displaying as Window Covering');
|
|
307
|
-
|
|
308
268
|
// Initialize WindowCovering Characteristics
|
|
309
269
|
this.WindowCovering.Service
|
|
310
270
|
.setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name)
|
|
311
271
|
.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
312
|
-
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
272
|
+
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
273
|
+
.setProps({
|
|
313
274
|
validValues: [0, 100],
|
|
314
275
|
minValue: 0,
|
|
315
276
|
maxValue: 100,
|
|
316
277
|
minStep: 100,
|
|
317
278
|
})
|
|
318
|
-
.onGet(() => {
|
|
319
|
-
return this.WindowCovering!.On;
|
|
320
|
-
})
|
|
321
279
|
.onSet(this.OnSet.bind(this));
|
|
322
|
-
|
|
323
280
|
// Remove other services
|
|
324
281
|
this.removeFanService(accessory);
|
|
325
282
|
this.removeLockService(accessory);
|
|
@@ -333,26 +290,20 @@ export class Bot extends deviceBase {
|
|
|
333
290
|
} else if (this.botDeviceType === 'lock') {
|
|
334
291
|
// Set category
|
|
335
292
|
accessory.category = this.hap.Categories.DOOR_LOCK;
|
|
336
|
-
|
|
337
293
|
// Initialize Lock Service
|
|
338
294
|
accessory.context.LockMechanism = accessory.context.LockMechanism ?? {};
|
|
339
295
|
this.LockMechanism = {
|
|
340
296
|
Name: accessory.context.LockMechanism.Name ?? accessory.displayName,
|
|
341
297
|
Service: accessory.getService(this.hap.Service.LockMechanism) ?? accessory.addService(this.hap.Service.LockMechanism) as Service,
|
|
342
|
-
On: accessory.context.On ?? false,
|
|
343
298
|
};
|
|
344
299
|
accessory.context.LockMechanism = this.LockMechanism as object;
|
|
345
300
|
this.debugLog('Displaying as Lock');
|
|
346
|
-
|
|
347
301
|
// Initialize Lock Characteristics
|
|
348
302
|
this.LockMechanism.Service
|
|
349
303
|
.setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name)
|
|
304
|
+
.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
350
305
|
.getCharacteristic(this.hap.Characteristic.LockTargetState)
|
|
351
|
-
.onGet(() => {
|
|
352
|
-
return this.LockMechanism!.On;
|
|
353
|
-
})
|
|
354
306
|
.onSet(this.OnSet.bind(this));
|
|
355
|
-
|
|
356
307
|
// Remove other services
|
|
357
308
|
this.removeFanService(accessory);
|
|
358
309
|
this.removeDoorService(accessory);
|
|
@@ -366,26 +317,19 @@ export class Bot extends deviceBase {
|
|
|
366
317
|
} else if (this.botDeviceType === 'faucet') {
|
|
367
318
|
// Set category
|
|
368
319
|
accessory.category = this.hap.Categories.FAUCET;
|
|
369
|
-
|
|
370
320
|
// Initialize Faucet Service
|
|
371
321
|
accessory.context.Faucet = accessory.context.Faucet ?? {};
|
|
372
322
|
this.Faucet = {
|
|
373
323
|
Name: accessory.context.Faucet.Name ?? accessory.displayName,
|
|
374
324
|
Service: accessory.getService(this.hap.Service.Faucet) ?? accessory.addService(this.hap.Service.Faucet) as Service,
|
|
375
|
-
On: accessory.context.On ?? false,
|
|
376
325
|
};
|
|
377
326
|
accessory.context.Faucet = this.Faucet as object;
|
|
378
327
|
this.debugLog('Displaying as Faucet');
|
|
379
|
-
|
|
380
328
|
// Initialize Faucet Characteristics
|
|
381
329
|
this.Faucet.Service
|
|
382
330
|
.setCharacteristic(this.hap.Characteristic.Name, this.Faucet.Name)
|
|
383
331
|
.getCharacteristic(this.hap.Characteristic.Active)
|
|
384
|
-
.onGet(() => {
|
|
385
|
-
return this.Faucet!.On;
|
|
386
|
-
})
|
|
387
332
|
.onSet(this.OnSet.bind(this));
|
|
388
|
-
|
|
389
333
|
// Remove other services
|
|
390
334
|
this.removeFanService(accessory);
|
|
391
335
|
this.removeLockService(accessory);
|
|
@@ -399,26 +343,19 @@ export class Bot extends deviceBase {
|
|
|
399
343
|
} else if (this.botDeviceType === 'fan') {
|
|
400
344
|
// Set category
|
|
401
345
|
accessory.category = this.hap.Categories.FAN;
|
|
402
|
-
|
|
403
346
|
// Initialize Fan Service
|
|
404
347
|
accessory.context.Fan = accessory.context.Fan ?? {};
|
|
405
348
|
this.Fan = {
|
|
406
349
|
Name: accessory.context.Fan.Name ?? accessory.displayName,
|
|
407
350
|
Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2) as Service,
|
|
408
|
-
On: accessory.context.On ?? false,
|
|
409
351
|
};
|
|
410
352
|
accessory.context.Fan = this.Fan as object;
|
|
411
353
|
this.debugLog('Displaying as Fan');
|
|
412
|
-
|
|
413
354
|
// Initialize Fan Characteristics
|
|
414
355
|
this.Fan.Service
|
|
415
356
|
.setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name)
|
|
416
|
-
.getCharacteristic(this.hap.Characteristic.
|
|
417
|
-
.onGet(() => {
|
|
418
|
-
return this.Fan!.On;
|
|
419
|
-
})
|
|
357
|
+
.getCharacteristic(this.hap.Characteristic.Active)
|
|
420
358
|
.onSet(this.OnSet.bind(this));
|
|
421
|
-
|
|
422
359
|
// Remove other services
|
|
423
360
|
this.removeLockService(accessory);
|
|
424
361
|
this.removeDoorService(accessory);
|
|
@@ -432,27 +369,20 @@ export class Bot extends deviceBase {
|
|
|
432
369
|
} else if (this.botDeviceType === 'stateful') {
|
|
433
370
|
// Set category
|
|
434
371
|
accessory.category = this.hap.Categories.PROGRAMMABLE_SWITCH;
|
|
435
|
-
|
|
436
372
|
// Initialize StatefulProgrammableSwitch Service
|
|
437
373
|
accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {};
|
|
438
374
|
this.StatefulProgrammableSwitch = {
|
|
439
375
|
Name: accessory.context.StatefulProgrammableSwitch.Name ?? accessory.displayName,
|
|
440
376
|
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
441
377
|
?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
|
|
442
|
-
On: accessory.context.On ?? false,
|
|
443
378
|
};
|
|
444
379
|
accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object;
|
|
445
380
|
this.debugLog('Displaying as Stateful Programmable Switch');
|
|
446
|
-
|
|
447
381
|
// Initialize StatefulProgrammableSwitch Characteristics
|
|
448
382
|
this.StatefulProgrammableSwitch.Service
|
|
449
383
|
.setCharacteristic(this.hap.Characteristic.Name, this.StatefulProgrammableSwitch.Name)
|
|
450
384
|
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
451
|
-
.onGet(() => {
|
|
452
|
-
return this.StatefulProgrammableSwitch!.On;
|
|
453
|
-
})
|
|
454
385
|
.onSet(this.OnSet.bind(this));
|
|
455
|
-
|
|
456
386
|
// Remove other services
|
|
457
387
|
this.removeFanService(accessory);
|
|
458
388
|
this.removeLockService(accessory);
|
|
@@ -463,29 +393,22 @@ export class Bot extends deviceBase {
|
|
|
463
393
|
this.removeWindowService(accessory);
|
|
464
394
|
this.removeGarageDoorService(accessory);
|
|
465
395
|
this.removeWindowCoveringService(accessory);
|
|
466
|
-
} else {
|
|
396
|
+
} else if (this.botDeviceType === 'outlet') {
|
|
467
397
|
// Set category
|
|
468
398
|
accessory.category = this.hap.Categories.OUTLET;
|
|
469
|
-
|
|
470
399
|
// Initialize Switch property
|
|
471
400
|
accessory.context.Outlet = accessory.context.Outlet ?? {};
|
|
472
401
|
this.Outlet = {
|
|
473
402
|
Name: accessory.context.Outlet.Name ?? accessory.displayName,
|
|
474
403
|
Service: accessory.getService(this.hap.Service.Outlet) ?? accessory.addService(this.hap.Service.Outlet) as Service,
|
|
475
|
-
On: accessory.context.On ?? false,
|
|
476
404
|
};
|
|
477
405
|
accessory.context.Outlet = this.Outlet as object;
|
|
478
406
|
this.debugLog('Displaying as Outlet');
|
|
479
|
-
|
|
480
407
|
// Initialize Outlet Characteristics
|
|
481
408
|
this.Outlet.Service
|
|
482
409
|
.setCharacteristic(this.hap.Characteristic.Name, this.Outlet.Name)
|
|
483
410
|
.getCharacteristic(this.hap.Characteristic.On)
|
|
484
|
-
.onGet(() => {
|
|
485
|
-
return this.Outlet!.On;
|
|
486
|
-
})
|
|
487
411
|
.onSet(this.OnSet.bind(this));
|
|
488
|
-
|
|
489
412
|
// Remove other services
|
|
490
413
|
this.removeFanService(accessory);
|
|
491
414
|
this.removeLockService(accessory);
|
|
@@ -496,6 +419,8 @@ export class Bot extends deviceBase {
|
|
|
496
419
|
this.removeGarageDoorService(accessory);
|
|
497
420
|
this.removeWindowCoveringService(accessory);
|
|
498
421
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
422
|
+
} else {
|
|
423
|
+
this.errorLog('Device Type not set');
|
|
499
424
|
}
|
|
500
425
|
|
|
501
426
|
// Retrieve initial values and updateHomekit
|
|
@@ -550,18 +475,10 @@ export class Bot extends deviceBase {
|
|
|
550
475
|
+ ` current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
551
476
|
|
|
552
477
|
// BLEmode (true if Switch Mode) | (false if Press Mode)
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
this.setOn(Boolean(this.serviceData.state));
|
|
558
|
-
}
|
|
559
|
-
this.debugLog(`Switch Mode, mode: ${this.serviceData.mode}, On: ${this.accessory.context.On}`);
|
|
560
|
-
} else {
|
|
561
|
-
this.setOn(false);
|
|
562
|
-
this.accessory.context.On = await this.getOn();
|
|
563
|
-
this.debugLog(`Press Mode, mode: ${this.serviceData.mode}, On: ${this.accessory.context.On}`);
|
|
564
|
-
}
|
|
478
|
+
this.On = this.serviceData.mode ? this.serviceData.state : false;
|
|
479
|
+
const mode = this.serviceData.mode ? 'Switch' : 'Press';
|
|
480
|
+
await this.debugLog(`${mode} Mode, On: ${this.accessory.context.On}`);
|
|
481
|
+
this.accessory.context.On = this.On;
|
|
565
482
|
|
|
566
483
|
// BatteryLevel
|
|
567
484
|
this.Battery.BatteryLevel = this.serviceData.battery;
|
|
@@ -583,16 +500,8 @@ export class Bot extends deviceBase {
|
|
|
583
500
|
+ ` current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
584
501
|
|
|
585
502
|
// On
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
this.accessory.context.On = await this.getOn();
|
|
589
|
-
} else {
|
|
590
|
-
this.setOn(this.deviceStatus.power === 'on' ? true : false);
|
|
591
|
-
this.accessory.context.On = await this.getOn();
|
|
592
|
-
if (this.getOn() === undefined) {
|
|
593
|
-
this.setOn(false);
|
|
594
|
-
}
|
|
595
|
-
}
|
|
503
|
+
this.On = this.botMode === 'press' ? false : this.deviceStatus.power === 'on' ? true : false;
|
|
504
|
+
this.accessory.context.On = this.On;
|
|
596
505
|
await this.debugLog(`On: ${this.accessory.context.On}`);
|
|
597
506
|
|
|
598
507
|
// Battery Level
|
|
@@ -622,14 +531,12 @@ export class Bot extends deviceBase {
|
|
|
622
531
|
|
|
623
532
|
async parseStatusWebhook(): Promise<void> {
|
|
624
533
|
await this.debugLog('parseStatusWebhook');
|
|
625
|
-
const getOn = await this.getOn();
|
|
626
534
|
await this.debugLog(`(power, battery, deviceMode) = Webhook:(${this.webhookContext.power}, ${this.webhookContext.battery},`
|
|
627
|
-
+ ` ${this.webhookContext.deviceMode}), current:(${
|
|
535
|
+
+ ` ${this.webhookContext.deviceMode}), current:(${this.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
628
536
|
|
|
629
537
|
// On
|
|
630
|
-
|
|
631
|
-
await this.
|
|
632
|
-
await this.debugLog(`On: ${setOn}`);
|
|
538
|
+
this.On = this.webhookContext.power === 'on' ? true : false;
|
|
539
|
+
await this.debugLog(`On: ${this.On}`);
|
|
633
540
|
|
|
634
541
|
// BatteryLevel
|
|
635
542
|
this.Battery.BatteryLevel = this.webhookContext.battery;
|
|
@@ -651,7 +558,7 @@ export class Bot extends deviceBase {
|
|
|
651
558
|
async refreshStatus(): Promise<void> {
|
|
652
559
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
653
560
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
654
|
-
} else if (this.BLE) {
|
|
561
|
+
} else if (this.BLE || this.config.options?.BLE) {
|
|
655
562
|
await this.BLERefreshStatus();
|
|
656
563
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
657
564
|
await this.openAPIRefreshStatus();
|
|
@@ -663,25 +570,41 @@ export class Bot extends deviceBase {
|
|
|
663
570
|
|
|
664
571
|
async BLERefreshStatus(): Promise<void> {
|
|
665
572
|
await this.debugLog('BLERefreshStatus');
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
await this.
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as botServiceData;
|
|
675
|
-
// Update HomeKit
|
|
676
|
-
if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
|
|
677
|
-
this.serviceData = serviceData;
|
|
573
|
+
if (this.config.options?.BLE) {
|
|
574
|
+
await this.debugLog('is listening to Platform BLE.');
|
|
575
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
576
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
577
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: botServiceData) => {
|
|
578
|
+
try {
|
|
579
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
580
|
+
this.serviceData = context;
|
|
678
581
|
await this.BLEparseStatus();
|
|
679
582
|
await this.updateHomeKitCharacteristics();
|
|
680
|
-
}
|
|
681
|
-
await this.errorLog(`failed to
|
|
682
|
-
await this.BLERefreshConnection(switchbot);
|
|
583
|
+
} catch (e: any) {
|
|
584
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
683
585
|
}
|
|
684
|
-
}
|
|
586
|
+
};
|
|
587
|
+
} else {
|
|
588
|
+
await this.debugLog('is using Device BLE Scanning.');
|
|
589
|
+
const switchbot = await this.switchbotBLE();
|
|
590
|
+
if (switchbot === undefined) {
|
|
591
|
+
await this.BLERefreshConnection(switchbot);
|
|
592
|
+
} else {
|
|
593
|
+
// Start to monitor advertisement packets
|
|
594
|
+
(async () => {
|
|
595
|
+
// Start to monitor advertisement packets
|
|
596
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as botServiceData;
|
|
597
|
+
// Update HomeKit
|
|
598
|
+
if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
|
|
599
|
+
this.serviceData = serviceData;
|
|
600
|
+
await this.BLEparseStatus();
|
|
601
|
+
await this.updateHomeKitCharacteristics();
|
|
602
|
+
} else {
|
|
603
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
604
|
+
await this.BLERefreshConnection(switchbot);
|
|
605
|
+
}
|
|
606
|
+
})();
|
|
607
|
+
}
|
|
685
608
|
}
|
|
686
609
|
}
|
|
687
610
|
|
|
@@ -753,30 +676,26 @@ export class Bot extends deviceBase {
|
|
|
753
676
|
|
|
754
677
|
async BLEpushChanges(): Promise<void> {
|
|
755
678
|
await this.debugLog('BLEpushChanges');
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
this.debugLog(`BLEpushChanges On: ${On} OnCached: ${this.accessory.context.On}`);
|
|
679
|
+
if (this.On !== this.accessory.context.On || this.allowPush) {
|
|
680
|
+
await this.debugLog(`BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
|
|
759
681
|
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
760
682
|
await this.convertBLEAddress();
|
|
761
683
|
//if (switchbot !== false) {
|
|
684
|
+
await this.debugLog(`Bot Mode: ${this.botMode}`);
|
|
762
685
|
if (this.botMode === 'press') {
|
|
763
|
-
this.debugLog(`Bot Mode: ${this.botMode}`);
|
|
764
686
|
switchbot
|
|
765
687
|
.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
766
688
|
.then(async (device_list: { press: (arg0: { id: string | undefined }) => any }[]) => {
|
|
767
|
-
this.infoLog(`On: ${On}`);
|
|
689
|
+
await this.infoLog(`On: ${this.On}`);
|
|
768
690
|
return await device_list[0].press({ id: this.device.bleMac });
|
|
769
691
|
})
|
|
770
692
|
.then(async () => {
|
|
771
|
-
await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
|
|
693
|
+
await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`);
|
|
772
694
|
await this.updateHomeKitCharacteristics();
|
|
773
|
-
setTimeout(() => {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
}
|
|
777
|
-
this.Outlet?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
|
|
778
|
-
}
|
|
779
|
-
this.debugLog(`On: ${On}, Switch Timeout`);
|
|
695
|
+
setTimeout(async () => {
|
|
696
|
+
this.On = false;
|
|
697
|
+
await this.updateHomeKitCharacteristics();
|
|
698
|
+
this.debugLog(`On: ${this.On}, Switch Timeout`);
|
|
780
699
|
}, 500);
|
|
781
700
|
})
|
|
782
701
|
.catch(async (e: any) => {
|
|
@@ -785,15 +704,14 @@ export class Bot extends deviceBase {
|
|
|
785
704
|
await this.BLEPushConnection();
|
|
786
705
|
});
|
|
787
706
|
} else if (this.botMode === 'switch') {
|
|
788
|
-
this.debugLog(`Press Mode: ${this.botMode}`);
|
|
789
707
|
switchbot
|
|
790
708
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
791
709
|
.then(async (device_list: any) => {
|
|
792
|
-
this.infoLog(`On: ${On}`);
|
|
710
|
+
this.infoLog(`On: ${this.On}`);
|
|
793
711
|
return await this.retryBLE({
|
|
794
712
|
max: await this.maxRetryBLE(),
|
|
795
713
|
fn: async () => {
|
|
796
|
-
if (On) {
|
|
714
|
+
if (this.On) {
|
|
797
715
|
return await device_list[0].turnOn({ id: this.device.bleMac });
|
|
798
716
|
} else {
|
|
799
717
|
return await device_list[0].turnOff({ id: this.device.bleMac });
|
|
@@ -802,7 +720,7 @@ export class Bot extends deviceBase {
|
|
|
802
720
|
});
|
|
803
721
|
})
|
|
804
722
|
.then(async () => {
|
|
805
|
-
await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
|
|
723
|
+
await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`);
|
|
806
724
|
await this.updateHomeKitCharacteristics();
|
|
807
725
|
})
|
|
808
726
|
.catch(async (e: any) => {
|
|
@@ -814,31 +732,24 @@ export class Bot extends deviceBase {
|
|
|
814
732
|
await this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`);
|
|
815
733
|
}
|
|
816
734
|
} else {
|
|
817
|
-
await this.debugLog(`No Changes (BLEpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
|
|
735
|
+
await this.debugLog(`No Changes (BLEpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`);
|
|
818
736
|
}
|
|
819
737
|
}
|
|
820
738
|
|
|
821
739
|
async openAPIpushChanges(): Promise<void> {
|
|
822
740
|
await this.debugLog('openAPIpushChanges');
|
|
823
|
-
let On = await this.getOn();
|
|
824
741
|
if (this.multiPressCount > 0) {
|
|
825
742
|
await this.debugLog(`${this.multiPressCount} request(s) queued.`);
|
|
826
|
-
On = true;
|
|
827
743
|
}
|
|
828
|
-
if (On !== this.accessory.context.On || this.allowPush || this.multiPressCount > 0) {
|
|
744
|
+
if (this.On !== this.accessory.context.On || this.allowPush || this.multiPressCount > 0) {
|
|
829
745
|
let command = '';
|
|
830
|
-
if (this.botMode === 'switch'
|
|
831
|
-
command = 'turnOn';
|
|
832
|
-
|
|
833
|
-
await this.debugLog(`Switch Mode, Turning ${On}`);
|
|
834
|
-
} else if (this.botMode === 'switch' && !On) {
|
|
835
|
-
command = 'turnOff';
|
|
836
|
-
On = false;
|
|
837
|
-
await this.debugLog(`Switch Mode, Turning ${On}`);
|
|
746
|
+
if (this.botMode === 'switch') {
|
|
747
|
+
command = this.On ? 'turnOn' : 'turnOff';
|
|
748
|
+
await this.debugLog(`Switch Mode, Command: ${command}`);
|
|
838
749
|
} else if (this.botMode === 'press' || this.botMode === 'multipress') {
|
|
839
750
|
command = 'press';
|
|
840
751
|
await this.debugLog('Press Mode');
|
|
841
|
-
On = false;
|
|
752
|
+
this.On = false;
|
|
842
753
|
} else {
|
|
843
754
|
throw new Error('Device Parameters not set for this Bot.');
|
|
844
755
|
}
|
|
@@ -863,7 +774,7 @@ export class Bot extends deviceBase {
|
|
|
863
774
|
this.multiPressCount--;
|
|
864
775
|
if (this.multiPressCount > 0) {
|
|
865
776
|
await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
|
|
866
|
-
On = true;
|
|
777
|
+
this.On = true;
|
|
867
778
|
await this.openAPIpushChanges();
|
|
868
779
|
}
|
|
869
780
|
}
|
|
@@ -872,7 +783,7 @@ export class Bot extends deviceBase {
|
|
|
872
783
|
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
873
784
|
}
|
|
874
785
|
} else {
|
|
875
|
-
await this.debugLog(`No Changes (openAPIpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
|
|
786
|
+
await this.debugLog(`No Changes (openAPIpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`);
|
|
876
787
|
}
|
|
877
788
|
}
|
|
878
789
|
|
|
@@ -880,104 +791,54 @@ export class Bot extends deviceBase {
|
|
|
880
791
|
* Handle requests to set the "On" characteristic
|
|
881
792
|
*/
|
|
882
793
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
883
|
-
if (this.botDeviceType === '
|
|
794
|
+
if (this.botDeviceType === 'switch') {
|
|
795
|
+
if (this.Switch) {
|
|
796
|
+
await this.debugLog(`Set On: ${value}`);
|
|
797
|
+
this.On = value === false ? false : true;
|
|
798
|
+
}
|
|
799
|
+
} else if (this.botDeviceType === 'garagedoor') {
|
|
884
800
|
if (this.GarageDoor) {
|
|
885
801
|
await this.debugLog(`Set TargetDoorState: ${value}`);
|
|
886
|
-
this.
|
|
887
|
-
if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
|
|
888
|
-
await this.setOn(false);
|
|
889
|
-
this.GarageDoor.On = false;
|
|
890
|
-
} else {
|
|
891
|
-
await this.setOn(true);
|
|
892
|
-
this.GarageDoor.On = true;
|
|
893
|
-
}
|
|
802
|
+
this.On = value === this.hap.Characteristic.TargetDoorState.CLOSED ? false : true;
|
|
894
803
|
}
|
|
895
804
|
} else if (this.botDeviceType === 'door') {
|
|
896
805
|
if (this.Door) {
|
|
897
806
|
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
898
|
-
|
|
899
|
-
await this.setOn(false);
|
|
900
|
-
this.Door.On = false;
|
|
901
|
-
} else {
|
|
902
|
-
await this.setOn(true);
|
|
903
|
-
this.Door.On = true;
|
|
904
|
-
}
|
|
807
|
+
this.On = value === 0 ? false : true;
|
|
905
808
|
}
|
|
906
809
|
} else if (this.botDeviceType === 'window') {
|
|
907
810
|
if (this.Window) {
|
|
908
811
|
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
909
|
-
|
|
910
|
-
await this.setOn(false);
|
|
911
|
-
this.Window.On = false;
|
|
912
|
-
} else {
|
|
913
|
-
await this.setOn(true);
|
|
914
|
-
this.Window.On = true;
|
|
915
|
-
}
|
|
812
|
+
this.On = value === 0 ? false : true;
|
|
916
813
|
}
|
|
917
814
|
} else if (this.botDeviceType === 'windowcovering') {
|
|
918
815
|
if (this.WindowCovering) {
|
|
919
816
|
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
920
|
-
|
|
921
|
-
await this.setOn(false);
|
|
922
|
-
this.WindowCovering.On = false;
|
|
923
|
-
} else {
|
|
924
|
-
await this.setOn(true);
|
|
925
|
-
this.WindowCovering.On = true;
|
|
926
|
-
}
|
|
817
|
+
this.On = value === 0 ? false : true;
|
|
927
818
|
}
|
|
928
819
|
} else if (this.botDeviceType === 'lock') {
|
|
929
820
|
if (this.LockMechanism) {
|
|
930
821
|
await this.debugLog(`Set LockTargetState: ${value}`);
|
|
931
|
-
|
|
932
|
-
await this.setOn(false);
|
|
933
|
-
this.LockMechanism.On = false;
|
|
934
|
-
} else {
|
|
935
|
-
await this.setOn(true);
|
|
936
|
-
this.LockMechanism.On = true;
|
|
937
|
-
}
|
|
822
|
+
this.On = value === this.hap.Characteristic.LockTargetState.SECURED ? false : true;
|
|
938
823
|
}
|
|
939
824
|
} else if (this.botDeviceType === 'faucet') {
|
|
940
825
|
if (this.Faucet) {
|
|
941
826
|
await this.debugLog(`Set Active: ${value}`);
|
|
942
|
-
|
|
943
|
-
await this.setOn(false);
|
|
944
|
-
this.Faucet.On = false;
|
|
945
|
-
} else {
|
|
946
|
-
await this.setOn(true);
|
|
947
|
-
this.Faucet.On = true;
|
|
948
|
-
}
|
|
827
|
+
this.On = value === this.hap.Characteristic.Active.INACTIVE ? false : true;
|
|
949
828
|
}
|
|
950
829
|
} else if (this.botDeviceType === 'stateful') {
|
|
951
830
|
if (this.StatefulProgrammableSwitch) {
|
|
952
831
|
await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
|
|
953
|
-
|
|
954
|
-
await this.setOn(false);
|
|
955
|
-
this.StatefulProgrammableSwitch.On = false;
|
|
956
|
-
} else {
|
|
957
|
-
await this.setOn(true);
|
|
958
|
-
this.StatefulProgrammableSwitch.On = true;
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
} else if (this.botDeviceType === 'switch') {
|
|
962
|
-
if (this.Switch) {
|
|
963
|
-
await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
|
|
964
|
-
if (value === 0) {
|
|
965
|
-
await this.setOn(false);
|
|
966
|
-
this.Switch.On = false;
|
|
967
|
-
} else {
|
|
968
|
-
await this.setOn(true);
|
|
969
|
-
this.Switch.On = true;
|
|
970
|
-
}
|
|
832
|
+
this.On = value === 0 ? false : true;
|
|
971
833
|
}
|
|
972
834
|
} else {
|
|
973
835
|
if (this.Outlet) {
|
|
974
836
|
await this.debugLog(`Set On: ${value}`);
|
|
975
|
-
|
|
976
|
-
this.Outlet.On = value;
|
|
837
|
+
this.On = value === false ? false : true;
|
|
977
838
|
}
|
|
978
839
|
}
|
|
979
840
|
if (this.device.bot?.mode === 'multipress') {
|
|
980
|
-
if (
|
|
841
|
+
if (this.On === true) {
|
|
981
842
|
this.multiPressCount++;
|
|
982
843
|
await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
|
|
983
844
|
}
|
|
@@ -989,176 +850,168 @@ export class Bot extends deviceBase {
|
|
|
989
850
|
* Updates the status for each of the HomeKit Characteristics
|
|
990
851
|
*/
|
|
991
852
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
853
|
+
await this.debugLog('updateHomeKitCharacteristics');
|
|
854
|
+
// BatteryLevel
|
|
855
|
+
if (this.Battery.BatteryLevel === undefined) {
|
|
856
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
857
|
+
} else {
|
|
858
|
+
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
859
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
860
|
+
await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
861
|
+
}
|
|
862
|
+
// StatusLowBattery
|
|
863
|
+
if (this.Battery.StatusLowBattery === undefined) {
|
|
864
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
865
|
+
} else {
|
|
866
|
+
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
867
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
868
|
+
await this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
869
|
+
}
|
|
992
870
|
// State
|
|
993
|
-
if (this.botDeviceType === '
|
|
994
|
-
if (this.
|
|
995
|
-
await this.debugLog(`On: ${this.
|
|
871
|
+
if (this.botDeviceType === 'switch' && this.Switch) {
|
|
872
|
+
if (this.On === undefined) {
|
|
873
|
+
await this.debugLog(`On: ${this.On}`);
|
|
996
874
|
} else {
|
|
997
|
-
|
|
875
|
+
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
876
|
+
await this.debugLog(`updateCharacteristic On: ${this.On}`);
|
|
877
|
+
}
|
|
878
|
+
} else if (this.botDeviceType === 'garagedoor' && this.GarageDoor) {
|
|
879
|
+
if (this.On === undefined) {
|
|
880
|
+
await this.debugLog(`On: ${this.On}`);
|
|
881
|
+
} else {
|
|
882
|
+
if (this.On) {
|
|
998
883
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
|
|
999
884
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
|
|
1000
|
-
await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.
|
|
885
|
+
await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.On})`);
|
|
1001
886
|
} else {
|
|
1002
887
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
|
|
1003
888
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
|
|
1004
|
-
await this.debugLog(`updateCharacteristicc TargetDoorState:
|
|
889
|
+
await this.debugLog(`updateCharacteristicc TargetDoorState: Closed, CurrentDoorState: Closed (${this.On})`);
|
|
1005
890
|
}
|
|
1006
891
|
}
|
|
1007
|
-
await this.
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
await this.debugLog(`On: ${this.Door?.On}`);
|
|
892
|
+
await this.debugLog(`Garage Door On: ${this.On}`);
|
|
893
|
+
} else if (this.botDeviceType === 'door' && this.Door) {
|
|
894
|
+
if (this.On === undefined) {
|
|
895
|
+
await this.debugLog(`On: ${this.On}`);
|
|
1012
896
|
} else {
|
|
1013
|
-
if (this.
|
|
897
|
+
if (this.On) {
|
|
1014
898
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
1015
899
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
1016
900
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
1017
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.
|
|
901
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`);
|
|
1018
902
|
} else {
|
|
1019
903
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
1020
904
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
1021
905
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
1022
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.
|
|
906
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`);
|
|
1023
907
|
}
|
|
1024
908
|
}
|
|
1025
|
-
await this.
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
await this.debugLog(`On: ${this.Window?.On}`);
|
|
909
|
+
await this.debugLog(`Door On: ${this.On}`);
|
|
910
|
+
} else if (this.botDeviceType === 'window' && this.Window) {
|
|
911
|
+
if (this.On === undefined) {
|
|
912
|
+
await this.debugLog(`On: ${this.On}`);
|
|
1030
913
|
} else {
|
|
1031
|
-
if (this.
|
|
914
|
+
if (this.On) {
|
|
1032
915
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
1033
916
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
1034
917
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
1035
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.
|
|
918
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`);
|
|
1036
919
|
} else {
|
|
1037
920
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
1038
921
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
1039
922
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
1040
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.
|
|
923
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`);
|
|
1041
924
|
}
|
|
1042
925
|
}
|
|
1043
|
-
await this.
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
await this.debugLog(`On: ${this.WindowCovering?.On}`);
|
|
926
|
+
await this.debugLog(`Window On: ${this.On}`);
|
|
927
|
+
} else if (this.botDeviceType === 'windowcovering' && this.WindowCovering) {
|
|
928
|
+
if (this.On === undefined) {
|
|
929
|
+
await this.debugLog(`On: ${this.On}`);
|
|
1048
930
|
} else {
|
|
1049
|
-
if (this.
|
|
931
|
+
if (this.On) {
|
|
1050
932
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
1051
933
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
1052
934
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
1053
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.
|
|
935
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`);
|
|
1054
936
|
} else {
|
|
1055
937
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
1056
938
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
1057
939
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
1058
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.
|
|
940
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`);
|
|
1059
941
|
}
|
|
1060
942
|
}
|
|
1061
|
-
await this.
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
await this.debugLog(`On: ${this.LockMechanism?.On}`);
|
|
943
|
+
await this.debugLog(`Window Covering On: ${this.On}`);
|
|
944
|
+
} else if (this.botDeviceType === 'lock' && this.LockMechanism) {
|
|
945
|
+
if (this.On === undefined) {
|
|
946
|
+
await this.debugLog(`On: ${this.On}`);
|
|
1066
947
|
} else {
|
|
1067
|
-
if (this.
|
|
948
|
+
if (this.On) {
|
|
1068
949
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
|
|
1069
950
|
this.hap.Characteristic.LockTargetState.UNSECURED);
|
|
1070
951
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
|
|
1071
952
|
this.hap.Characteristic.LockCurrentState.UNSECURED);
|
|
1072
|
-
await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.
|
|
953
|
+
await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.On})`);
|
|
1073
954
|
} else {
|
|
1074
955
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
|
|
1075
956
|
this.hap.Characteristic.LockTargetState.SECURED);
|
|
1076
957
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
|
|
1077
958
|
this.hap.Characteristic.LockCurrentState.SECURED);
|
|
1078
|
-
await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.
|
|
959
|
+
await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.On})`);
|
|
1079
960
|
}
|
|
1080
961
|
}
|
|
1081
|
-
await this.
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
await this.debugLog(`On: ${this.Faucet?.On}`);
|
|
962
|
+
await this.debugLog(`Lock On: ${this.On}`);
|
|
963
|
+
} else if (this.botDeviceType === 'faucet' && this.Faucet) {
|
|
964
|
+
if (this.On === undefined) {
|
|
965
|
+
await this.debugLog(`On: ${this.On}`);
|
|
1086
966
|
} else {
|
|
1087
|
-
if (this.
|
|
967
|
+
if (this.On) {
|
|
1088
968
|
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
|
|
1089
|
-
await this.debugLog(`updateCharacteristic Active: ${this.
|
|
969
|
+
await this.debugLog(`updateCharacteristic Active: ${this.On}`);
|
|
1090
970
|
} else {
|
|
1091
971
|
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
1092
|
-
await this.debugLog(`updateCharacteristic Active: ${this.
|
|
972
|
+
await this.debugLog(`updateCharacteristic Active: ${this.On}`);
|
|
1093
973
|
}
|
|
1094
974
|
}
|
|
1095
|
-
await this.
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
await this.debugLog(`On: ${this.Fan?.On}`);
|
|
975
|
+
await this.debugLog(`Faucet On: ${this.On}`);
|
|
976
|
+
} else if (this.botDeviceType === 'fan' && this.Fan) {
|
|
977
|
+
if (this.On === undefined) {
|
|
978
|
+
await this.debugLog(`On: ${this.On}`);
|
|
1100
979
|
} else {
|
|
1101
|
-
if (this.
|
|
1102
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.
|
|
1103
|
-
await this.debugLog(`updateCharacteristic
|
|
980
|
+
if (this.On) {
|
|
981
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
|
|
982
|
+
await this.debugLog(`updateCharacteristic Active: ${this.On}`);
|
|
1104
983
|
} else {
|
|
1105
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.
|
|
1106
|
-
await this.debugLog(`updateCharacteristic
|
|
984
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
985
|
+
await this.debugLog(`updateCharacteristic Active: ${this.On}`);
|
|
1107
986
|
}
|
|
1108
987
|
}
|
|
1109
|
-
await this.
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
await this.debugLog(`On: ${this.StatefulProgrammableSwitch?.On}`);
|
|
988
|
+
await this.debugLog(`Fan On: ${this.On}`);
|
|
989
|
+
} else if (this.botDeviceType === 'stateful' && this.StatefulProgrammableSwitch) {
|
|
990
|
+
if (this.On === undefined) {
|
|
991
|
+
await this.debugLog(`On: ${this.On}`);
|
|
1114
992
|
} else {
|
|
1115
|
-
if (this.
|
|
993
|
+
if (this.On) {
|
|
1116
994
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
|
|
1117
995
|
this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
1118
996
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
|
|
1119
|
-
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.
|
|
997
|
+
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`);
|
|
1120
998
|
} else {
|
|
1121
999
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
|
|
1122
1000
|
this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
1123
1001
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
|
|
1124
|
-
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.
|
|
1002
|
+
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`);
|
|
1125
1003
|
}
|
|
1126
1004
|
}
|
|
1127
|
-
await this.
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
await this.debugLog(`On: ${this.Switch?.On}`);
|
|
1132
|
-
} else {
|
|
1133
|
-
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
|
|
1134
|
-
await this.debugLog(`updateCharacteristic On: ${this.Switch.On}`);
|
|
1135
|
-
}
|
|
1136
|
-
await this.setOn(Boolean(this.Switch?.On));
|
|
1137
|
-
} else {
|
|
1138
|
-
if (this.Outlet?.On === undefined) {
|
|
1139
|
-
await this.debugLog(`On: ${this.Outlet?.On}`);
|
|
1005
|
+
await this.debugLog(`StatefulProgrammableSwitch On: ${this.On}`);
|
|
1006
|
+
} else if (this.botDeviceType === 'outlet' && this.Outlet) {
|
|
1007
|
+
if (this.On === undefined) {
|
|
1008
|
+
await this.debugLog(`On: ${this.On}`);
|
|
1140
1009
|
} else {
|
|
1141
|
-
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.
|
|
1142
|
-
await this.debugLog(`updateCharacteristic On: ${this.
|
|
1010
|
+
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
1011
|
+
await this.debugLog(`updateCharacteristic On: ${this.On}`);
|
|
1143
1012
|
}
|
|
1144
|
-
await this.setOn(Boolean(this.Outlet?.On));
|
|
1145
|
-
}
|
|
1146
|
-
this.accessory.context.On = await this.getOn();
|
|
1147
|
-
// BatteryLevel
|
|
1148
|
-
if (this.Battery.BatteryLevel === undefined) {
|
|
1149
|
-
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
1150
1013
|
} else {
|
|
1151
|
-
this.
|
|
1152
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
1153
|
-
await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
1154
|
-
}
|
|
1155
|
-
// StatusLowBattery
|
|
1156
|
-
if (this.Battery.StatusLowBattery === undefined) {
|
|
1157
|
-
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1158
|
-
} else {
|
|
1159
|
-
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
1160
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
1161
|
-
await this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1014
|
+
await this.errorLog(`botDeviceType: ${this.botDeviceType}, On: ${this.On}`);
|
|
1162
1015
|
}
|
|
1163
1016
|
}
|
|
1164
1017
|
|
|
@@ -1168,7 +1021,6 @@ export class Bot extends deviceBase {
|
|
|
1168
1021
|
this.Outlet = {
|
|
1169
1022
|
Name: accessory.context.Outlet.Name ?? accessory.displayName,
|
|
1170
1023
|
Service: accessory.getService(this.hap.Service.Outlet) as Service,
|
|
1171
|
-
On: accessory.context.On ?? false,
|
|
1172
1024
|
};
|
|
1173
1025
|
accessory.context.Outlet = this.Outlet as object;
|
|
1174
1026
|
await this.warnLog('Removing any leftover Outlet Service');
|
|
@@ -1181,7 +1033,6 @@ export class Bot extends deviceBase {
|
|
|
1181
1033
|
this.GarageDoor = {
|
|
1182
1034
|
Name: accessory.context.GarageDoor.Name ?? accessory.displayName,
|
|
1183
1035
|
Service: accessory.getService(this.hap.Service.GarageDoorOpener) as Service,
|
|
1184
|
-
On: accessory.context.On ?? false,
|
|
1185
1036
|
};
|
|
1186
1037
|
accessory.context.GarageDoor = this.GarageDoor as object;
|
|
1187
1038
|
await this.warnLog('Removing any leftover Garage Door Service');
|
|
@@ -1194,7 +1045,6 @@ export class Bot extends deviceBase {
|
|
|
1194
1045
|
this.Door = {
|
|
1195
1046
|
Name: accessory.context.Door.Name ?? accessory.displayName,
|
|
1196
1047
|
Service: accessory.getService(this.hap.Service.Door) as Service,
|
|
1197
|
-
On: accessory.context.On ?? false,
|
|
1198
1048
|
};
|
|
1199
1049
|
accessory.context.Door = this.Door as object;
|
|
1200
1050
|
await this.warnLog('Removing any leftover Door Service');
|
|
@@ -1207,7 +1057,6 @@ export class Bot extends deviceBase {
|
|
|
1207
1057
|
this.LockMechanism = {
|
|
1208
1058
|
Name: accessory.context.LockMechanism.Name ?? accessory.displayName,
|
|
1209
1059
|
Service: accessory.getService(this.hap.Service.LockMechanism) as Service,
|
|
1210
|
-
On: accessory.context.On ?? false,
|
|
1211
1060
|
};
|
|
1212
1061
|
accessory.context.LockMechanism = this.LockMechanism as object;
|
|
1213
1062
|
this.warnLog('Removing any leftover Lock Service');
|
|
@@ -1220,7 +1069,6 @@ export class Bot extends deviceBase {
|
|
|
1220
1069
|
this.Faucet = {
|
|
1221
1070
|
Name: accessory.context.Faucet.Name ?? accessory.displayName,
|
|
1222
1071
|
Service: accessory.getService(this.hap.Service.Valve) as Service,
|
|
1223
|
-
On: accessory.context.On ?? false,
|
|
1224
1072
|
};
|
|
1225
1073
|
accessory.context.Faucet = this.Faucet as object;
|
|
1226
1074
|
await this.warnLog('Removing any leftover Faucet Service');
|
|
@@ -1233,7 +1081,6 @@ export class Bot extends deviceBase {
|
|
|
1233
1081
|
this.Fan = {
|
|
1234
1082
|
Name: accessory.context.Fan.Name ?? accessory.displayName,
|
|
1235
1083
|
Service: accessory.getService(this.hap.Service.Fan) as Service,
|
|
1236
|
-
On: accessory.context.On ?? false,
|
|
1237
1084
|
};
|
|
1238
1085
|
accessory.context.Fan = this.Fan as object;
|
|
1239
1086
|
this.warnLog('Removing any leftover Fan Service');
|
|
@@ -1246,7 +1093,6 @@ export class Bot extends deviceBase {
|
|
|
1246
1093
|
this.Window = {
|
|
1247
1094
|
Name: accessory.context.Window.Name ?? accessory.displayName,
|
|
1248
1095
|
Service: accessory.getService(this.hap.Service.Window) as Service,
|
|
1249
|
-
On: accessory.context.On ?? false,
|
|
1250
1096
|
};
|
|
1251
1097
|
accessory.context.Window = this.Window as object;
|
|
1252
1098
|
await this.warnLog('Removing any leftover Window Service');
|
|
@@ -1259,7 +1105,6 @@ export class Bot extends deviceBase {
|
|
|
1259
1105
|
this.WindowCovering = {
|
|
1260
1106
|
Name: accessory.context.WindowCovering.Name ?? accessory.displayName,
|
|
1261
1107
|
Service: accessory.getService(this.hap.Service.WindowCovering) as Service,
|
|
1262
|
-
On: accessory.context.On ?? false,
|
|
1263
1108
|
};
|
|
1264
1109
|
accessory.context.WindowCovering = this.WindowCovering as object;
|
|
1265
1110
|
await this.warnLog('Removing any leftover Window Covering Service');
|
|
@@ -1272,7 +1117,6 @@ export class Bot extends deviceBase {
|
|
|
1272
1117
|
this.StatefulProgrammableSwitch = {
|
|
1273
1118
|
Name: accessory.context.StatefulProgrammableSwitch.Name ?? accessory.displayName,
|
|
1274
1119
|
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service,
|
|
1275
|
-
On: accessory.context.On ?? false,
|
|
1276
1120
|
};
|
|
1277
1121
|
accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object;
|
|
1278
1122
|
await this.warnLog('Removing any leftover Stateful Programmable Switch Service');
|
|
@@ -1285,83 +1129,12 @@ export class Bot extends deviceBase {
|
|
|
1285
1129
|
this.Switch = {
|
|
1286
1130
|
Name: accessory.context.Switch.Name ?? accessory.displayName,
|
|
1287
1131
|
Service: accessory.getService(this.hap.Service.Switch) as Service,
|
|
1288
|
-
On: accessory.context.On ?? false,
|
|
1289
1132
|
};
|
|
1290
1133
|
accessory.context.Switch = this.Switch as object;
|
|
1291
1134
|
await this.warnLog('Removing any leftover Switch Service');
|
|
1292
1135
|
accessory.removeService(this.Switch.Service);
|
|
1293
1136
|
}
|
|
1294
1137
|
|
|
1295
|
-
async getOn(): Promise<boolean> {
|
|
1296
|
-
let On: boolean;
|
|
1297
|
-
if (this.botDeviceType === 'garagedoor') {
|
|
1298
|
-
On = this.GarageDoor?.On ? true : false;
|
|
1299
|
-
} else if (this.botDeviceType === 'door') {
|
|
1300
|
-
On = this.Door?.On ? true : false;
|
|
1301
|
-
} else if (this.botDeviceType === 'window') {
|
|
1302
|
-
On = this.Window?.On ? true : false;
|
|
1303
|
-
} else if (this.botDeviceType === 'windowcovering') {
|
|
1304
|
-
On = this.WindowCovering?.On ? true : false;
|
|
1305
|
-
} else if (this.botDeviceType === 'lock') {
|
|
1306
|
-
On = this.LockMechanism?.On ? true : false;
|
|
1307
|
-
} else if (this.botDeviceType === 'faucet') {
|
|
1308
|
-
On = this.Faucet?.On ? true : false;
|
|
1309
|
-
} else if (this.botDeviceType === 'fan') {
|
|
1310
|
-
On = this.Fan?.On ? true : false;
|
|
1311
|
-
} else if (this.botDeviceType === 'stateful') {
|
|
1312
|
-
On = this.StatefulProgrammableSwitch?.On ? true : false;
|
|
1313
|
-
} else if (this.botDeviceType === 'switch') {
|
|
1314
|
-
On = this.Switch?.On ? true : false;
|
|
1315
|
-
} else {
|
|
1316
|
-
On = this.Outlet?.On ? true : false;
|
|
1317
|
-
}
|
|
1318
|
-
return On;
|
|
1319
|
-
}
|
|
1320
|
-
|
|
1321
|
-
async setOn(On: boolean): Promise<void> {
|
|
1322
|
-
if (this.botDeviceType === 'garagedoor') {
|
|
1323
|
-
if (this.GarageDoor) {
|
|
1324
|
-
this.GarageDoor.On = On;
|
|
1325
|
-
}
|
|
1326
|
-
} else if (this.botDeviceType === 'door') {
|
|
1327
|
-
if (this.Door) {
|
|
1328
|
-
this.Door.On = On;
|
|
1329
|
-
}
|
|
1330
|
-
} else if (this.botDeviceType === 'window') {
|
|
1331
|
-
if (this.Window) {
|
|
1332
|
-
this.Window.On = On;
|
|
1333
|
-
}
|
|
1334
|
-
} else if (this.botDeviceType === 'windowcovering') {
|
|
1335
|
-
if (this.WindowCovering) {
|
|
1336
|
-
this.WindowCovering.On = On;
|
|
1337
|
-
}
|
|
1338
|
-
} else if (this.botDeviceType === 'lock') {
|
|
1339
|
-
if (this.LockMechanism) {
|
|
1340
|
-
this.LockMechanism.On = On;
|
|
1341
|
-
}
|
|
1342
|
-
} else if (this.botDeviceType === 'faucet') {
|
|
1343
|
-
if (this.Faucet) {
|
|
1344
|
-
this.Faucet.On = On;
|
|
1345
|
-
}
|
|
1346
|
-
} else if (this.botDeviceType === 'fan') {
|
|
1347
|
-
if (this.Fan) {
|
|
1348
|
-
this.Fan.On = On;
|
|
1349
|
-
}
|
|
1350
|
-
} else if (this.botDeviceType === 'stateful') {
|
|
1351
|
-
if (this.StatefulProgrammableSwitch) {
|
|
1352
|
-
this.StatefulProgrammableSwitch.On = On;
|
|
1353
|
-
}
|
|
1354
|
-
} else if (this.botDeviceType === 'switch') {
|
|
1355
|
-
if (this.Switch) {
|
|
1356
|
-
this.Switch.On = On;
|
|
1357
|
-
}
|
|
1358
|
-
} else {
|
|
1359
|
-
if (this.Outlet) {
|
|
1360
|
-
this.Outlet.On = On;
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
|
|
1365
1138
|
async getBotConfigSettings(device: device & devicesConfig) {
|
|
1366
1139
|
//Bot Device Type
|
|
1367
1140
|
this.botDeviceType = this.accessory.context.botDeviceType === device.bot?.deviceType ? this.accessory.context.botDeviceType
|
|
@@ -1476,6 +1249,8 @@ export class Bot extends deviceBase {
|
|
|
1476
1249
|
}
|
|
1477
1250
|
|
|
1478
1251
|
async apiError(e: any): Promise<void> {
|
|
1252
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
1253
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
1479
1254
|
if (this.botDeviceType === 'garagedoor') {
|
|
1480
1255
|
if (this.GarageDoor) {
|
|
1481
1256
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, e);
|
|
@@ -1527,7 +1302,5 @@ export class Bot extends deviceBase {
|
|
|
1527
1302
|
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
1528
1303
|
}
|
|
1529
1304
|
}
|
|
1530
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
1531
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
1532
1305
|
}
|
|
1533
1306
|
}
|