Changing Verify API call scheme for device handlers.
[smartthings-infrastructure.git] / AccelerationSensor / AccelerationSensors.groovy
1 //Create a class for acceleration sensor
2 package AccelerationSensor
3 import Timer.SimulatedTimer
4
5 public class AccelerationSensors {
6         private int deviceNumbers
7         private List accelerationSensors
8         def sendEvent
9
10         //For one device(We cannot have obj.id)-> We should have obj[0].id
11         private String id = "accelerationSensorID0"
12         private String label = "accelerationSensor0"
13         private String displayName = "accelerationSensor0"
14         private String acceleration = "inactive"
15         private String currentAcceleration = "inactive"
16         private String accelerationLatestValue = "inactive"
17         
18
19                 
20         AccelerationSensors(Closure sendEvent, int deviceNumbers, boolean init) {
21                 this.sendEvent = sendEvent              
22                 this.deviceNumbers = deviceNumbers
23                 this.accelerationSensors = []
24
25                 if (init) {
26                         this.acceleration = "inactive"
27                         this.accelerationLatestValue = "inactive"
28                 } else {
29                         this.acceleration = "active"
30                         this.accelerationLatestValue = "active"
31                 }
32                 accelerationSensors.add(new AccelerationSensor(id, label, displayName, this.acceleration, this.accelerationLatestValue))
33         }
34
35         //By Model Checker
36         def setValue(LinkedHashMap eventDataMap) {
37                 if (eventDataMap["value"] != accelerationSensors[0].acceleration) {
38                         this.accelerationLatestValue = eventDataMap["value"]
39                         this.acceleration = eventDataMap["value"]
40                         this.currentAcceleration = eventDataMap["value"]
41                         accelerationSensors[0].setValue(eventDataMap["value"])
42                         sendEvent(eventDataMap)
43                 }
44         }
45
46         //methods
47         def eventsSince(Date dateObj) {
48                 return accelerationSensors[0].eventsSince()
49         }
50                 
51         def statesSince(String info, Date dateObj) {
52                 return accelerationSensors[0].statesSince()
53         }
54
55         //Methods for closures
56         def count(Closure Input) {
57                 accelerationSensors.count(Input)
58         }
59         def size() {
60                 accelerationSensors.size()
61         }
62         def each(Closure Input) {
63                 accelerationSensors.each(Input)
64         }
65         def sort(Closure Input) {
66                 accelerationSensors.each(Input)
67         }
68         def find(Closure Input) {
69                 accelerationSensors.find(Input)
70         }
71         def collect(Closure Input) {
72                 accelerationSensors.collect(Input)
73         }
74
75
76         def currentValue(String deviceFeature) {
77                 accelerationSensors[0].currentValue(deviceFeature)//It is called if we have only one device
78         }
79
80         def latestValue(String deviceFeature) {
81                 accelerationSensors[0].latestValue(deviceFeature)//It is called if we have only one device
82         }
83
84         def getAt(int ix) {
85                 accelerationSensors[ix]
86         }
87 }