mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-25 05:04:09 +00:00
Treat over voltage as 100% battery level
Many DTHs that are generating battery events use the same bit of copy/pasted code and in that code over voltage is sent as a battery event with a value of "--" however, that non-numeric value results in stack traces. Instead we now report over voltage as 100% battery. This resolves: https://smartthings.atlassian.net/browse/DVCSMP-2177
This commit is contained in:
@@ -211,48 +211,37 @@ private Map getBatteryResult(rawValue) {
|
|||||||
log.debug "Battery rawValue = ${rawValue}"
|
log.debug "Battery rawValue = ${rawValue}"
|
||||||
def linkText = getLinkText(device)
|
def linkText = getLinkText(device)
|
||||||
|
|
||||||
def result = [
|
def result = [:]
|
||||||
name: 'battery',
|
|
||||||
value: '--',
|
|
||||||
translatable: true
|
|
||||||
]
|
|
||||||
|
|
||||||
def volts = rawValue / 10
|
def volts = rawValue / 10
|
||||||
|
|
||||||
if (rawValue == 0 || rawValue == 255) {}
|
if (!(rawValue == 0 || rawValue == 255)) {
|
||||||
else {
|
result.name = 'battery'
|
||||||
if (volts > 3.5) {
|
result.translatable = true
|
||||||
result.descriptionText = "{{ device.displayName }} battery has too much power: (> 3.5) volts."
|
result.descriptionText = "{{ device.displayName }} battery was {{ value }}%"
|
||||||
}
|
if (device.getDataValue("manufacturer") == "SmartThings") {
|
||||||
else {
|
volts = rawValue // For the batteryMap to work the key needs to be an int
|
||||||
if (device.getDataValue("manufacturer") == "SmartThings") {
|
def batteryMap = [28: 100, 27: 100, 26: 100, 25: 90, 24: 90, 23: 70,
|
||||||
volts = rawValue // For the batteryMap to work the key needs to be an int
|
22: 70, 21: 50, 20: 50, 19: 30, 18: 30, 17: 15, 16: 1, 15: 0]
|
||||||
def batteryMap = [28:100, 27:100, 26:100, 25:90, 24:90, 23:70,
|
def minVolts = 15
|
||||||
22:70, 21:50, 20:50, 19:30, 18:30, 17:15, 16:1, 15:0]
|
def maxVolts = 28
|
||||||
def minVolts = 15
|
|
||||||
def maxVolts = 28
|
|
||||||
|
|
||||||
if (volts < minVolts)
|
if (volts < minVolts)
|
||||||
volts = minVolts
|
volts = minVolts
|
||||||
else if (volts > maxVolts)
|
else if (volts > maxVolts)
|
||||||
volts = maxVolts
|
volts = maxVolts
|
||||||
def pct = batteryMap[volts]
|
def pct = batteryMap[volts]
|
||||||
if (pct != null) {
|
result.value = pct
|
||||||
result.value = pct
|
} else {
|
||||||
result.descriptionText = "{{ device.displayName }} battery was {{ value }}%"
|
def minVolts = 2.1
|
||||||
}
|
def maxVolts = 3.0
|
||||||
}
|
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
||||||
else {
|
def roundedPct = Math.round(pct * 100)
|
||||||
def minVolts = 2.1
|
if (roundedPct <= 0)
|
||||||
def maxVolts = 3.0
|
roundedPct = 1
|
||||||
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
result.value = Math.min(100, roundedPct)
|
||||||
def roundedPct = Math.round(pct * 100)
|
|
||||||
if (roundedPct <= 0)
|
|
||||||
roundedPct = 1
|
|
||||||
result.value = Math.min(100, roundedPct)
|
|
||||||
result.descriptionText = "{{ device.displayName }} battery was {{ value }}%"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -229,48 +229,35 @@ private Map getBatteryResult(rawValue) {
|
|||||||
log.debug "Battery rawValue = ${rawValue}"
|
log.debug "Battery rawValue = ${rawValue}"
|
||||||
def linkText = getLinkText(device)
|
def linkText = getLinkText(device)
|
||||||
|
|
||||||
def result = [
|
def result = [:]
|
||||||
name: 'battery',
|
|
||||||
value: '--',
|
|
||||||
translatable: true
|
|
||||||
]
|
|
||||||
|
|
||||||
def volts = rawValue / 10
|
def volts = rawValue / 10
|
||||||
|
|
||||||
if (rawValue == 0 || rawValue == 255) {}
|
if (!(rawValue == 0 || rawValue == 255)) {
|
||||||
else {
|
result.name = 'battery'
|
||||||
if (volts > 3.5) {
|
result.translatable = true
|
||||||
result.descriptionText = "{{ device.displayName }} battery has too much power: (> 3.5) volts."
|
result.descriptionText = "{{ device.displayName }} battery was {{ value }}%"
|
||||||
}
|
if (device.getDataValue("manufacturer") == "SmartThings") {
|
||||||
else {
|
volts = rawValue // For the batteryMap to work the key needs to be an int
|
||||||
if (device.getDataValue("manufacturer") == "SmartThings") {
|
def batteryMap = [28: 100, 27: 100, 26: 100, 25: 90, 24: 90, 23: 70,
|
||||||
volts = rawValue // For the batteryMap to work the key needs to be an int
|
22: 70, 21: 50, 20: 50, 19: 30, 18: 30, 17: 15, 16: 1, 15: 0]
|
||||||
def batteryMap = [28:100, 27:100, 26:100, 25:90, 24:90, 23:70,
|
def minVolts = 15
|
||||||
22:70, 21:50, 20:50, 19:30, 18:30, 17:15, 16:1, 15:0]
|
def maxVolts = 28
|
||||||
def minVolts = 15
|
|
||||||
def maxVolts = 28
|
|
||||||
|
|
||||||
if (volts < minVolts)
|
if (volts < minVolts)
|
||||||
volts = minVolts
|
volts = minVolts
|
||||||
else if (volts > maxVolts)
|
else if (volts > maxVolts)
|
||||||
volts = maxVolts
|
volts = maxVolts
|
||||||
def pct = batteryMap[volts]
|
def pct = batteryMap[volts]
|
||||||
if (pct != null) {
|
result.value = pct
|
||||||
result.value = pct
|
} else {
|
||||||
def value = pct
|
def minVolts = 2.1
|
||||||
result.descriptionText = "{{ device.displayName }} battery was {{ value }}%"
|
def maxVolts = 3.0
|
||||||
}
|
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
||||||
}
|
def roundedPct = Math.round(pct * 100)
|
||||||
else {
|
if (roundedPct <= 0)
|
||||||
def minVolts = 2.1
|
roundedPct = 1
|
||||||
def maxVolts = 3.0
|
result.value = Math.min(100, roundedPct)
|
||||||
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
|
||||||
def roundedPct = Math.round(pct * 100)
|
|
||||||
if (roundedPct <= 0)
|
|
||||||
roundedPct = 1
|
|
||||||
result.value = Math.min(100, roundedPct)
|
|
||||||
result.descriptionText = "{{ device.displayName }} battery was {{ value }}%"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,29 +188,20 @@ private Map getBatteryResult(rawValue) {
|
|||||||
|
|
||||||
log.debug rawValue
|
log.debug rawValue
|
||||||
|
|
||||||
def result = [
|
def result = [:]
|
||||||
name: 'battery',
|
|
||||||
value: '--'
|
|
||||||
]
|
|
||||||
|
|
||||||
def volts = rawValue / 10
|
def volts = rawValue / 10
|
||||||
def descriptionText
|
|
||||||
|
|
||||||
if (rawValue == 0 || rawValue == 255) {}
|
if (!(rawValue == 0 || rawValue == 255)) {
|
||||||
else {
|
def minVolts = 2.1
|
||||||
if (volts > 3.5) {
|
def maxVolts = 3.0
|
||||||
result.descriptionText = "${linkText} battery has too much power (${volts} volts)."
|
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
||||||
}
|
def roundedPct = Math.round(pct * 100)
|
||||||
else if (volts > 0){
|
if (roundedPct <= 0)
|
||||||
def minVolts = 2.1
|
roundedPct = 1
|
||||||
def maxVolts = 3.0
|
result.name = 'battery'
|
||||||
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
result.value = Math.min(100, roundedPct)
|
||||||
def roundedPct = Math.round(pct * 100)
|
result.descriptionText = "${linkText} battery was ${result.value}%"
|
||||||
if (roundedPct <= 0)
|
|
||||||
roundedPct = 1
|
|
||||||
result.value = Math.min(100, roundedPct)
|
|
||||||
result.descriptionText = "${linkText} battery was ${result.value}%"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -286,47 +286,35 @@ def getTemperature(value) {
|
|||||||
private Map getBatteryResult(rawValue) {
|
private Map getBatteryResult(rawValue) {
|
||||||
log.debug "Battery rawValue = ${rawValue}"
|
log.debug "Battery rawValue = ${rawValue}"
|
||||||
|
|
||||||
def result = [
|
def result = [:]
|
||||||
name: 'battery',
|
|
||||||
value: '--',
|
|
||||||
translatable: true
|
|
||||||
]
|
|
||||||
|
|
||||||
def volts = rawValue / 10
|
def volts = rawValue / 10
|
||||||
|
|
||||||
if (rawValue == 0 || rawValue == 255) {}
|
if (!(rawValue == 0 || rawValue == 255)) {
|
||||||
else {
|
result.name = 'battery'
|
||||||
if (volts > 3.5) {
|
result.translatable = true
|
||||||
result.descriptionText = "{{ device.displayName }} battery has too much power: (> 3.5) volts."
|
result.descriptionText = "{{ device.displayName }} battery was {{ value }}%"
|
||||||
}
|
if (device.getDataValue("manufacturer") == "SmartThings") {
|
||||||
else {
|
volts = rawValue // For the batteryMap to work the key needs to be an int
|
||||||
if (device.getDataValue("manufacturer") == "SmartThings") {
|
def batteryMap = [28: 100, 27: 100, 26: 100, 25: 90, 24: 90, 23: 70,
|
||||||
volts = rawValue // For the batteryMap to work the key needs to be an int
|
22: 70, 21: 50, 20: 50, 19: 30, 18: 30, 17: 15, 16: 1, 15: 0]
|
||||||
def batteryMap = [28:100, 27:100, 26:100, 25:90, 24:90, 23:70,
|
def minVolts = 15
|
||||||
22:70, 21:50, 20:50, 19:30, 18:30, 17:15, 16:1, 15:0]
|
def maxVolts = 28
|
||||||
def minVolts = 15
|
|
||||||
def maxVolts = 28
|
|
||||||
|
|
||||||
if (volts < minVolts)
|
if (volts < minVolts)
|
||||||
volts = minVolts
|
volts = minVolts
|
||||||
else if (volts > maxVolts)
|
else if (volts > maxVolts)
|
||||||
volts = maxVolts
|
volts = maxVolts
|
||||||
def pct = batteryMap[volts]
|
def pct = batteryMap[volts]
|
||||||
if (pct != null) {
|
result.value = pct
|
||||||
result.value = pct
|
} else {
|
||||||
result.descriptionText = "{{ device.displayName }} battery was {{ value }}%"
|
def minVolts = 2.1
|
||||||
}
|
def maxVolts = 3.0
|
||||||
}
|
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
||||||
else {
|
def roundedPct = Math.round(pct * 100)
|
||||||
def minVolts = 2.1
|
if (roundedPct <= 0)
|
||||||
def maxVolts = 3.0
|
roundedPct = 1
|
||||||
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
result.value = Math.min(100, roundedPct)
|
||||||
def roundedPct = Math.round(pct * 100)
|
|
||||||
if (roundedPct <= 0)
|
|
||||||
roundedPct = 1
|
|
||||||
result.value = Math.min(100, roundedPct)
|
|
||||||
result.descriptionText = "{{ device.displayName }} battery was {{ value }}%"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -187,35 +187,31 @@ def getTemperature(value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map getBatteryResult(rawValue) {
|
private Map getBatteryResult(rawValue) {
|
||||||
log.debug 'Battery'
|
log.debug 'Battery'
|
||||||
def linkText = getLinkText(device)
|
def linkText = getLinkText(device)
|
||||||
|
|
||||||
def result = [
|
def result = [:]
|
||||||
name: 'battery'
|
|
||||||
]
|
|
||||||
|
|
||||||
def volts = rawValue / 10
|
def volts = rawValue / 10
|
||||||
def descriptionText
|
|
||||||
if (rawValue == 0 || rawValue == 255) {}
|
if (!(rawValue == 0 || rawValue == 255)) {
|
||||||
else if (volts > 3.5) {
|
def minVolts = 2.1
|
||||||
result.descriptionText = "${linkText} battery has too much power (${volts} volts)."
|
def maxVolts = 3.0
|
||||||
}
|
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
||||||
else {
|
def roundedPct = Math.round(pct * 100)
|
||||||
def minVolts = 2.1
|
if (roundedPct <= 0)
|
||||||
def maxVolts = 3.0
|
roundedPct = 1
|
||||||
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
result.name = 'battery'
|
||||||
def roundedPct = Math.round(pct * 100)
|
result.value = Math.min(100, roundedPct)
|
||||||
if (roundedPct <= 0)
|
result.descriptionText = "${linkText} battery was ${result.value}%"
|
||||||
roundedPct = 1
|
|
||||||
result.value = Math.min(100, roundedPct)
|
|
||||||
result.descriptionText = "${linkText} battery was ${result.value}%"
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map getTemperatureResult(value) {
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map getTemperatureResult(value) {
|
||||||
log.debug 'TEMP'
|
log.debug 'TEMP'
|
||||||
def linkText = getLinkText(device)
|
def linkText = getLinkText(device)
|
||||||
if (tempOffset) {
|
if (tempOffset) {
|
||||||
|
|||||||
@@ -205,25 +205,19 @@ private Map getBatteryResult(rawValue) {
|
|||||||
log.debug 'Battery'
|
log.debug 'Battery'
|
||||||
def linkText = getLinkText(device)
|
def linkText = getLinkText(device)
|
||||||
|
|
||||||
def result = [
|
def result = [:]
|
||||||
name: 'battery'
|
|
||||||
]
|
|
||||||
|
|
||||||
def volts = rawValue / 10
|
def volts = rawValue / 10
|
||||||
def descriptionText
|
if (!(rawValue == 0 || rawValue == 255)) {
|
||||||
if (rawValue == 0 || rawValue == 255) {}
|
|
||||||
else if (volts > 3.5) {
|
|
||||||
result.descriptionText = "${linkText} battery has too much power (${volts} volts)."
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
def minVolts = 2.1
|
def minVolts = 2.1
|
||||||
def maxVolts = 3.0
|
def maxVolts = 3.0
|
||||||
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
||||||
def roundedPct = Math.round(pct * 100)
|
def roundedPct = Math.round(pct * 100)
|
||||||
if (roundedPct <= 0)
|
if (roundedPct <= 0)
|
||||||
roundedPct = 1
|
roundedPct = 1
|
||||||
result.value = Math.min(100, roundedPct)
|
result.value = Math.min(100, roundedPct)
|
||||||
result.descriptionText = "${linkText} battery was ${result.value}%"
|
result.descriptionText = "${linkText} battery was ${result.value}%"
|
||||||
|
result.name = 'battery'
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -216,25 +216,20 @@ private Map getBatteryResult(rawValue) {
|
|||||||
log.debug 'Battery'
|
log.debug 'Battery'
|
||||||
def linkText = getLinkText(device)
|
def linkText = getLinkText(device)
|
||||||
|
|
||||||
def result = [
|
def result = [:]
|
||||||
name: 'battery'
|
|
||||||
]
|
|
||||||
|
|
||||||
def volts = rawValue / 10
|
def volts = rawValue / 10
|
||||||
def descriptionText
|
if (!(rawValue == 0 || rawValue == 255)) {
|
||||||
if (rawValue == 0 || rawValue == 255) {}
|
|
||||||
else if (volts > 3.5) {
|
|
||||||
result.descriptionText = "${linkText} battery has too much power (${volts} volts)."
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
def minVolts = 2.1
|
def minVolts = 2.1
|
||||||
def maxVolts = 3.0
|
def maxVolts = 3.0
|
||||||
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
||||||
def roundedPct = Math.round(pct * 100)
|
def roundedPct = Math.round(pct * 100)
|
||||||
if (roundedPct <= 0)
|
if (roundedPct <= 0)
|
||||||
roundedPct = 1
|
roundedPct = 1
|
||||||
result.value = Math.min(100, roundedPct)
|
result.value = Math.min(100, roundedPct)
|
||||||
result.descriptionText = "${linkText} battery was ${result.value}%"
|
result.descriptionText = "${linkText} battery was ${result.value}%"
|
||||||
|
result.name = 'battery'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -181,22 +181,17 @@ private Map getBatteryResult(rawValue) {
|
|||||||
log.debug 'Battery'
|
log.debug 'Battery'
|
||||||
def linkText = getLinkText(device)
|
def linkText = getLinkText(device)
|
||||||
|
|
||||||
def result = [
|
def result = [:]
|
||||||
name: 'battery'
|
|
||||||
]
|
|
||||||
|
|
||||||
def volts = rawValue / 10
|
if (!(rawValue == 0 || rawValue == 255)) {
|
||||||
def descriptionText
|
def volts = rawValue / 10
|
||||||
if (volts > 3.5) {
|
|
||||||
result.descriptionText = "${linkText} battery has too much power (${volts} volts)."
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
def minVolts = 2.1
|
def minVolts = 2.1
|
||||||
def maxVolts = 3.0
|
def maxVolts = 3.0
|
||||||
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
||||||
def roundedPct = Math.round(pct * 100)
|
def roundedPct = Math.round(pct * 100)
|
||||||
result.value = Math.min(100, roundedPct)
|
result.value = Math.min(100, roundedPct)
|
||||||
result.descriptionText = "${linkText} battery was ${result.value}%"
|
result.descriptionText = "${linkText} battery was ${result.value}%"
|
||||||
|
result.name = 'battery'
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user