@@ -9,6 +9,7 @@ const STATUS_COALLESCE_WINDOW_MILLIS = 5_000;
9
9
interface Status {
10
10
error : null
11
11
running : boolean
12
+ docking : boolean
12
13
charging : boolean
13
14
batteryLevel : number | null
14
15
binFull : boolean
@@ -41,6 +42,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
41
42
private dockService ?: Service
42
43
private runningService ?: Service
43
44
private binService ?: Service
45
+ private dockingService ?: Service
44
46
45
47
/**
46
48
* The last known state from Roomba, if any.
@@ -71,6 +73,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
71
73
const showDockAsContactSensor = config . dockContactSensor === undefined ? true : config . dockContactSensor ;
72
74
const showRunningAsContactSensor = config . runningContactSensor ;
73
75
const showBinStatusAsContactSensor = config . binContactSensor ;
76
+ const showDockingAsContactSensor = config . dockingContactSensor ;
74
77
75
78
const Service = api . hap . Service ;
76
79
@@ -87,6 +90,9 @@ export default class RoombaAccessory implements AccessoryPlugin {
87
90
if ( showBinStatusAsContactSensor ) {
88
91
this . binService = new Service . ContactSensor ( this . name + " Bin Full" , "Full" ) ;
89
92
}
93
+ if ( showDockingAsContactSensor ) {
94
+ this . dockingService = new Service . ContactSensor ( this . name + " Docking" , "docking" ) ;
95
+ }
90
96
91
97
this . pendingStatusRequests = [ ] ;
92
98
}
@@ -150,6 +156,12 @@ export default class RoombaAccessory implements AccessoryPlugin {
150
156
. on ( "get" , this . createCharacteristicGetter ( "Bin status" , this . binStatus ) ) ;
151
157
services . push ( this . binService ) ;
152
158
}
159
+ if ( this . dockingService ) {
160
+ this . dockingService
161
+ . getCharacteristic ( Characteristic . ContactSensorState )
162
+ . on ( "get" , this . createCharacteristicGetter ( "Docking status" , this . dockingStatus ) ) ;
163
+ services . push ( this . dockingService ) ;
164
+ }
153
165
154
166
return services ;
155
167
}
@@ -182,6 +194,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
182
194
this . mergeStatus ( {
183
195
running : true ,
184
196
charging : false ,
197
+ docking : false ,
185
198
} ) ;
186
199
187
200
this . log ( "Roomba is running" ) ;
@@ -209,6 +222,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
209
222
this . mergeStatus ( {
210
223
running : false ,
211
224
charging : false ,
225
+ docking : false ,
212
226
} ) ;
213
227
214
228
this . log ( "Roomba paused, returning to Dock" ) ;
@@ -245,6 +259,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
245
259
this . mergeStatus ( {
246
260
running : false ,
247
261
charging : false ,
262
+ docking : true ,
248
263
} ) ;
249
264
250
265
break ;
@@ -373,6 +388,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
373
388
const status : Status = {
374
389
error : null ,
375
390
running : false ,
391
+ docking : false ,
376
392
charging : false ,
377
393
batteryLevel : null ,
378
394
binFull : false ,
@@ -385,16 +401,33 @@ export default class RoombaAccessory implements AccessoryPlugin {
385
401
case "run" :
386
402
status . running = true ;
387
403
status . charging = false ;
404
+ status . docking = false ;
388
405
389
406
break ;
390
407
case "charge" :
391
408
status . running = false ;
392
409
status . charging = true ;
410
+ status . docking = false ;
411
+
412
+ break ;
413
+ case "hmUsrDock" :
414
+ status . running = false ;
415
+ status . charging = false ;
416
+ status . docking = true ;
417
+
418
+ break ;
419
+ case "stop" :
420
+ status . running = false ;
421
+ status . charging = true ;
422
+ status . docking = false ;
393
423
394
424
break ;
395
425
default :
426
+ this . log . info ( `Unsupported phase: ${ state . cleanMissionStatus ! . phase } ` ) ;
427
+
396
428
status . running = false ;
397
429
status . charging = false ;
430
+ status . docking = false ;
398
431
399
432
break ;
400
433
}
@@ -434,6 +467,11 @@ export default class RoombaAccessory implements AccessoryPlugin {
434
467
. getCharacteristic ( Characteristic . ContactSensorState )
435
468
. updateValue ( this . binStatus ( status ) ) ;
436
469
}
470
+ if ( this . dockingService ) {
471
+ this . dockingService
472
+ . getCharacteristic ( Characteristic . ContactSensorState )
473
+ . updateValue ( this . dockingStatus ( status ) ) ;
474
+ }
437
475
}
438
476
439
477
private runningStatus = ( status : Status ) => status . running
@@ -442,6 +480,9 @@ export default class RoombaAccessory implements AccessoryPlugin {
442
480
private chargingStatus = ( status : Status ) => status . charging
443
481
? this . api . hap . Characteristic . ChargingState . CHARGING
444
482
: this . api . hap . Characteristic . ChargingState . NOT_CHARGING ;
483
+ private dockingStatus = ( status : Status ) => status . docking
484
+ ? this . api . hap . Characteristic . ContactSensorState . CONTACT_NOT_DETECTED
485
+ : this . api . hap . Characteristic . ContactSensorState . CONTACT_DETECTED ;
445
486
private dockedStatus = ( status : Status ) => status . charging
446
487
? this . api . hap . Characteristic . ContactSensorState . CONTACT_NOT_DETECTED
447
488
: this . api . hap . Characteristic . ContactSensorState . CONTACT_DETECTED ;
0 commit comments