From 633bef2ac524d9a104ceed58b36ad421f2cc6a44 Mon Sep 17 00:00:00 2001 From: Lars Finander Date: Tue, 22 Mar 2016 14:29:32 -0700 Subject: [PATCH] Revert "DVCSMP-1615 & DEVC-372" This reverts commit 6fbef3b297158c32dec393a9c33fd5ff7b31ab44. (temporary for staging, MArch 25 deploy) --- .../smartthings/hue-bulb.src/hue-bulb.groovy | 56 +++++++++----- .../hue-lux-bulb.src/hue-lux-bulb.groovy | 9 ++- .../hue-connect.src/hue-connect.groovy | 73 ++----------------- 3 files changed, 55 insertions(+), 83 deletions(-) diff --git a/devicetypes/smartthings/hue-bulb.src/hue-bulb.groovy b/devicetypes/smartthings/hue-bulb.src/hue-bulb.groovy index a5d41ef..f49ec95 100644 --- a/devicetypes/smartthings/hue-bulb.src/hue-bulb.groovy +++ b/devicetypes/smartthings/hue-bulb.src/hue-bulb.groovy @@ -3,7 +3,6 @@ * * Author: SmartThings */ - // for the UI metadata { // Automatically generated. Make future change here. @@ -28,10 +27,10 @@ metadata { tiles (scale: 2){ multiAttributeTile(name:"rich-control", type: "lighting", width: 6, height: 4, canChangeIcon: true){ tileAttribute ("device.switch", key: "PRIMARY_CONTROL") { - attributeState "on", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#00A0DC", nextState:"turningOff" - attributeState "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#C6C7CC", nextState:"turningOn" - attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#00A0DC", nextState:"turningOff" - attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#C6C7CC", nextState:"turningOn" + attributeState "on", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff" + attributeState "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn" + attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff" + attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn" } tileAttribute ("device.level", key: "SLIDER_CONTROL") { attributeState "level", action:"switch level.setLevel", range:"(0..100)" @@ -44,10 +43,16 @@ metadata { } } + standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) { + state "on", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff" + state "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn" + state "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff" + state "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn" + } + controlTile("colorTempSliderControl", "device.colorTemperature", "slider", width: 4, height: 2, inactiveLabel: false, range:"(2000..6500)") { state "colorTemperature", action:"color temperature.setColorTemperature" } - valueTile("colorTemp", "device.colorTemperature", inactiveLabel: false, decoration: "flat", width: 2, height: 2) { state "colorTemperature", label: '${currentValue} K' } @@ -55,12 +60,29 @@ metadata { standardTile("reset", "device.reset", height: 2, width: 2, inactiveLabel: false, decoration: "flat") { state "default", label:"Reset Color", action:"reset", icon:"st.lights.philips.hue-single" } - - standardTile("refresh", "device.refresh", height: 2, width: 2, inactiveLabel: false, decoration: "flat") { + standardTile("refresh", "device.switch", height: 2, width: 2, inactiveLabel: false, decoration: "flat") { state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh" } + controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 2, inactiveLabel: false, range:"(0..100)") { + state "level", action:"switch level.setLevel" + } + valueTile("level", "device.level", inactiveLabel: false, decoration: "flat") { + state "level", label: 'Level ${currentValue}%' + } + controlTile("saturationSliderControl", "device.saturation", "slider", height: 1, width: 2, inactiveLabel: false) { + state "saturation", action:"color control.setSaturation" + } + valueTile("saturation", "device.saturation", inactiveLabel: false, decoration: "flat") { + state "saturation", label: 'Sat ${currentValue} ' + } + controlTile("hueSliderControl", "device.hue", "slider", height: 1, width: 2, inactiveLabel: false) { + state "hue", action:"color control.setHue" + } + valueTile("hue", "device.hue", inactiveLabel: false, decoration: "flat") { + state "hue", label: 'Hue ${currentValue} ' + } - main(["rich-control"]) + main(["switch"]) details(["rich-control", "colorTempSliderControl", "colorTemp", "reset", "refresh"]) } } @@ -105,34 +127,34 @@ void nextLevel() { void setLevel(percent) { log.debug "Executing 'setLevel'" parent.setLevel(this, percent) - sendEvent(name: "level", value: percent, descriptionText: "Level has changed to ${percent}%") + sendEvent(name: "level", value: percent) } void setSaturation(percent) { log.debug "Executing 'setSaturation'" parent.setSaturation(this, percent) - sendEvent(name: "saturation", value: percent, displayed: false) + sendEvent(name: "saturation", value: percent) } void setHue(percent) { log.debug "Executing 'setHue'" parent.setHue(this, percent) - sendEvent(name: "hue", value: percent, displayed: false) + sendEvent(name: "hue", value: percent) } void setColor(value) { log.debug "setColor: ${value}, $this" parent.setColor(this, value) - if (value.hue) { sendEvent(name: "hue", value: value.hue, displayed: false)} - if (value.saturation) { sendEvent(name: "saturation", value: value.saturation, displayed: false)} + if (value.hue) { sendEvent(name: "hue", value: value.hue)} + if (value.saturation) { sendEvent(name: "saturation", value: value.saturation)} if (value.hex) { sendEvent(name: "color", value: value.hex)} - if (value.level) { sendEvent(name: "level", value: value.level, descriptionText: "Level has changed to ${value.level}%")} - sendEvent(name: "switch", value: "on") + if (value.level) { sendEvent(name: "level", value: value.level)} + if (value.switch) { sendEvent(name: "switch", value: value.switch)} } void reset() { log.debug "Executing 'reset'" - def value = [level:100, saturation:56, hue:23] + def value = [level:100, hex:"#90C638", saturation:56, hue:23] setAdjustedColor(value) parent.poll() } diff --git a/devicetypes/smartthings/hue-lux-bulb.src/hue-lux-bulb.groovy b/devicetypes/smartthings/hue-lux-bulb.src/hue-lux-bulb.groovy index 18affa4..49e7f2f 100644 --- a/devicetypes/smartthings/hue-lux-bulb.src/hue-lux-bulb.groovy +++ b/devicetypes/smartthings/hue-lux-bulb.src/hue-lux-bulb.groovy @@ -36,6 +36,13 @@ metadata { } } + standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) { + state "on", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff" + state "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn" + state "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff" + state "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn" + } + controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 2, inactiveLabel: false, range:"(0..100)") { state "level", action:"switch level.setLevel" } @@ -44,7 +51,7 @@ metadata { state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh" } - main(["rich-control"]) + main(["switch"]) details(["rich-control", "refresh"]) } } diff --git a/smartapps/smartthings/hue-connect.src/hue-connect.groovy b/smartapps/smartthings/hue-connect.src/hue-connect.groovy index 5b908d8..93453ac 100644 --- a/smartapps/smartthings/hue-connect.src/hue-connect.groovy +++ b/smartapps/smartthings/hue-connect.src/hue-connect.groovy @@ -24,7 +24,7 @@ definition( category: "SmartThings Labs", iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/hue.png", iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/hue@2x.png", - singleInstance: true + //singleInstance: true ) preferences { @@ -643,25 +643,21 @@ def setColorTemperature(childDevice, huesettings) { def setColor(childDevice, huesettings) { log.debug "Executing 'setColor($huesettings)'" - def hue = null - def sat = null - def xy = null - if (huesettings.hex) { - xy = getHextoXY(huesettings.hex) - } else if (huesettings.hue && huesettings.saturation) { - hue = Math.min(Math.round(huesettings.hue * 65535 / 100), 65535) - sat = Math.min(Math.round(huesettings.saturation * 255 / 100), 255) - } + def hue = Math.min(Math.round(huesettings.hue * 65535 / 100), 65535) + def sat = Math.min(Math.round(huesettings.saturation * 255 / 100), 255) def alert = huesettings.alert ? huesettings.alert : "none" def transition = huesettings.transition ? huesettings.transition : 4 - def value = [xy: xy, sat: sat, hue: hue, alert: alert, transitiontime: transition, on: true] - + def value = [sat: sat, hue: hue, alert: alert, transitiontime: transition] if (huesettings.level != null) { if (huesettings.level == 1) value.bri = 1 else value.bri = Math.min(Math.round(huesettings.level * 255 / 100), 255) value.on = value.bri > 0 } + if (huesettings.switch) { + value.on = huesettings.switch == "on" + } + log.debug "sending command $value" put("lights/${getId(childDevice)}/state", value) } @@ -747,59 +743,6 @@ private getBridgeIP() { return host } -private getHextoXY(String colorStr) { - // For the hue bulb the corners of the triangle are: - // -Red: 0.675, 0.322 - // -Green: 0.4091, 0.518 - // -Blue: 0.167, 0.04 - - def cred = Integer.valueOf( colorStr.substring( 1, 3 ), 16 ) - def cgreen = Integer.valueOf( colorStr.substring( 3, 5 ), 16 ) - def cblue = Integer.valueOf( colorStr.substring( 5, 7 ), 16 ) - - double[] normalizedToOne = new double[3]; - normalizedToOne[0] = (cred / 255); - normalizedToOne[1] = (cgreen / 255); - normalizedToOne[2] = (cblue / 255); - float red, green, blue; - - // Make red more vivid - if (normalizedToOne[0] > 0.04045) { - red = (float) Math.pow( - (normalizedToOne[0] + 0.055) / (1.0 + 0.055), 2.4); - } else { - red = (float) (normalizedToOne[0] / 12.92); - } - - // Make green more vivid - if (normalizedToOne[1] > 0.04045) { - green = (float) Math.pow((normalizedToOne[1] + 0.055) - / (1.0 + 0.055), 2.4); - } else { - green = (float) (normalizedToOne[1] / 12.92); - } - - // Make blue more vivid - if (normalizedToOne[2] > 0.04045) { - blue = (float) Math.pow((normalizedToOne[2] + 0.055) - / (1.0 + 0.055), 2.4); - } else { - blue = (float) (normalizedToOne[2] / 12.92); - } - - float X = (float) (red * 0.649926 + green * 0.103455 + blue * 0.197109); - float Y = (float) (red * 0.234327 + green * 0.743075 + blue * 0.022598); - float Z = (float) (red * 0.0000000 + green * 0.053077 + blue * 1.035763); - - float x = X / (X + Y + Z); - float y = Y / (X + Y + Z); - - double[] xy = new double[2]; - xy[0] = x; - xy[1] = y; - return xy; -} - private Integer convertHexToInt(hex) { Integer.parseInt(hex,16) }