@@ -197,20 +197,23 @@ private clearLoginState() {
197
197
sendEvent(name : ' isLoggedIn' , value : false , displayed : true )
198
198
}
199
199
200
+ // Send a request to change mode to Abode
200
201
private changeMode (String new_mode ) {
201
- current_mode = mode
202
- if (current_mode != new_mode) {
202
+ if (new_mode != device . currentValue( ' gatewayMode ' )) {
203
+ // Only update area 1 since area is not returned in event messages
203
204
reply = doHttpRequest(' PUT' ,' /api/v1/panel/mode/1/' + new_mode)
204
- if (reply[' area' ] == 1 )
205
- log. info " Successfully sent request to change gateway mode to ${ new_mode} "
205
+ if (reply[' area' ] == ' 1' ) {
206
+ log. info " Sent request to change Abode gateway mode to ${ new_mode} "
207
+ state. localModeChange = new_mode
208
+ }
206
209
} else {
207
210
if (logDebug) log. debug " Gateway is already in mode ${ new_mode} "
208
211
}
209
212
}
210
213
211
- // Only update area 1 since area is not provided in event messages
214
+ // Process an update from Abode that the mode has changed
212
215
private updateMode (String new_mode ) {
213
- if (logDebug) log. info ' Gateway mode has changed to ' + new_mode
216
+ log. info ' Abode gateway mode has changed to ' + new_mode
214
217
sendEvent(name : " gatewayMode" , value : new_mode, descriptionText : ' Gateway mode has changed to ' + new_mode, displayed : true )
215
218
216
219
// Set isArmed?
@@ -219,10 +222,20 @@ private updateMode(String new_mode) {
219
222
isArmed. off()
220
223
else {
221
224
isArmed. on()
222
- if (targetModeAway && new_mode == ' away' )
223
- location. setMode(targetModeAway)
224
- else if (targetModeHome)
225
- location. setMode(targetModeHome)
225
+
226
+ // Avoid changing the mode if it's a rebound from a local action
227
+ if (new_mode == state. localModeChange) {
228
+ state. remove(' localModeChange' )
229
+ } else {
230
+ if (targetModeAway && new_mode == ' away' ) {
231
+ log. info ' Changing Hubitat mode to ' + new_mode
232
+ location. setMode(targetModeAway)
233
+ }
234
+ else if (targetModeHome) {
235
+ log. info ' Changing Hubitat mode to ' + new_mode
236
+ location. setMode(targetModeHome)
237
+ }
238
+ }
226
239
}
227
240
}
228
241
@@ -285,7 +298,7 @@ private parseMode(Map mode, Set areas) {
285
298
modeMap[number] = mode[" area_${ number} " ]
286
299
}
287
300
// Status is based on area 1 only
288
- if (gatewayMode != modeMap[' 1' ])
301
+ if (device . currentValue( ' gatewayMode' ) != modeMap[' 1' ])
289
302
sendEvent(name : " gatewayMode" , value : modeMap[' 1' ], descriptionText : " Gateway mode is ${ modeMap['1']} " , displayed : true )
290
303
291
304
state. modes = modeMap
@@ -359,7 +372,7 @@ private doHttpRequest(String method, String path, Map body = [:]) {
359
372
}
360
373
361
374
// Abode event websocket handling
362
- private connectEventSocket () {
375
+ def connectEventSocket () {
363
376
if (! state. webSocketConnectAttempt) state. webSocketConnectAttempt = 0
364
377
if (logDebug) log. debug " Attempting WebSocket connection for Abode events (attempt ${ state.webSocketConnectAttempt} )"
365
378
try {
@@ -388,10 +401,10 @@ private terminateEventSocket() {
388
401
}
389
402
}
390
403
404
+ // failure handler: validate state and reconnect in 5 seconds
391
405
private restartEventSocket () {
392
406
terminateEventSocket()
393
- refresh()
394
- runInMillis(30000 , connectEventSocket) // Try connect again in 30 seconds
407
+ runInMillis(5000 , refresh)
395
408
}
396
409
397
410
def sendPing () {
@@ -408,11 +421,16 @@ def receivePong() {
408
421
runInMillis(state. webSocketPingInterval, sendPing)
409
422
}
410
423
424
+ // This is called every 5 minutes whether we are connected or not
411
425
def checkSocketTimeout () {
412
- responseTimeout = state. lastMsgReceived + state. webSocketPingTimeout + (timeoutSlack* 1000 )
413
- if (now() > responseTimeout) {
414
- log. warn ' Socket ping timeout - Disconnecting Abode event socket'
415
- restartEventSocket()
426
+ if (state. webSocketConnected) {
427
+ responseTimeout = state. lastMsgReceived + state. webSocketPingTimeout + (timeoutSlack* 1000 )
428
+ if (now() > responseTimeout) {
429
+ log. warn ' Socket ping timeout - Disconnecting Abode event socket'
430
+ restartEventSocket()
431
+ }
432
+ } else {
433
+ connectEventSocket()
416
434
}
417
435
}
418
436
0 commit comments