mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-08 05:31:56 +00:00
DVCSMP-2688 Remove sending turningOn/Off events
-Removed createSwitchEvent()
This commit is contained in:
@@ -1083,7 +1083,6 @@ def on(childDevice) {
|
|||||||
log.debug "Executing 'on'"
|
log.debug "Executing 'on'"
|
||||||
def id = getId(childDevice)
|
def id = getId(childDevice)
|
||||||
updateInProgress()
|
updateInProgress()
|
||||||
createSwitchEvent(childDevice, "on")
|
|
||||||
put("lights/$id/state", [on: true])
|
put("lights/$id/state", [on: true])
|
||||||
return "Bulb is turning On"
|
return "Bulb is turning On"
|
||||||
}
|
}
|
||||||
@@ -1092,7 +1091,6 @@ def off(childDevice) {
|
|||||||
log.debug "Executing 'off'"
|
log.debug "Executing 'off'"
|
||||||
def id = getId(childDevice)
|
def id = getId(childDevice)
|
||||||
updateInProgress()
|
updateInProgress()
|
||||||
createSwitchEvent(childDevice, "off")
|
|
||||||
put("lights/$id/state", [on: false])
|
put("lights/$id/state", [on: false])
|
||||||
return "Bulb is turning Off"
|
return "Bulb is turning Off"
|
||||||
}
|
}
|
||||||
@@ -1108,8 +1106,6 @@ def setLevel(childDevice, percent) {
|
|||||||
else
|
else
|
||||||
level = Math.min(Math.round(percent * 254 / 100), 254)
|
level = Math.min(Math.round(percent * 254 / 100), 254)
|
||||||
|
|
||||||
createSwitchEvent(childDevice, level > 0, percent)
|
|
||||||
|
|
||||||
// For Zigbee lights, if level is set to 0 ST just turns them off without changing level
|
// For Zigbee lights, if level is set to 0 ST just turns them off without changing level
|
||||||
// that means that the light will still be on when on is called next time
|
// that means that the light will still be on when on is called next time
|
||||||
// Lets emulate that here
|
// Lets emulate that here
|
||||||
@@ -1128,7 +1124,6 @@ def setSaturation(childDevice, percent) {
|
|||||||
// 0 - 254
|
// 0 - 254
|
||||||
def level = Math.min(Math.round(percent * 254 / 100), 254)
|
def level = Math.min(Math.round(percent * 254 / 100), 254)
|
||||||
// TODO should this be done by app only or should we default to on?
|
// TODO should this be done by app only or should we default to on?
|
||||||
createSwitchEvent(childDevice, "on")
|
|
||||||
put("lights/$id/state", [sat: level, on: true])
|
put("lights/$id/state", [sat: level, on: true])
|
||||||
return "Setting saturation to $percent"
|
return "Setting saturation to $percent"
|
||||||
}
|
}
|
||||||
@@ -1140,7 +1135,6 @@ def setHue(childDevice, percent) {
|
|||||||
// 0 - 65535
|
// 0 - 65535
|
||||||
def level = Math.min(Math.round(percent * 65535 / 100), 65535)
|
def level = Math.min(Math.round(percent * 65535 / 100), 65535)
|
||||||
// TODO should this be done by app only or should we default to on?
|
// TODO should this be done by app only or should we default to on?
|
||||||
createSwitchEvent(childDevice, "on")
|
|
||||||
put("lights/$id/state", [hue: level, on: true])
|
put("lights/$id/state", [hue: level, on: true])
|
||||||
return "Setting hue to $percent"
|
return "Setting hue to $percent"
|
||||||
}
|
}
|
||||||
@@ -1151,7 +1145,6 @@ def setColorTemperature(childDevice, huesettings) {
|
|||||||
updateInProgress()
|
updateInProgress()
|
||||||
// 153 (6500K) to 500 (2000K)
|
// 153 (6500K) to 500 (2000K)
|
||||||
def ct = hueSettings == 6500 ? 153 : Math.round(1000000 / huesettings)
|
def ct = hueSettings == 6500 ? 153 : Math.round(1000000 / huesettings)
|
||||||
createSwitchEvent(childDevice, "on")
|
|
||||||
put("lights/$id/state", [ct: ct, on: true])
|
put("lights/$id/state", [ct: ct, on: true])
|
||||||
return "Setting color temperature to $ct"
|
return "Setting color temperature to $ct"
|
||||||
}
|
}
|
||||||
@@ -1210,7 +1203,6 @@ def setColor(childDevice, huesettings) {
|
|||||||
if (huesettings.switch == "off")
|
if (huesettings.switch == "off")
|
||||||
value.on = false
|
value.on = false
|
||||||
|
|
||||||
createSwitchEvent(childDevice, value.on ? "on" : "off")
|
|
||||||
put("lights/$id/state", value)
|
put("lights/$id/state", value)
|
||||||
return "Setting color to $value"
|
return "Setting color to $value"
|
||||||
}
|
}
|
||||||
@@ -1322,32 +1314,6 @@ private List getRealHubFirmwareVersions() {
|
|||||||
return location.hubs*.firmwareVersionString.findAll { it }
|
return location.hubs*.firmwareVersionString.findAll { it }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends appropriate turningOn/turningOff state events depending on switch or level changes.
|
|
||||||
*
|
|
||||||
* @param childDevice device to send event for
|
|
||||||
* @param setSwitch The new switch state, "on" or "off"
|
|
||||||
* @param setLevel Optional, switchLevel between 0-100, used if you set level to 0 for example since
|
|
||||||
* that should generate "off" instead of level change
|
|
||||||
*/
|
|
||||||
private void createSwitchEvent(childDevice, setSwitch, setLevel = null) {
|
|
||||||
|
|
||||||
if (setLevel == null) {
|
|
||||||
setLevel = childDevice.device?.currentValue("level")
|
|
||||||
}
|
|
||||||
// Create on, off, turningOn or turningOff event as necessary
|
|
||||||
def currentState = childDevice.device?.currentValue("switch")
|
|
||||||
if ((currentState == "off" || currentState == "turningOff")) {
|
|
||||||
if (setSwitch == "on" || setLevel > 0) {
|
|
||||||
childDevice.sendEvent(name: "switch", value: "turningOn", displayed: false)
|
|
||||||
}
|
|
||||||
} else if ((currentState == "on" || currentState == "turningOn")) {
|
|
||||||
if (setSwitch == "off" || setLevel == 0) {
|
|
||||||
childDevice.sendEvent(name: "switch", value: "turningOff", displayed: false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the supported color range for different Hue lights. If model is not specified
|
* Return the supported color range for different Hue lights. If model is not specified
|
||||||
* it defaults to the smallest Gamut (B) to ensure that colors set on a mix of devices
|
* it defaults to the smallest Gamut (B) to ensure that colors set on a mix of devices
|
||||||
|
|||||||
Reference in New Issue
Block a user