mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-08 05:31:56 +00:00
[DVCSMP-2273] Fix for NPE for slave/master settings
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
/**
|
/**
|
||||||
* Color Coordinator
|
* Color Coordinator
|
||||||
* Version 1.1.0 - 11/9/16
|
* Version 1.1.1 - 11/9/16
|
||||||
* By Michael Struck
|
* By Michael Struck
|
||||||
*
|
*
|
||||||
* 1.0.0 - Initial release
|
* 1.0.0 - Initial release
|
||||||
* 1.1.0 - Fixed issue where master can be part of slaves. This causes a loop that impacts SmartThings.
|
* 1.1.0 - Fixed issue where master can be part of slaves. This causes a loop that impacts SmartThings.
|
||||||
|
* 1.1.1 - Fix NPE being thrown for slave/master inputs being empty.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
@@ -40,10 +41,10 @@ def mainPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
section("Master Light") {
|
section("Master Light") {
|
||||||
input "master", "capability.colorControl", title: "Colored Light"
|
input "master", "capability.colorControl", title: "Colored Light", required: true
|
||||||
}
|
}
|
||||||
section("Lights that follow the master settings") {
|
section("Lights that follow the master settings") {
|
||||||
input "slaves", "capability.colorControl", title: "Colored Lights", multiple: true, required: false, submitOnChange: true
|
input "slaves", "capability.colorControl", title: "Colored Lights", multiple: true, required: true, submitOnChange: true
|
||||||
}
|
}
|
||||||
section([mobileOnly:true], "Options") {
|
section([mobileOnly:true], "Options") {
|
||||||
input "randomYes", "bool",title: "When Master Turned On, Randomize Color", defaultValue: false
|
input "randomYes", "bool",title: "When Master Turned On, Randomize Color", defaultValue: false
|
||||||
@@ -81,40 +82,44 @@ def init() {
|
|||||||
}
|
}
|
||||||
//-----------------------------------
|
//-----------------------------------
|
||||||
def onOffHandler(evt){
|
def onOffHandler(evt){
|
||||||
if (!slaves.id.find{it==master.id}){
|
if (slaves && master) {
|
||||||
if (master.currentValue("switch") == "on"){
|
if (!slaves?.id.find{it==master.id}){
|
||||||
if (randomYes) getRandomColorMaster()
|
if (master?.currentValue("switch") == "on"){
|
||||||
else slaves?.on()
|
if (randomYes) getRandomColorMaster()
|
||||||
}
|
else slaves?.on()
|
||||||
else {
|
}
|
||||||
slaves?.off()
|
else {
|
||||||
}
|
slaves?.off()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def colorHandler(evt) {
|
def colorHandler(evt) {
|
||||||
if (!slaves.id.find{it==master.id} && master.currentValue("switch") == "on"){
|
if (slaves && master) {
|
||||||
log.debug "Changing Slave units H,S,L"
|
if (!slaves?.id?.find{it==master.id} && master?.currentValue("switch") == "on"){
|
||||||
def dimLevel = master.currentValue("level")
|
log.debug "Changing Slave units H,S,L"
|
||||||
def hueLevel = master.currentValue("hue")
|
def dimLevel = master?.currentValue("level")
|
||||||
def saturationLevel = master.currentValue("saturation")
|
def hueLevel = master?.currentValue("hue")
|
||||||
def newValue = [hue: hueLevel, saturation: saturationLevel, level: dimLevel as Integer]
|
def saturationLevel = master.currentValue("saturation")
|
||||||
slaves?.setColor(newValue)
|
def newValue = [hue: hueLevel, saturation: saturationLevel, level: dimLevel as Integer]
|
||||||
try {
|
slaves?.setColor(newValue)
|
||||||
log.debug "Changing Slave color temp"
|
try {
|
||||||
def tempLevel = master.currentValue("colorTemperature")
|
log.debug "Changing Slave color temp"
|
||||||
slaves?.setColorTemperature(tempLevel)
|
def tempLevel = master?.currentValue("colorTemperature")
|
||||||
}
|
slaves?.setColorTemperature(tempLevel)
|
||||||
catch (e){
|
}
|
||||||
log.debug "Color temp for master --"
|
catch (e){
|
||||||
}
|
log.debug "Color temp for master --"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def getRandomColorMaster(){
|
def getRandomColorMaster(){
|
||||||
def hueLevel = Math.floor(Math.random() *1000)
|
def hueLevel = Math.floor(Math.random() *1000)
|
||||||
def saturationLevel = Math.floor(Math.random() * 100)
|
def saturationLevel = Math.floor(Math.random() * 100)
|
||||||
def dimLevel = master.currentValue("level")
|
def dimLevel = master?.currentValue("level")
|
||||||
def newValue = [hue: hueLevel, saturation: saturationLevel, level: dimLevel as Integer]
|
def newValue = [hue: hueLevel, saturation: saturationLevel, level: dimLevel as Integer]
|
||||||
log.debug hueLevel
|
log.debug hueLevel
|
||||||
log.debug saturationLevel
|
log.debug saturationLevel
|
||||||
@@ -123,12 +128,14 @@ def getRandomColorMaster(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
def tempHandler(evt){
|
def tempHandler(evt){
|
||||||
if (!slaves.id.find{it==master.id} && master.currentValue("switch") == "on"){
|
if (slaves && master) {
|
||||||
if (evt.value != "--") {
|
if (!slaves?.id?.find{it==master?.id} && master?.currentValue("switch") == "on"){
|
||||||
log.debug "Changing Slave color temp based on Master change"
|
if (evt.value != "--") {
|
||||||
def tempLevel = master.currentValue("colorTemperature")
|
log.debug "Changing Slave color temp based on Master change"
|
||||||
slaves?.setColorTemperature(tempLevel)
|
def tempLevel = master.currentValue("colorTemperature")
|
||||||
}
|
slaves?.setColorTemperature(tempLevel)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +146,7 @@ private def textAppName() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def textVersion() {
|
private def textVersion() {
|
||||||
def text = "Version 1.1.0 (11/09/2016)"
|
def text = "Version 1.1.1 (12/13/2016)"
|
||||||
}
|
}
|
||||||
|
|
||||||
private def textCopyright() {
|
private def textCopyright() {
|
||||||
@@ -166,4 +173,4 @@ private def textHelp() {
|
|||||||
"This application will allow you to control the settings of multiple colored lights with one control. " +
|
"This application will allow you to control the settings of multiple colored lights with one control. " +
|
||||||
"Simply choose a master control light, and then choose the lights that will follow the settings of the master, "+
|
"Simply choose a master control light, and then choose the lights that will follow the settings of the master, "+
|
||||||
"including on/off conditions, hue, saturation, level and color temperature. Also includes a random color feature."
|
"including on/off conditions, hue, saturation, level and color temperature. Also includes a random color feature."
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user