e6d8848831097af1ff2c61d0bf648e8d4ceae8aa
[smartthings-infrastructure.git] / ContactSensor / contacting.groovy
1 //Create a class for contact sensor
2 package ContactSensor
3
4 public class contacting{
5         List contacts
6         int count
7         
8         contacting(int count) {
9                 this.count = count
10                 if (count == 1) {
11                         contacts = [new contacts(0, "contact0", "closed", "closed")]
12                 } else if (count == 2) {
13                         contacts = [new contacts(0, "contact0", "closed", "closed"), new contacts(1, "contact1", "closed", "closed")]
14                 } else if (count == 3) {
15                         contacts = [new contacts(0, "contact0", "closed", "closed"), new contacts(1, "contact1", "closed", "closed"), new contacts(2,"contact2", "closed", "closed")]
16                 }
17         }
18
19         def currentValue(String S) {
20                 if (count == 1) {
21                         contacts[0].currentValue(S)
22                 } else {
23                         contacts*.currentValue(S)
24                 }
25         }
26
27         def latestValue(String S) {
28                 if (count == 1) {
29                         contacts[0].latestValue(S)
30                 } else {
31                         contacts*.latestValue(S)
32                 }
33         }
34 }