From d68f70b3dd7362b93b2298d50bb617b7f43aee39 Mon Sep 17 00:00:00 2001 From: jackchi Date: Fri, 12 Aug 2016 14:33:42 -0700 Subject: [PATCH] [CHF-204] Implementation of PING in SmartPower Outlet --- .../smartpower-outlet.groovy | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy b/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy index 11febf1..4a71834 100644 --- a/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy +++ b/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy @@ -101,6 +101,12 @@ def parse(String description) { else { def descriptionText = finalResult.value == "on" ? '{{ device.displayName }} is On' : '{{ device.displayName }} is Off' sendEvent(name: finalResult.type, value: finalResult.value, descriptionText: descriptionText, translatable: true) + // Temporary fix for the case when Device is OFFLINE and is connected again + if (state.lastOnOff == null){ + state.lastOnOff = now() + sendEvent(name: "deviceWatch-lastActivity", value: state.lastOnOff, description: "Last Activity is on ${new Date(state.lastOnOff)}", displayed: false, isStateChange: true) + } + state.lastOnOff = now() } } else { @@ -116,9 +122,24 @@ def off() { def on() { zigbee.on() } +/** + * PING is used by Device-Watch in attempt to reach the Outlet + * */ +def ping() { + + // send read attribute onOFF if the last time we heard from the outlet is outside of the checkInterval + if (state.lastOnOff < (now() - (1000 * device.currentValue("checkInterval"))) ){ + log.info "ping, alive=no, lastOnOff=${new Date(state.lastOnOff)}" + state.lastOnOff = null + return zigbee.onOffRefresh() + } else { // if the last onOff activity is within the checkInterval we artificially create a Device-Watch event + log.info "ping, alive=yes, lastOnOff=${new Date(state.lastOnOff)}" + sendEvent(name: "deviceWatch-lastActivity", value: state.lastOnOff, description: "Last Activity is on ${new Date(state.lastOnOff)}", displayed: false, isStateChange: true) + } +} def refresh() { - zigbee.onOffRefresh() + zigbee.refreshData("0x0B04", "0x050B") + zigbee.onOffRefresh() + zigbee.electricMeasurementPowerRefresh() } def configure() {