//Create a class for sleep sensor
package SleepSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
-public class SleepSensors {
- private int deviceNumbers
- private List sleepSensors
- def sendEvent
+public class SleepSensors extends SmartThings {
+ List sleepSensors = new ArrayList()
+
+ SleepSensors(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ sleepSensors = smartThings
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private String id = "sleepSensorID0"
- private String label = "sleepSensor0"
- private String displayName = "sleepSensor0"
- private String sleeping = "sleeping"
+ // Initialization
+ String id = "sleepSensorID0"
+ String label = "sleeping"
+ String displayName = "sleepSensor"
+ String sleeping
-
- SleepSensors(Closure sendEvent, int deviceNumbers) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.sleepSensors = []
+ if (init)
+ sleeping = "sleeping"
+ else
+ sleeping = "not sleeping"
- sleepSensors.add(new SleepSensor(id, label, displayName, this.sleeping))
- }
-
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["value"] != sleepSensors[0].sleeping) {
- sleepSensors[0].setValue(eventDataMap["value"])
- this.sleeping = sleepSensors[0].sleeping
- sendEvent(eventDataMap)
- }
- }
-
- //Methods for closures
- def count(Closure Input) {
- sleepSensors.count(Input)
- }
- def size() {
- sleepSensors.size()
- }
- def each(Closure Input) {
- sleepSensors.each(Input)
- }
- def find(Closure Input) {
- sleepSensors.find(Input)
- }
- def collect(Closure Input) {
- sleepSensors.collect(Input)
- }
-
- def getAt(int ix) {
- sleepSensors[ix]
+ sleepSensors.add(new SleepSensor(sendEvent, id, label, displayName, sleeping))
}
}