From b10308fe5cd21c32f5ee2df7913dfa5804674c0c Mon Sep 17 00:00:00 2001 From: Vinay Rao Date: Tue, 25 Aug 2015 20:57:27 -0700 Subject: [PATCH] Handling the power issues via configuring --- .../smartpower-dimming-outlet.groovy | 3 +- .../smartpower-outlet.groovy | 32 +++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/devicetypes/smartthings/smartpower-dimming-outlet.src/smartpower-dimming-outlet.groovy b/devicetypes/smartthings/smartpower-dimming-outlet.src/smartpower-dimming-outlet.groovy index 51084ec..d77fe0a 100644 --- a/devicetypes/smartthings/smartpower-dimming-outlet.src/smartpower-dimming-outlet.groovy +++ b/devicetypes/smartthings/smartpower-dimming-outlet.src/smartpower-dimming-outlet.groovy @@ -287,7 +287,8 @@ def isDescriptionPower(descMap) { def powerValue = "undefined" if (descMap.cluster == "0B04") { if (descMap.attrId == "050b") { - powerValue = convertHexToInt(descMap.value) + if(descMap.value!="ffff") + powerValue = convertHexToInt(descMap.value) } } else if (descMap.clusterId == "0B04") { diff --git a/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy b/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy index a33ed59..4876815 100644 --- a/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy +++ b/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy @@ -70,9 +70,10 @@ def parse(String description) { log.debug "description is $description" def finalResult = zigbee.getKnownDescription(description) + //TODO: Remove this after getKnownDescription can parse it automatically - if (!finalResult) - finalResult = zigbee.getPowerDescription(zigbee.parseDescriptionAsMap(description)) + if (!finalResult && description!="updated") + finalResult = getPowerDescription(zigbee.parseDescriptionAsMap(description)) if (finalResult) { log.info finalResult @@ -124,3 +125,30 @@ def powerConfig() { "send 0x${device.deviceNetworkId} 1 ${endpointId}", "delay 500" ] } + +private getEndpointId() { + new BigInteger(device.endpointId, 16).toString() +} + +//TODO: Remove this after getKnownDescription can parse it automatically +def getPowerDescription(descMap) { + def powerValue = "undefined" + if (descMap.cluster == "0B04") { + if (descMap.attrId == "050b") { + if(descMap.value!="ffff") + powerValue = convertHexToInt(descMap.value) + } + } + else if (descMap.clusterId == "0B04") { + if(descMap.command=="07"){ + return [type: "update", value : "power (0B04) capability configured successfully"] + } + } + + if (powerValue != "undefined"){ + return [type: "power", value : powerValue] + } + else { + return "false" + } +}