e9c027e5a9a4834d4c9bef865c10945780f745b8
[smartthings-infrastructure.git] / ThreeAxis / ThreeAxises.groovy
1 //Create a class for three axis
2 package ThreeAxis
3 import Timer.SimulatedTimer
4
5 public class ThreeAxises {
6         private int deviceNumbers
7         private List threeAxises
8         def sendEvent
9
10         //For one device(We cannot have obj.id)-> We should have obj[0].id
11         private String id = "threeAxisID0"
12         private String label = "threeAxis0"
13         private String displayName = "threeAxis0"
14         private LinkedHashMap threeAxis = [x:0, y:0, z:0]
15         
16                 
17         ThreeAxises(Closure sendEvent, int deviceNumbers, boolean init) {
18                 this.sendEvent = sendEvent              
19                 this.deviceNumbers = deviceNumbers
20                 this.threeAxises = []
21                 
22                 if (init) {
23                         this.threeAxis = [x:0, y:0, z:0]
24                 } else {
25                         this.threeAxis = [x:1, y:2, z:3]
26                 }
27                 threeAxises.add(new ThreeAxis(id, label, displayName, threeAxis))
28         }
29
30         //By Model Checker
31         def setValue(LinkedHashMap eventDataMap) {
32                 threeAxises[0].setValue(eventDataMap)
33                 sendEvent(eventDataMap)
34         }
35
36         //Methods for closures
37         def count(Closure Input) {
38                 threeAxises.count(Input)
39         }
40         def size() {
41                 threeAxises.size()
42         }
43         def each(Closure Input) {
44                 threeAxises.each(Input)
45         }
46         def sort(Closure Input) {
47                 threeAxises.sort(Input)
48         }
49         def find(Closure Input) {
50                 threeAxises.find(Input)
51         }
52         def collect(Closure Input) {
53                 threeAxises.collect(Input)
54         }
55
56
57         def currentValue(String deviceFeature) {
58                 threeAxises[0].currentValue(deviceFeature)
59         }
60
61         def latestValue(String deviceFeature) {
62                 threeAxises[0].latestValue(deviceFeature)
63         }
64
65         def getAt(int ix) {
66                 threeAxises[ix]
67         }
68 }