1 //Create a class for switch device
3 import Timer.SimulatedTimer
5 public class Switches {
11 //If we have only one device
12 private String id = "switchID0"
13 private String label = "switch0"
14 private String displayName = "switch0"
15 private String switchState = "off"
16 private String currentSwitch = "off"
17 private int currentLevel = 50
18 private String switchLatestValue = "off"
20 Switches(Closure sendEvent, int deviceNumbers) {
21 this.sendEvent = sendEvent
22 this.timers = new SimulatedTimer()
23 this.deviceNumbers = deviceNumbers
26 switches.add(new Switch(sendEvent, id, label, displayName, this.switchState, this.currentSwitch, this.currentLevel, this.switchLatestValue))
29 //Methods for closures
30 def count(Closure Input) {
36 def each(Closure Input) {
39 def find(Closure Input) {
42 def collect(Closure Input) {
43 switches.collect(Input)
47 def setLevel(int level) {
48 switches[0].setLevel(level)
55 def on(LinkedHashMap metaData) {
56 def task = timers.runAfter(metaData["delay"]) {
65 def off(LinkedHashMap metaData) {
66 def task = timers.runAfter(metaData["delay"]) {
72 def setValue(LinkedHashMap eventDataMap) {
73 switches[0].setValue(eventDataMap["value"])
74 this.switchState = switches[0].switchState
75 this.switchLatestValue = switches[0].switchLatestValue
76 sendEvent(eventDataMap)
80 def currentValue(String deviceFeature) {
81 switches[0].currentValue(deviceFeature)
84 def latestValue(String deviceFeature) {
85 switches[0].latestValue(deviceFeature)