SSVD-2603 Prevent removing of Hue bridge

-Moved warning messages to top of bridge DTH screen
-User is now presented with a warning message when removing
This commit is contained in:
Lars Finander
2016-08-29 15:17:40 -06:00
parent d5b8db99a2
commit cdf5d21e8f
2 changed files with 32 additions and 20 deletions

View File

@@ -28,8 +28,8 @@ metadata {
} }
} }
valueTile("doNotRemove", "v", decoration: "flat", height: 2, width: 6, inactiveLabel: false) { valueTile("doNotRemove", "v", decoration: "flat", height: 2, width: 6, inactiveLabel: false) {
state "default", label:'Do not remove' state "default", label:'If removed, Hue lights will not work properly'
} }
valueTile("idNumber", "device.idNumber", decoration: "flat", height: 2, width: 6, inactiveLabel: false) { valueTile("idNumber", "device.idNumber", decoration: "flat", height: 2, width: 6, inactiveLabel: false) {
state "default", label:'ID: ${currentValue}' state "default", label:'ID: ${currentValue}'
} }
@@ -38,7 +38,7 @@ metadata {
} }
main (["rich-control"]) main (["rich-control"])
details(["rich-control", "idNumber", "networkAddress", "doNotRemove"]) details(["rich-control", "doNotRemove", "idNumber", "networkAddress"])
} }
} }

View File

@@ -290,8 +290,11 @@ def manualRefresh() {
} }
def uninstalled(){ def uninstalled(){
// Remove bridgedevice connection to allow uninstall of smartapp even though bridge is listed
// as user of smartapp
app.updateSetting("bridgeDevice", null)
state.bridges = [:] state.bridges = [:]
state.username = null state.username = null
} }
// Handles events to add new bulbs // Handles events to add new bulbs
@@ -415,23 +418,32 @@ def addBridge() {
// Hue uses last 6 digits of MAC address as ID number, this number is shown on the bottom of the bridge // Hue uses last 6 digits of MAC address as ID number, this number is shown on the bottom of the bridge
def idNumber = getBridgeIdNumber(selectedHue) def idNumber = getBridgeIdNumber(selectedHue)
d = addChildDevice("smartthings", "Hue Bridge", selectedHue, vbridge.value.hub, ["label": "Hue Bridge ($idNumber)"]) d = addChildDevice("smartthings", "Hue Bridge", selectedHue, vbridge.value.hub, ["label": "Hue Bridge ($idNumber)"])
d?.completedSetup = true if (d) {
log.debug "created ${d.displayName} with id ${d.deviceNetworkId}" // Associate smartapp to bridge so user will be warned if trying to delete bridge
def childDevice = getChildDevice(d.deviceNetworkId) app.updateSetting("bridgeDevice", [type: "device.hueBridge", value: d.id])
updateBridgeStatus(childDevice)
childDevice.sendEvent(name: "idNumber", value: idNumber) d.completedSetup = true
if (vbridge.value.ip && vbridge.value.port) { log.debug "created ${d.displayName} with id ${d.deviceNetworkId}"
if (vbridge.value.ip.contains(".")) { def childDevice = getChildDevice(d.deviceNetworkId)
childDevice.sendEvent(name: "networkAddress", value: vbridge.value.ip + ":" + vbridge.value.port) updateBridgeStatus(childDevice)
childDevice.updateDataValue("networkAddress", vbridge.value.ip + ":" + vbridge.value.port) childDevice.sendEvent(name: "idNumber", value: idNumber)
} else {
childDevice.sendEvent(name: "networkAddress", value: convertHexToIP(vbridge.value.ip) + ":" + convertHexToInt(vbridge.value.port))
childDevice.updateDataValue("networkAddress", convertHexToIP(vbridge.value.ip) + ":" + convertHexToInt(vbridge.value.port)) if (vbridge.value.ip && vbridge.value.port) {
} if (vbridge.value.ip.contains(".")) {
childDevice.sendEvent(name: "networkAddress", value: vbridge.value.ip + ":" + vbridge.value.port)
childDevice.updateDataValue("networkAddress", vbridge.value.ip + ":" + vbridge.value.port)
} else {
childDevice.sendEvent(name: "networkAddress", value: convertHexToIP(vbridge.value.ip) + ":" + convertHexToInt(vbridge.value.port))
childDevice.updateDataValue("networkAddress", convertHexToIP(vbridge.value.ip) + ":" + convertHexToInt(vbridge.value.port))
}
} else {
childDevice.sendEvent(name: "networkAddress", value: convertHexToIP(vbridge.value.networkAddress) + ":" + convertHexToInt(vbridge.value.deviceAddress))
childDevice.updateDataValue("networkAddress", convertHexToIP(vbridge.value.networkAddress) + ":" + convertHexToInt(vbridge.value.deviceAddress))
}
} else { } else {
childDevice.sendEvent(name: "networkAddress", value: convertHexToIP(vbridge.value.networkAddress) + ":" + convertHexToInt(vbridge.value.deviceAddress)) log.error "Failed to create Hue Bridge device"
childDevice.updateDataValue("networkAddress", convertHexToIP(vbridge.value.networkAddress) + ":" + convertHexToInt(vbridge.value.deviceAddress)) }
}
} }
} else { } else {
log.debug "found ${d.displayName} with id $selectedHue already exists" log.debug "found ${d.displayName} with id $selectedHue already exists"