Infrastruction modification
[smartthings-infrastructure.git] / SwitchLevel / SwitchLevels.groovy
1 //Create a class for switch level
2 package SwitchLevel
3 import SmartThing.SmartThings
4
5 public class SwitchLevels extends SmartThings {
6         List switchLevels = new ArrayList()
7
8         SwitchLevels(Closure sendEvent, boolean init) {
9                 // Only initialize one time since we only have one device for each capability
10                 switchLevels = smartThings
11
12                 // Initialization
13                 StringBuilder id = new StringBuilder("switchLevelID0")
14                 StringBuilder label = new StringBuilder("switchLevel")
15                 StringBuilder displayName = new StringBuilder("switchLevel0")
16                 MutableInteger level = new MutableInteger()
17
18                 if (init)
19                         level.setValue(50)
20                 else
21                         level.setValue(60)
22
23                 switchLevels.add(new SwitchLevel(sendEvent, id, label, displayName, level))
24         }
25
26         // Methods to set values
27         def setLevel(String newValue) {
28                 setLevel(newValue.toInteger())
29         }
30
31         def setLevel(long newValue) {
32                 setLevel((int) newValue)
33         }
34
35         def setLevel(int newValue) {
36                 switchLevels[0].setLevel(newValue)
37         }
38
39         // Methods to return values
40         def getCurrentLevel() {
41                 List tmpValues = new ArrayList()
42                 tmpValues.add(switchLevels[0].getCurrentLevel())
43                 return tmpValues
44         }
45 }