File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " homebridge-roomba2 " : patch
3
+ ---
4
+
5
+ Add a timeout when waiting for the full status from Roomba so we release our connection to Roomba
Original file line number Diff line number Diff line change @@ -23,6 +23,11 @@ const WATCH_IDLE_TIMEOUT_MILLIS = 600_000;
23
23
*/
24
24
const MAX_CACHED_STATUS_AGE_MILLIS = 60_000 ;
25
25
26
+ /**
27
+ * How long will we wait for the Roomba to send status before giving up?
28
+ */
29
+ const MAX_WAIT_FOR_STATUS_MILLIS = 60_000 ;
30
+
26
31
/**
27
32
* Coalesce refreshState requests into one when they're less than this many millis apart.
28
33
*/
@@ -236,10 +241,27 @@ export default class RoombaAccessory implements AccessoryPlugin {
236
241
return ;
237
242
}
238
243
244
+ const startedWaitingForStatus = Date . now ( ) ;
245
+
239
246
/* Wait until we've received a state with all of the information we desire */
240
247
return new Promise ( ( resolve ) => {
248
+ let receivedState : RobotState | undefined = undefined ;
249
+
250
+ const timeout = setTimeout ( ( ) => {
251
+ this . log . debug (
252
+ "Timeout waiting for full state from Roomba ({}ms). Last state received was: %s" ,
253
+ Date . now ( ) - startedWaitingForStatus ,
254
+ receivedState ? JSON . stringify ( receivedState ) : "<none>" ,
255
+ ) ;
256
+ resolve ( ) ;
257
+ } , MAX_WAIT_FOR_STATUS_MILLIS ) ;
258
+
241
259
const updateState = ( state : RobotState ) => {
260
+ receivedState = state ;
261
+
242
262
if ( this . receivedRobotStateIsComplete ( state ) ) {
263
+ clearTimeout ( timeout ) ;
264
+
243
265
/* NB: the actual state is received and updated in the listener in connect() */
244
266
this . log . debug (
245
267
"Refreshed Roomba's state in %ims: %s" ,
You can’t perform that action at this time.
0 commit comments