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