mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-31 14:13:11 +01:00
Merge pull request #1172 from SmartThingsCommunity/staging
Rolling down staging hotfix to master
This commit is contained in:
@@ -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"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,14 +133,23 @@ def bulbDiscovery() {
|
|||||||
state.inBulbDiscovery = true
|
state.inBulbDiscovery = true
|
||||||
def bridge = null
|
def bridge = null
|
||||||
if (selectedHue) {
|
if (selectedHue) {
|
||||||
bridge = getChildDevice(selectedHue)
|
bridge = getChildDevice(selectedHue)
|
||||||
subscribe(bridge, "bulbList", bulbListData)
|
subscribe(bridge, "bulbList", bulbListData)
|
||||||
}
|
}
|
||||||
state.bridgeRefreshCount = 0
|
state.bridgeRefreshCount = 0
|
||||||
def bulboptions = bulbsDiscovered() ?: [:]
|
def allLightsFound = bulbsDiscovered() ?: [:]
|
||||||
def numFound = bulboptions.size() ?: 0
|
|
||||||
if (numFound == 0)
|
// List lights currently not added to the user (editable)
|
||||||
app.updateSetting("selectedBulbs", "")
|
def newLights = allLightsFound.findAll {getChildDevice(it.key) == null} ?: [:]
|
||||||
|
newLights = newLights.sort {it.value.toLowerCase()}
|
||||||
|
|
||||||
|
// List lights already added to the user (not editable)
|
||||||
|
def existingLights = allLightsFound.findAll {getChildDevice(it.key) != null} ?: [:]
|
||||||
|
existingLights = existingLights.sort {it.value.toLowerCase()}
|
||||||
|
|
||||||
|
def numFound = newLights.size() ?: 0
|
||||||
|
if (numFound == 0)
|
||||||
|
app.updateSetting("selectedBulbs", "")
|
||||||
|
|
||||||
if((bulbRefreshCount % 5) == 0) {
|
if((bulbRefreshCount % 5) == 0) {
|
||||||
discoverHueBulbs()
|
discoverHueBulbs()
|
||||||
@@ -148,14 +157,25 @@ def bulbDiscovery() {
|
|||||||
def selectedBridge = state.bridges.find { key, value -> value?.serialNumber?.equalsIgnoreCase(selectedHue) }
|
def selectedBridge = state.bridges.find { key, value -> value?.serialNumber?.equalsIgnoreCase(selectedHue) }
|
||||||
def title = selectedBridge?.value?.name ?: "Find bridges"
|
def title = selectedBridge?.value?.name ?: "Find bridges"
|
||||||
|
|
||||||
|
// List of all lights previously added shown to user
|
||||||
|
def existingLightsDescription = ""
|
||||||
|
if (existingLights) {
|
||||||
|
existingLights.each {
|
||||||
|
if (existingLightsDescription.isEmpty()) {
|
||||||
|
existingLightsDescription += it.value
|
||||||
|
} else {
|
||||||
|
existingLightsDescription += ", ${it.value}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return dynamicPage(name:"bulbDiscovery", title:"Light Discovery Started!", nextPage:"", refreshInterval:refreshInterval, install:true, uninstall: true) {
|
return dynamicPage(name:"bulbDiscovery", title:"Light Discovery Started!", nextPage:"", refreshInterval:refreshInterval, install:true, uninstall: true) {
|
||||||
section("Please wait while we discover your Hue Lights. Discovery can take five minutes or more, so sit back and relax! Select your device below once discovered.") {
|
section("Please wait while we discover your Hue Lights. Discovery can take five minutes or more, so sit back and relax! Select your device below once discovered.") {
|
||||||
input "selectedBulbs", "enum", required:false, title:"Select Hue Lights (${numFound} found)", multiple:true, options:bulboptions
|
input "selectedBulbs", "enum", required:false, title:"Select Hue Lights to add (${numFound} found)", multiple:true, options:newLights
|
||||||
|
paragraph title: "Previously added Hue Lights (${existingLights.size()} added)", existingLightsDescription
|
||||||
}
|
}
|
||||||
section {
|
section {
|
||||||
href "bridgeDiscovery", title: title, description: "", state: selectedHue ? "complete" : "incomplete", params: [override: true]
|
href "bridgeDiscovery", title: title, description: "", state: selectedHue ? "complete" : "incomplete", params: [override: true]
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,8 +310,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 +438,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"
|
||||||
@@ -1017,12 +1049,12 @@ def setColor(childDevice, huesettings) {
|
|||||||
log.debug "Executing 'setColor($huesettings)'"
|
log.debug "Executing 'setColor($huesettings)'"
|
||||||
|
|
||||||
updateInProgress()
|
updateInProgress()
|
||||||
|
|
||||||
def value = [:]
|
def value = [:]
|
||||||
def hue = null
|
def hue = null
|
||||||
def sat = null
|
def sat = null
|
||||||
def xy = null
|
def xy = null
|
||||||
|
|
||||||
// For now ignore model to get a consistent color if same color is set across multiple devices
|
// For now ignore model to get a consistent color if same color is set across multiple devices
|
||||||
// def model = state.bulbs[getId(childDevice)]?.modelid
|
// def model = state.bulbs[getId(childDevice)]?.modelid
|
||||||
if (huesettings.hex != null) {
|
if (huesettings.hex != null) {
|
||||||
@@ -1038,11 +1070,12 @@ def setColor(childDevice, huesettings) {
|
|||||||
else
|
else
|
||||||
value.hue = Math.min(Math.round(childDevice.device?.currentValue("hue") * 65535 / 100), 65535)
|
value.hue = Math.min(Math.round(childDevice.device?.currentValue("hue") * 65535 / 100), 65535)
|
||||||
|
|
||||||
if (huesettings.saturation != null)
|
if (huesettings.saturation != null)
|
||||||
value.sat = Math.min(Math.round(huesettings.saturation * 254 / 100), 254)
|
value.sat = Math.min(Math.round(huesettings.saturation * 254 / 100), 254)
|
||||||
else
|
else
|
||||||
value.sat = Math.min(Math.round(childDevice.device?.currentValue("saturation") * 254 / 100), 254)
|
value.sat = Math.min(Math.round(childDevice.device?.currentValue("saturation") * 254 / 100), 254)
|
||||||
|
|
||||||
|
/* Disabled for now due to bad behavior via Lightning Wizard
|
||||||
if (!value.xy) {
|
if (!value.xy) {
|
||||||
// Below will translate values to hex->XY to take into account the color support of the different hue types
|
// Below will translate values to hex->XY to take into account the color support of the different hue types
|
||||||
def hex = colorUtil.hslToHex((int) huesettings.hue, (int) huesettings.saturation)
|
def hex = colorUtil.hslToHex((int) huesettings.hue, (int) huesettings.saturation)
|
||||||
@@ -1050,6 +1083,7 @@ def setColor(childDevice, huesettings) {
|
|||||||
// Once groups, or scenes are introduced it might be a good idea to use unique models again
|
// Once groups, or scenes are introduced it might be a good idea to use unique models again
|
||||||
value.xy = calculateXY(hex)
|
value.xy = calculateXY(hex)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Default behavior is to turn light on
|
// Default behavior is to turn light on
|
||||||
value.on = true
|
value.on = true
|
||||||
@@ -1059,7 +1093,7 @@ def setColor(childDevice, huesettings) {
|
|||||||
value.on = false
|
value.on = false
|
||||||
else if (huesettings.level == 1)
|
else if (huesettings.level == 1)
|
||||||
value.bri = 1
|
value.bri = 1
|
||||||
else
|
else
|
||||||
value.bri = Math.min(Math.round(huesettings.level * 254 / 100), 254)
|
value.bri = Math.min(Math.round(huesettings.level * 254 / 100), 254)
|
||||||
}
|
}
|
||||||
value.alert = huesettings.alert ? huesettings.alert : "none"
|
value.alert = huesettings.alert ? huesettings.alert : "none"
|
||||||
|
|||||||
Reference in New Issue
Block a user