10c4aa61aed7270292d1c03dc77ba2a18cf80a23
[smartthings-infrastructure.git] / ContactSensor / ContactSensors.groovy
1 //Create a class for contact sensor
2 package ContactSensor
3 import Timer.SimulatedTimer
4
5 public class ContactSensors {
6         private int deviceNumbers
7         private List contacts
8         def sendEvent
9
10         //For one device(We cannot have obj.id)-> We should have obj[0].id
11         private String id = "contactSensorID0"
12         private String label = "contactSensor0"
13         private String displayName = "contactSensor0"
14         private String contactState = "closed"
15         private String latestValue = "closed"
16
17                 
18         ContactSensors(Closure sendEvent, int deviceNumbers) {
19                 this.sendEvent = sendEvent              
20                 this.deviceNumbers = deviceNumbers
21                 this.contacts = []
22
23                 contacts.add(new ContactSensor(id, label, displayName, this.contactState, this.latestValue))
24         }
25
26         //Methods for closures
27         def count(Closure Input) {
28                 contacts.count(Input)
29         }
30         def size() {
31                 contacts.size()
32         }
33         def each(Closure Input) {
34                 contacts.each(Input)
35         }
36         def find(Closure Input) {
37                 contacts.find(Input)
38         }
39         def collect(Closure Input) {
40                 contacts.collect(Input)
41         }
42
43         //By Model Checker
44         def setValue(LinkedHashMap eventDataMap) {
45                 contacts[0].setValue(eventDataMap["value"])
46                 this.latestValue = contacts[0].latestValue
47                 this.contactState = contacts[0].contactState
48                 sendEvent(eventDataMap)
49         }
50
51         def currentValue(String deviceFeature) {
52                 contacts[0].currentValue(deviceFeature)//It is called if we have only one device
53         }
54
55         def latestValue(String deviceFeature) {
56                 contacts[0].latestValue(deviceFeature)//It is called if we have only one device
57         }
58
59         def getAt(int ix) {
60                 contacts[ix]
61         }
62 }