@@ -90,6 +90,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
90
90
private runningService ?: Service
91
91
private binService ?: Service
92
92
private dockingService ?: Service
93
+ private homeService ?: Service
93
94
94
95
/**
95
96
* The last known state from Roomba, if any.
@@ -138,6 +139,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
138
139
const showRunningAsContactSensor = config . runningContactSensor ;
139
140
const showBinStatusAsContactSensor = config . binContactSensor ;
140
141
const showDockingAsContactSensor = config . dockingContactSensor ;
142
+ const showHomeSwitch = config . homeSwitch ;
141
143
142
144
const Service = api . hap . Service ;
143
145
@@ -156,7 +158,10 @@ export default class RoombaAccessory implements AccessoryPlugin {
156
158
this . binService = new Service . ContactSensor ( this . name + " Bin Full" , "Full" ) ;
157
159
}
158
160
if ( showDockingAsContactSensor ) {
159
- this . dockingService = new Service . Switch ( this . name + " Docking" , "docking" ) ;
161
+ this . dockingService = new Service . ContactSensor ( this . name + " Docking" , "docking" ) ;
162
+ }
163
+ if ( showHomeSwitch ) {
164
+ this . homeService = new Service . Switch ( this . name + " Home" , "returning" ) ;
160
165
}
161
166
162
167
const Characteristic = this . api . hap . Characteristic ;
@@ -204,9 +209,14 @@ export default class RoombaAccessory implements AccessoryPlugin {
204
209
}
205
210
if ( this . dockingService ) {
206
211
this . dockingService
212
+ . getCharacteristic ( Characteristic . ContactSensorState )
213
+ . on ( "get" , this . createCharacteristicGetter ( "Docking status" , this . dockingStatus ) ) ;
214
+ }
215
+ if ( this . homeService ) {
216
+ this . homeService
207
217
. getCharacteristic ( Characteristic . On )
208
218
. on ( "set" , this . setDockingState . bind ( this ) )
209
- . on ( "get" , this . createCharacteristicGetter ( "Docking status " , this . dockingStatus ) ) ;
219
+ . on ( "get" , this . createCharacteristicGetter ( "Returning Home " , this . dockingStatus ) ) ;
210
220
}
211
221
212
222
this . startLongWatch ( ) ;
@@ -236,6 +246,9 @@ export default class RoombaAccessory implements AccessoryPlugin {
236
246
if ( this . dockingService ) {
237
247
services . push ( this . dockingService ) ;
238
248
}
249
+ if ( this . homeService ) {
250
+ services . push ( this . homeService ) ;
251
+ }
239
252
240
253
return services ;
241
254
}
@@ -720,6 +733,9 @@ export default class RoombaAccessory implements AccessoryPlugin {
720
733
if ( this . dockingService ) {
721
734
updateCharacteristic ( this . dockingService , Characteristic . ContactSensorState , this . dockingStatus ) ;
722
735
}
736
+ if ( this . homeService ) {
737
+ updateCharacteristic ( this . homeService , Characteristic . On , this . dockingStatus ) ;
738
+ }
723
739
724
740
this . lastUpdatedStatus = {
725
741
...this . lastUpdatedStatus ,
@@ -792,8 +808,8 @@ export default class RoombaAccessory implements AccessoryPlugin {
792
808
private dockingStatus = ( status : Status ) => status . docking === undefined
793
809
? undefined
794
810
: status . docking
795
- ? 1
796
- : 0 ;
811
+ ? this . api . hap . Characteristic . ContactSensorState . CONTACT_NOT_DETECTED
812
+ : this . api . hap . Characteristic . ContactSensorState . CONTACT_DETECTED ;
797
813
private dockedStatus = ( status : Status ) => status . charging === undefined
798
814
? undefined
799
815
: status . charging
0 commit comments