X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=SwitchLevel%2FSwitchLevels.groovy;h=1bae6a1c30ccf519b1f7535cefafde160581c251;hb=b7cf952d275d7cb67250c52404cf855ef57c1119;hp=4ace3612708741914db1dd0d13f155c5b065836e;hpb=b5602bde1f6ac15ef1fa8b1d6eceb68708a51ad1;p=smartthings-infrastructure.git diff --git a/SwitchLevel/SwitchLevels.groovy b/SwitchLevel/SwitchLevels.groovy index 4ace361..1bae6a1 100644 --- a/SwitchLevel/SwitchLevels.groovy +++ b/SwitchLevel/SwitchLevels.groovy @@ -55,6 +55,9 @@ public class SwitchLevels { def find(Closure Input) { switchLevels.find(Input) } + def sort(Closure Input) { + switchLevels.sort(Input) + } def collect(Closure Input) { switchLevels.collect(Input) } @@ -69,47 +72,66 @@ public class SwitchLevels { } def on() { - switchLevels[0].on() - switchLatestValue = switchState + switchLatestValue = "on" switchState = "on" currentSwitch = "on" + switchLevels[0].on() } def on(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { - switchLevels[0].on() - switchLatestValue = switchState + switchLatestValue = "on" switchState = "on" currentSwitch = "on" + switchLevels[0].on() } } def off() { - switchLevels[0].off() - switchLatestValue = switchState + switchLatestValue = "off" switchState = "off" currentSwitch = "off" + switchLevels[0].off() } def off(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { - switchLevels[0].off() - switchLatestValue = switchState + switchLatestValue = "off" switchState = "off" currentSwitch = "off" + switchLevels[0].off() } } //By Model Checker def setValue(LinkedHashMap eventDataMap) { - if (eventDataMap["value"] != switchLevels[0].level) { - switchLevels[0].setValue(eventDataMap["value"]) - this.level = switchLevels[0].level - this.rate = switchLevels[0].level - sendEvent(eventDataMap) + if (eventDataMap["name"] == "switch") { + if (eventDataMap["value"] != switchLevels[0].switchState) { + this.switchState = eventDataMap["value"] + this.switchLatestValue = eventDataMap["value"] + this.currentSwitch = eventDataMap["value"] + switchLevels[0].setValue(eventDataMap["value"], "switch") + sendEvent(eventDataMap) + } + } else if (eventDataMap["name"] == "level") { + if (eventDataMap["value"].toInteger() != switchLevels[0].level) { + this.level = eventDataMap["value"].toInteger() + this.rate = eventDataMap["value"].toInteger() + switchLevels[0].setValue(eventDataMap["value"], "level") + sendEvent(eventDataMap) + } } } + def currentValue(String deviceFeature) { + switchLevels[0].currentValue(deviceFeature) + } + + def latestValue(String deviceFeature) { + switchLevels[0].latestValue(deviceFeature) + } + + def getAt(int ix) { switchLevels[ix] }