9889793eb3bdd6296434fe51da5d06089897dcfd
[smartthings-infrastructure.git] / ContactSensor / ContactSensors.groovy
1 //Create a class for contact sensor
2 package ContactSensor
3 import SmartThing.SmartThings
4
5 public class ContactSensors extends SmartThings {
6         List contacts = new ArrayList()
7
8         ContactSensors(Closure sendEvent, boolean init) {
9                 // Only initialize one time since we only have one device for each capability
10                 contacts = smartThings
11
12                 // Initialization
13                 StringBuilder id = new StringBuilder("contactID0")
14                 StringBuilder label = new StringBuilder("contact")
15                 StringBuilder displayName = new StringBuilder("contact0")
16                 StringBuilder currentContact = new StringBuilder()
17                 
18                 if (init)
19                         currentContact.append("closed")
20                 else
21                         currentContact.append("open")
22
23                 contacts.add(new ContactSensor(sendEvent, id, label, displayName, currentContact))
24         }
25
26         // Methods to return values
27         def getCurrentContact() {
28                 List tmpValues = new ArrayList()
29                 tmpValues.add(contacts[0].getCurrentContact())
30                 return tmpValues
31         }
32 }