@@ -260,9 +260,14 @@ export default class RoombaAccessory implements AccessoryPlugin {
260
260
return services ;
261
261
}
262
262
263
- private refreshState ( ) {
263
+ /**
264
+ * Refresh our knowledge of Roomba's state by connecting to Roomba and getting its status.
265
+ * @param force whether to force a refresh, or whether it's okay to use a recent cached state.
266
+ * @returns `true` if the state was refreshed, or `false` if a recent cached state is available instead.
267
+ */
268
+ private refreshState ( force ?: boolean ) : boolean {
264
269
const now = Date . now ( ) ;
265
- if ( now - this . lastRefreshState < REFRESH_STATE_COALESCE_MILLIS ) {
270
+ if ( ! force && now - this . lastRefreshState < REFRESH_STATE_COALESCE_MILLIS ) {
266
271
return false ;
267
272
}
268
273
this . lastRefreshState = now ;
@@ -450,7 +455,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
450
455
callback ( ) ;
451
456
452
457
/* Force a refresh of state so we pick up the new state quickly */
453
- this . refreshState ( ) ;
458
+ this . refreshState ( true ) ;
454
459
455
460
/* After sending an action to Roomba, we start watching to ensure HomeKit has up to date status */
456
461
this . startWatching ( ) ;
@@ -481,7 +486,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
481
486
callback ( ) ;
482
487
483
488
/* Force a refresh of state so we pick up the new state quickly */
484
- this . refreshState ( ) ;
489
+ this . refreshState ( true ) ;
485
490
486
491
if ( this . stopBehaviour === "home" ) {
487
492
this . log . debug ( "Roomba paused, returning to Dock" ) ;
@@ -496,7 +501,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
496
501
callback ( ) ;
497
502
498
503
/* Force a refresh of state so we pick up the new state quickly */
499
- this . refreshState ( ) ;
504
+ this . refreshState ( true ) ;
500
505
501
506
this . log . debug ( "Roomba paused" ) ;
502
507
} else if ( state . charging ) {
@@ -538,7 +543,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
538
543
callback ( ) ;
539
544
540
545
/* Force a refresh of state so we pick up the new state quickly */
541
- this . refreshState ( ) ;
546
+ this . refreshState ( true ) ;
542
547
543
548
/* After sending an action to Roomba, we start watching to ensure HomeKit has up to date status */
544
549
this . startWatching ( ) ;
@@ -563,7 +568,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
563
568
this . log . debug ( "Roomba docking" ) ;
564
569
565
570
/* Force a refresh of state so we pick up the new state quickly */
566
- this . refreshState ( ) ;
571
+ this . refreshState ( true ) ;
567
572
568
573
break ;
569
574
case "run" :
0 commit comments