//Create a class for smoke detector
package SmokeDetector
-import Timer.SimulatedTimer
-
-public class SmokeDetectors {
- private int deviceNumbers
- private List smokeDetectors
- def sendEvent
-
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private String id = "smokeDetectorID0"
- private String label = "smokeDetector0"
- private String displayName = "smokeDetector0"
- private String smoke = "clear"
- private String currentSmokeValue = "clear"
- private String smokeLatestValue = "clear"
+import SmartThing.SmartThings
+public class SmokeDetectors extends SmartThings {
+ List smokeDetectors = new ArrayList()
- SmokeDetectors(Closure sendEvent, int deviceNumbers) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.smokeDetectors = []
-
- smokeDetectors.add(new SmokeDetector(id, label, displayName, this.currentSmokeValue, this.smokeLatestValue))
- }
-
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["value"] != smokeDetectors[0].currentSmokeValue) {
- smokeDetectors[0].setValue(eventDataMap["value"])
- this.smokeLatestValue = smokeDetectors[0].smokeLatestValue
- this.smoke = smokeDetectors[0].currentSmokeValue
- this.currentSmokeValue = smokeDetectors[0].currentSmokeValue
- sendEvent(eventDataMap)
- }
- }
-
- //Methods for closures
- def count(Closure Input) {
- smokeDetectors.count(Input)
- }
- def size() {
- smokeDetectors.size()
- }
- def each(Closure Input) {
- smokeDetectors.each(Input)
- }
- def find(Closure Input) {
- smokeDetectors.find(Input)
- }
- def collect(Closure Input) {
- smokeDetectors.collect(Input)
- }
-
-
- def currentValue(String deviceFeature) {
- smokeDetectors[0].currentValue(deviceFeature)//It is called if we have only one device
- }
-
- def latestValue(String deviceFeature) {
- smokeDetectors[0].latestValue(deviceFeature)//It is called if we have only one device
- }
-
- def getAt(int ix) {
- smokeDetectors[ix]
+ SmokeDetectors(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ smokeDetectors = smartThings
+
+ // Initialization
+ String id = "smokeDetectorID0"
+ String label = "smoke"
+ String displayName = "smokeDetector"
+ String smoke
+
+ if (init)
+ smoke = "clear"
+ else
+ smoke = "detected"
+
+ smokeDetectors.add(new SmokeDetector(sendEvent, id, label, displayName, smoke))
}
}