Adding threeAxis event to the python script!
[smartthings-infrastructure.git] / WaterSensor / WaterSensors.groovy
1 //Create a class for water sensor
2 package WaterSensor
3 import Timer.SimulatedTimer
4
5 public class WaterSensors {
6         private int deviceNumbers
7         private List waterSensors
8         def sendEvent
9
10         //For one device(We cannot have obj.id)-> We should have obj[0].id
11         private String id = "waterSensorID0"
12         private String label = "waterSensor0"
13         private String displayName = "waterSensor0"
14         private String water = "dry"
15
16                 
17         WaterSensors(Closure sendEvent, int deviceNumbers, boolean init) {
18                 this.sendEvent = sendEvent              
19                 this.deviceNumbers = deviceNumbers
20                 this.waterSensors = []
21
22                 if (init) {
23                         this.water = "dry"
24                 } else {
25                         this.water = "wet"
26                 }
27                 waterSensors.add(new WaterSensor(id, label, displayName, this.water))
28         }
29
30         //By Model Checker
31         def setValue(LinkedHashMap eventDataMap) {
32                 if (eventDataMap["value"] != waterSensors[0].water) {
33                         this.water = eventDataMap["value"]
34                         waterSensors[0].setValue(eventDataMap["value"])
35                         sendEvent(eventDataMap)
36                 }
37         }
38
39         //Methods for closures
40         def count(Closure Input) {
41                 waterSensors.count(Input)
42         }
43         def size() {
44                 waterSensors.size()
45         }
46         def each(Closure Input) {
47                 waterSensors.each(Input)
48         }
49         def find(Closure Input) {
50                 waterSensors.find(Input)
51         }
52         def sort(Closure Input) {
53                 waterSensors.sort(Input)
54         }
55         def collect(Closure Input) {
56                 waterSensors.collect(Input)
57         }
58
59         def getAt(int ix) {
60                 waterSensors[ix]
61         }
62 }