Removing getXXX methods + properties. Adding getProperty feature to SmartThing(s)
[smartthings-infrastructure.git] / Switch / Switch.groovy
1 //Create a class for switch device
2 package Switch
3 import SmartThing.SmartThing
4
5 public class Switch extends SmartThing {
6         // id, label, and display name of the device
7         String id
8         String label
9         String displayName
10         // Maps from features to values
11         HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
12         // Possible values for eventsSince method
13         List<String> possibleValues = new ArrayList<String>();
14
15         Switch(Closure sendEvent, String id, String label, String displayName, String currentSwitch) {
16                 deviceValueSmartThing = deviceValuesMap
17                 idSmartThing = id
18                 labelSmartThing = label
19                 displayNameSmartThing = displayName
20                 sendEventSmartThings = sendEvent
21                 possibleValuesSmartThings = possibleValues
22
23                 // Initialization
24                 this.id = id
25                 this.label = label
26                 this.displayName = displayName
27                 possibleValues.add("on")
28                 possibleValues.add("off")
29
30                 deviceValuesMap.put("switch", currentSwitch)
31         }
32
33         // Methods to set values
34         def on() {
35                 action("on", "switch")
36         }
37
38         def on(LinkedHashMap metaData) {
39                 on()
40         }
41
42         def off() {
43                 action("off", "switch")
44         }
45
46         def off(LinkedHashMap metaData) {
47                 off()
48         }
49 }