Guard against devices that don't support necessary commands

This commit is contained in:
vlaminck
2016-06-23 09:27:54 -05:00
parent 9b285ec93b
commit f5d3cca6a0

View File

@@ -528,14 +528,16 @@ def updateDimmers(percentComplete) {
} else { } else {
def shouldChangeColors = (colorize && colorize != "false") def shouldChangeColors = (colorize && colorize != "false")
def canChangeColors = hasSetColorCommand(dimmer)
log.debug "Setting ${deviceLabel(dimmer)} to ${nextLevel}" if (shouldChangeColors && hasSetColorCommand(dimmer)) {
def hue = getHue(dimmer, nextLevel)
if (shouldChangeColors && canChangeColors) { log.debug "Setting ${deviceLabel(dimmer)} level to ${nextLevel} and hue to ${hue}"
dimmer.setColor([hue: getHue(dimmer, nextLevel), saturation: 100, level: nextLevel]) dimmer.setColor([hue: hue, saturation: 100, level: nextLevel])
} else { } else if (hasSetLevelCommand(dimmer)) {
log.debug "Setting ${deviceLabel(dimmer)} level to ${nextLevel}"
dimmer.setLevel(nextLevel) dimmer.setLevel(nextLevel)
} else {
log.warn "${deviceLabel(dimmer)} does not have setColor or setLevel commands."
} }
} }
@@ -818,23 +820,15 @@ private getRedHue(level) {
} }
private hasSetLevelCommand(device) { private hasSetLevelCommand(device) {
def isDimmer = false return hasCommand(device, "setLevel")
device.supportedCommands.each {
if (it.name.contains("setLevel")) {
isDimmer = true
}
}
return isDimmer
} }
private hasSetColorCommand(device) { private hasSetColorCommand(device) {
def hasColor = false return hasCommand(device, "setColor")
device.supportedCommands.each { }
if (it.name.contains("setColor")) {
hasColor = true private hasCommand(device, String command) {
} return (device.supportedCommands.find { it.name == command } != null)
}
return hasColor
} }
private dimmersWithSetColorCommand() { private dimmersWithSetColorCommand() {