Merge pull request #2208 from SmartThingsCommunity/staging

Rolling up staging to production
This commit is contained in:
Vinay Rao
2017-08-01 12:24:56 -07:00
committed by GitHub
6 changed files with 57 additions and 24 deletions

View File

@@ -133,8 +133,8 @@ def updated() {
} }
def initialize() { def initialize() {
// Arrival sensors only goes OFFLINE when Hub is off // Device only goes OFFLINE when Hub is off
sendEvent(name: "DeviceWatch-Enroll", value: JsonOutput.toJson([protocol: "zigbee", scheme:"untracked"]), displayed: false) sendEvent(name: "DeviceWatch-Enroll", value: JsonOutput.toJson([protocol: "zwave", scheme:"untracked"]), displayed: false)
def zwMap = getZwaveInfo() def zwMap = getZwaveInfo()
def buttons = 4 // Default for Key Fob def buttons = 4 // Default for Key Fob

View File

@@ -111,7 +111,6 @@ def configure() {
return cmds return cmds
} }
def installed() { def installed() {
initialize() initialize()
} }
@@ -121,7 +120,7 @@ def updated() {
} }
def initialize() { def initialize() {
// Arrival sensors only goes OFFLINE when Hub is off // Device only goes OFFLINE when Hub is off
sendEvent(name: "DeviceWatch-Enroll", value: JsonOutput.toJson([protocol: "zigbee", scheme:"untracked"]), displayed: false) sendEvent(name: "DeviceWatch-Enroll", value: JsonOutput.toJson([protocol: "zwave", scheme:"untracked"]), displayed: false)
sendEvent(name: "numberOfButtons", value: 4) sendEvent(name: "numberOfButtons", value: 4)
} }

View File

@@ -173,11 +173,27 @@ private Map getBatteryResult(rawValue) {
} else { } else {
def minVolts = 2.4 def minVolts = 2.4
def maxVolts = 2.7 def maxVolts = 2.7
def pct = (volts - minVolts) / (maxVolts - minVolts) // Get the current battery percentage as a multiplier 0 - 1
def roundedPct = Math.round(pct * 100) def curValVolts = Integer.parseInt(device.currentState("battery")?.value ?: "100") / 100.0
if (roundedPct <= 0) // Find the corresponding voltage from our range
roundedPct = 1 curValVolts = curValVolts * (maxVolts - minVolts) + minVolts
result.value = Math.min(100, roundedPct) // Round to the nearest 10th of a volt
curValVolts = Math.round(10 * curValVolts) / 10.0
// Only update the battery reading if we don't have a last reading,
// OR we have received the same reading twice in a row
// OR we don't currently have a battery reading
// OR the value we just received is at least 2 steps off from the last reported value
if(state?.lastVolts == null || state?.lastVolts == volts || device.currentState("battery")?.value == null || Math.abs(curValVolts - volts) > 0.1) {
def pct = (volts - minVolts) / (maxVolts - minVolts)
def roundedPct = Math.round(pct * 100)
if (roundedPct <= 0)
roundedPct = 1
result.value = Math.min(100, roundedPct)
} else {
// Don't update as we want to smooth the battery values
result = null
}
state.lastVolts = volts
} }
} }

View File

@@ -275,11 +275,27 @@ private Map getBatteryResult(rawValue) {
} else { } else {
def minVolts = 2.1 def minVolts = 2.1
def maxVolts = 2.7 def maxVolts = 2.7
def pct = (volts - minVolts) / (maxVolts - minVolts) // Get the current battery percentage as a multiplier 0 - 1
def roundedPct = Math.round(pct * 100) def curValVolts = Integer.parseInt(device.currentState("battery")?.value ?: "100") / 100.0
if (roundedPct <= 0) // Find the corresponding voltage from our range
roundedPct = 1 curValVolts = curValVolts * (maxVolts - minVolts) + minVolts
result.value = Math.min(100, roundedPct) // Round to the nearest 10th of a volt
curValVolts = Math.round(10 * curValVolts) / 10.0
// Only update the battery reading if we don't have a last reading,
// OR we have received the same reading twice in a row
// OR we don't currently have a battery reading
// OR the value we just received is at least 2 steps off from the last reported value
if(state?.lastVolts == null || state?.lastVolts == volts || device.currentState("battery")?.value == null || Math.abs(curValVolts - volts) > 0.1) {
def pct = (volts - minVolts) / (maxVolts - minVolts)
def roundedPct = Math.round(pct * 100)
if (roundedPct <= 0)
roundedPct = 1
result.value = Math.min(100, roundedPct)
} else {
// Don't update as we want to smooth the battery values
result = null
}
state.lastVolts = volts
} }
} }

View File

@@ -88,19 +88,21 @@ import physicalgraph.zwave.commands.usercodev1.*
def installed() { def installed() {
// Device-Watch pings if no device events received for 1 hour (checkInterval) // Device-Watch pings if no device events received for 1 hour (checkInterval)
sendEvent(name: "checkInterval", value: 1 * 60 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID]) sendEvent(name: "checkInterval", value: 1 * 60 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
try {
if (!state.init) {
state.init = true
// Wait long enough for behind-the-scenes z-wave magic to finish, but be quick enough before hub goes back into inclusion and blocks us
response(["delay 2000"] + secureSequence([zwave.doorLockV1.doorLockOperationGet(), zwave.batteryV1.batteryGet()], 2200))
}
} catch (e) {
log.warn "installed() threw $e"
}
} }
def updated() { def updated() {
// Device-Watch pings if no device events received for 1 hour (checkInterval) // Device-Watch pings if no device events received for 1 hour (checkInterval)
sendEvent(name: "checkInterval", value: 1 * 60 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID]) sendEvent(name: "checkInterval", value: 1 * 60 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
try {
if (!state.init) {
state.init = true
response(secureSequence([zwave.doorLockV1.doorLockOperationGet(), zwave.batteryV1.batteryGet()]))
}
} catch (e) {
log.warn "updated() threw $e"
}
} }
def parse(String description) { def parse(String description) {

View File

@@ -72,7 +72,7 @@ def createEvents(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd) {
def poll() { def poll() {
if (secondsPast(state.lastbatt, 36*60*60)) { if (secondsPast(state.lastbatt, 36*60*60)) {
return zwave.batteryV1.batteryGet().format return zwave.batteryV1.batteryGet().format()
} else { } else {
return null return null
} }