Infrastruction modification
[smartthings-infrastructure.git] / BeaconSensor / BeaconSensors.groovy
index 4550965ad876a28d4c30425ee5fb257a4914d145..c5b4cf62e5585b9c2119b5a8f2d91ba79e6230f1 100644 (file)
@@ -1,79 +1,31 @@
 //Create a class for beacon sensor
 package BeaconSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-public class BeaconSensors {
-       private int deviceNumbers
-       private List beaconSensors
-       def sendEvent
+public class BeaconSensors extends SmartThings {
+       List beaconSensors = new ArrayList()
 
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "beaconSensorID0"
-       private String label = "beaconSensor0"
-       private String displayName = "beaconSensor0"
-       private String presence = "not present"
-       private String currentPresence = "not present"
-       private String presenceLatestValue = "not present"
+       BeaconSensors(Closure sendEvent, boolean init) {
+               beaconSensors = smartThings
 
-               
-       BeaconSensors(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent              
-               this.deviceNumbers = deviceNumbers
-               this.beaconSensors = []
+               // Initialization
+               StringBuilder id = new StringBuilder("beaconID0")
+               StringBuilder label = new StringBuilder("beacon")
+               StringBuilder displayName = new StringBuilder("beacon0")
+               StringBuilder presence = new StringBuilder()
 
-               if (init) {
-                       this.presence = "not present"
-                       this.currentPresence = "not present"
-                       this.presenceLatestValue = "not present"
-               } else {
-                       this.presence = "present"
-                       this.currentPresence = "present"
-                       this.presenceLatestValue = "present"
-               }
-               beaconSensors.add(new BeaconSensor(id, label, displayName, this.presence, this.presenceLatestValue))
-       }
-
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"] != beaconSensors[0].presence) {
-                       this.presenceLatestValue = eventDataMap["value"]
-                       this.presence = eventDataMap["value"]
-                       this.currentPresence = eventDataMap["value"]
-                       beaconSensors[0].setValue(eventDataMap["value"])
-                       sendEvent(eventDataMap)
-               }
-       }
-
-       //Methods for closures
-       def count(Closure Input) {
-               beaconSensors.count(Input)
-       }
-       def size() {
-               beaconSensors.size()
-       }
-       def each(Closure Input) {
-               beaconSensors.each(Input)
-       }
-       def sort(Closure Input) {
-               beaconSensors.sort(Input)
-       }
-       def find(Closure Input) {
-               beaconSensors.find(Input)
-       }
-       def collect(Closure Input) {
-               beaconSensors.collect(Input)
-       }
-
-
-       def currentValue(String deviceFeature) {
-               beaconSensors[0].currentValue(deviceFeature)//It is called if we have only one device
-       }
+               if (init)
+                       presence.append("not present")
+               else
+                       presence.append("present")
 
-       def latestValue(String deviceFeature) {
-               beaconSensors[0].latestValue(deviceFeature)//It is called if we have only one device
+               beaconSensors.add(new BeaconSensor(sendEvent, id, label, displayName, presence))
        }
 
-       def getAt(int ix) {
-               beaconSensors[ix]
+       // Methods to return values
+       def getCurrentPresence() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(beaconSensors[0].getCurrentPresence())
+               return tmpValues
        }
 }