From 778adedfd6aac6e953ba1c4e39f8c7724622db4e Mon Sep 17 00:00:00 2001 From: Jo Rhett Date: Tue, 7 Apr 2020 22:24:28 -0700 Subject: [PATCH] Simplify and unify timeline event processing --- drivers/AbodeAlarm.groovy | 65 ++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/drivers/AbodeAlarm.groovy b/drivers/AbodeAlarm.groovy index 4f9dc42..3845cb8 100644 --- a/drivers/AbodeAlarm.groovy +++ b/drivers/AbodeAlarm.groovy @@ -529,29 +529,7 @@ def parseEvent(String event_text) { // JSON format case ~/^\{.*\}$/: - details = parseJson(event_data) - - // These may or may not exist on any given event - user_info = formatEventUser(details) - message = details.event_name ?: details.message ?: '' - device_type = details.device_type ?: '' - event_type = details.event_type ?: '' - alert_value = [ - details.device_name, - event_type - ].findAll { it.isEmpty() == false }.join(' ') - - if (event_type == 'Automation') { - alert_type = 'CUE Automation' - // Automation puts the rule name in device_name, which is backwards for our purposes - alert_value = details.device_name - } - else if (user_info.isEmpty() == false) - alert_type = user_info - else if (device_type.isEmpty() == false) - alert_type = device_type - else - alert_type = '' + json_data = parseJson(event_data) break default: @@ -564,20 +542,43 @@ def parseEvent(String event_text) { updateMode(message) break + // Presence/Geofence updates + case ~/fence.update.*/: + if (saveGeofence) + sendEvent(name: 'gatewayTimeline', + value: "${json_data.name}@${json_data.location}=${json_data.state}", + descriptionText: json_data.message, + type: 'Geofence' + ) + break + case ~/^gateway\.timeline.*/: - if (logDebug) log.debug "${event_class} -${device_type} ${message}" + event_type = json_data.event_type + message = json_data.event_name + user_info = formatEventUser(json_data) + + if (logDebug) log.debug "${event_class} -${json_data.device_type} ${message}" + + if (event_type == 'Automation') { + alert_type = 'CUE Automation' + // Automation puts the rule name in device_name, which is backwards for our purposes + alert_value = json_data.device_name + } + else { + alert_value = [json_data.device_name, event_type].findAll { it.isEmpty() == false }.join('=') + if (user_info.isEmpty() == false) + alert_type = user_info + else if (json_data.device_type.isEmpty() == false) + alert_type = json_data.device_type + else + alert_type = '' + } // Devices we ignore events for - if (! devicesToIgnore().contains(details.device_name)) { + if (! devicesToIgnore().contains(json_data.device_name)) { if (syncArming) syncArmingEvents(event_type) - sendEnabledEvents(alert_value, message, alert_type) + sendEnabledEvents(alert_value, message, alert_type) } - break - - // Presence/Geofence updates - case ~/fence.update.*/: - if (saveGeofence) - sendEvent(name: 'gatewayTimeline', value: details.location, descriptionText: details.message, type: 'Geofence') break default: