@@ -18,10 +18,15 @@ const WATCH_INTERVAL_MILLIS = 30_000;
18
18
*/
19
19
const WATCH_IDLE_TIMEOUT_MILLIS = 600_000 ;
20
20
21
+ /**
22
+ * How often to query Roomba and update HomeKit when not actively watching Roomba's status.
23
+ */
24
+ const LONG_WATCH_INTERVAL_MILLIS = 3600 * 1000 ; // 24 * 60 * 60 * 1000;
25
+
21
26
/**
22
27
* How old a cached status can be before we ignore it.
23
28
*/
24
- const MAX_CACHED_STATUS_AGE_MILLIS = 60_000 ;
29
+ const MAX_CACHED_STATUS_AGE_MILLIS = LONG_WATCH_INTERVAL_MILLIS + 600_000 ;
25
30
26
31
/**
27
32
* How long will we wait for the Roomba to send status before giving up?
@@ -202,6 +207,8 @@ export default class RoombaAccessory implements AccessoryPlugin {
202
207
. getCharacteristic ( Characteristic . ContactSensorState )
203
208
. on ( "get" , this . createCharacteristicGetter ( "Docking status" , this . dockingStatus ) ) ;
204
209
}
210
+
211
+ this . startLongWatch ( ) ;
205
212
}
206
213
207
214
public identify ( ) : void {
@@ -715,7 +722,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
715
722
}
716
723
717
724
this . log . debug (
718
- "Refreshing Roomba's status (repeating in %is, idle timeout in %is)" ,
725
+ "Watching Roomba's status (repeating in %is, idle timeout in %is)" ,
719
726
WATCH_INTERVAL_MILLIS / 1000 ,
720
727
( WATCH_IDLE_TIMEOUT_MILLIS - timeSinceLastWatchingRequest ) / 1000
721
728
) ;
@@ -734,6 +741,18 @@ export default class RoombaAccessory implements AccessoryPlugin {
734
741
}
735
742
}
736
743
744
+ private startLongWatch ( ) {
745
+ const checkStatus = ( ) => {
746
+ this . log . info ( "Refreshing Roomba's status (repeating in %im)" , LONG_WATCH_INTERVAL_MILLIS / 60_000 ) ;
747
+
748
+ this . refreshState ( ) ;
749
+
750
+ setTimeout ( checkStatus , LONG_WATCH_INTERVAL_MILLIS ) ;
751
+ } ;
752
+
753
+ checkStatus ( ) ;
754
+ }
755
+
737
756
private runningStatus = ( status : Status ) => status . running === undefined
738
757
? undefined
739
758
: status . running
0 commit comments