Fix to Hue reverts dimmer settings (DVCSMP-1227)

if you use the hue native app to adjust the dimmer setting, smartthings will reset the dimmer to previous value when toggling from ST app (and automations)
This commit is contained in:
Juan Pablo Risso
2015-10-28 14:12:35 -04:00
committed by Yaima Valdivia
parent 0f3b730f26
commit fc587ef15a

View File

@@ -143,7 +143,7 @@ def bulbDiscovery() {
if (numFound == 0) if (numFound == 0)
app.updateSetting("selectedBulbs", "") app.updateSetting("selectedBulbs", "")
if((bulbRefreshCount % 3) == 0) { if((bulbRefreshCount % 5) == 0) {
discoverHueBulbs() discoverHueBulbs()
} }
@@ -318,11 +318,15 @@ def addBulbs() {
def newHueBulb def newHueBulb
if (bulbs instanceof java.util.Map) { if (bulbs instanceof java.util.Map) {
newHueBulb = bulbs.find { (app.id + "/" + it.value.id) == dni } newHueBulb = bulbs.find { (app.id + "/" + it.value.id) == dni }
if (newHueBulb?.value?.type?.equalsIgnoreCase("Dimmable light")) { if (newHueBulb != null) {
d = addChildDevice("smartthings", "Hue Lux Bulb", dni, newHueBulb?.value.hub, ["label":newHueBulb?.value.name]) if (newHueBulb?.value?.type?.equalsIgnoreCase("Dimmable light") ) {
} else { d = addChildDevice("smartthings", "Hue Lux Bulb", dni, newHueBulb?.value.hub, ["label":newHueBulb?.value.name])
d = addChildDevice("smartthings", "Hue Bulb", dni, newHueBulb?.value.hub, ["label":newHueBulb?.value.name]) } else {
} d = addChildDevice("smartthings", "Hue Bulb", dni, newHueBulb?.value.hub, ["label":newHueBulb?.value.name])
}
} else {
log.debug "$dni in not longer paired to the Hue Bridge or ID changed"
}
} else { } else {
//backwards compatable //backwards compatable
newHueBulb = bulbs.find { (app.id + "/" + it.id) == dni } newHueBulb = bulbs.find { (app.id + "/" + it.id) == dni }
@@ -604,18 +608,16 @@ def parse(childDevice, description) {
} }
} }
def on(childDevice, transition_deprecated = 0) { def on(childDevice) {
log.debug "Executing 'on'" log.debug "Executing 'on'"
def percent = childDevice.device?.currentValue("level") as Integer put("lights/${getId(childDevice)}/state", [on: true])
def level = Math.min(Math.round(percent * 255 / 100), 255) return "Bulb is On"
put("lights/${getId(childDevice)}/state", [bri: level, on: true])
return "level: $percent"
} }
def off(childDevice, transition_deprecated = 0) { def off(childDevice) {
log.debug "Executing 'off'" log.debug "Executing 'off'"
put("lights/${getId(childDevice)}/state", [on: false]) put("lights/${getId(childDevice)}/state", [on: false])
return "level: 0" return "Bulb is Off"
} }
def setLevel(childDevice, percent) { def setLevel(childDevice, percent) {
@@ -636,7 +638,7 @@ def setHue(childDevice, percent) {
put("lights/${getId(childDevice)}/state", [hue: level]) put("lights/${getId(childDevice)}/state", [hue: level])
} }
def setColor(childDevice, huesettings, alert_deprecated = "", transition_deprecated = 0) { def setColor(childDevice, huesettings) {
log.debug "Executing 'setColor($huesettings)'" log.debug "Executing 'setColor($huesettings)'"
def hue = Math.min(Math.round(huesettings.hue * 65535 / 100), 65535) def hue = Math.min(Math.round(huesettings.hue * 65535 / 100), 65535)
def sat = Math.min(Math.round(huesettings.saturation * 255 / 100), 255) def sat = Math.min(Math.round(huesettings.saturation * 255 / 100), 255)
@@ -720,13 +722,8 @@ private getBridgeIP() {
host = d.latestState('networkAddress').stringValue host = d.latestState('networkAddress').stringValue
} }
if (host == null || host == "") { if (host == null || host == "") {
def serialNumber = selectedHue def macAddress = selectedHue
def bridge = getHueBridges().find { it?.value?.serialNumber?.equalsIgnoreCase(serialNumber) }?.value def bridge = getHueBridges().find { it?.value?.mac?.equalsIgnoreCase(macAddress) }?.value
if (!bridge) {
//failed because mac address sent from hub is wrong and doesn't match the hue's real mac address and serial number
//in this case we will look up the bridge by comparing the incorrect mac addresses
bridge = getHueBridges().find { it?.value?.mac?.equalsIgnoreCase(serialNumber) }?.value
}
if (bridge?.ip && bridge?.port) { if (bridge?.ip && bridge?.port) {
if (bridge?.ip.contains(".")) if (bridge?.ip.contains("."))
host = "${bridge?.ip}:${bridge?.port}" host = "${bridge?.ip}:${bridge?.port}"