Skip to content

Commit

Permalink
Icp 5475 [UK] Incorrect device states on ST Classic app (SmartThingsC…
Browse files Browse the repository at this point in the history
…ommunity#3278)

* ICP-5475 [UK] Incorrect device states on ST Classic app
Fixed device states according to temperatureAlarm capability
Added battery initial state check

* ICP-5475 Post review fixes

* ICP-5475 clearHeat changed to clear
  • Loading branch information
Mariusz A authored and greens committed Jul 23, 2018
1 parent a347569 commit 2923f14
Showing 1 changed file with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ metadata {

tiles(scale: 2) {
multiAttributeTile(name: "heat", type: "lighting", width: 6, height: 4) {
tileAttribute("device.heat", key: "PRIMARY_CONTROL") {
tileAttribute("device.temperatureAlarm", key: "PRIMARY_CONTROL") {
attributeState("cleared", label: "cleared", icon: "st.alarm.smoke.clear", backgroundColor: "#ffffff")
attributeState("detected", label: "HEAT", icon: "st.alarm.smoke.smoke", backgroundColor: "#e86d13")
attributeState("tested", label: "TEST", icon: "st.alarm.smoke.test", backgroundColor: "#e86d13")
attributeState("heat", label: "HEAT", icon: "st.alarm.smoke.smoke", backgroundColor: "#e86d13")
}
}
valueTile("battery", "device.battery", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
Expand All @@ -49,15 +48,19 @@ metadata {

def installed() {
def cmds = []
// Device checks in every 4 hours, this interval allows us to miss one check-in notification before marking offline
cmds << createEvent(name: "checkInterval", value: 8 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
cmds << createHeatEvents("heatClear")
cmds << checkIntervalEvent
cmds << createHeatEvents("clear")
cmds.each { cmd -> sendEvent(cmd) }
response(initialPoll())
}

def updated() {
//sendEvent(checkIntervalEvent)
}

def getCheckIntervalEvent() {
// Device checks in every 4 hours, this interval allows us to miss one check-in notification before marking offline
sendEvent(name: "checkInterval", value: 8 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
createEvent(name: "checkInterval", value: 8 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
}

def getCommandClassVersions() {
Expand Down Expand Up @@ -123,17 +126,15 @@ def zwaveEvent(physicalgraph.zwave.commands.notificationv3.NotificationReport cm
switch (cmd.event) {
case 0x00:
case 0xFE:
result = createHeatEvents("heatClear")
result = createHeatEvents("clear")
break
case 0x01: //Overheat detected
case 0x02: //Overheat detected Unknown Location
case 0x03: //Rapid Temperature Rise
case 0x03: //Rapid Temperature Rise Unknown Location
case 0x07: //Tested
result = createHeatEvents("heat")
break
case 0x07:
result = createHeatEvents("tested")
break
}
}
return result
Expand All @@ -145,20 +146,32 @@ def createHeatEvents(name) {
switch (name) {
case "heat":
text = "$device.displayName heat was detected!"
result = createEvent(name: "heat", value: "detected", descriptionText: text)
result = createEvent(name: "temperatureAlarm", value: "heat", descriptionText: text)
break
case "tested":
text = "$device.displayName heat tested"
result = createEvent(name: "heat", value: "tested", descriptionText: text)
break
case "heatClear":
case "clear":
text = "$device.displayName heat is clear"
result = createEvent(name: "heat", value: "cleared", descriptionText: text)
break
case "testClear":
text = "$device.displayName heat cleared"
result = createEvent(name: "heat", value: "cleared", descriptionText: text)
result = createEvent(name: "temperatureAlarm", value: "cleared", descriptionText: text, isStateChange: true)
log.debug "Clear event created"
break
}
return result
}

private command(physicalgraph.zwave.Command cmd) {
if (zwaveInfo?.zw?.endsWith("s")) {
zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
} else {
cmd.format()
}
}

private commands(commands, delay = 200) {
delayBetween(commands.collect { command(it) }, delay)
}

def initialPoll() {
def request = []
// check initial battery
request << zwave.batteryV1.batteryGet()
commands(request, 500) + ["delay 6000", command(zwave.wakeUpV1.wakeUpNoMoreInformation())]
}

0 comments on commit 2923f14

Please sign in to comment.