Infrastruction modification
authoramiraj <amiraj.95@uci.edu>
Wed, 22 Jan 2020 19:37:08 +0000 (11:37 -0800)
committeramiraj <amiraj.95@uci.edu>
Wed, 22 Jan 2020 19:37:08 +0000 (11:37 -0800)
74 files changed:
AccelerationSensor/AccelerationSensor.groovy
AccelerationSensor/AccelerationSensors.groovy
AeonKeyFob/AeonKeyFob.groovy
AeonKeyFob/AeonKeyFobs.groovy
Alarm/Alarm.groovy
Alarm/Alarms.groovy
Battery/Batteries.groovy
Battery/Battery.groovy
BeaconSensor/BeaconSensor.groovy
BeaconSensor/BeaconSensors.groovy
Button/Button.groovy
Button/Buttons.groovy
CarbonMonoxideDetector/CarbonMonoxideDetector.groovy
CarbonMonoxideDetector/CarbonMonoxideDetectors.groovy
ColorControl/ColorControl.groovy
ColorControl/ColorControls.groovy
ColorTemperature/ColorTemperature.groovy
ColorTemperature/ColorTemperatures.groovy
ContactSensor/ContactSensor.groovy
ContactSensor/ContactSensors.groovy
DoorControl/DoorControl.groovy
DoorControl/DoorControls.groovy
EnergyMeter/EnergyMeter.groovy
EnergyMeter/EnergyMeters.groovy
Event/Event.groovy
Extractor/Extractor.groovy
IlluminanceMeasurement/IlluminanceMeasurement.groovy
IlluminanceMeasurement/IlluminanceMeasurements.groovy
ImageCapture/ImageCapture.groovy
ImageCapture/ImageCaptures.groovy
Location/LocationVar.groovy
Lock/Lock.groovy
Lock/Locks.groovy
MobilePresence/MobilePresence.groovy
MobilePresence/MobilePresences.groovy
Momentary/Momentaries.groovy
Momentary/Momentary.groovy
MotionSensor/MotionSensor.groovy
MotionSensor/MotionSensors.groovy
MusicPlayer/MusicPlayer.groovy
MusicPlayer/MusicPlayers.groovy
NfcTouch/NfcTouch.groovy
PowerMeter/PowerMeter.groovy
PowerMeter/PowerMeters.groovy
PresenceSensor/PresenceSensor.groovy
PresenceSensor/PresenceSensors.groovy
RelativeHumidityMeasurement/RelativeHumidityMeasurement.groovy
RelativeHumidityMeasurement/RelativeHumidityMeasurements.groovy
RelaySwitch/RelaySwitch.groovy
RelaySwitch/RelaySwitches.groovy
SleepSensor/SleepSensor.groovy
SleepSensor/SleepSensors.groovy
SmokeDetector/SmokeDetector.groovy
SmokeDetector/SmokeDetectors.groovy
SpeechSynthesis/SpeechSynthesis.groovy
SpeechSynthesis/SpeechSynthesises.groovy
StepSensor/StepSensor.groovy
StepSensor/StepSensors.groovy
Switch/Switch.groovy
Switch/Switches.groovy
SwitchLevel/SwitchLevel.groovy
SwitchLevel/SwitchLevels.groovy
TemperatureMeasurement/TemperatureMeasurement.groovy
TemperatureMeasurement/TemperatureMeasurements.groovy
Thermostat/Thermostat.groovy
Thermostat/Thermostats.groovy
ThreeAxis/ThreeAxis.groovy
ThreeAxis/ThreeAxises.groovy
Valve/Valve.groovy
Valve/Valves.groovy
WaterSensor/WaterSensor.groovy
WaterSensor/WaterSensors.groovy
appLists/device-interaction/switchesAppList
appTouch/Touched.groovy

index 905e018..3352e7d 100644 (file)
-//Create a class for acceleration sensor
+// Create a class for acceleration sensor
 package AccelerationSensor
-import Timer.SimulatedTimer
-
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
-public class AccelerationSensor {
-       private String id
-       private String label
-       private String displayName
-       private String acceleration
-       private String currentAcceleration
-       private String accelerationLatestValue
-
-       AccelerationSensor(String id, String label, String displayName, String acceleration, String accelerationLatestValue) {
+import SmartThing.SmartThing
+
+public class AccelerationSensor extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with string values
+       StringBuilder currentAcceleration = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+       // Possible values for eventsSince method
+       List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
+
+       AccelerationSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentAcceleration) {
+               deviceValuesMap = deviceValueSmartThing
+               deviceIntValuesMap = deviceIntValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+               possibleValuesSmartThings = possibleValues
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.acceleration = acceleration
-               this.currentAcceleration = acceleration
-               this.accelerationLatestValue = accelerationLatestValue
-       }
-
-       def setValue(String value) {
-               println("the acceleration sensor with id:$id is triggered to $value!")
-               this.accelerationLatestValue = value
-               this.acceleration = value
-               this.currentAcceleration = value
-       }
-
-       def statesSince() {
-               def evtActive = [[name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def evtInactive = [[name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
-                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def init = Verify.getInt(0,4)
-               def evtToSend = []
-               if (init == 0) {//return empty set
-                       return evtToSend
-               } else if (init == 1) {//send one active event
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 2) {//send two active events
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 3) {//send one inactive event
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 4) {//send two inactive events
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               }
-       }
-
-       def eventsSince() {
-               def evtActive = [[name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def evtInactive = [[name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
-                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def init = Verify.getInt(0,4)
-               def evtToSend = []
-               if (init == 0) {//return empty set
-                       return evtToSend
-               } else if (init == 1) {//send one active event
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 2) {//send two active events
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 3) {//send one inactive event
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 4) {//send two inactive events
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               }
-       }
+               this.currentAcceleration = currentAcceleration
+               possibleValues.add("active")
+               possibleValues.add("inactive")
 
-       
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "acceleration") {
-                       return acceleration
-               }
+               deviceValuesMap.put("acceleration", currentAcceleration)
        }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "acceleration") {
-                       return accelerationLatestValue
-               }
+       // Methods to return values
+       def getCurrentAcceleration() {
+               return currentAcceleration.toString()
        }
 }
index 7cfe1d0..5827622 100644 (file)
@@ -1,87 +1,32 @@
 //Create a class for acceleration sensor
 package AccelerationSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-public class AccelerationSensors {
-       private int deviceNumbers
-       private List accelerationSensors
-       def sendEvent
-
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "accelerationSensorID0"
-       private String label = "accelerationSensor0"
-       private String displayName = "accelerationSensor0"
-       private String acceleration = "inactive"
-       private String currentAcceleration = "inactive"
-       private String accelerationLatestValue = "inactive"
-       
-
-               
-       AccelerationSensors(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent              
-               this.deviceNumbers = deviceNumbers
-               this.accelerationSensors = []
-
-               if (init) {
-                       this.acceleration = "inactive"
-                       this.accelerationLatestValue = "inactive"
-               } else {
-                       this.acceleration = "active"
-                       this.accelerationLatestValue = "active"
-               }
-               accelerationSensors.add(new AccelerationSensor(id, label, displayName, this.acceleration, this.accelerationLatestValue))
-       }
-
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"] != accelerationSensors[0].acceleration) {
-                       this.accelerationLatestValue = eventDataMap["value"]
-                       this.acceleration = eventDataMap["value"]
-                       this.currentAcceleration = eventDataMap["value"]
-                       accelerationSensors[0].setValue(eventDataMap["value"])
-                       sendEvent(eventDataMap)
-               }
-       }
-
-       //methods
-       def eventsSince(Date dateObj) {
-               return accelerationSensors[0].eventsSince()
-       }
+public class AccelerationSensors extends SmartThings {
+       List accelerationSensors = new ArrayList()
                
-       def statesSince(String info, Date dateObj) {
-               return accelerationSensors[0].statesSince()
-       }
+       AccelerationSensors(Closure sendEvent, boolean init) {
+               accelerationSensors = smartThings
 
-       //Methods for closures
-       def count(Closure Input) {
-               accelerationSensors.count(Input)
-       }
-       def size() {
-               accelerationSensors.size()
-       }
-       def each(Closure Input) {
-               accelerationSensors.each(Input)
-       }
-       def sort(Closure Input) {
-               accelerationSensors.each(Input)
-       }
-       def find(Closure Input) {
-               accelerationSensors.find(Input)
-       }
-       def collect(Closure Input) {
-               accelerationSensors.collect(Input)
-       }
+               // Initialize
+               StringBuilder id = new StringBuilder("accelerationID0")
+               StringBuilder label = new StringBuilder("acceleration")
+               StringBuilder displayName = new StringBuilder("acceleration0")
+               StringBuilder acceleration = new StringBuilder()
 
+               // Initialization
+               if (init)
+                       acceleration.append("inactive")
+               else
+                       acceleration.append("active")
 
-       def currentValue(String deviceFeature) {
-               accelerationSensors[0].currentValue(deviceFeature)//It is called if we have only one device
-       }
-
-       def latestValue(String deviceFeature) {
-               accelerationSensors[0].latestValue(deviceFeature)//It is called if we have only one device
+               accelerationSensors.add(new AccelerationSensor(sendEvent, id, label, displayName, acceleration))
        }
 
-       def getAt(int ix) {
-               accelerationSensors[ix]
+       // Methods to return values
+       def getCurrentAcceleration() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(accelerationSensors[0].getCurrentAcceleration())
+               return tmpValues
        }
 }
index 72e5afd..6fcdb78 100644 (file)
@@ -1,62 +1,27 @@
 //Create a class for aeon key fob
 package AeonKeyFob
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
+public class AeonKeyFob extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Possible values for eventsSince method
+       List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
 
-public class AeonKeyFob {
-       private String id
-       private String label
-       private String displayName
+       AeonKeyFob(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName) {
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+               possibleValuesSmartThings = possibleValues
 
-       AeonKeyFob(String id, String label, String displayName) {
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-       }
-
-       def setValue(LinkedHashMap eventDataMap) {
-               def data = eventDataMap["data"]
-               def value = eventDataMap["value"]
-               println("the button with number $data is $value!")
-       }
-
-       def eventsSince() {
-               def evtHeld = [[name: "button", value: "held", deviceId: "aeonKeyFobID0", descriptionText: "",
-                               displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def evtPushed = [[name: "button", value: "pushed", deviceId: "aeonKeyFobID0", descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def init = Verify.getInt(0,4)
-               def evtToSend = []
-               if (init == 0) {//return empty set
-                       return evtToSend
-               } else if (init == 1) {//send one held event
-                       evtHeld.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 2) {//send two held events
-                       evtHeld.each{
-                               evtToSend.add(it)
-                       }
-                       evtHeld.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 3) {//send one pushed event
-                       evtPushed.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 4) {//send two pushed events
-                       evtPushed.each{
-                               evtToSend.add(it)
-                       }
-                       evtPushed.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               }
+               possibleValues.add("pushed")
+               possibleValues.add("held")
        }
 }
index f001f0d..bbb45b3 100644 (file)
@@ -1,60 +1,18 @@
 //Create a class for aeon key fob
 package AeonKeyFob
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-public class AeonKeyFobs {
-       private int deviceNumbers
-       private List aeonKeyFobs
-       def sendEvent
-
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "aeonKeyFobID0"
-       private String label = "aeonKeyFob0"
-       private String displayName = "aeonKeyFob0"
-       
+public class AeonKeyFobs extends SmartThings {
+       List aeonKeyFobs = new ArrayList()
                
-       AeonKeyFobs(Closure sendEvent, int deviceNumbers) {
-               this.sendEvent = sendEvent              
-               this.deviceNumbers = deviceNumbers
-               this.aeonKeyFobs = []
-
-               aeonKeyFobs.add(new AeonKeyFob(id, label, displayName))
-       }
-
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               aeonKeyFobs[0].setValue(eventDataMap)
-               sendEvent(eventDataMap)
-       }
-
-       //Methods for closures
-       def count(Closure Input) {
-               aeonKeyFobs.count(Input)
-       }
-       def size() {
-               aeonKeyFobs.size()
-       }
-       def each(Closure Input) {
-               aeonKeyFobs.each(Input)
-       }
-       def sort(Closure Input) {
-               aeonKeyFobs.sort(Input)
-       }
-       def find(Closure Input) {
-               aeonKeyFobs.find(Input)
-       }
-       def collect(Closure Input) {
-               aeonKeyFobs.collect(Input)
-       }
-
-
-       //methods
-       def eventsSince(Date dateObj) {
-               return aeonKeyFobs[0].eventsSince()
-       }
-
+       AeonKeyFobs(Closure sendEvent) {
+               aeonKeyFobs = smartThings
+               
+               // Initialization
+               StringBuilder id = new StringBuilder("aeonKeyFobID0")
+               StringBuilder label = new StringBuilder("button")
+               StringBuilder displayName = new StringBuilder("aeonKeyFob0")
 
-       def getAt(int ix) {
-               aeonKeyFobs[ix]
+               aeonKeyFobs.add(new AeonKeyFob(sendEvent, id, label, displayName))
        }
 }
index 6a0a24f..f03f5d6 100644 (file)
@@ -1,96 +1,66 @@
 //Create a class for alarm device
 package Alarm
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-public class Alarm {
-       private String id
-       private String label
-       private String displayName
-       private String alarm
-       private String currentAlarm
-       private String alarmLatestValue
-       def sendEvent   
-       def timers
-       
+public class Alarm extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with string values
+       StringBuilder currentAlarm = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
 
-       Alarm(Closure sendEvent, String id, String label, String displayName, String alarm, String currentAlarm, String alarmLatestValue) {
-               this.sendEvent = sendEvent
-               this.timers = new SimulatedTimer()
+       Alarm(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentAlarm) {
+               deviceValuesMap = deviceValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.alarm = alarm
                this.currentAlarm = currentAlarm
-               this.alarmLatestValue = alarmLatestValue
-       }
 
-       //By model checker
-       def setValue(String value) {
-               println("the alarm with id:$id is triggered to $value!")
-               this.alarmLatestValue = value
-               this.alarm = value
-               this.currentAlarm = value
+               deviceValuesMap.put("alarm", currentAlarm)
        }
 
-
-       //By Apps
+       // Methods to set values
        def both() {
-               if (alarm != "both") {
-                       println("the alarm with id:$id is changed to both!")
-                       this.alarmLatestValue = "both"
-                       this.alarm = "both"
-                       this.currentAlarm = "both"
-                       sendEvent([name: "alarm", value: "both", deviceId: this.id, descriptionText: "",
-                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               action("both")
        }
 
        def on() {
-               both()
+               action("both")
        }
 
        def off() {
-               if (alarm != "off") {
-                       println("the alarm with id:$id is changed to off!")
-                       this.alarmLatestValue = "off"
-                       this.alarm = "off"
-                       this.currentAlarm = "off"
-                       sendEvent([name: "alarm", value: "off", deviceId: this.id, descriptionText: "",
-                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               action("off")
        }
 
        def siren() {
-               if (alarm != "siren") {
-                       println("the alarm with id:$id is changed to siren!")
-                       this.alarmLatestValue = "siren"
-                       this.alarm = "siren"
-                       this.currentAlarm = "siren"
-                       sendEvent([name: "alarm", value: "siren", deviceId: this.id, descriptionText: "",
-                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               action("siren")
        }
 
        def strobe() {
-               if (alarm != "strobe") {
-                       println("the alarm with id:$id is changed to strobe!")
-                       this.alarmLatestValue = "strobe"
-                       this.alarm = "strobe"
-                       this.currentAlarm = "strobe"
-                       sendEvent([name: "alarm", value: "strobe", deviceId: this.id, descriptionText: "",
-                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               action("strobe")
        }
 
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "alarm") {
-                       return currentAlarm
+       def action(String newValue) {
+               if (!currentAlarm.equals(newValue)) {
+                       String tmpID = id.toString()
+                       currentAlarm.replace(0, currentAlarm.length(), newValue)
+                       println("the alarm with id:$tmpID is changed to $newValue!")
+                       sendEvent([name: "alarm", value: newValue, deviceId: tmpID, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "alarm") {
-                       return alarmLatestValue
-               }
+       // Methods to return values
+       def getCurrentAlarm() {
+               return currentAlarm.toString()
        }
 }
index 7e5edd4..ac37de6 100644 (file)
 //Create a class for alarm device
 package Alarm
-import Timer.SimulatedTimer
-
-public class Alarms {
-       int deviceNumbers       
-       List alarms
-       def timers
-       def sendEvent
-
-       //If we have only one device
-       private String id = "alarmID0"
-       private String label = "alarm0"
-       private String displayName = "alarm0"
-       private String alarm = "off"
-       private String currentAlarm = "off"
-       private String alarmLatestValue = "off"
-
-       Alarms(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent
-               this.timers = new SimulatedTimer()
-               this.deviceNumbers = deviceNumbers
-               this.alarms = []
-
-               if (init) {
-                       this.alarm = "off"
-                       this.currentAlarm = "off"
-                       this.alarmLatestValue = "off"
-               } else {
-                       this.alarm = "on"
-                       this.currentAlarm = "on"
-                       this.alarmLatestValue = "on"
-               }
-               alarms.add(new Alarm(sendEvent, id, label, displayName, this.alarm, this.currentAlarm, this.alarmLatestValue))
-       }
+import SmartThing.SmartThings
+
+public class Alarms extends SmartThings {
+       List alarms = new ArrayList()
+
+       Alarms(Closure sendEvent, boolean init) {
+               alarms = smartThings
+
+               // Initialization
+               StringBuilder id = new StringBuilder("alarmID0")
+               StringBuilder label = new StringBuilder("alarm")
+               StringBuilder displayName = new StringBuilder("alarm0")
+               StringBuilder alarm = new StringBuilder()
+       
+               if (init)
+                       alarm.append("off")
+               else
+                       alarm.append("on")
                
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"] != alarms[0].alarm) {
-                       this.alarmLatestValue = eventDataMap["value"]
-                       this.alarm = eventDataMap["value"]
-                       this.currentAlarm = eventDataMap["value"]
-                       alarms[0].setValue(eventDataMap["value"])
-                       sendEvent(eventDataMap)
-               }
-       }
-
-       //Methods for closures
-       def count(Closure Input) {
-               alarms.count(Input)
-       }
-       def size() {
-               alarms.size()
-       }
-       def each(Closure Input) {
-               alarms.each(Input)
-       }
-       def find(Closure Input) {
-               alarms.find(Input)
-       }
-       def sort(Closure Input) {
-               alarms.sort(Input)
-       }
-       def collect(Closure Input) {
-               alarms.collect(Input)
+               alarms.add(new Alarm(sendEvent, id, label, displayName, alarm))
        }
 
-       //By Apps
+       // Methods to set values
        def both() {
-               if (alarm != "both") {
-                       alarmLatestValue = "both"
-                       alarm = "both"
-                       currentAlarm = "both"
-                       alarms[0].both()
-               }
+               alarms[0].both()
        }
 
        def off() {
-               if (alarm != "off") {
-                       alarmLatestValue = "off"
-                       alarm = "off"
-                       currentAlarm = "off"
-                       alarms[0].off()
-               }
+               alarms[0].off()
        }
 
        def on() {
-               both()
+               alarms[0].on()
        }
 
        def siren() {
-               if (alarm != "siren") {
-                       alarmLatestValue = "siren"
-                       alarm = "siren"
-                       currentAlarm = "siren"
-                       alarms[0].siren()
-               }
+               alarms[0].siren()
        }
 
        def strobe() {
-               if (alarm != "strobe") {
-                       alarmLatestValue = "strobe"
-                       alarm = "strobe"
-                       currentAlarm = "strobe"
-                       alarms[0].strobe()
-               }
-       }
-
-       def currentValue(String deviceFeature) {
-               alarms[0].currentValue(deviceFeature)
-       }
-
-       def latestValue(String deviceFeature) {
-               alarms[0].latestValue(deviceFeature)
+               alarms[0].strobe()
        }
 
-       def getAt(int ix) {
-               alarms[ix]
+       // Methods to return values
+       def getCurrentAlarm() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(alarms[0].getCurrentAlarm())
+               return tmpValues
        }
 }
index 732b6bd..2bd29c1 100644 (file)
@@ -1,80 +1,31 @@
 //Create a class for battery
 package Battery
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-public class Batteries {
-       private int deviceNumbers
-       private List batteries
-       def sendEvent
+public class Batteries extends SmartThings {
+       List batteries = new ArrayList()
 
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "batteryID0"
-       private String label = "battery0"
-       private String displayName = "battery0"
-       private int battery = 50
-       private int currentBattery = 50
-       private int batteryLatestValue = 50
+       Batteries(Closure sendEvent, boolean init) {
+               batteries = smartThings
 
-               
-       Batteries(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent              
-               this.deviceNumbers = deviceNumbers
-               this.batteries = []
+               StringBuilder id = new StringBuilder("batteryID0")
+               StringBuilder label = new StringBuilder("battery")
+               StringBuilder displayName = new StringBuilder("battery0")
+               MutableInteger battery = new MutableInteger()
 
-               if (init) {
-                       this.battery = 50
-                       this.currentBattery = 50
-                       this.batteryLatestValue = 50
-               } else {
-                       this.battery = 35
-                       this.currentBattery = 35
-                       this.batteryLatestValue = 35
-               }
+               // Initialization
+               if (init)
+                       battery.setValue(50)
+               else
+                       battery.setValue(0)
 
-               batteries.add(new Battery(id, label, displayName, this.battery))
+               batteries.add(new Battery(sendEvent, id, label, displayName, battery))
        }
 
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"].toInteger() != batteries[0].battery) {
-                       this.battery = eventDataMap["value"].toInteger()
-                       this.currentBattery = eventDataMap["value"].toInteger()
-                       this.batteryLatestValue = eventDataMap["value"].toInteger()
-                       batteries[0].setValue(eventDataMap["value"])
-                       sendEvent(eventDataMap)
-               }
-       }
-
-       //Methods for closures
-       def count(Closure Input) {
-               batteries.count(Input)
-       }
-       def size() {
-               batteries.size()
-       }
-       def each(Closure Input) {
-               batteries.each(Input)
-       }
-       def sort(Closure Input) {
-               batteries.sort(Input)
-       }
-       def find(Closure Input) {
-               batteries.find(Input)
-       }
-       def collect(Closure Input) {
-               batteries.collect(Input)
-       }
-
-
-       def currentValue(String deviceFeature) {
-               batteries[0].currentValue(deviceFeature)//It is called if we have only one device
-       }
-
-       def latestValue(String deviceFeature) {
-               batteries[0].latestValue(deviceFeature)//It is called if we have only one device
-       }
-
-       def getAt(int ix) {
-               batteries[ix]
+       // Methods to return values
+       def getCurrentBattery() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(batteries[0].getCurrentBattery())
+               return tmpValues
        }
 }
index df4b01a..5be240d 100644 (file)
@@ -1,42 +1,35 @@
 //Create a class for battery
 package Battery
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-public class Battery {
-       private String id
-       private String label
-       private String displayName
-       private int battery
-       private int currentBattery
-       private int batteryLatestValue
+public class Battery extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with numberical values
+       MutableInteger currentBattery = new MutableInteger()
+       // Maps from features to values
+       HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
 
-       Battery(String id, String label, String displayName, int battery) {
+       Battery(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentBattery) {
+               deviceIntValuesMap = deviceIntValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.battery = battery
-               this.currentBattery = battery
-               this.batteryLatestValue = battery
-       }
+               this.currentBattery = currentBattery
 
-       //By Model Checker
-       def setValue(String value) {
-               println("the battery level with id:$id is changed to $value!")
-               this.battery = value.toInteger()
-               this.currentBattery = value.toInteger()
-               this.batteryLatestValue = value.toInteger()
+               deviceIntValuesMap.put("battery", currentBattery)
        }
 
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "battery") {
-                       return battery
-               }
+       // Methods to return values
+       def getCurrentBattery() {
+               return currentBattery.toString()
        }
-
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "battery") {
-                       return batteryLatestValue
-               }
-       }
-
 }
index 1aafbb4..be77c04 100644 (file)
@@ -1,41 +1,35 @@
 //Create a class for beacon sensor
 package BeaconSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-public class BeaconSensor {
-       private String id
-       private String label
-       private String displayName
-       private String presence
-       private String currentPresence
-       private String presenceLatestValue
+public class BeaconSensor extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with string values
+       StringBuilder currentPresence = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
 
-       BeaconSensor(String id, String label, String displayName, String presence, String presenceLatestValue) {
+       BeaconSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentPresence) {
+               deviceValuesMap = deviceValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.presence = presence
-               this.currentPresence = presence
-               this.presenceLatestValue = presenceLatestValue
-       }
-
-       def setValue(String value) {
-               println("the beacon sensor with id:$id is triggered to $value!")
-               this.presenceLatestValue = value
-               this.presence = value
-               this.currentPresence = value
-       }
-
-       
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "beacon") {
-                       return presence
-               }
+               this.currentPresence = currentPresence
+               
+               deviceValuesMap.put("beacon", currentPresence)
        }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "beacon") {
-                       return presenceLatestValue
-               }
+       // Methods to return values
+       def getCurrentPresence() {
+               return currentPresence.toString()
        }
 }
index 4550965..c5b4cf6 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
        }
 }
index 45123fa..bb0399e 100644 (file)
@@ -1,65 +1,27 @@
 //Create a class for button
 package Button
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
+public class Button extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Possible values for eventsSince method
+       List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
 
-public class Button {
-       private String id
-       private String label
-       private String displayName
-       private String button
-       private int numberOfButtons
+       Button(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName) {
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+               possibleValuesSmartThings = possibleValues
 
-       Button(String id, String label, String displayName, String button, int numberOfButtons) {
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.button = button
-               this.numberOfButtons = numberOfButtons
-       }
-
-       def setValue(LinkedHashMap eventDataMap) {
-               button = eventDataMap["value"]
-               println("the button is $button!")
-       }
-
-       def eventsSince() {
-               def evtHeld = [[name: "button", value: "held", deviceId: "buttonID0", descriptionText: "",
-                               displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def evtPushed = [[name: "button", value: "pushed", deviceId: "buttonID0", descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def init = Verify.getInt(0,4)
-               def evtToSend = []
-               if (init == 0) {//return empty set
-                       return evtToSend
-               } else if (init == 1) {//send one held event
-                       evtHeld.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 2) {//send two held events
-                       evtHeld.each{
-                               evtToSend.add(it)
-                       }
-                       evtHeld.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 3) {//send one pushed event
-                       evtPushed.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 4) {//send two pushed events
-                       evtPushed.each{
-                               evtToSend.add(it)
-                       }
-                       evtPushed.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               }
+               possibleValues.add("held")
+               possibleValues.add("pushed")
        }
 }
index f15a300..2b94073 100644 (file)
@@ -1,67 +1,18 @@
 //Create a class for button
 package Button
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-public class Buttons {
-       private int deviceNumbers
-       private List buttons
-       def sendEvent
-
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "buttonID0"
-       private String label = "button0"
-       private String displayName = "button0"
-       private String button = "pushed"
-       private int numberOfButtons = 4
-       
+public class Buttons extends SmartThings {
+       List buttons = new ArrayList()
                
-       Buttons(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent              
-               this.deviceNumbers = deviceNumbers
-               this.buttons = []
-
-               if (init) {
-                       this.button = "pushed"
-               } else {
-                       this.button = "held"
-               }
-               buttons.add(new Button(id, label, displayName, button, numberOfButtons))
-       }
-
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               buttons[0].setValue(eventDataMap)
-               sendEvent(eventDataMap)
-       }
-
-       //Methods for closures
-       def count(Closure Input) {
-               buttons.count(Input)
-       }
-       def size() {
-               buttons.size()
-       }
-       def each(Closure Input) {
-               buttons.each(Input)
-       }
-       def sort(Closure Input) {
-               buttons.sort(Input)
-       }
-       def find(Closure Input) {
-               buttons.find(Input)
-       }
-       def collect(Closure Input) {
-               buttons.collect(Input)
-       }
-
-
-       //methods
-       def eventsSince(Date dateObj) {
-               return buttons[0].eventsSince()
-       }
+       Buttons(Closure sendEvent) {
+               buttons = smartThings
 
+               // Initialization
+               StringBuilder id = new StringBuilder("buttonID0")
+               StringBuilder label = new StringBuilder("button")
+               StringBuilder displayName = new StringBuilder("button0")
 
-       def getAt(int ix) {
-               buttons[ix]
+               buttons.add(new Button(sendEvent, id, label, displayName))
        }
 }
index 213d153..65f1ce0 100644 (file)
@@ -1,41 +1,35 @@
 //Create a class for carbon monoxide detector
 package CarbonMonoxideDetector
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-public class CarbonMonoxideDetector {
-       private String id
-       private String label
-       private String displayName
-       private String carbonMonoxide
-       private String currentCarbonMonoxideValue
-       private String carbonMonoxideLatestValue
+public class CarbonMonoxideDetector extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with string values
+       StringBuilder currentCarbonMonoxideValue = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
 
-       CarbonMonoxideDetector(String id, String label, String displayName, String carbonMonoxide, String carbonMonoxideLatestValue) {
+       CarbonMonoxideDetector(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentCarbonMonoxideValue) {
+               deviceValuesMap = deviceValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.carbonMonoxide = carbonMonoxide
-               this.currentCarbonMonoxideValue = carbonMonoxide
-               this.carbonMonoxideLatestValue = carbonMonoxideLatestValue
-       }
-
-       def setValue(String value) {
-               println("the carbon monoxide detector with id:$id is triggered to $value!")
-               this.carbonMonoxideLatestValue = value
-               this.carbonMonoxide = value
-               this.currentCarbonMonoxideValue = value
-       }
+               this.currentCarbonMonoxideValue = currentCarbonMonoxideValue
 
-       
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "carbonMonoxide") {
-                       return currentCarbonMonoxideValue
-               }
+               deviceValuesMap.put("carbonMonoxide", currentCarbonMonoxideValue)
        }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "carbonMonoxide") {
-                       return carbonMonoxideLatestValue
-               }
+       // Methods to return values
+       def getCurrentCarbonMonoxideValue() {
+               return currentCarbonMonoxideValue.toString()
        }
 }
index ba828d7..162ca8d 100644 (file)
@@ -1,79 +1,31 @@
 //Create a class for carbon monoxide detector
 package CarbonMonoxideDetector
-import Timer.SimulatedTimer
-
-public class CarbonMonoxideDetectors {
-       private int deviceNumbers
-       private List carbonMonoxideDetectors
-       def sendEvent
-
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "carbonMonoxideDetectorID0"
-       private String label = "carbonMonoxideDetector0"
-       private String displayName = "carbonMonoxideDetector0"
-       private String carbonMonoxide = "clear"
-       private String currentCarbonMonoxideValue = "clear"
-       private String carbonMonoxideLatestValue = "clear"
+import SmartThing.SmartThings
 
+public class CarbonMonoxideDetectors extends SmartThings {
+       List carbonMonoxideDetectors = new ArrayList()
                
-       CarbonMonoxideDetectors(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent              
-               this.deviceNumbers = deviceNumbers
-               this.carbonMonoxideDetectors = []
-               
-               if (init) {
-                       this.carbonMonoxide = "clear"
-                       this.currentCarbonMonoxideValue = "clear"
-                       this.carbonMonoxideLatestValue = "clear"
-               } else if (init == 1) {
-                       this.carbonMonoxide = "detected"
-                       this.currentCarbonMonoxideValue = "detected"
-                       this.carbonMonoxideLatestValue = "detected"
-               }
-               carbonMonoxideDetectors.add(new CarbonMonoxideDetector(id, label, displayName, this.currentCarbonMonoxideValue, this.carbonMonoxideLatestValue))
-       }
-
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"] != carbonMonoxideDetectors[0].currentCarbonMonoxideValue) {
-                       this.carbonMonoxideLatestValue = eventDataMap["value"]
-                       this.carbonMonoxide = eventDataMap["value"]
-                       this.currentCarbonMonoxideValue = eventDataMap["value"]
-                       carbonMonoxideDetectors[0].setValue(eventDataMap["value"])
-                       sendEvent(eventDataMap)
-               }
-       }
-
-       //Methods for closures
-       def count(Closure Input) {
-               carbonMonoxideDetectors.count(Input)
-       }
-       def size() {
-               carbonMonoxideDetectors.size()
-       }
-       def each(Closure Input) {
-               carbonMonoxideDetectors.each(Input)
-       }
-       def find(Closure Input) {
-               carbonMonoxideDetectors.find(Input)
-       }
-       def sort(Closure Input) {
-               carbonMonoxideDetectors.sort(Input)
-       }
-       def collect(Closure Input) {
-               carbonMonoxideDetectors.collect(Input)
-       }
+       CarbonMonoxideDetectors(Closure sendEvent, boolean init) {
+               carbonMonoxideDetectors = smartThings
 
+               // Initialization
+               StringBuilder id = new StringBuilder("carbonMonoxideID0")
+               StringBuilder label = new StringBuilder("carbonMonoxide")
+               StringBuilder displayName = new StringBuilder("carbonMonoxide0")
+               StringBuilder carbonMonoxide = new StringBuilder()
 
-       def currentValue(String deviceFeature) {
-               carbonMonoxideDetectors[0].currentValue(deviceFeature)//It is called if we have only one device
-       }
+               if (init)
+                       carbonMonoxide.append("clear")
+               else
+                       carbonMonoxide.append("detected")
 
-       def latestValue(String deviceFeature) {
-               carbonMonoxideDetectors[0].latestValue(deviceFeature)//It is called if we have only one device
+               carbonMonoxideDetectors.add(new CarbonMonoxideDetector(sendEvent, id, label, displayName, carbonMonoxide))
        }
 
-       def getAt(int ix) {
-               carbonMonoxideDetectors[ix]
+       // Methods to return values
+       def getCurrentCarbonMonoxideValue() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(carbonMonoxideDetectors[0].getCurrentCarbonMonoxideValue())
+               return tmpValues
        }
 }
index f24d274..63cdaf1 100644 (file)
@@ -1,69 +1,42 @@
 //Create a class for color control
 package ColorControl
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
+public class ColorControl extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with numberical values
+       MutableInteger currentHue = new MutableInteger()
+       MutableInteger currentSaturation = new MutableInteger()
+       // Features with string values
+       StringBuilder currentColor = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+       HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
 
-public class ColorControl {
-       def sendEvent
-       private String id
-       private String label
-       private String displayName
-       private String color
-       private String currentColor
-       private String currentSwitch
-       private int level
-       private int currentLevel
-       private int hue
-       private int currentHue
-       private int saturation
-       private int currentSaturation
-       private int colorTemperature
-       
-       ColorControl(Closure sendEvent, String id, String label, String displayName, String color, int hue, int saturation, int level, String currentSwitch, int colorTemperature) {
+       ColorControl(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentColor, MutableInteger currentHue, MutableInteger currentSaturation) {
+               deviceValuesMap = deviceValueSmartThing
+               deviceIntValuesMap = deviceIntValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.color = color
-               this.currentColor = color
-               this.hue = hue
-               this.currentHue = hue
-               this.saturation = saturation
-               this.currentSaturation = saturation
-               this.level = level
-               this.currentLevel = level
-               this.currentSwitch = currentSwitch
-               this.colorTemperature = colorTemperature
-               this.sendEvent = sendEvent
-       }
-       
-       //By model checker
-       def setValue(String value, String name) {
-               if ((name == "color") && (value != this.color)) {
-                       this.color = value
-                       this.currentColor = value
-                       println("the color of the light is changed to $value!")
-               } else if ((name == "hue") && (value != this.hue)) {
-                       this.hue = value.toInteger()
-                       this.currentHue = value.toInteger()
-                       println("The hue level of the light is changed to $value!")
-               } else if ((name == "saturation") && (value != this.saturation)) {
-                       this.saturation = value.toInteger()
-                       this.currentSaturation = value.toInteger()
-                       println("The saturation level of the light is changed to $value!")
-               } else if ((name == "level") && (value != this.level)) {
-                       this.currentLevel = value.toInteger()
-                       this.level = value.toInteger()
-                       println("The level of the light is changed to $value!")
-               } else if ((name == "currentSwitch") && (value != this.currentSwitch)) {
-                       this.currentSwitch = value
-                       println("The light is changed to $value!")
-               } else if ((name == "colorTemperature") && (value != this.colorTemperature)) {
-                       this.colorTemperature = value.toInteger()
-                       println("The color temperature level of the light is changed to $value!")
-               }
+               this.currentHue = currentHue
+               this.currentSaturation = currentSaturation
+               this.currentColor = currentColor
+
+               deviceValuesMap.put("color", currentColor)
+               deviceIntValuesMap.put("hue", currentHue)
+               deviceIntValuesMap.put("saturation", currentSaturation)
        }
 
-       //methods
        def setColor(LinkedHashMap metaData) {
                def hexColor = metaData.hex
                def newColor
@@ -93,142 +66,60 @@ public class ColorControl {
                                newColor = "Blue"
                                break;
                }
-               if (newColor != this.color) {
-                       this.currentColor = newColor
-                       this.color = newColor
-                       println("The color of the light is changed to $newColor!")
-                       sendEvent([name: "color", value: "$newColor", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               setColor(newColor)
        }
 
-       def setColor(String color) {
-               if (color != this.color) {
-                       this.currentColor = color
-                       this.color = color
-                       println("The color of the light is changed to $color!")
-                       sendEvent([name: "color", value: "$color", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+       // Methods to set values
+       def setColor(String newValue) {
+               action(currentColor, newValue, "color")
        }
 
-       def setHue(int hue) {
-               if (hue != this.hue) {
-                       this.hue = hue
-                       this.currentHue = hue
-                       println("The hue level of the light is changed to $hue!")
-                       sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+       def setHue(int newValue) {
+               action(currentHue, newValue, "hue")
        }
        
-       def setHue(double hue) {
-               if (hue != this.hue) {
-                       this.hue = hue
-                       this.currentHue = hue
-                       println("The hue level of the light is changed to $hue!")
-                       sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+       def setHue(double newValue) {
+               setHue((int) newValue)
        }
 
-       def setSaturation(int saturation) {
-               if (saturation != this.saturation) {
-                       this.currentSaturation = saturation
-                       this.saturation = saturation
-                       println("The saturation level of the light is changed to $saturation!")
-                       sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+       def setSaturation(int newValue) {
+               action(currentSaturation, newValue, "saturation")
        }
        
-       def setSaturation(double saturation) {
-               if (saturation != this.saturation) {
-                       this.currentSaturation = saturation
-                       this.saturation = saturation
-                       println("The saturation level of the light is changed to $saturation!")
-                       sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+       def setSaturation(double newValue) {
+               setSaturation((int) newValue)
        }
 
-
-       def setLevel(int level) {
-               if (level != this.level) {
-                       this.currentLevel = level
-                       this.level = level
-                       println("The level of the light is changed to $level!")
-                       sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
-       }
-
-       def setLevel(long level) {
-               if (level != this.level) {
-                       this.currentLevel = level
-                       this.level = level
-                       println("The level of the light is changed to $level!")
-                       sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
-       }
-
-       def setColorTemperature(int colorTemperature) {
-               if (colorTemperature != this.colorTemperature) {
-                       this.colorTemperature = colorTemperature
-                       println("The color temperature level of the light is changed to $colorTemperature!")
-                       sendEvent([name: "colorTemperature", value: "$colorTemperature", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+       def action(StringBuilder variable, String newValue, String feature) {
+               if (!variable.toString().equals(newValue)) {
+                       String tmpID = id.toString()
+                       variable.replace(0, variable.length(), newValue)
+                       println("$feature of the light with id:$id is changed to $newValue!")
+                       sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
-       def on() {
-               if (this.currentSwitch != "on") {
-                       this.currentSwitch = currentSwitch
-                       println("The light is changed to on!")
-                       sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+       def action(MutableInteger variable, int newValue, String feature) {
+               if (!variable.getValue().equals(newValue)) {
+                       String tmpID = id.toString()
+                       variable.setValue(newValue)
+                       println("$feature of the light with id:$id is changed to $newValue!")
+                       sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
-       def off() {
-               if (this.currentSwitch != "off") {
-                       this.currentSwitch = currentSwitch
-                       println("The light is changed to off!")
-                       sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+       // Methods to return values
+       def getCurrentHue() {
+               return currentHue.getValue()
        }
 
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "color") {
-                       return color
-               } else if (deviceFeature == "saturation") {
-                       return saturation
-               } else if (deviceFeature == "hue") {
-                       return hue
-               } else if (deviceFeature == "level") {
-                       return level
-               } else if (deviceFeature == "colorTemperature") {
-                       return colorTemperature
-               } else if (deviceFeature == "switch") {
-                       return currentSwitch
-               }
+       def getCurrentSaturation() {
+               return currentSaturation.getValue()
        }
-
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "color") {
-                       return color
-               } else if (deviceFeature == "saturation") {
-                       return saturation
-               } else if (deviceFeature == "hue") {
-                       return hue
-               } else if (deviceFeature == "level") {
-                       return level
-               } else if (deviceFeature == "colorTemperature") {
-                       return colorTemperature
-               } else if (deviceFeature == "switch") {
-                       return currentSwitch
-               }
+       
+       def getCurrentColor() {
+               return currentColor.toString()
        }
 }
index a2c93de..adac0b8 100644 (file)
 //Create a class for color control
 package ColorControl
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-public class ColorControls {
-       private int deviceNumbers
-       private List colorControls
-       def sendEvent
-
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "colorControlID0"
-       private String label = "colorControl0"
-       private String displayName = "colorControl0"
-       private String color = "Red"
-       private String currentColor = "Red"
-       private String currentSwitch = "on"
-       private int level = 50
-       private int currentLevel = 50
-       private int hue = 50
-       private int currentHue = 50
-       private int saturation = 50
-       private int currentSaturation = 50
-       private int colorTemperature = 15000
-       private boolean colorChanged = false
+public class ColorControls extends SmartThings {
+       List colorControls = new ArrayList()
        
-
-       ColorControls(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent
-               this.deviceNumbers = deviceNumbers
-               this.colorControls = []
+       ColorControls(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               colorControls = smartThings
+
+               // Initialization
+               StringBuilder id = new StringBuilder("colorControlID0")
+               StringBuilder label = new StringBuilder("colorControl")
+               StringBuilder displayName = new StringBuilder("colorControl0")
+               StringBuilder color = new StringBuilder()
+               MutableInteger hue = new MutableInteger()
+               MutableInteger saturation = new MutableInteger()
 
                if (init) {
-                       this.level = 20
-                       this.currentLevel = 20
-                       this.hue = 30
-                       this.currentHue = 30
-                       this.saturation = 40
-                       this.currentSaturation = 40
-                       this.colorTemperature = 10000
-                       this.color = "Red"
-                       this.currentSwitch = "on"
-               } else {
-                       this.level = 50
-                       this.currentLevel = 50
-                       this.hue = 50
-                       this.currentHue = 50
-                       this.saturation = 50
-                       this.currentSaturation = 50
-                       this.colorTemperature = 15000
-                       this.color = "Blue"
-                       this.currentSwitch = "off"
+                       color.append("Red")
+                       hue.setValue(30)
+                       saturation.setValue(40)
+               } else {                
+                       color.append("Blue")
+                       hue.setValue(50)
+                       saturation.setValue(50)
                }
-               colorControls.add(new ColorControl(sendEvent, id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature))
-       }
 
-       //Methods for closures
-       def count(Closure Input) {
-               colorControls.count(Input)
-       }
-       def size() {
-               colorControls.size()
-       }
-       def each(Closure Input) {
-               colorControls.each(Input)
-       }
-       def find(Closure Input) {
-               colorControls.find(Input)
-       }
-       def sort(Closure Input) {
-               colorControls.sort(Input)
-       }
-       def collect(Closure Input) {
-               colorControls.collect(Input)
+               colorControls.add(new ColorControl(sendEvent, id, label, displayName, color, hue,
+                                                  saturation))
        }
 
-       //By model checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["name"] == "color") {
-                       if (eventDataMap["value"] != colorControls[0].color) {
-                               this.currentColor = eventDataMap["value"]
-                               this.color = eventDataMap["value"]
-                               colorControls[0].setValue(eventDataMap["value"], "color")
-                               sendEvent(eventDataMap)
-                       }       
-               } else if (eventDataMap["name"] == "hue") {
-                       if (eventDataMap["value"].toInteger() != colorControls[0].hue) {
-                               this.hue = eventDataMap["value"].toInteger()
-                               this.currentHue = eventDataMap["value"].toInteger()
-                               colorControls[0].setValue(eventDataMap["value"], "hue")
-                               sendEvent(eventDataMap)
-                       }
-               } else if (eventDataMap["name"] == "saturation") {
-                       if (eventDataMap["value"].toInteger() != colorControls[0].saturation) {
-                               this.saturation = eventDataMap["value"].toInteger()
-                               this.currentSaturation = eventDataMap["value"].toInteger()
-                               colorControls[0].setValue(eventDataMap["value"], "saturation")
-                               sendEvent(eventDataMap)
-                       }
-               } else if (eventDataMap["name"] == "switch") {
-                       if (eventDataMap["value"] != colorControls[0].currentSwitch) {
-                               this.currentSwitch = eventDataMap["value"]
-                               colorControls[0].setValue(eventDataMap["value"], "switch")
-                               sendEvent(eventDataMap)
-                       }
-               } else if (eventDataMap["name"] == "colorTemperature") {
-                       if (eventDataMap["value"].toInteger() != colorControls[0].colorTemperature) {
-                               this.colorTemperature = eventDataMap["value"].toInteger()
-                               colorControls[0].setValue(eventDataMap["value"], "colorTemperature")
-                               sendEvent(eventDataMap)
-                       }
-               } else if (eventDataMap["name"] == "level") {
-                       if (eventDataMap["value"].toInteger() != colorControls[0].level) {
-                               this.currentLevel = eventDataMap["value"].toInteger() 
-                               this.level = eventDataMap["value"].toInteger()
-                               colorControls[0].setValue(eventDataMap["value"], "level")
-                               sendEvent(eventDataMap)
-                       }
-               }
-       }
-
-
-       //methods
+       // Methods to set values
        def setColor(LinkedHashMap metaData) {
-               def hexColor = metaData.hex
-               def newColor
-               switch (hexColor) {
-                       case "#0000FF":
-                               newColor = "Blue"
-                               break;
-                       case "#00FF00":
-                               newColor = "Green"
-                               break;
-                       case "#FFFF00":
-                               newColor = "Yellow"
-                               break;
-                       case "#FF6000":
-                               newColor = "Orange"
-                               break;
-                       case "#BF7FBF":
-                               newColor = "Purple"
-                               break;
-                       case "#FF5F5F":
-                               newColor = "Pink"
-                               break;
-                       case "#FF0000":
-                               newColor = "Red"
-                               break;
-                       default:
-                               newColor = "Blue"
-                               break;
-               }
-               if (newColor != this.color) {
-                       this.currentColor = newColor
-                       this.color = newColor
-                       colorControls[0].setColor(newColor)
-                       if (this.colorChanged) {
-                               this.colorChanged = false
-                       } else {
-                               this.colorChanged = true
-                       }
-               }
-               def newLevel = metaData.level
-               def newHue = metaData.hue
-               def newSaturation = metaData.saturation
-               if (newLevel != null) {
-                       setLevel(newLevel)
-               }
-               if (newHue != null) {
-                       setHue(newHue)
-               }
-               if (newSaturation != null) {
-                       setSaturation(newSaturation)
-               }
+               colorControls[0].setColor(metaData)
        }
 
        def setColor(String color) {
-               if (color != this.color) {
-                       this.currentColor = color
-                       this.color = color
-                       colorControls[0].setColor(color)                        
-               }
+               colorControls[0].setColor(color)
        }
 
        def setHue(int hue) {
-               if (hue != this.hue) {
-                       this.hue = hue
-                       this.currentHue = hue
-                       colorControls[0].setHue(hue)
-               }
+               colorControls[0].setHue(hue)
        }
        
        def setHue(double hue) {
-               if (hue != this.hue) {
-                       this.hue = hue
-                       this.currentHue = hue
-                       colorControls[0].setHue((int) hue)
-               }
+               colorControls[0].setHue((int) hue)
        }
 
        def setSaturation(int saturation) {
-               if (saturation != this.saturation) {
-                       this.currentSaturation = saturation
-                       this.saturation = saturation
-                       colorControls[0].setSaturation(saturation)                      
-               }       
+               colorControls[0].setSaturation(saturation)      
        }
        
        def setSaturation(double saturation) {
-               if (saturation != this.saturation) {
-                       this.currentSaturation = saturation
-                       this.saturation = saturation
-                       colorControls[0].setSaturation(saturation)                      
-               }       
-       }
-
-       def setLevel(int level) {
-               if (level != this.level) {
-                       this.currentLevel = level
-                       this.level = level
-                       colorControls[0].setLevel(level)
-               }
-       }
-
-       def setLevel(long level) {
-               if (level != this.level) {
-                       this.currentLevel = level
-                       this.level = level
-                       colorControls[0].setLevel(level)
-               }
-       }
-
-       def setColorTemperature(int colorTemperature) {
-               if (colorTemperature != this.colorTemperature) {
-                       this.colorTemperature = colorTemperature
-                       colorControls[0].setColorTemperature(colorTemperature)                  
-               }
-       }
-
-       def setColorTemperature(long colorTemperature) {
-               if (colorTemperature != this.colorTemperature) {
-                       this.colorTemperature = colorTemperature
-                       colorControls[0].setColorTemperature(colorTemperature)                  
-               }
+               colorControls[0].setSaturation((int) saturation)
        }
 
        def on() {
-               if (this.currentSwitch != "on") {
-                       this.currentSwitch = "on"
-                       colorControls[0].on()                   
-               }
+               colorControls[0].on()
        }
 
        def off() {
-               if (this.currentSwitch != "off") {
-                       this.currentSwitch = "off"
-                       colorControls[0].off()
-               }
+               colorControls[0].off()
        }
 
-       def currentValue(String deviceFeature) {
-               colorControls[0].currentValue(deviceFeature)
+       // Methods to return values
+       def getCurrentHue() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(colorControls[0].getCurrentHue())
+               return tmpValues
        }
 
-       def latestValue(String deviceFeature) {
-               colorControls[0].latestValue(deviceFeature)
-       }       
-
-       def getAt(int ix) {
-               colorControls[ix]
+       def getCurrentSaturation() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(colorControls[0].getCurrentSaturation())
+               return tmpValues
+       }
+       
+       def getCurrentColor() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(colorControls[0].getCurrentColor())
+               return tmpValues
        }
 }
index 250ac12..087ee8a 100644 (file)
 //Create a class for color temperature
 package ColorTemperature
-import Timer.SimulatedTimer
-
-
-public class ColorTemperature {
-       def sendEvent
-       private String id
-       private String label
-       private String displayName
-       private String currentSwitch
-       private int level
-       private int currentLevel
-       private int colorTemperature
-       
-       ColorTemperature(Closure sendEvent, String id, String label, String displayName, int level, String currentSwitch, int colorTemperature) {
+import SmartThing.SmartThing
+
+public class ColorTemperature extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with numberical values
+       MutableInteger currentColorTemperature = new MutableInteger()
+       // Maps from features to values
+       HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+
+       ColorTemperature(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger colorTemperature) {
+               deviceIntValuesMap = deviceIntValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.level = level
-               this.currentLevel = level
-               this.currentSwitch = currentSwitch
-               this.colorTemperature = colorTemperature
-               this.sendEvent = sendEvent
-       }
-       
-       //By model checker
-       def setValue(String value, String name) {
-               if ((name == "level") && (value != this.level)) {
-                       this.currentLevel = value.toInteger()
-                       this.level = value.toInteger()
-                       println("The level of the light is changed to $value!")
-               } else if ((name == "currentSwitch") && (value != this.currentSwitch)) {
-                       this.currentSwitch = value
-                       println("The light is changed to $value!")
-               } else if ((name == "colorTemperature") && (value != this.colorTemperature)) {
-                       this.colorTemperature = value.toInteger()
-                       println("The color temperature level of the light is changed to $value!")
-               }
-       }
-
-       //methods
-       def setLevel(int level) {
-               if (level != this.level) {
-                       this.currentLevel = level
-                       this.level = level
-                       println("The level of the light is changed to $level!")
-                       sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
-       }
-       
-       def setLevel(long level) {
-               if (level != this.level) {
-                       this.currentLevel = level
-                       this.level = level
-                       println("The level of the light is changed to $level!")
-                       sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
-       }
+               this.currentColorTemperature = currentColorTemperature
 
-       def setColorTemperature(int colorTemperature) {
-               if (colorTemperature != this.colorTemperature) {
-                       this.colorTemperature = colorTemperature
-                       println("The color temperature level of the light is changed to $colorTemperature!")
-                       sendEvent([name: "colorTemperature", value: "$colorTemperature", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               deviceIntValuesMap.put("colorTemperature", currentColorTemperature)
        }
 
-       def on(String currentSwitch) {
-               if (currentSwitch != this.currentSwitch) {
-                       this.currentSwitch = currentSwitch
-                       println("The light is changed to $currentSwitch!")
-                       sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
+       // Methods to set values
+       def setColorTemperature(int newValue) {
+               if (!currentColorTemperature.getValue().equals(newValue)) {
+                       String tmpID = id.toString()
+                       currentColorTemperature.setValue(newValue)
+                       println("The color temperature of the light with id $tmpID is changed to $newValue!")
+                       sendEvent([name: "colorTemperature", value: "$newValue", deviceId: tmpID, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
-       def off(String currentSwitch) {
-               if (currentSwitch != this.currentSwitch) {
-                       this.currentSwitch = currentSwitch
-                       println("The light is changed to $currentSwitch!")
-                       sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
-       }
-
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "level") {
-                       return level
-               } else if (deviceFeature == "colorTemperature") {
-                       return colorTemperature
-               } else if (deviceFeature == "switch") {
-                       return currentSwitch
-               }
-       }
-
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "level") {
-                       return level
-               } else if (deviceFeature == "colorTemperature") {
-                       return colorTemperature
-               } else if (deviceFeature == "switch") {
-                       return currentSwitch
-               }
+       // Methods to return values
+       def getCurrentColorTemperature() {
+               return currentColorTemperature.getValue()
        }
 }
index d382680..c53ec35 100644 (file)
 //Create a class for color temperature
 package ColorTemperature
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-public class ColorTemperatures {
-       private int deviceNumbers
-       private List colorTemperatues
-       def sendEvent
+public class ColorTemperatures extends SmartThings {
+       List colorTemperatues = new ArrayList()
 
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "colorTemperatureID0"
-       private String label = "colorTemperature0"
-       private String displayName = "colorTemperature0"
-       private String currentSwitch = "on"
-       private int level = 50
-       private int currentLevel = 50
-       private int colorTemperature = 15000
-       
-
-       ColorTemperatures(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent
-               this.deviceNumbers = deviceNumbers
-               this.colorTemperatues = []
-
-               if (init) {
-                       this.level = 30
-                       this.currentLevel = 40
-                       this.colorTemperature = 10000
-               } else {
-                       this.level = 50
-                       this.currentLevel = 50
-                       this.colorTemperature = 15000
-               }
-
-               colorTemperatues.add(new ColorTemperature(sendEvent, id, label, displayName, this.level, this.currentSwitch, this.colorTemperature))
-       }
-
-       //Methods for closures
-       def count(Closure Input) {
-               colorTemperatues.count(Input)
-       }
-       def size() {
-               colorTemperatues.size()
-       }
-       def each(Closure Input) {
-               colorTemperatues.each(Input)
-       }
-       def find(Closure Input) {
-               colorTemperatues.find(Input)
-       }
-       def sort(Closure Input) {
-               colorTemperatues.sort(Input)
-       }
-       def collect(Closure Input) {
-               colorTemperatues.collect(Input)
-       }
+       ColorTemperatures(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               colorTemperatues = smartThings
 
-       //By model checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["name"] == "switch") {
-                       if (eventDataMap["value"] != colorTemperatues[0].currentSwitch) {
-                               this.currentSwitch = eventDataMap["value"]
-                               colorTemperatues[0].setValue(eventDataMap["value"], "switch")
-                               sendEvent(eventDataMap)
-                       }
-               } else if (eventDataMap["name"] == "colorTemperature") {
-                       if (eventDataMap["value"].toInteger() != colorTemperatues[0].colorTemperature) {
-                               this.colorTemperature = eventDataMap["value"].toInteger()
-                               colorTemperatues[0].setValue(eventDataMap["value"], "colorTemperature")
-                               sendEvent(eventDataMap)
-                       }
-               } else if (eventDataMap["name"] == "level") {
-                       if (eventDataMap["value"].toInteger() != colorTemperatues[0].level) {
-                               this.currentLevel = eventDataMap["value"].toInteger() 
-                               this.level = eventDataMap["value"].toInteger()
-                               colorTemperatues[0].setValue(eventDataMap["value"], "level")
-                               sendEvent(eventDataMap)
-                       }
-               }
-       }
-
-
-       //methods
-       def setLevel(long level) {
-               if (level != this.level) {
-                       this.currentLevel = level
-                       this.level = level
-                       colorTemperatues[0].setLevel(level)
-               }
-       }
+               // Initialization
+               StringBuilder id = new StringBuilder("colorTemperatureID0")
+               StringBuilder label = new StringBuilder("colorTemperature")
+               StringBuilder displayName = new StringBuilder("colorTemperature0")
+               MutableInteger colorTemperatue = new MutableInteger()
 
-       def setLevel(int level) {
-               if (level != this.level) {
-                       this.currentLevel = level
-                       this.level = level
-                       colorTemperatues[0].setLevel(level)
-               }
-       }
+               if (init)
+                       colorTemperature = 10000
+               else
+                       colorTemperatues = 15000
 
-       def setColorTemperature(String colorTemperature) {
-               if (colorTemperature != this.colorTemperature) {
-                       this.colorTemperature = colorTemperature
-                       colorTemperatues[0].setColorTemperature(colorTemperature)                       
-               }
+               colorTemperatues.add(new ColorTemperature(sendEvent, id, label, displayName, colorTemperature))
        }
        
-       def setColorTemperature(int colorTemperature) {
-               if (colorTemperature != this.colorTemperature) {
-                       this.colorTemperature = colorTemperature
-                       colorTemperatues[0].setColorTemperature(colorTemperature)                       
-               }
-       }
-
-       def on(String currentSwitch) {
-               if (currentSwitch != this.currentSwitch) {
-                       this.currentSwitch = currentSwitch
-                       colorTemperatues[0].on(currentSwitch)                   
-               }
-       }
-
-       def off(String currentSwitch) {
-               if (currentSwitch != this.currentSwitch) {
-                       this.currentSwitch = currentSwitch
-                       colorTemperatues[0].off(currentSwitch)                  
-               }
+       // Methods to set values
+       def setColorTemperature(int newValue) {
+               colorTemperatues[0].setColorTemperature(newValue)
        }
 
-       def currentValue(String deviceFeature) {
-               colorTemperatues[0].currentValue(deviceFeature)
-       }
-
-       def latestValue(String deviceFeature) {
-               colorTemperatues[0].latestValue(deviceFeature)
-       }       
-
-       def getAt(int ix) {
-               colorTemperatues[ix]
+       // Methods to return values
+       def getCurrentColorTemperature() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(colorTemperatues[0].getCurrentColorTemperature())
+               return tmpValues
        }
 }
index 281e793..91fdfd1 100644 (file)
 //Create a class for contact sensor
 package ContactSensor
-import Timer.SimulatedTimer
-
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
-public class ContactSensor {
-       private String id
-       private String label
-       private String displayName
-       private String contactState
-       private String currentContact   
-       private String latestValue
-       private String alarmState
-       private List events = []
-       private List timeOfEvents = []
-       
-
-       ContactSensor(String id, String label, String displayName, String contactState, String currentContact, String alarmState, String latestValue) {
+import SmartThing.SmartThing
+
+public class ContactSensor extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with string values
+       StringBuilder currentContact = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+       // Possible values for eventsSince method
+       List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
+
+       ContactSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentContact) {
+               deviceValuesMap = deviceValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+               possibleValuesSmartThings = possibleValues
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.contactState = contactState
                this.currentContact = currentContact
-               this.latestValue = latestValue
-               this.alarmState = alarmState
-       }
-
-       def eventsSince() {
-               def evtOpen = [[name: "contact", value: "open", deviceId: "contactSensorID0", descriptionText: "",
-                               displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def evtClosed = [[name: "contact", value: "closed", deviceId: "contactSensorID0", descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def init = Verify.getInt(0,4)
-               def evtToSend = []
-               if (init == 0) {//return empty set
-                       return evtToSend
-               } else if (init == 1) {//send one open event
-                       evtOpen.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 2) {//send two open events
-                       evtOpen.each{
-                               evtToSend.add(it)
-                       }
-                       evtOpen.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 3) {//send one closed event
-                       evtClosed.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 4) {//send two closed events
-                       evtClosed.each{
-                               evtToSend.add(it)
-                       }
-                       evtClosed.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               }
-       }
-
-       def setValue(String value) {
-               println("the contact sensor with id:$id is triggered to $value!")
-               this.contactState = value
-               this.currentContact = value
-               this.latestValue = value
-       }
-
-       
-       def on() {
-               println("the contact sensor with id:$id is armed!")
-               this.alarmState = "armed"
-       }
-
-       def off() {
-               println("the contact sensor with id:$id is not armed!")
-               this.alarmState = "not armed"
-       }
-       
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "contact") {
-                       return contactState
-               }
-       }
+               possibleValues.add("closed")
+               possibleValues.add("open")
 
-       def currentState(String deviceFeature) {
-               if (deviceFeature == "contact") {
-                       return contactState
-               }
+               deviceValuesMap.put("contact", currentContact)
        }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "contact") {
-                       return latestValue
-               }
+       // Methods to return values
+       def getCurrentContact() {
+               return currentContact.toString()
        }
 }
index c4136e3..9889793 100644 (file)
 //Create a class for contact sensor
 package ContactSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-public class ContactSensors {
-       private int deviceNumbers
-       private List contacts
-       def sendEvent
+public class ContactSensors extends SmartThings {
+       List contacts = new ArrayList()
 
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "contactSensorID0"
-       private String label = "contactSensor0"
-       private String displayName = "contactSensor0"
-       private String contactState = "closed"
-       private String currentContact = "closed"
-       private String latestValue = "closed"
-       private String alarmState = "armed"
+       ContactSensors(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               contacts = smartThings
 
+               // Initialization
+               StringBuilder id = new StringBuilder("contactID0")
+               StringBuilder label = new StringBuilder("contact")
+               StringBuilder displayName = new StringBuilder("contact0")
+               StringBuilder currentContact = new StringBuilder()
                
-       ContactSensors(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent              
-               this.deviceNumbers = deviceNumbers
-               this.contacts = []
-               
-               if (init) {
-                       this.contactState = "closed"
-                       this.currentContact = "closed"
-                       this.latestValue = "closed"
-                       this.alarmState = "armed"
-               } else {
-                       this.contactState = "open"
-                       this.currentContact = "open"
-                       this.latestValue = "open"
-                       this.alarmState = "not armed"
-               }
-
-               contacts.add(new ContactSensor(id, label, displayName, this.contactState, this.currentContact, this.alarmState, this.latestValue))
-       }
-
-       //Methods for closures
-       def count(Closure Input) {
-               contacts.count(Input)
-       }
-       def size() {
-               contacts.size()
-       }
-       def each(Closure Input) {
-               contacts.each(Input)
-       }
-       def find(Closure Input) {
-               contacts.find(Input)
-       }
-       def sort(Closure Input) {
-               contacts.sort(Input)
-       }
-       def collect(Closure Input) {
-               contacts.collect(Input)
-       }
-
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"] != contacts[0].contactState) {
-                       this.latestValue = eventDataMap["value"]
-                       this.contactState = eventDataMap["value"]
-                       this.currentContact = eventDataMap["value"]
-                       contacts[0].setValue(eventDataMap["value"])
-                       sendEvent(eventDataMap)
-               }
-       }
-
-       def eventsSince(Date dateObj) {
-               return contacts[0].eventsSince()
-       }
-
-       def on() {
-               this.alarmState = "armed"
-               contacts[0].on()
-       }
-
-       def off() {
-               this.alarmState = "not armed"
-               contacts[0].off()
-       }
-
-       def currentValue(String deviceFeature) {
-               contacts[0].currentValue(deviceFeature)//It is called if we have only one device
-       }
-
-       def currentState(String deviceFeature) {
-               contacts[0].currentState(deviceFeature)//It is called if we have only one device
-       }
+               if (init)
+                       currentContact.append("closed")
+               else
+                       currentContact.append("open")
 
-       def latestValue(String deviceFeature) {
-               contacts[0].latestValue(deviceFeature)//It is called if we have only one device
+               contacts.add(new ContactSensor(sendEvent, id, label, displayName, currentContact))
        }
 
-       def getAt(int ix) {
-               contacts[ix]
+       // Methods to return values
+       def getCurrentContact() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(contacts[0].getCurrentContact())
+               return tmpValues
        }
 }
index c825879..d002727 100644 (file)
@@ -1,88 +1,62 @@
 //Create a class for door control device
 package DoorControl
-import Timer.SimulatedTimer
-
-public class DoorControl {
-       private String id
-       private String label
-       private String displayName
-       private String doorState
-       private String doorLatestValue
-       def sendEvent   
-       def timers
-       
-
-       DoorControl(Closure sendEvent, String id, String label, String displayName, String doorState, String doorLatestValue) {
-               this.sendEvent = sendEvent
-               this.timers = new SimulatedTimer()
+import SmartThing.SmartThing
+
+public class DoorControl extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with string values
+       StringBuilder currentDoorState = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+
+       DoorControl(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentDoorState) {
+               deviceValuesMap = deviceValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.doorState = doorState
-               this.doorLatestValue = doorLatestValue
+               this.currentDoorState = currentDoorState
+
+               deviceValuesMap.put("status", currentDoorState)
        }
 
-       //By Apps
+       // Methods to set values
        def open() {
-               if (doorState != "open") {
-                       println("the door with id:$id is open!")
-                       this.doorLatestValue = "open"
-                       this.doorState = "open"
-                       sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
-                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               action(currentDoorState, "open", "status")
        }
 
        def open(LinkedHashMap metaData) {
-               if (doorState != "open") {
-                       def task = timers.runAfter(metaData["delay"]) {
-                               println("the door with id:$id is open!")
-                               this.doorLatestValue = "open"
-                               this.doorState = "open"
-                               sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
-                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-                       }
-               }
+               open()
        }
 
        def close() {
-               if (doorState != "closed") {
-                       println("the door with id:$id is closed!")
-                       this.doorLatestValue = "closed"
-                       this.doorState = "closed"
-                       sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
-                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               action(currentDoorState, "closed", "status")
        }
 
        def close(LinkedHashMap metaData) {
-               if (doorState != "closed") {
-                       def task = timers.runAfter(metaData["delay"]) {
-                               println("the door with id:$id is closed!")
-                               this.doorLatestValue = "closed"
-                               this.doorState = "closed"
-                               sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
-                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-                       }
-               }
+               close()
        }
 
-       //By Model Checker
-       def setValue(String value) {
-               println("the door with id:$id is $value!")
-               this.doorLatestValue = value
-               this.doorState = value
-       }
-       
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "status") {
-                       return doorState
+       def action(StringBuilder variable, String newValue, String feature) {
+               if (!variable.toString().equals(newValue)) {
+                       String tmpID = id.toString()
+                       variable.replace(0, variable.length(), newValue)
+                       println("$feature of the door with id:$tmpID is changed to $newValue!")
+                       sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "status") {
-                       return doorLatestValue
-               }
+       // Methods to return values
+       def getCurrentDoorState() {
+               return currentDoorState.toString()
        }
 }
index 5327be0..069a161 100644 (file)
 //Create a class for door control device
 package DoorControl
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-public class DoorControls {
-       int deviceNumbers       
-       List doorControls
-       def timers
-       def sendEvent
+public class DoorControls extends SmartThings {
+       List doorControls = new ArrayList()
 
-       //If we have only one device
-       private String id = "DoorControlID0"
-       private String label = "DoorControl0"
-       private String displayName = "DoorControl0"
-       private String doorState = "closed"
-       private String doorLatestValue = "closed"
+       DoorControls(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               doorControls = smartThings
 
-       DoorControls(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent
-               this.timers = new SimulatedTimer()
-               this.deviceNumbers = deviceNumbers
-               this.doorControls = []
-               
-               if (init) {
-                       this.doorState = "closed"
-                       this.doorLatestValue = "closed"
-               } else {
-                       this.doorState = "open"
-                       this.doorLatestValue = "open"
-               }
-               doorControls.add(new DoorControl(sendEvent, id, label, displayName, this.doorState, this.doorLatestValue))
-       }
+               // Initialization
+               StringBuilder id = new StringBuilder("doorControlID0")
+               StringBuilder label = new StringBuilder("doorControl")
+               StringBuilder displayName = new StringBuilder("doorControl0")
+               StringBuilder doorState = new StringBuilder()
 
-       //Methods for closures
-       def count(Closure Input) {
-               doorControls.count(Input)
-       }
-       def size() {
-               doorControls.size()
-       }
-       def each(Closure Input) {
-               doorControls.each(Input)
-       }
-       def find(Closure Input) {
-               doorControls.find(Input)
-       }
-       def sort(Closure Input) {
-               doorControls.sort(Input)
-       }
-       def collect(Closure Input) {
-               doorControls.collect(Input)
+               if (init)
+                       doorState.append("open")
+               else
+                       doorState.append("closed")
+
+               doorControls.add(new DoorControl(sendEvent, id, label, displayName, doorState))
        }
 
-       //By Apps
+       // Methods to set values
        def open() {
-               if (doorState != "open")
-                       doorControls[0].open()
+               doorControls[0].open()
        }
 
        def open(LinkedHashMap metaData) {
-               if (doorState != "open") {
-                       def task = timers.runAfter(metaData["delay"]) {
-                               doorControls[0].open()
-                       }
-               }
+               open()
        }
 
        def close() {
-               if (doorState != "closed")
-                       doorControls[0].close()
+               doorControls[0].close()
        }
 
        def close(LinkedHashMap metaData) {
-               if (doorState != "closed") {
-                       def task = timers.runAfter(metaData["delay"]) {
-                               doorControls[0].close()
-                       }
-               }
-       }
-
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"] != doorControls[0].doorState) {
-                       this.doorState = eventDataMap["value"]
-                       this.doorLatestValue = eventDataMap["value"]
-                       doorControls[0].setValue(eventDataMap["value"])
-                       sendEvent(eventDataMap)
-               }
-       }
-
-
-       def currentValue(String deviceFeature) {
-               doorControls[0].currentValue(deviceFeature)
-       }
-
-       def latestValue(String deviceFeature) {
-               doorControls[0].latestValue(deviceFeature)
+               close()
        }
 
-       def getAt(int ix) {
-               doorControls[ix]
+       // Methods to return values
+       def getCurrentDoorState() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(doorControls[0].getCurrentDoorState())
+               return tmpValues
        }
 }
index 83f2283..cfaa6d0 100644 (file)
@@ -1,53 +1,35 @@
 //Create a class for energy meter
 package EnergyMeter
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-public class EnergyMeter {
-       private String id
-       private String label
-       private String displayName
-       private int energy
-       private int currentEnergy
-       private String status
+public class EnergyMeter extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with numberical values
+       MutableInteger currentEnergy = new MutableInteger()
+       // Maps from features to values
+       HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
 
-       EnergyMeter(String id, String label, String displayName, int energy, String status) {
+       EnergyMeter(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentEnergy) {
+               deviceIntValuesMap = deviceIntValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.energy = energy
-               this.status = status
-       }
-
-       //By Model Checker
-       def setValue(String value) {
-               println("the enery is changed to $value!")
-               this.energy = value.toInteger()
-               this.currentEnergy = value.toInteger()
-       }
-
-       def reset() {
-               if (status != "on") {
-                       status = "on"
-                       println("the energy meter is on!")
-               }
-       }
-
-       def off() {
-               if (status != "off") {
-                       status = "off"
-                       println("the energy meter is off!")
-               }
-       }
+               this.currentEnergy = currentEnergy
 
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "energy") {
-                       return energy
-               }
+               deviceIntValuesMap.put("energy", currentEnergy)
        }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "energy") {
-                       return energy
-               }
+       // Methods to return values
+       def getCurrentEnergy() {
+               return currentEnergy.getValue()
        }
 }
index 5d8b74a..ba9188a 100644 (file)
@@ -1,89 +1,32 @@
 //Create a class for energy meter
 package EnergyMeter
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-public class EnergyMeters {
-       private int deviceNumbers
-       private List energyMeters
-       def sendEvent
+public class EnergyMeters extends SmartThings {
+       List energyMeters = new ArrayList()
 
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "energyMeterID0"
-       private String label = "energyMeter0"
-       private String displayName = "energyMeter0"
-       private int energy = 50
-       private int currentEnergy = 50
-       private String status = "off"
+       EnergyMeters(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               energyMeters = smartThings
 
-               
-       EnergyMeters(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent              
-               this.deviceNumbers = deviceNumbers
-               this.energyMeters = []
+               // Initialization
+               StringBuilder id = new StringBuilder("energyID0")
+               StringBuilder label = new StringBuilder("energy")
+               StringBuilder displayName = new StringBuilder("energy0")
+               MutableInteger energy = new MutableInteger()
 
-               if (init) {
-                       this.energy = 50
-                       this.currentEnergy = 50
-               } else {
-                       this.energy = 60
-                       this.currentEnergy = 60
-               }
-               energyMeters.add(new EnergyMeter(id, label, displayName, this.energy, this.status))
-       }
-
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"].toInteger() != energyMeters[0].energy) {
-                       this.energy = eventDataMap["value"].toInteger()
-                       this.currentEnergy = eventDataMap["value"].toInteger()
-                       energyMeters[0].setValue(eventDataMap["value"]) 
-                       sendEvent(eventDataMap)
-               }
-       }
-
-       //Methods for closures
-       def count(Closure Input) {
-               energyMeters.count(Input)
-       }
-       def size() {
-               energyMeters.size()
-       }
-       def each(Closure Input) {
-               energyMeters.each(Input)
-       }
-       def find(Closure Input) {
-               energyMeters.find(Input)
-       }
-       def sort(Closure Input) {
-               energyMeters.sort(Input)
-       }
-       def collect(Closure Input) {
-               energyMeters.collect(Input)
-       }
-
-       def reset() {
-               if (status != "on") {
-                       status = "on"
-                       energyMeters[0].reset()
-               }
-       }
-       
-       def off() {
-               if (status != "off") {
-                       status = "off"
-                       energyMeters[0].off()
-               }
-       }
-
-       def currentValue(String deviceFeature) {
-               energyMeters[0].currentValue(deviceFeature)//It is called if we have only one device
-       }
+               if (init)
+                       energy.setValue(50)
+               else
+                       energy.setValue(60)
 
-       def latestValue(String deviceFeature) {
-               energyMeters[0].latestValue(deviceFeature)//It is called if we have only one device
+               energyMeters.add(new EnergyMeter(sendEvent, id, label, displayName, energy))
        }
 
-       def getAt(int ix) {
-               energyMeters[ix]
+       // Methods to return values
+       def getCurrentEnergy() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(energyMeters[0].getCurrentEnergy())
+               return tmpValues
        }
 }
index d7abdf4..aac847b 100644 (file)
@@ -4,7 +4,7 @@ import groovy.json.JsonSlurper
 
 public class Event {
        private String deviceId
-       private String value
+       private Object value
        private String linkText
        private String displayName
        private boolean displayed
@@ -19,7 +19,7 @@ public class Event {
        private boolean physical
        private def date
        
-       Event(String value, String name, String deviceId, String descriptionText, boolean displayed, String linkText, String displayName, boolean isStateChange, String unit, String data) {
+       Event(Object value, String name, String deviceId, String descriptionText, boolean displayed, String linkText, String displayName, boolean isStateChange, String unit, String data) {
                this.deviceId = deviceId
                this.linkText = linkText
                this.value = value
@@ -32,11 +32,8 @@ public class Event {
                this.jsonData = new groovy.json.JsonSlurper().parseText(data)
                this.displayed = displayed
                if (["battery", "hue", "saturation", "energy", "level", "temperature", "heatingSetpoint", "coolingSetpoint", "thermostatSetpoint", "illuminance"].contains(name)) {
-                       int dot = value.indexOf('.')
-                       if (dot != -1)
-                       value = value.substring(0, dot)
-                       this.integerValue = value.toInteger()
-                       this.doubleValue = Double.parseDouble(value);           
+                       this.integerValue = value
+                       this.doubleValue = value
                }
                this.physical = true
                this.date = new Date()
index cf19c45..15edc66 100644 (file)
@@ -436,22 +436,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def lockObject = new Locks(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def lockObject = new Locks(sendEvent, init)\n")
 
                        if (lockObjects == 0) {
                                lockObject0 = metaData['name']
-                               this[lockObject0] = new Locks({}, 1, true)
+                               this[lockObject0] = new Locks({}, true)
                        } else if (lockObjects == 1) {
                                lockObject1 = metaData['name']
-                               this[lockObject1] = new Locks({}, 1, true)
+                               this[lockObject1] = new Locks({}, true)
                        } else if (lockObjects == 2) {
                                lockObject2 = metaData['name']
-                               this[lockObject2] = new Locks({}, 1, true)
+                               this[lockObject2] = new Locks({}, true)
                        }
 
                        lockObjects=lockObjects+1
 
-                       settings.put(metaData['name'], new Locks({}, 1, true)) 
+                       settings.put(metaData['name'], new Locks({}, true)) 
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class lock!\n")
@@ -471,22 +471,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def alarmObject = new Alarms(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def alarmObject = new Alarms(sendEvent, init)\n")
 
                        if (alarmObjects == 0) {
                                alarmObject0 = metaData['name']
-                               this[alarmObject0] = new Alarms({}, 1, true)
+                               this[alarmObject0] = new Alarms({}, true)
                        } else if (alarmObjects == 1) {
                                alarmObject1 = metaData['name']
-                               this[alarmObject1] = new Alarms({}, 1, true)
+                               this[alarmObject1] = new Alarms({}, true)
                        } else if (alarmObjects == 2) {
                                alarmObject2 = metaData['name']
-                               this[alarmObject2] = new Alarms({}, 1, true)
+                               this[alarmObject2] = new Alarms({}, true)
                        }
 
                        alarmObjects=alarmObjects+1
 
-                       settings.put(metaData['name'], new Alarms({}, 1, true)) 
+                       settings.put(metaData['name'], new Alarms({}, true)) 
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class alarm!\n")
@@ -506,22 +506,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def buttonObject = new Buttons(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def buttonObject = new Buttons(sendEvent, init)\n")
 
                        if (buttonObjects == 0) {
                                buttonObject0 = metaData['name']
-                               this[buttonObject0] = new Buttons({}, 1, true)
+                               this[buttonObject0] = new Buttons({}, true)
                        } else if (buttonObjects == 1) {
                                buttonObject1 = metaData['name']
-                               this[buttonObject1] = new Buttons({}, 1, true)
+                               this[buttonObject1] = new Buttons({}, true)
                        } else if (buttonObjects == 2) {
                                buttonObject2 = metaData['name']
-                               this[buttonObject2] = new Buttons({}, 1, true)
+                               this[buttonObject2] = new Buttons({}, true)
                        }
 
                        buttonObjects=buttonObjects+1
 
-                       settings.put(metaData['name'], new Buttons({}, 1, true))
+                       settings.put(metaData['name'], new Buttons({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class Button!\n")
@@ -541,22 +541,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def batteryObject = new Batteries(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def batteryObject = new Batteries(sendEvent, init)\n")
 
                        if (batteryObjects == 0) {
                                batteryObject0 = metaData['name']
-                               this[batteryObject0] = new Batteries({}, 1, true)
+                               this[batteryObject0] = new Batteries({}, true)
                        } else if (batteryObjects == 1) {
                                batteryObject1 = metaData['name']
-                               this[batteryObject1] = new Batteries({}, 1, true)
+                               this[batteryObject1] = new Batteries({}, true)
                        } else if (batteryObjects == 2) {
                                batteryObject2 = metaData['name']
-                               this[batteryObject2] = new Batteries({}, 1, true)
+                               this[batteryObject2] = new Batteries({}, true)
                        }
 
                        batteryObjects=batteryObjects+1
 
-                       settings.put(metaData['name'], new Batteries({}, 1, true))
+                       settings.put(metaData['name'], new Batteries({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class Battery!\n")
@@ -576,22 +576,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def beaconSensorObject = new BeaconSensors(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def beaconSensorObject = new BeaconSensors(sendEvent, init)\n")
 
                        if (beaconSensorObjects == 0) {
                                beaconSensorObject0 = metaData['name']
-                               this[beaconSensorObject0] = new BeaconSensors({}, 1, true)
+                               this[beaconSensorObject0] = new BeaconSensors({}, true)
                        } else if (beaconSensorObjects == 1) {
                                beaconSensorObject1 = metaData['name']
-                               this[beaconSensorObject1] = new BeaconSensors({}, 1, true)
+                               this[beaconSensorObject1] = new BeaconSensors({}, true)
                        } else if (beaconSensorObjects == 2) {
                                beaconSensorObject2 = metaData['name']
-                               this[beaconSensorObject2] = new BeaconSensors({}, 1, true)
+                               this[beaconSensorObject2] = new BeaconSensors({}, true)
                        }
 
                        beaconSensorObjects=beaconSensorObjects+1
 
-                       settings.put(metaData['name'], new BeaconSensors({}, 1, true))
+                       settings.put(metaData['name'], new BeaconSensors({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class beacon sensor!\n")
@@ -611,22 +611,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def carbonMonoxideDetectorObject = new CarbonMonoxideDetectors(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def carbonMonoxideDetectorObject = new CarbonMonoxideDetectors(sendEvent, init)\n")
 
                        if (carbonMonoxideDetectorObjects == 0) {
                                carbonMonoxideDetectorObject0 = metaData['name']
-                               this[carbonMonoxideDetectorObject0] = new CarbonMonoxideDetectors({}, 1, true)
+                               this[carbonMonoxideDetectorObject0] = new CarbonMonoxideDetectors({}, true)
                        } else if (carbonMonoxideDetectorObjects == 1) {
                                carbonMonoxideDetectorObject1 = metaData['name']
-                               this[carbonMonoxideDetectorObject1] = new CarbonMonoxideDetectors({}, 1, true)
+                               this[carbonMonoxideDetectorObject1] = new CarbonMonoxideDetectors({}, true)
                        } else if (carbonMonoxideDetectorObjects == 2) {
                                carbonMonoxideDetectorObject2 = metaData['name']
-                               this[carbonMonoxideDetectorObject2] = new CarbonMonoxideDetectors({}, 1, true)
+                               this[carbonMonoxideDetectorObject2] = new CarbonMonoxideDetectors({}, true)
                        }
 
                        carbonMonoxideDetectorObjects=carbonMonoxideDetectorObjects+1
                        
-                       settings.put(metaData['name'], new CarbonMonoxideDetectors({}, 1, true))
+                       settings.put(metaData['name'], new CarbonMonoxideDetectors({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class carbon monoxide detector!\n")
@@ -646,22 +646,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def colorTemperatureObject = new ColorTemperatures(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def colorTemperatureObject = new ColorTemperatures(sendEvent, init)\n")
 
                        if (colorTemperatureObjects == 0) {
                                colorTemperatureObject0 = metaData['name']
-                               this[colorTemperatureObject0] = new ColorTemperatures({}, 1, true)
+                               this[colorTemperatureObject0] = new ColorTemperatures({}, true)
                        } else if (colorTemperatureObjects == 1) {
                                colorTemperatureObject1 = metaData['name']
-                               this[colorTemperatureObject1] = new ColorTemperatures({}, 1, true)
+                               this[colorTemperatureObject1] = new ColorTemperatures({}, true)
                        } else if (colorTemperatureObjects == 2) {
                                colorTemperatureObject2 = metaData['name']
-                               this[colorTemperatureObject2] = new ColorTemperatures({}, 1, true)
+                               this[colorTemperatureObject2] = new ColorTemperatures({}, true)
                        }
 
                        colorTemperatureObjects=colorTemperatureObjects+1
 
-                       settings.put(metaData['name'], new ColorTemperatures({}, 1, true))
+                       settings.put(metaData['name'], new ColorTemperatures({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class color temperature!\n")
@@ -681,22 +681,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def colorControlObject = new ColorControls(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def colorControlObject = new ColorControls(sendEvent, init)\n")
 
                        if (colorControlObjects == 0) {
                                colorControlObject0 = metaData['name']
-                               this[colorControlObject0] = new ColorControls({}, 1, true)
+                               this[colorControlObject0] = new ColorControls({}, true)
                        } else if (colorControlObjects == 1) {
                                colorControlObject1 = metaData['name']
-                               this[colorControlObject1] = new ColorControls({}, 1, true)
+                               this[colorControlObject1] = new ColorControls({}, true)
                        } else if (colorControlObjects == 2) {
                                colorControlObject2 = metaData['name']
-                               this[colorControlObject2] = new ColorControls({}, 1, true)
+                               this[colorControlObject2] = new ColorControls({}, true)
                        }
 
                        colorControlObjects=colorControlObjects+1
 
-                       settings.put(metaData['name'], new ColorControls({}, 1, true))
+                       settings.put(metaData['name'], new ColorControls({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class color control!\n")
@@ -716,22 +716,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def contactObject = new ContactSensors(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def contactObject = new ContactSensors(sendEvent, init)\n")
 
                        if (contactObjects == 0) {
                                contactObject0 = metaData['name']
-                               this[contactObject0] = new ContactSensors({}, 1, true)
+                               this[contactObject0] = new ContactSensors({}, true)
                        } else if (contactObjects == 1) {
                                contactObject1 = metaData['name']
-                               this[contactObject1] = new ContactSensors({}, 1, true)
+                               this[contactObject1] = new ContactSensors({}, true)
                        } else if (contactObjects == 2) {
                                contactObject2 = metaData['name']
-                               this[contactObject2] = new ContactSensors({}, 1, true)
+                               this[contactObject2] = new ContactSensors({}, true)
                        }
 
                        contactObjects=contactObjects+1
 
-                       settings.put(metaData['name'], new ContactSensors({}, 1, true))
+                       settings.put(metaData['name'], new ContactSensors({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class contactSensor!\n")
@@ -751,22 +751,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def threeAxisObject = new ThreeAxises(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def threeAxisObject = new ThreeAxises(sendEvent, init)\n")
 
                        if (threeAxisObjects == 0) {
                                threeAxisObject0 = metaData['name']
-                               this[threeAxisObject0] = new ThreeAxises({}, 1, true)
+                               this[threeAxisObject0] = new ThreeAxises({}, true)
                        } else if (threeAxisObjects == 1) {
                                threeAxisObject1 = metaData['name']
-                               this[threeAxisObject1] = new ThreeAxises({}, 1, true)
+                               this[threeAxisObject1] = new ThreeAxises({}, true)
                        } else if (threeAxisObjects == 2) {
                                threeAxisObject2 = metaData['name']
-                               this[threeAxisObject2] = new ThreeAxises({}, 1, true)
+                               this[threeAxisObject2] = new ThreeAxises({}, true)
                        }
 
                        threeAxisObjects=threeAxisObjects+1
 
-                       settings.put(metaData['name'], new ThreeAxises({}, 1, true))
+                       settings.put(metaData['name'], new ThreeAxises({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class three axis!\n")
@@ -786,22 +786,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def doorControlObject = new DoorControls(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def doorControlObject = new DoorControls(sendEvent, init)\n")
 
                        if (doorControlObjects == 0) {
                                doorControlObject0 = metaData['name']
-                               this[doorControlObject0] = new DoorControls({}, 1, true)
+                               this[doorControlObject0] = new DoorControls({}, true)
                        } else if (doorControlObjects == 1) {
                                doorControlObject1 = metaData['name']
-                               this[doorControlObject1] = new DoorControls({}, 1, true)
+                               this[doorControlObject1] = new DoorControls({}, true)
                        } else if (doorControlObjects == 2) {
                                doorControlObject2 = metaData['name']
-                               this[doorControlObject2] = new DoorControls({}, 1, true)
+                               this[doorControlObject2] = new DoorControls({}, true)
                        }
 
                        doorControlObjects=doorControlObjects+1
 
-                       settings.put(metaData['name'], new DoorControls({}, 1, true))
+                       settings.put(metaData['name'], new DoorControls({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class door control!\n")
@@ -821,22 +821,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def energyMeterObject = new EnergyMeters(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def energyMeterObject = new EnergyMeters(sendEvent, init)\n")
 
                        if (energyMeterObjects == 0) {
                                energyMeterObject0 = metaData['name']
-                               this[energyMeterObject0] = new EnergyMeters({}, 1, true)
+                               this[energyMeterObject0] = new EnergyMeters({}, true)
                        } else if (energyMeterObjects == 1) {
                                energyMeterObject1 = metaData['name']
-                               this[energyMeterObject1] = new EnergyMeters({}, 1, true)
+                               this[energyMeterObject1] = new EnergyMeters({}, true)
                        } else if (energyMeterObjects == 2) {
                                energyMeterObject2 = metaData['name']
-                               this[energyMeterObject2] = new EnergyMeters({}, 1, true)
+                               this[energyMeterObject2] = new EnergyMeters({}, true)
                        }
 
                        energyMeterObjects=energyMeterObjects+1
 
-                       settings.put(metaData['name'], new EnergyMeters({}, 1, true))
+                       settings.put(metaData['name'], new EnergyMeters({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class energy meter!\n")
@@ -856,22 +856,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def illuminanceMeasurementObject = new IlluminanceMeasurements(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def illuminanceMeasurementObject = new IlluminanceMeasurements(sendEvent, init)\n")
 
                        if (illuminanceMeasurementObjects == 0) {
                                illuminanceMeasurementObject0 = metaData['name']
-                               this[illuminanceMeasurementObject0] = new IlluminanceMeasurements({}, 1, true)
+                               this[illuminanceMeasurementObject0] = new IlluminanceMeasurements({}, true)
                        } else if (illuminanceMeasurementObjects == 1) {
                                illuminanceMeasurementObject1 = metaData['name']
-                               this[illuminanceMeasurementObject1] = new IlluminanceMeasurements({}, 1, true)
+                               this[illuminanceMeasurementObject1] = new IlluminanceMeasurements({}, true)
                        } else if (illuminanceMeasurementObjects == 2) {
                                illuminanceMeasurementObject2 = metaData['name']
-                               this[illuminanceMeasurementObject2] = new IlluminanceMeasurements({}, 1, true)
+                               this[illuminanceMeasurementObject2] = new IlluminanceMeasurements({}, true)
                        }
 
                        illuminanceMeasurementObjects=illuminanceMeasurementObjects+1
 
-                       settings.put(metaData['name'], new IlluminanceMeasurements({}, 1, true))
+                       settings.put(metaData['name'], new IlluminanceMeasurements({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class illuminance measurement!\n")
@@ -891,22 +891,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def accelerationSensorObject = new AccelerationSensors(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def accelerationSensorObject = new AccelerationSensors(sendEvent, init)\n")
 
                        if (accelerationSensorObjects == 0) {
                                accelerationSensorObject0 = metaData['name']
-                               this[accelerationSensorObject0] = new AccelerationSensors({}, 1, true)
+                               this[accelerationSensorObject0] = new AccelerationSensors({}, true)
                        } else if (accelerationSensorObjects == 1) {
                                accelerationSensorObject1 = metaData['name']
-                               this[accelerationSensorObject1] = new AccelerationSensors({}, 1, true)
+                               this[accelerationSensorObject1] = new AccelerationSensors({}, true)
                        } else if (accelerationSensorObjects == 2) {
                                accelerationSensorObject2 = metaData['name']
-                               this[accelerationSensorObject2] = new AccelerationSensors({}, 1, true)
+                               this[accelerationSensorObject2] = new AccelerationSensors({}, true)
                        }
 
                        accelerationSensorObjects=accelerationSensorObjects+1
 
-                       settings.put(metaData['name'], new AccelerationSensors({}, 1, true))
+                       settings.put(metaData['name'], new AccelerationSensors({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class Acceleration Sensor!\n")
@@ -961,22 +961,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def motionSensorObject = new MotionSensors(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def motionSensorObject = new MotionSensors(sendEvent, init)\n")
 
                        if (motionSensorObjects == 0) {
                                motionSensorObject0 = metaData['name']
-                               this[motionSensorObject0] = new MotionSensors({}, 1, true)
+                               this[motionSensorObject0] = new MotionSensors({}, true)
                        } else if (motionSensorObjects == 1) {
                                motionSensorObject1 = metaData['name']
-                               this[motionSensorObject1] = new MotionSensors({}, 1, true)
+                               this[motionSensorObject1] = new MotionSensors({}, true)
                        } else if (motionSensorObjects == 2) {
                                motionSensorObject2 = metaData['name']
-                               this[motionSensorObject2] = new MotionSensors({}, 1, true)
+                               this[motionSensorObject2] = new MotionSensors({}, true)
                        }
 
                        motionSensorObjects=motionSensorObjects+1
 
-                       settings.put(metaData['name'], new MotionSensors({}, 1, true))
+                       settings.put(metaData['name'], new MotionSensors({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class Motion Sensor!\n")
@@ -996,22 +996,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def musicPlayerObject = new MusicPlayers(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def musicPlayerObject = new MusicPlayers(sendEvent, init)\n")
 
                        if (musicPlayerObjects == 0) {
                                musicPlayerObject0 = metaData['name']
-                               this[musicPlayerObject0] = new MusicPlayers({}, 1, true)
+                               this[musicPlayerObject0] = new MusicPlayers({}, true)
                        } else if (musicPlayerObjects == 1) {
                                musicPlayerObject1 = metaData['name']
-                               this[musicPlayerObject1] = new MusicPlayers({}, 1, true)
+                               this[musicPlayerObject1] = new MusicPlayers({}, true)
                        } else if (musicPlayerObjects == 2) {
                                musicPlayerObject2 = metaData['name']
-                               this[musicPlayerObject2] = new MusicPlayers({}, 1, true)
+                               this[musicPlayerObject2] = new MusicPlayers({}, true)
                        }
 
                        musicPlayerObjects=musicPlayerObjects+1
 
-                       settings.put(metaData['name'], new MusicPlayers({}, 1, true)) 
+                       settings.put(metaData['name'], new MusicPlayers({}, true)) 
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class music player!\n")
@@ -1031,22 +1031,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def powerMeterObject = new PowerMeters(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def powerMeterObject = new PowerMeters(sendEvent, init)\n")
 
                        if (powerMeterObjects == 0) {
                                powerMeterObject0 = metaData['name']
-                               this[powerMeterObject0] = new PowerMeters({}, 1, true)
+                               this[powerMeterObject0] = new PowerMeters({}, true)
                        } else if (powerMeterObjects == 1) {
                                powerMeterObject1 = metaData['name']
-                               this[powerMeterObject1] = new PowerMeters({}, 1, true)
+                               this[powerMeterObject1] = new PowerMeters({}, true)
                        } else if (powerMeterObjects == 2) {
                                powerMeterObject2 = metaData['name']
-                               this[powerMeterObject2] = new PowerMeters({}, 1, true)
+                               this[powerMeterObject2] = new PowerMeters({}, true)
                        }
 
                        powerMeterObjects=powerMeterObjects+1
 
-                       settings.put(metaData['name'], new PowerMeters({}, 1, true))
+                       settings.put(metaData['name'], new PowerMeters({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class power meter!\n")
@@ -1066,22 +1066,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def presenceSensorObject = new PresenceSensors(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def presenceSensorObject = new PresenceSensors(sendEvent, init)\n")
 
                        if (presenceSensorObjects == 0) {
                                presenceSensorObject0 = metaData['name']
-                               this[presenceSensorObject0] = new PresenceSensors({}, 1, true)
+                               this[presenceSensorObject0] = new PresenceSensors({}, true)
                        } else if (presenceSensorObjects == 1) {
                                presenceSensorObject1 = metaData['name']
-                               this[presenceSensorObject1] = new PresenceSensors({}, 1, true)
+                               this[presenceSensorObject1] = new PresenceSensors({}, true)
                        } else if (presenceSensorObjects == 2) {
                                presenceSensorObject2 = metaData['name']
-                               this[presenceSensorObject2] = new PresenceSensors({}, 1, true)
+                               this[presenceSensorObject2] = new PresenceSensors({}, true)
                        }
 
                        presenceSensorObjects=presenceSensorObjects+1
 
-                       settings.put(metaData['name'], new PresenceSensors({}, 1, true))
+                       settings.put(metaData['name'], new PresenceSensors({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class presence sensor!\n")
@@ -1101,22 +1101,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def humidityMeasurementObject = new RelativeHumidityMeasurements(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def humidityMeasurementObject = new RelativeHumidityMeasurements(sendEvent, init)\n")
 
                        if (humidityMeasurementObjects == 0) {
                                humidityMeasurementObject0 = metaData['name']
-                               this[humidityMeasurementObject0] = new RelativeHumidityMeasurements({}, 1, true)
+                               this[humidityMeasurementObject0] = new RelativeHumidityMeasurements({}, true)
                        } else if (humidityMeasurementObjects == 1) {
                                humidityMeasurementObject1 = metaData['name']
-                               this[humidityMeasurementObject1] = new RelativeHumidityMeasurements({}, 1, true)
+                               this[humidityMeasurementObject1] = new RelativeHumidityMeasurements({}, true)
                        } else if (humidityMeasurementObjects == 2) {
                                humidityMeasurementObject2 = metaData['name']
-                               this[humidityMeasurementObject2] = new RelativeHumidityMeasurements({}, 1, true)
+                               this[humidityMeasurementObject2] = new RelativeHumidityMeasurements({}, true)
                        }
 
                        humidityMeasurementObjects=humidityMeasurementObjects+1
 
-                       settings.put(metaData['name'], new RelativeHumidityMeasurements({}, 1, true))
+                       settings.put(metaData['name'], new RelativeHumidityMeasurements({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class humidity measurement!\n")
@@ -1136,22 +1136,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def relaySwitchObject = new RelaySwitches(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def relaySwitchObject = new RelaySwitches(sendEvent, init)\n")
 
                        if (relaySwitchObjects == 0) {
                                relaySwitchObject0 = metaData['name']
-                               this[relaySwitchObject0] = new RelaySwitches({}, 1, true)
+                               this[relaySwitchObject0] = new RelaySwitches({}, true)
                        } else if (relaySwitchObjects == 1) {
                                relaySwitchObject1 = metaData['name']
-                               this[relaySwitchObject1] = new RelaySwitches({}, 1, true)
+                               this[relaySwitchObject1] = new RelaySwitches({}, true)
                        } else if (relaySwitchObjects == 2) {
                                relaySwitchObject2 = metaData['name']
-                               this[relaySwitchObject2] = new RelaySwitches({}, 1, true)
+                               this[relaySwitchObject2] = new RelaySwitches({}, true)
                        }
 
                        relaySwitchObjects=relaySwitchObjects+1
                        
-                       settings.put(metaData['name'], new RelaySwitches({}, 1, true))
+                       settings.put(metaData['name'], new RelaySwitches({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class relay switch!\n")
@@ -1171,22 +1171,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def sleepSensorObject = new SleepSensors(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def sleepSensorObject = new SleepSensors(sendEvent, init)\n")
 
                        if (sleepSensorObjects == 0) {
                                sleepSensorObject0 = metaData['name']
-                               this[sleepSensorObject0] = new SleepSensors({}, 1, true)
+                               this[sleepSensorObject0] = new SleepSensors({}, true)
                        } else if (sleepSensorObjects == 1) {
                                sleepSensorObject1 = metaData['name']
-                               this[sleepSensorObject1] = new SleepSensors({}, 1, true)
+                               this[sleepSensorObject1] = new SleepSensors({}, true)
                        } else if (sleepSensorObjects == 2) {
                                sleepSensorObject2 = metaData['name']
-                               this[sleepSensorObject2] = new SleepSensors({}, 1, true)
+                               this[sleepSensorObject2] = new SleepSensors({}, true)
                        }
 
                        sleepSensorObjects=sleepSensorObjects+1
                        
-                       settings.put(metaData['name'], new SleepSensors({}, 1, true))
+                       settings.put(metaData['name'], new SleepSensors({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class sleep sensor!\n")
@@ -1206,22 +1206,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def smokeDetectorObject = new SmokeDetectors(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def smokeDetectorObject = new SmokeDetectors(sendEvent, init)\n")
 
                        if (smokeDetectorObjects == 0) {
                                smokeDetectorObject0 = metaData['name']
-                               this[smokeDetectorObject0] = new SmokeDetectors({}, 1, true)
+                               this[smokeDetectorObject0] = new SmokeDetectors({}, true)
                        } else if (smokeDetectorObjects == 1) {
                                smokeDetectorObject1 = metaData['name']
-                               this[smokeDetectorObject1] = new SmokeDetectors({}, 1, true)
+                               this[smokeDetectorObject1] = new SmokeDetectors({}, true)
                        } else if (smokeDetectorObjects == 2) {
                                smokeDetectorObject2 = metaData['name']
-                               this[smokeDetectorObject2] = new SmokeDetectors({}, 1, true)
+                               this[smokeDetectorObject2] = new SmokeDetectors({}, true)
                        }
 
                        smokeDetectorObjects=smokeDetectorObjects+1
                        
-                       settings.put(metaData['name'], new SmokeDetectors({}, 1, true))
+                       settings.put(metaData['name'], new SmokeDetectors({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class smoke detector!\n")
@@ -1241,22 +1241,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def stepSensorObject = new StepSensors(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def stepSensorObject = new StepSensors(sendEvent, init)\n")
 
                        if (stepSensorObjects == 0) {
                                stepSensorObject0 = metaData['name']
-                               this[stepSensorObject0] = new StepSensors({}, 1, true)
+                               this[stepSensorObject0] = new StepSensors({}, true)
                        } else if (stepSensorObjects == 1) {
                                stepSensorObject1 = metaData['name']
-                               this[stepSensorObject1] = new StepSensors({}, 1, true)
+                               this[stepSensorObject1] = new StepSensors({}, true)
                        } else if (stepSensorObjects == 2) {
                                stepSensorObject2 = metaData['name']
-                               this[stepSensorObject2] = new StepSensors({}, 1, true)
+                               this[stepSensorObject2] = new StepSensors({}, true)
                        }
 
                        stepSensorObjects=stepSensorObjects+1
                        
-                       settings.put(metaData['name'], new StepSensors({}, 1, true))
+                       settings.put(metaData['name'], new StepSensors({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class step sensor!\n")
@@ -1276,22 +1276,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def switchObject = new Switches(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def switchObject = new Switches(sendEvent, init)\n")
 
                        if (switchObjects == 0) {
                                switchObject0 = metaData['name']
-                               this[switchObject0] = new Switches({}, 1, true)
+                               this[switchObject0] = new Switches({}, true)
                        } else if (switchObjects == 1) {
                                switchObject1 = metaData['name']
-                               this[switchObject1] = new Switches({}, 1, true)
+                               this[switchObject1] = new Switches({}, true)
                        } else if (switchObjects == 2) {
                                switchObject2 = metaData['name']
-                               this[switchObject2] = new Switches({}, 1, true)
+                               this[switchObject2] = new Switches({}, true)
                        }
 
                        switchObjects=switchObjects+1
                        
-                       settings.put(metaData['name'], new Switches({}, 1, true))
+                       settings.put(metaData['name'], new Switches({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class switch!\n")
@@ -1311,22 +1311,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def switchLevelObject = new SwitchLevels(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def switchLevelObject = new SwitchLevels(sendEvent, init)\n")
 
                        if (switchLevelObjects == 0) {
                                switchLevelObject0 = metaData['name']
-                               this[switchLevelObject0] = new SwitchLevels({}, 1, true)
+                               this[switchLevelObject0] = new SwitchLevels({}, true)
                        } else if (switchLevelObjects == 1) {
                                switchLevelObject1 = metaData['name']
-                               this[switchLevelObject1] = new SwitchLevels({}, 1, true)
+                               this[switchLevelObject1] = new SwitchLevels({}, true)
                        } else if (switchLevelObjects == 2) {
                                switchLevelObject2 = metaData['name']
-                               this[switchLevelObject2] = new SwitchLevels({}, 1, true)
+                               this[switchLevelObject2] = new SwitchLevels({}, true)
                        }
 
                        switchLevelObjects=switchLevelObjects+1
 
-                       settings.put(metaData['name'], new SwitchLevels({}, 1, true))
+                       settings.put(metaData['name'], new SwitchLevels({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class switch level!\n")
@@ -1346,22 +1346,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def temperatureMeasurementObject = new TemperatureMeasurements(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def temperatureMeasurementObject = new TemperatureMeasurements(sendEvent, init)\n")
 
                        if (temperatureMeasurementObjects == 0) {
                                temperatureMeasurementObject0 = metaData['name']
-                               this[temperatureMeasurementObject0] = new TemperatureMeasurements({}, 1, true)
+                               this[temperatureMeasurementObject0] = new TemperatureMeasurements({}, true)
                        } else if (temperatureMeasurementObjects == 1) {
                                temperatureMeasurementObject1 = metaData['name']
-                               this[temperatureMeasurementObject1] = new TemperatureMeasurements({}, 1, true)
+                               this[temperatureMeasurementObject1] = new TemperatureMeasurements({}, true)
                        } else if (temperatureMeasurementObjects == 2) {
                                temperatureMeasurementObject2 = metaData['name']
-                               this[temperatureMeasurementObject2] = new TemperatureMeasurements({}, 1, true)
+                               this[temperatureMeasurementObject2] = new TemperatureMeasurements({}, true)
                        }
 
                        temperatureMeasurementObjects=temperatureMeasurementObjects+1
 
-                       settings.put(metaData['name'], new TemperatureMeasurements({}, 1, true))
+                       settings.put(metaData['name'], new TemperatureMeasurements({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class temperature measurement!\n")
@@ -1381,22 +1381,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def thermostatObject = new Thermostats(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def thermostatObject = new Thermostats(sendEvent, init)\n")
                                
                        if (thermostatObjects == 0) {
                                thermostatObject0 = metaData['name']
-                               this[thermostatObject0] = new Thermostats({}, 1, true)
+                               this[thermostatObject0] = new Thermostats({}, true)
                        } else if (thermostatObjects == 1) {
                                thermostatObject1 = metaData['name']
-                               this[thermostatObject1] = new Thermostats({}, 1, true)
+                               this[thermostatObject1] = new Thermostats({}, true)
                        } else if (thermostatObjects == 2) {
                                thermostatObject2 = metaData['name']
-                               this[thermostatObject2] = new Thermostats({}, 1, true)
+                               this[thermostatObject2] = new Thermostats({}, true)
                        }
 
                        thermostatObjects=thermostatObjects+1
 
-                       settings.put(metaData['name'], new Thermostats({}, 1, true))
+                       settings.put(metaData['name'], new Thermostats({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class thermostat!\n")
@@ -1416,22 +1416,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def valveObject = new Valves(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def valveObject = new Valves(sendEvent, init)\n")
 
                        if (valveObjects == 0) {
                                valveObject0 = metaData['name']
-                               this[valveObject0] = new Valves({}, 1, true)
+                               this[valveObject0] = new Valves({}, true)
                        } else if (valveObjects == 1) {
                                valveObject1 = metaData['name']
-                               this[valveObject1] = new Valves({}, 1, true)
+                               this[valveObject1] = new Valves({}, true)
                        } else if (valveObjects == 2) {
                                valveObject2 = metaData['name']
-                               this[valveObject2] = new Valves({}, 1, true)
+                               this[valveObject2] = new Valves({}, true)
                        }
 
                        valveObjects=valveObjects+1
 
-                       settings.put(metaData['name'], new Valves({}, 1, true))
+                       settings.put(metaData['name'], new Valves({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class valve!\n")
@@ -1451,22 +1451,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def speechSynthesisObject = new SpeechSynthesises(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def speechSynthesisObject = new SpeechSynthesises(sendEvent, init)\n")
 
                        if (speechSynthesisObjects == 0) {
                                speechSynthesisObject0 = metaData['name']
-                               this[speechSynthesisObject0] = new SpeechSynthesises({}, 1, true)
+                               this[speechSynthesisObject0] = new SpeechSynthesises({}, true)
                        } else if (speechSynthesisObjects == 1) {
                                speechSynthesisObject1 = metaData['name']
-                               this[speechSynthesisObject1] = new SpeechSynthesises({}, 1, true)
+                               this[speechSynthesisObject1] = new SpeechSynthesises({}, true)
                        } else if (speechSynthesisObjects == 2) {
                                speechSynthesisObject2 = metaData['name']
-                               this[speechSynthesisObject2] = new SpeechSynthesises({}, 1, true)
+                               this[speechSynthesisObject2] = new SpeechSynthesises({}, true)
                        }
 
                        speechSynthesisObjects=speechSynthesisObjects+1
 
-                       settings.put(metaData['name'], new SpeechSynthesises({}, 1, true))
+                       settings.put(metaData['name'], new SpeechSynthesises({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class speech synthesis!\n")
@@ -1486,22 +1486,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def waterSensorObject = new WaterSensors(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def waterSensorObject = new WaterSensors(sendEvent, init)\n")
 
                        if (waterSensorObjects == 0) {
                                waterSensorObject0 = metaData['name']
-                               this[waterSensorObject0] = new WaterSensors({}, 1, true)
+                               this[waterSensorObject0] = new WaterSensors({}, true)
                        } else if (waterSensorObjects == 1) {
                                waterSensorObject1 = metaData['name']
-                               this[waterSensorObject1] = new WaterSensors({}, 1, true)
+                               this[waterSensorObject1] = new WaterSensors({}, true)
                        } else if (waterSensorObjects == 2) {
                                waterSensorObject2 = metaData['name']
-                               this[waterSensorObject2] = new WaterSensors({}, 1, true)
+                               this[waterSensorObject2] = new WaterSensors({}, true)
                        }
 
                        waterSensorObjects=waterSensorObjects+1
 
-                       settings.put(metaData['name'], new WaterSensors({}, 1, true))
+                       settings.put(metaData['name'], new WaterSensors({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class water sensor!\n")
@@ -1556,22 +1556,22 @@ def input(LinkedHashMap metaData) {
                        }
 
                        if (contains == 0)
-                               globalObjects.append("@Field def imageCaptureObject = new ImageCaptures(sendEvent, 1, init)\n")
+                               globalObjects.append("@Field def imageCaptureObject = new ImageCaptures(sendEvent, init)\n")
 
                        if (imageCaptureObjects == 0) {
                                imageCaptureObject0 = metaData['name']
-                               this[imageCaptureObject0] = new ImageCaptures({}, 1, true)
+                               this[imageCaptureObject0] = new ImageCaptures({}, true)
                        } else if (imageCaptureObjects == 1) {
                                imageCaptureObject1 = metaData['name']
-                               this[imageCaptureObject1] = new ImageCaptures({}, 1, true)
+                               this[imageCaptureObject1] = new ImageCaptures({}, true)
                        } else if (imageCaptureObjects == 2) {
                                imageCaptureObject2 = metaData['name']
-                               this[imageCaptureObject2] = new ImageCaptures({}, 1, true)
+                               this[imageCaptureObject2] = new ImageCaptures({}, true)
                        }
 
                        imageCaptureObjects=imageCaptureObjects+1
 
-                       settings.put(metaData['name'], new ImageCaptures({}, 1, true))
+                       settings.put(metaData['name'], new ImageCaptures({}, true))
 
                        if (App == "App1") {
                                extractedObjectsApp1.append("//Object for class Image Capture!\n")
index 644db1b..e59e6ef 100644 (file)
@@ -1,39 +1,35 @@
 //Create a class for illuminance measurement
 package IlluminanceMeasurement
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-public class IlluminanceMeasurement {
-       private String id
-       private String label
-       private String displayName
-       private int illuminance
-       private int currentIlluminance
+public class IlluminanceMeasurement extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with numberical values
+       MutableInteger currentIlluminance = new MutableInteger()
+       // Maps from features to values
+       HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
 
-       IlluminanceMeasurement(String id, String label, String displayName, int illuminance) {
+       IlluminanceMeasurement(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentIlluminance) {
+               deviceIntValuesMap = deviceIntValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.illuminance = illuminance
-               this.currentIlluminance = illuminance
-       }
+               this.currentIlluminance = currentIlluminance
 
-       //By Model Checker
-       def setValue(String value) {
-               println("the illuminance level is changed to $value!")
-               this.illuminance = value.toInteger()
-               this.currentIlluminance = value.toInteger()
+               deviceIntValuesMap.put("illuminance", currentIlluminance)
        }
 
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "illuminance") {
-                       return illuminance
-               }
+       // Methods to return values
+       def getCurrentIlluminance() {
+               return currentIlluminance.getValue()
        }
-
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "illuminance") {
-                       return illuminance
-               }
-       }
-
 }
index 2345610..e210623 100644 (file)
@@ -1,76 +1,32 @@
 //Create a class for illuminance measurement
 package IlluminanceMeasurement
-import Timer.SimulatedTimer
-
-public class IlluminanceMeasurements {
-       private int deviceNumbers
-       private List illuminanceMeasurements
-       def sendEvent
-
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "illuminanceMeasurementsID0"
-       private String label = "illuminanceMeasurements0"
-       private String displayName = "illuminanceMeasurements0"
-       private int illuminance = 5
-       private int currentIlluminance = 5
+import SmartThing.SmartThings
 
+public class IlluminanceMeasurements extends SmartThings {
+       List illuminanceMeasurements = new ArrayList()
                
-       IlluminanceMeasurements(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent              
-               this.deviceNumbers = deviceNumbers
-               this.illuminanceMeasurements = []
-
-               if (init) {
-                       this.illuminance = 20000
-                       this.currentIlluminance = 20000
-               } else {
-                       this.illuminance = 5
-                       this.currentIlluminance = 5
-               }
-
-               illuminanceMeasurements.add(new IlluminanceMeasurement(id, label, displayName, this.illuminance))
-       }
+       IlluminanceMeasurements(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               illuminanceMeasurements = smartThings
 
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"].toInteger() != illuminanceMeasurements[0].illuminance) {
-                       this.illuminance = eventDataMap["value"].toInteger()
-                       this.currentIlluminance = eventDataMap["value"].toInteger()
-                       illuminanceMeasurements[0].setValue(eventDataMap["value"])
-                       sendEvent(eventDataMap)
-               }
-       }
+               // Initialization
+               StringBuilder id = new StringBuilder("illuminanceID0")
+               StringBuilder label = new StringBuilder("illuminance")
+               StringBuilder displayName = new StringBuilder("illuminance0")
+               MutableInteger illuminance = new MutableInteger()
 
-       //Methods for closures
-       def count(Closure Input) {
-               illuminanceMeasurements.count(Input)
-       }
-       def size() {
-               illuminanceMeasurements.size()
-       }
-       def each(Closure Input) {
-               illuminanceMeasurements.each(Input)
-       }
-       def find(Closure Input) {
-               illuminanceMeasurements.find(Input)
-       }
-       def sort(Closure Input) {
-               illuminanceMeasurements.sort(Input)
-       }
-       def collect(Closure Input) {
-               illuminanceMeasurements.collect(Input)
-       }
-
-
-       def currentValue(String deviceFeature) {
-               illuminanceMeasurements[0].currentValue(deviceFeature)//It is called if we have only one device
-       }
+               if (init)
+                       illuminance.setValue(20000)
+               else
+                       illuminance.setValue(5)
 
-       def latestValue(String deviceFeature) {
-               illuminanceMeasurements[0].latestValue(deviceFeature)//It is called if we have only one device
+               illuminanceMeasurements.add(new IlluminanceMeasurement(sendEvent, id, label, displayName, illuminance))
        }
 
-       def getAt(int ix) {
-               illuminanceMeasurements[ix]
+       // Methods to return values
+       def getCurrentIlluminance() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(illuminanceMeasurements[0].getCurrentIlluminance())
+               return tmpValues
        }
 }
index 0672e60..a8ab0ee 100644 (file)
@@ -1,45 +1,44 @@
 //Create a class for image capture sensor
 package ImageCapture
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-public class ImageCapture {
-       private String id
-       private String label
-       private String displayName
-       private String image
-       private String alarmState
-       def timers
+public class ImageCapture extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with string values
+       StringBuilder currentImage = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
 
-       ImageCapture(String id, String label, String displayName, String image, String alarmState) {
+       ImageCapture(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentImage) {
+               deviceValuesMap = deviceValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.image = image
-               this.alarmState = alarmState
-               this.timers = new SimulatedTimer()
-       }
-       
-       def alarmOn() {
-               if (alarmState != "armed") {
-                       println("The camera with id:$id is armed!")
-                       this.alarmState = "armed"
-               }
-       }
+               this.currentImage = currentImage
 
-       def alarmOff() {
-               if (alarmState != "not armed") {
-                       println("The camera with id:$id is not armed!")
-                       this.alarmState = "not armed"
-               }
+               deviceValuesMap.put("image", currentImage)
        }
 
        def take() {
-               println("The camera with id:$id is taken a picture!")
+               String tmpID = id.toString()
+               println("The camera with id:$tmpID is taken a picture!")
        }
 
        def take(LinkedHashMap metaData) {
-               def task = timers.runAfter(metaData["delay"]) {
-                       println("The camera with id:$id is taken a picture!")
-               }
+               take()
+       }
+
+       // Methods to return values
+       def getCurrentImage() {
+               return currentImage.toString()
        }
 }
index 0588035..0b6c447 100644 (file)
@@ -1,66 +1,21 @@
 //Create a class for image capture sensor
 package ImageCapture
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-public class ImageCaptures {
-       private int deviceNumbers
-       private List imageCaptureSensors
-       def sendEvent
+public class ImageCaptures extends SmartThings {
+       List imageCaptureSensors = new ArrayList()
 
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "imageCaptureID0"
-       private String label = "imageCapture0"
-       private String displayName = "imageCapture0"
-       private String image = "imageData"
-       private String alarmState = "armed"
+       ImageCaptures(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               imageCaptureSensors = smartThings
 
-               
-       ImageCaptures(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent              
-               this.deviceNumbers = deviceNumbers
-               this.imageCaptureSensors = []
+               // Initialization
+               StringBuilder id = new StringBuilder("imageCaptureID0")
+               StringBuilder label = new StringBuilder("imageCapture")
+               StringBuilder displayName = new StringBuilder("imageCapture0")
+               StringBuilder image = new StringBuilder("image0")
 
-               if (init) {
-                       this.alarmState = "armed"
-               } else {
-                       this.alarmState = "not armed"
-               }
-               imageCaptureSensors.add(new ImageCapture(id, label, displayName, this.image, this.alarmState))
-       }
-
-
-       //Methods for closures
-       def count(Closure Input) {
-               imageCaptureSensors.count(Input)
-       }
-       def size() {
-               imageCaptureSensors.size()
-       }
-       def each(Closure Input) {
-               imageCaptureSensors.each(Input)
-       }
-       def find(Closure Input) {
-               imageCaptureSensors.find(Input)
-       }
-       def sort(Closure Input) {
-               imageCaptureSensors.sort(Input)
-       }
-       def collect(Closure Input) {
-               imageCaptureSensors.collect(Input)
-       }
-
-       def alarmOn() {
-               if (alarmState != "armed") {
-                       this.alarmState = "armed"
-                       imageCaptureSensors[0].alarmOn()
-               }
-       }
-
-       def alarmOff() {
-               if (alarmState != "not armed") {
-                       this.alarmState = "not armed"
-                       imageCaptureSensors[0].alarmOff()
-               }
+               imageCaptureSensors.add(new ImageCapture(sendEvent, id, label, displayName, image))
        }
 
        def take() {
@@ -68,10 +23,13 @@ public class ImageCaptures {
        }
 
        def take(LinkedHashMap metaData) {
-               imageCaptureSensors[0].take(metaData)
-       }
-
-       def getAt(int ix) {
-               imageCaptureSensors[ix]
+               take()
+       }
+       
+       // Methods to return values
+       def getCurrentImage() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(imageCaptureSensors[0].getCurrentImage())
+               return tmpValues
        }
 }
index 3f5e46e..9257012 100755 (executable)
@@ -1,66 +1,79 @@
 //Create a class for location variable
 package Location
+import SmartThing.SmartThing
 
-class LocationVar {
-       private int contactBookEnabled
-    private def modes
-       private def timeZone
-       private def hubs
-    private String mode
-       private String locationMode
-       private String name
-    private List contacts
-    private List phoneNumbers
-       private String temperatureScale 
-       def sendEvent
+public class LocationVar extends SmartThing {
+       // Features with numberical values
+       MutableInteger contactBookEnabled = new MutableInteger()
+       // Features with string values
+       StringBuilder mode = new StringBuilder()
+       StringBuilder locationMode = mode
+       StringBuilder name = new StringBuilder()
+       StringBuilder temperatureScale = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+       // Other variables
+       Phrase helloHome
+       TimeZone timeZone
+       def modes
+       def hubs
+       List contacts
+       List phoneNumbers
        
-       private Phrase helloHome
-
        LocationVar(Closure sendEvent, boolean init) {
-       
-                       if (init) {
-                               this.hubs = [[id:0, localIP:"128.195.204.105"]]
-                               this.modes = [[name: "home"],[name: "away"],[name: "night"]]
-                               this.mode = "away"
-                               this.locationMode = "away"
-                               this.helloHome = new Phrase()
-                               this.contactBookEnabled = 1
-                               this.contacts = ['AJ']
-                               this.phoneNumbers = [9495379373]
-                               this.sendEvent = sendEvent
-                               this.timeZone = TimeZone.getTimeZone("America/New_York")
-                               this.name = "hub0"
-                               this.temperatureScale = "F"
-                       } else {
-                               this.hubs = [[id:0, localIP:"128.195.204.105"]]
-                               this.modes = [[name: "home"],[name: "away"],[name: "night"]]
-                               this.mode = "home"
-                               this.locationMode = "home"
-                               this.helloHome = new Phrase()
-                               this.contactBookEnabled = 1
-                               this.contacts = ['AJ']
-                               this.phoneNumbers = [9495379373]
-                               this.sendEvent = sendEvent
-                               this.timeZone = TimeZone.getTimeZone("America/New_York")
-                               this.name = "hub0"
-                               this.temperatureScale = "F"
+                       deviceValuesMap = deviceValueSmartThing
+                       sendEventSmartThings = sendEvent
+
+                       // Initialization
+                       StringBuilder sunset = new StringBuilder("sunset")
+                       StringBuilder sunsetTime = sunset
+                       StringBuilder sunrise = new StringBuilder("sunrise")
+                       StringBuilder sunriseTime = sunrise
+                       hubs = [[id:0, localIP:"128.195.204.105"]]
+                       modes = [[name: "home"],[name: "away"],[name: "night"]]
+                       helloHome = new Phrase()
+                       contactBookEnabled.setValue(1)
+                       contacts = ['AJ']
+                       phoneNumbers = [9495379373]
+                       name.append("hub0")
+                       temperatureScale.append("F")
+                       timeZone = TimeZone.getTimeZone("America/New_York")
                        
-                       }
-       }
 
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (this.mode != eventDataMap['value']) {
-                       def sentMode = eventDataMap['value']
-                       println("The location is changed to $sentMode!")
-                       this.mode = sentMode
-                       this.locationMode = sentMode
-                       sendEvent(eventDataMap)
-               }
-       }
+                       if (init)
+                               mode.append("away")     
+                       else
+                               mode.append("home")
 
+                       deviceValuesMap.put("mode", mode)
+                       deviceValuesMap.put("Location", mode)
+                       deviceValuesMap.put("sunset", sunset)
+                       deviceValuesMap.put("sunrise", sunrise)
+       }
+
+       // Methods to return values
        def currentValue(String deviceFeature) {
                if (deviceFeature == "sunsetTime" || deviceFeature == "sunset")
                        return System.currentTimeMillis()
        }
+
+       def getMode() {
+               return mode.toString()
+       }
+
+       def getLocationMode() {
+               return locationMode.toString()
+       }
+
+       def getName() {
+               return name.toString()
+       }
+
+       def getTemperatureScale() {
+               return temperatureScale.toString()
+       }
+
+       def getContactBookEnabled() {
+               return contactBookEnabled.getValue()
+       }
 }
index 1b2e472..1ceac32 100644 (file)
@@ -1,95 +1,64 @@
 //Create a class for lock device
 package Lock
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-public class Lock {
-       private String id
-       private String label
-       private String displayName
-       private String lockState
-       private String currentLock
-       private String lockLatestValue
-       def sendEvent   
-       def timers
+public class Lock extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with string values
+       StringBuilder currentLock = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
 
 
-       Lock(Closure sendEvent, String id, String label, String displayName, String lockState, String lockLatestValue) {
+       Lock(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentLock) {
+               deviceValuesMap = deviceValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
-               this.sendEvent = sendEvent
                this.displayName = displayName
-               this.lockState = lockState
-               this.currentLock = lockState
-               this.lockLatestValue = lockLatestValue
-               this.timers = new SimulatedTimer()
+               this.currentLock = currentLock
+
+               deviceValuesMap.put("lock", currentLock)
        }
 
-       //By Apps
+       // Methods to set values
        def lock() {
-               if (lockState != "locked") {
-                       println("the door with id:$id is locked!")
-                       this.lockLatestValue = "locked"
-                       this.lockState = "locked"
-                       this.currentLock = "locked"
-                       sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               action(currentLock, "locked")
        }
 
        def lock(LinkedHashMap metaData) {
-               if (lockState != "locked") {
-                       def task = timers.runAfter(metaData["delay"]) {
-                               println("the door with id:$id is locked!")
-                               this.lockLatestValue = "locked"
-                               this.lockState = "locked"
-                               this.currentLock = "locked"
-                               sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
-                                         displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-                       }
-               }
+               lock()
        }
        
        def unlock() {
-               if (lockState != "unlocked") {
-                       println("the door with id:$id is unlocked!")
-                       this.lockLatestValue = "unlocked"
-                       this.lockState = "unlocked"
-                       this.currentLock = "unlocked"
-                       sendEvent([name: "lock", value: "unlocked", deviceId: this.id, descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               action(currentLock, "unlocked")
        }
 
        def unlock(LinkedHashMap metaData) {
-               if (lockState != "unlocked") {
-                       def task = timers.runAfter(metaData["delay"]) {
-                               println("the door with id:$id is locked!")
-                               this.lockLatestValue = "unlocked"
-                               this.lockState = "unlocked"
-                               this.currentLock = "unlocked"
-                               sendEvent([name: "lock", value: "unlocked", deviceId: this.id, descriptionText: "",
-                                         displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])                             
-                       }
-               }
+               unlock()
        }
 
-       //By Model Checker
-       def setValue(String value) {
-               println("the door with id:$id is $value!")
-               this.lockLatestValue = value
-               this.lockState = value
-               this.currentLock = value
-       }
-       
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "lock") {
-                       return lockState
+       def action(StringBuilder variable, String newValue) {
+               if (!variable.toString().equals(newValue)) {
+                       String tmpID = id.toString()
+                       variable.replace(0, variable.length(), newValue)
+                       println("Lock with id:$tmpID is changed to $newValue!")
+                       sendEvent([name: "lock", value: newValue, deviceId: tmpID, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "lock") {
-                       return lockLatestValue
-               }
+       // Methods to return values
+       def getCurrentLock() {
+               return currentLock.toString()
        }
+
 }
index ad297ab..d65e3f6 100644 (file)
 //Create a class for lock device
 package Lock
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-public class Locks{
-       int deviceNumbers       
-       List locks      
-       def sendEvent   
-       def timers
+public class Locks extends SmartThing {
+       List locks = new ArrayList()
 
-       //When we have only one device
-       private String id = "lockID0"
-       private String label = "lock0"
-       private String displayName = "lock0"
-       private String lockState = "locked"
-       private String currentLock = "locked"
-       private String lockLatestValue = "locked"
+       Locks(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               thermostats = smartThings
 
-       Locks(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent
-               this.timers = new SimulatedTimer()
-               this.deviceNumbers = deviceNumbers
-               this.locks = []
+               // Initialization
+               StringBuilder id = new StringBuilder("lockID0")
+               StringBuilder label = new StringBuilder("lock")
+               StringBuilder displayName = new StringBuilder("lock0")
+               StringBuilder lock = new StringBuilder()
 
-               if (init) {
-                       this.lockState = "locked"
-                       this.currentLock = "locked"
-                       this.lockLatestValue = "locked"
-               } else {
-                       this.lockState = "unlocked"
-                       this.currentLock = "unlocked"
-                       this.lockLatestValue = "unlocked"
-               }
-               locks.add(new Lock(sendEvent,id, label, displayName, this.lockState, this.lockLatestValue))
+               if (init)
+                       lock.append("locked")
+               else
+                       lock.append("unlocked")
+
+               locks.add(new Lock(sendEvent,id, label, displayName, lock))
        }
 
-       //By Apps
+       // Methods to set values
        def lock() {
-               if (lockState != "locked") {
-                       //lockLatestValue = lockState
-                       lockLatestValue = "locked"
-                       lockState = "locked"
-                       currentLock = "locked"
-                       locks[0].lock()
-               }
+               lock[0].lock()
        }
 
        def lock(LinkedHashMap metaData) {
-               if (lockState != "locked") {
-                       def task = timers.runAfter(metaData["delay"]) {
-                               //lockLatestValue = lockState
-                               lockLatestValue = "locked"
-                               lockState = "locked"
-                               currentLock = "locked"
-                               locks[0].lock()
-                       }
-               }
+               lock()
        }
 
        def unlock() {
-               if (lockState != "unlocked") {
-                       //lockLatestValue = lockState
-                       lockLatestValue = "unlocked"
-                       lockState = "unlocked"
-                       currentLock = "unlocked"
-                       locks[0].unlock()
-               }
+               lock[0].unlock()
        }
 
 
        def unlock(LinkedHashMap metaData) {
-               if (lockState != "unlocked") {
-                       def task = timers.runAfter(metaData["delay"]) {
-                               //lockLatestValue = lockState
-                               lockLatestValue = "unlocked"
-                               lockState = "unlocked"
-                               currentLock = "unlocked"
-                               locks[0].unlock()
-                       }
-               }
-       }
-
-       //Methods for closures
-       def count(Closure Input) {
-               locks.count(Input)
-       }
-       def size() {
-               locks.size()
-       }
-       def each(Closure Input) {
-               locks.each(Input)
-       }
-       def find(Closure Input) {
-               locks.find(Input)
-       }
-       def sort(Closure Input) {
-               locks.sort(Input)
-       }
-       def collect(Closure Input) {
-               locks.collect(Input)
-       }
-
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"] != locks[0].lockState) {
-                       locks[0].setValue(eventDataMap["value"])
-                       this.lockState = locks[0].lockState
-                       this.currentLock = locks[0].lockState
-                       this.lockLatestValue = locks[0].lockLatestValue
-                       sendEvent(eventDataMap)
-               }
-       }
-
-       def currentValue(String deviceFeature) {
-               locks[0].currentValue(deviceFeature)
-       }
-
-       def latestValue(String deviceFeature) {
-               locks[0].latestValue(deviceFeature)
+               unlock()
        }
 
-       def getAt(int ix) {
-               locks[ix]
+       // Methods to return values
+       def getCurrentLock() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(locks[0].getCurrentLock())
+               return tmpValues
        }
 }
 
index f78bbec..4f9e4a9 100644 (file)
@@ -1,17 +1,37 @@
 //Create a class for mobile presence
 package MobilePresence
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-public class MobilePresence {
-       private String id
-       private String label
-       private String displayName
-       private String deviceNetworkId
+public class MobilePresence extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with string values
+       StringBuilder deviceNetworkId = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+       
 
-       MobilePresence(String id, String label, String displayName, String deviceNetworkId) {
+       MobilePresence(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder deviceNetworkId) {
+               deviceValuesMap = deviceValueSmartThing
+               deviceIntValuesMap = deviceIntValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+               
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
                this.deviceNetworkId = deviceNetworkId
+
+               deviceValuesMap.put("deviceNetworkId", deviceNetworkId)
+       }
+
+       // Methods to return values
+       def getDeviceNetworkId() {
+               return deviceNetworkId.toString()
        }
 }
index a462b9f..2cea988 100644 (file)
@@ -1,50 +1,27 @@
 //Create a class for mobile presence
 package MobilePresence
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-public class MobilePresences {
-       private int deviceNumbers
-       private List mobilePresences
-       private String deviceNetworkId
-       def sendEvent
-
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "mobilePresenceID0"
-       private String label = "mobilePresence0"
-       private String displayName = "mobilePresence0"
+public class MobilePresences extends SmartThings {
+       List mobilePresences = new ArrayList()
        
-               
-       MobilePresences(Closure sendEvent, int deviceNumbers) {
-               this.sendEvent = sendEvent              
-               this.deviceNumbers = deviceNumbers
-               this.mobilePresences = []
-               this.deviceNetworkId = "mobile0"
+       MobilePresences(Closure sendEvent) {
+               // Only initialize one time since we only have one device for each capability
+               mobilePresences = smartThings
 
-               mobilePresences.add(new MobilePresence(id, label, displayName, deviceNetworkId))
-       }
+               // Initialization
+               StringBuilder id = new StringBuilder("mobileDeviceID0")
+               StringBuilder label = new StringBuilder("mobileDevice")
+               StringBuilder displayName = new StringBuilder("mobileDevice0")
+               StringBuilder deviceNetworkId = new StringBuilder("mobile0")
 
-       //Methods for closures
-       def count(Closure Input) {
-               mobilePresences.count(Input)
-       }
-       def size() {
-               mobilePresences.size()
-       }
-       def each(Closure Input) {
-               mobilePresences.each(Input)
+               mobilePresences.add(new MobilePresence(sendEvent, id, label, displayName, deviceNetworkId))
        }
-       def find(Closure Input) {
-               mobilePresences.find(Input)
-       }
-       def sort(Closure Input) {
-               mobilePresences.sort(Input)
-       }
-       def collect(Closure Input) {
-               mobilePresences.collect(Input)
-       }
-
 
-       def getAt(int ix) {
-               mobilePresences[ix]
+       // Methods to return values
+       def getDeviceNetworkId() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(mobilePresences[0].getDeviceNetworkId())
+               return tmpValues
        }
 }
index aa4e177..f08ea09 100644 (file)
@@ -1,68 +1,24 @@
 //Create a class for momentory switch device
 package Momentary
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
+public class Momentaries extends SmartThings {
+       List momentaries = new ArrayList()
 
-public class Momentaries {
-       int deviceNumbers       
-       List momentaries
-       def sendEvent
+       Momentaries(Closure sendEvent) {
+               // Only initialize one time since we only have one device for each capability
+               momentaries = smartThings
 
-       //If we have only one device
-       private String id = "momentaryID0"
-       private String label = "momentary0"
-       private String displayName = "momentary0"
+               // Initialization
+               StringBuilder id = new StringBuilder("momentaryID0")
+               StringBuilder label = new StringBuilder("momentary")
+               StringBuilder displayName = new StringBuilder("momentary0")
 
-       Momentaries(Closure sendEvent, int deviceNumbers) {
-               this.sendEvent = sendEvent
-               this.deviceNumbers = deviceNumbers
-               this.momentaries = []
-               
-               /*def init = Verify.getBoolean()
-               if (init) {
-                       this.doorState = "closed"
-                       this.doorLatestValue = "closed"
-               } else {
-                       this.doorState = "open"
-                       this.doorLatestValue = "open"
-               }*/
                momentaries.add(new Momentary(sendEvent, id, label, displayName))
        }
 
-       //Methods for closures
-       def count(Closure Input) {
-               momentaries.count(Input)
-       }
-       def size() {
-               momentaries.size()
-       }
-       def each(Closure Input) {
-               momentaries.each(Input)
-       }
-       def find(Closure Input) {
-               momentaries.find(Input)
-       }
-       def sort(Closure Input) {
-               momentaries.sort(Input)
-       }
-       def collect(Closure Input) {
-               momentaries.collect(Input)
-       }
-
-       //By Apps
+       // Methods to set values
        def push() {
                momentaries[0].push()
        }
-
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               momentaries[0].setValue(eventDataMap["value"])
-               sendEvent(eventDataMap)
-       }
-
-       def getAt(int ix) {
-               momentaries[ix]
-       }
 }
index 6b9f0e0..4e72815 100644 (file)
@@ -1,31 +1,29 @@
 //Create a class for momentory switch device
 package Momentary
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-public class Momentary {
-       private String id
-       private String label
-       private String displayName
-       def sendEvent   
-       
+public class Momentary extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
 
-       Momentary(Closure sendEvent, String id, String label, String displayName) {
-               this.sendEvent = sendEvent
+       Momentary(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName) {
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
        }
 
-       //By Apps
+       // Methods to set values
        def push() {
                println("the momentary switch with id:$id is pushed!")
-               sendEvent([name: "momentary", value: "pushed", deviceId: this.id, descriptionText: "",
+               sendEvent([name: "momentary", value: "pushed", deviceId: id, descriptionText: "",
                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-       }
-
-       //By Model Checker
-       def setValue(String value) {
-               println("the momentary switch with id:$id is pushed!")
-       }
-       
+       }       
 }
index 931069b..85b5618 100644 (file)
@@ -1,90 +1,40 @@
-//Create a class for presence sensor
+//Create a class for motion sensor
 package MotionSensor
-import Timer.SimulatedTimer
-
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
-public class MotionSensor {
-       private String id
-       private String label
-       private String displayName
-       private String motion
-       private String currentMotion
-       private String motionLatestValue
-
-       MotionSensor(String id, String label, String displayName, String motion, String motionLatestValue) {
+import SmartThing.SmartThing
+
+public class MotionSensor extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with string values
+       StringBuilder currentMotion = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+       // Possible values for eventsSince method
+       List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
+
+       MotionSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentMotion) {
+               deviceValuesMap = deviceValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+               possibleValuesSmartThings = possibleValues
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.motion = motion
-               this.currentMotion = motion
-               this.motionLatestValue = motionLatestValue
-       }
-
-       def setValue(String value) {
-               println("the motion sensor with id:$id is triggered to $value!")
-               this.motionLatestValue = value
-               this.motion = value
-               this.currentMotion = value
-       }
-
-       def statesSince() {
-               eventsSince()
-       }
-
-       def eventsSince() {
-               def evtActive = [[name: "motion", value: "active", deviceId: "motionSensorID0", descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def evtInactive = [[name: "motion", value: "inactive", deviceId: "motionSensorID0", descriptionText: "",
-                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def init = Verify.getInt(0,4)
-               def evtToSend = []
-               if (init == 0) {//return empty set
-                       return evtToSend
-               } else if (init == 1) {//send one active event
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 2) {//send two active events
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 3) {//send one inactive event
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 4) {//send two inactive events
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               }
-       }
-
-       def currentState(String deviceFeature) {
-               currentValue(deviceFeature)
-       }
+               this.currentMotion = currentMotion
+               possibleValues.add("active")
+               possibleValues.add("inactive")
 
-       
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "motion") {
-                       return motion
-               }
+               deviceValuesMap.put("motion", currentMotion)
        }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "motion") {
-                       return motionLatestValue
-               }
+       // Methods to return values
+       def getCurrentMotion() {
+               return currentMotion.toString()
        }
 }
index 5c03ebf..194fc3f 100644 (file)
@@ -1,93 +1,32 @@
-//Create a class for presence sensor
+//Create a class for motion sensor
 package MotionSensor
-import Timer.SimulatedTimer
-
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
-public class MotionSensors {
-       private int deviceNumbers
-       private List motionSensors
-       def sendEvent
-
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "motionSensorID0"
-       private String label = "motionSensor0"
-       private String displayName = "motionSensor0"
-       private String motion = "inactive"
-       private String currentMotion = "inactive"
-       private String motionLatestValue = "inactive"
+import SmartThing.SmartThings
 
+public class MotionSensors extends SmartThings {
+       List motionSensors = new ArrayList()
                
-       MotionSensors(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent              
-               this.deviceNumbers = deviceNumbers
-               this.motionSensors = []
-
-               if (init) {
-                       this.motion = "inactive"
-                       this.currentMotion = "inactive"
-                       this.motionLatestValue = "inactive"
-               } else {
-                       this.motion = "active"
-                       this.currentMotion = "active"
-                       this.motionLatestValue = "active"
-               }
-               motionSensors.add(new MotionSensor(id, label, displayName, this.motion, this.motionLatestValue))
-       }
+       MotionSensors(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               motionSensors = smartThings
 
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"] != motionSensors[0].motion) {
-                       this.motionLatestValue = eventDataMap["value"]
-                       this.motion = eventDataMap["value"]
-                       this.currentMotion = eventDataMap["value"]
-                       motionSensors[0].setValue(eventDataMap["value"])
-                       sendEvent(eventDataMap)
-               }
-       }
+               // Initialization
+               StringBuilder id = new StringBuilder("motionSensorID0")
+               StringBuilder label = new StringBuilder("motion")
+               StringBuilder displayName = new StringBuilder("motionSensor0")
+               StringBuilder motion = new StringBuilder()
 
-       //Methods for closures
-       def count(Closure Input) {
-               motionSensors.count(Input)
-       }
-       def size() {
-               motionSensors.size()
-       }
-       def each(Closure Input) {
-               motionSensors.each(Input)
-       }
-       def find(Closure Input) {
-               motionSensors.find(Input)
-       }
-       def sort(Closure Input) {
-               motionSensors.sort(Input)
-       }
-       def collect(Closure Input) {
-               motionSensors.collect(Input)
-       }
-       
-       def currentState(String deviceFeature) {
-               currentValue(deviceFeature)
-       }
-
-       def currentValue(String deviceFeature) {
-               motionSensors[0].currentValue(deviceFeature)//It is called if we have only one device
-       }
-
-       def latestValue(String deviceFeature) {
-               motionSensors[0].latestValue(deviceFeature)//It is called if we have only one device
-       }
-
-       def statesSince(String info, Date dateObj) {
-               return motionSensors[0].statesSince()
-       }
+               if (init)
+                       motion.append("inactive")
+               else
+                       motion.append("active")
 
-       def eventsSince(Date dateObj) {
-               return motionSensors[0].statesSince()
+               motionSensors.add(new MotionSensor(sendEvent, id, label, displayName, motion))
        }
 
-       def getAt(int ix) {
-               motionSensors[ix]
+       // Methods to return values
+       def getCurrentMotion() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(motionSensors[0].getCurrentMotion())
+               return tmpValues
        }
 }
index 67db554..17f56c9 100644 (file)
 //Create a class for music player
 package MusicPlayer
-import Timer.SimulatedTimer
-
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
-public class MusicPlayer {
-       private String id
-       private String label
-       private String displayName
-       private int level
-       private String mute
-       private String status
-       private int trackNumber
-       private String trackData
-       private String trackDescription
-       def sendEvent
+import SmartThing.SmartThing
+
+public class MusicPlayer extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with numberical values
+       MutableInteger currentLevel = new MutableInteger()
+       // Features with string values
+       StringBuilder currentMute = new StringBuilder()
+       StringBuilder currentStatus = new StringBuilder()
+       StringBuilder currentTrackData = new StringBuilder()
+       StringBuilder currentTrackDescription = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+       HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+       // Possible values for eventsSince method
+       List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
        
-       MusicPlayer(Closure sendEvent, String id, String label, String displayName, int level, String mute, String status, int trackNumber, String trackData, String trackDescription) {
-               this.sendEvent = sendEvent
+       MusicPlayer(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentLevel, 
+                   StringBuilder currentMute, StringBuilder currentStatus, StringBuilder currentTrackData, StringBuilder currentTrackDescription) {
+               deviceValuesMap = deviceValueSmartThing
+               deviceIntValuesMap = deviceIntValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+               possibleValuesSmartThings = possibleValues
+
+               // Initialization
                this.id = id
                this.label = label
-               this.displayName = displayName
-               this.level = level
-               this.mute = mute
-               this.status = status
-               this.trackNumber = trackNumber
-               this.trackData = trackData
-               this.trackDescription = trackDescription
-       }
-
-       //By model checker
-       def setValue(String value, String name) {
-               if ((name == "status") && (value != this.status)) {
-                       this.status = value
-                       println("the status of the music player with id:$id is changed to $value!")
-               } else if ((name == "level") && (value != this.level)) {
-                       this.level = value.toInteger()
-                       println("the level sound of the music player with id:$id is changed to $value!")
-               } else if ((name == "trackDescription") && (value != this.trackDescription)) {
-                       this.trackDescription = value
-                       println("the trackDescription of the music player with id:$id is changed to $value!")
-               } else if ((name == "trackData") && (value != this.trackData)) {
-                       this.trackData = value
-                       println("the trackData of the music player with id:$id is changed to $value!")
-               } else if ((name == "mute") && (value != this.mute)) {
-                       this.mute = value
-                       println("the mute state of the music player with id:$id is changed to $value!")
-               }
+               this.currentLevel = currentLevel
+               this.currentMute = currentMute
+               this.currentStatus = currentStatus
+               this.currentTrackData = currentTrackData
+               this.currentTrackDescription = currentTrackDescription
+               possibleValues.add("on")
+               possibleValues.add("off")
+
+               deviceValuesMap.put("status", currentStatus)
+               deviceValuesMap.put("playpause", currentStatus)
+               deviceValuesMap.put("trackDescription", currentTrackDescription)
+               deviceValuesMap.put("mute", currentMute)
+               deviceValuesMap.put("trackData", currentTrackData)
+               deviceIntValuesMap.put("level", currentLevel)
        }
 
-       //methods
+       // Methods to set values
        def on(LinkedHashMap metaData) {
                on()
        }
+
        def on() {
-               if (status != "on") {
-                       println("the music player with id:$id is on!")
-                       this.status = "on"
-                       sendEvent([name: "status", value: "on", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               action(currentStatus, "on", "status")
        }
+
        def off(LinkedHashMap metaData) {
                off()
        }
+
        def off() {
-               if (status != "off") {
-                       println("the music player with id:$id is off!")
-                       this.status = "off"
-                       sendEvent([name: "status", value: "off", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               action(currentStatus, "off", "status")
        }
+
        def mute(LinkedHashMap metaData) {
                mute()
        }
+
        def mute() {
-               if (mute != "muted") {
-                       println("the music player with id:$id is muted!")
-                       this.mute = "muted"
-                       sendEvent([name: "mute", value: "muted", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               action(currentMute, "muted", "mute")
+       }
+
+       def unmute(LinkedHashMap metaData) {
+               unmute()
        }
+
+       def unmute() {
+               action(currentMute, "unmuted", "mute")
+       }
+
        def nextTrack(LinkedHashMap metaData) {
                nextTrack()
        }
+
        def nextTrack() {
-               trackNumber = trackNumber+1
-               def trackPlaying = trackData
-               println("the $trackPlaying is selected!")
-               if (status != "play") {
-                       this.status = "play"
-                       sendEvent([name: "status", value: "play", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
-               sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               sendEvent([name: "trackData", value: "someTrack", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               play()
+               musicChangeEvents()
        }
+
        def pause(LinkedHashMap metaData) {
                pause()
        }
+
        def pause() {
-               if (status != "pause") {
-                       println("the music player with id:$id is paused!")
-                       this.status = "pause"
-                       sendEvent([name: "status", value: "pause", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               action(currentStatus, "pause", "status")
        }
+
        def play(LinkedHashMap metaData) {
                play()
        }
+
        def play() {
-               if (status != "play") {
-                       println("the music player with id:$id is starting to play!")
-                       this.status = "play"
-                       sendEvent([name: "status", value: "play", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               action(currentStatus, "play", "status")
        }
+
        def playTrack(LinkedHashMap metaData) {
                playTrack()
        }
+
        def playTrack(String trackToPlay) {
-               def trackPlaying = trackData
-               println("the $trackPlaying is selected to play!")
-               if (status != "play") {         
-                       this.status = "play"
-                       sendEvent([name: "status", value: "play", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
-               sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               sendEvent([name: "trackData", value: "someTrack", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               play()
+               musicChangeEvents()
        }
+
        def previousTrack(LinkedHashMap metaData) {
                previousTrack()
        }
+
        def previousTrack() {
-               if (trackNumber != 1)
-                       trackNumber = trackNumber-1
-               def trackPlaying = trackData
-               println("the $trackPlaying is selected!")
-               if (status != "playing") {
-                       this.status = "playing"
-                       sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
-               sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               sendEvent([name: "trackData", value: "someTrack", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               play()
+               musicChangeEvents()
        }
-       /*def restoreTrack(String trackToRestore) {
-               musicPlayers*.restoreTrack(trackToRestore)
-       }*/
+       
        def resumeTrack(LinkedHashMap metaData) {
                resumeTrack()
        }
+
        def resumeTrack(String trackToResume) {
-               def trackPlaying = trackData
-               println("the $trackPlaying is resumed!")
-               if (status != "play") {
-                       this.status = "play"
-                       sendEvent([name: "status", value: "play", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               play()
+       }
+
+       def restoreTrack(LinkedHashMap metaData) {
+               restoreTrack()
+       }
+
+       def restoreTrack(String trackToRestore) {
+               play()
+               musicChangeEvents()
        }
+
        def setLevel(LinkedHashMap metaData) {
                setLevel()
        }
+
        def setLevel(int level) {
-               if (level != this.level) {
-                       this.level = level
-                       println("the level of sound is changed to $level!")
-                       sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+               action(currentLevel, level, "level")
        }
+
        def setTrack(LinkedHashMap metaData) {
                setTrack()
        }
+
        def setTrack(String trackToSet) {
-               def trackPlaying = trackData
-               println("the $trackPlaying is set!")
-               if (status != "play") {
-                       this.status = "play"
-                       sendEvent([name: "status", value: "play", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
-               sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               sendEvent([name: "trackData", value: "someTrack", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               play()
+               
        }
+
        def stop(LinkedHashMap metaData) {
                stop()
        }
+
        def stop() {
-               if (status != "stop") {
-                       println("the music player with id:$id is stop!")
-                       this.status = "stop"
-                       sendEvent([name: "status", value: "stop", deviceId: this.id, descriptionText: "",
+               action(currentStatus, "stop", "status")
+       }
+
+       def action(StringBuilder variable, String newValue, String feature) {
+               if (!variable.toString().equals(newValue)) {
+                       String tmpID = id.toString()
+                       variable.replace(0, variable.length(), newValue)
+                       println("$feature of the music player with id:$tmpID is changed to $newValue!")
+                       sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
-       def statesSince(String info, Date dateObj) {
-               statesSince()
-       }
-       def statesSince() {
-               eventsSince()
-       }
-       def eventsSince(Date dateObj) {
-               eventsSince()
-       }
-
-       def eventsSince() {
-               def evtActive = [[name: "status", value: "on", deviceId: "musicPlayerID0", descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def evtInactive = [[name: "status", value: "off", deviceId: "musicPlayerID0", descriptionText: "",
-                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def init = Verify.getInt(0,4)
-               def evtToSend = []
-               if (init == 0) {//return empty set
-                       return evtToSend
-               } else if (init == 1) {//send one active event
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 2) {//send two active events
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 3) {//send one inactive event
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 4) {//send two inactive events
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
+
+       def action(MutableInteger variable, int newValue, String feature) {
+               if (!variable.getValue().equals(newValue)) {
+                       String tmpID = id.toString()
+                       variable.setValue(newValue)
+                       println("$feature for the thermostat with id:$tmpID is changed to $newValue!")
+                       sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
-       def playText(LinkedHashMap metaData) {
-               playText()
+
+       def musicChangeEvents() {
+               sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: id.toString(), descriptionText: "",
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               sendEvent([name: "trackData", value: "someTrack", deviceId: id.toString(), descriptionText: "",
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
        }
-       def playText(String text) {
-               println("the music player with id:$id is playing the text:$text!")
-               if (status != "play") {
-                       this.status = "play"
-                       sendEvent([name: "status", value: "play", deviceId: this.id, descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
+
+       // Methods to return values
+       def getCurrentLevel() {
+               return currentLevel.getValue()
        }
 
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "playpause") {
-                       return status
-               }
+       def getCurrentMute() {
+               return currentMute.toString()
+       }
+       
+       def getCurrentStatus() {
+               return currentStatus.toString()
        }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "playpause") {
-                       return status
-               }
+       def getCurrentTrackData() {
+               return currentTrackData.toString()
+       }
+
+       def getCurrentTrackDescription() {
+               return currentTrackDescription.toString()
        }
 }
index 92f6c55..14c8ecb 100644 (file)
 //Create a class for music player
 package MusicPlayer
-import Timer.SimulatedTimer
-
-public class MusicPlayers {
-       private int deviceNumbers
-       private List musicPlayers
-       def sendEvent
-
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "musicPlayerID0"
-       private String label = "musicPlayer0"
-       private String displayName = "musicPlayer0"
-       private int level = 20
-       private int duration = 10
-       private String mute = "unmuted"
-       private String status = "pause"
-       private int trackNumber = 1
-       private String trackData = "someTrack"
-       private String trackDescription = "someDescriptions"
+import SmartThing.SmartThings
 
+public class MusicPlayers extends SmartThings {
+       List musicPlayers = new ArrayList()
        
-               
-       MusicPlayers(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent
-               this.deviceNumbers = deviceNumbers
-               this.musicPlayers = []
-               
+       MusicPlayers(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               musicPlayers = smartThings
+
+               // Initialization
+               StringBuilder id = new StringBuilder("musicPlayerID0")
+               StringBuilder label = new StringBuilder("status")
+               StringBuilder displayName = new StringBuilder("musicPlayer0")
+               StringBuilder mute = new StringBuilder()
+               StringBuilder status = new StringBuilder()
+               StringBuilder trackData = new StringBuilder()
+               StringBuilder trackDescription = new StringBuilder()
+               MutableInteger level = new MutableInteger()
+
                if (init) {
-                       this.level = 20
-                       this.duration = 10
-                       this.mute = "unmuted"
-                       this.status = "paused"
-                       this.trackNumber = 1
-                       this.trackData = "someTrack"
-                       this.trackDescription = "someDescriptions"
+                       level.setValue(20)
+                       mute.append("unmuted")
+                       status.append("paused")
+                       trackData.append("someTrack")
+                       trackDescription.append("someDescriptions")
                } else {
-                       this.level = 30
-                       this.duration = 20
-                       this.mute = "muted"
-                       this.status = "playing"
-                       this.trackNumber = 2
-                       this.trackData = "someOtherTrack"
-                       this.trackDescription = "someOtherDescriptions"
-               }
-               musicPlayers.add(new MusicPlayer(sendEvent, id, label, displayName, this.level, this.mute, this.status, this.trackNumber, this.trackData, this.trackDescription))
-       }
-
-       //By model checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["name"] == "status") {
-                       if (eventDataMap["value"] != musicPlayers[0].status) {
-                               this.status = eventDataMap["value"]
-                               musicPlayers[0].setValue(eventDataMap["value"], "status")
-                               sendEvent(eventDataMap)
-                       }       
-               } else if (eventDataMap["name"] == "level") {
-                       if (eventDataMap["value"].toInteger() != musicPlayers[0].level) {
-                               this.level = eventDataMap["value"].toInteger()
-                               musicPlayers[0].setValue(eventDataMap["value"], "level")
-                               sendEvent(eventDataMap)
-                       }
-               } else if (eventDataMap["name"] == "trackDescription") {
-                       if (eventDataMap["value"] != musicPlayers[0].trackDescription) {
-                               this.trackDescription = eventDataMap["value"]
-                               musicPlayers[0].setValue(eventDataMap["value"], "trackDescription")
-                               sendEvent(eventDataMap)
-                       }
-               } else if (eventDataMap["name"] == "trackData") {
-                       if (eventDataMap["value"] != musicPlayers[0].trackData) {
-                               this.trackData = eventDataMap["value"]
-                               musicPlayers[0].setValue(eventDataMap["value"], "trackData")                            
-                               sendEvent(eventDataMap)
-                       }
-               } else if (eventDataMap["name"] == "mute") {
-                       if (eventDataMap["value"] != musicPlayers[0].mute) {
-                               this.mute = eventDataMap["value"]
-                               musicPlayers[0].setValue(eventDataMap["value"], "mute")
-                               sendEvent(eventDataMap)
-                       }
+                       level.setValue(30)
+                       mute.append("muted")
+                       status.append("play")
+                       trackData.append("someTrack")
+                       trackDescription.append("someDescriptions")
                }
-       }
 
-       //Methods for closures
-       def count(Closure Input) {
-               musicPlayers.count(Input)
-       }
-       def size() {
-               musicPlayers.size()
-       }
-       def each(Closure Input) {
-               musicPlayers.each(Input)
-       }
-       def find(Closure Input) {
-               musicPlayers.find(Input)
-       }
-       def sort(Closure Input) {
-               musicPlayers.sort(Input)
-       }
-       def collect(Closure Input) {
-               musicPlayers.collect(Input)
+               musicPlayers.add(new MusicPlayer(sendEvent, id, label, displayName, level, mute, status, trackData, trackDescription))
        }
 
-       //methods
+       // Methods to set values
        def on(LinkedHashMap metaData) {
                on()
        }
+
        def on() {
-               if (status != "on") {
-                       this.status = "on"
-                       musicPlayers[0].on()
-               }
+               musicPlayers[0].on()
        }
+
        def off(LinkedHashMap metaData) {
                off()
        }
+
        def off() {
-               if (status != "off") {
-                       this.status = "off"
-                       musicPlayers[0].off()
-               }
+               musicPlayers[0].off()
        }
+
        def mute(LinkedHashMap metaData) {
                mute()
        }
+
        def mute() {
-               if (mute != "muted") {
-                       this.mute = "muted"
-                       musicPlayers[0].mute()
-               }
+               musicPlayers[0].mute()
        }
+
+       def unmute(LinkedHashMap metaData) {
+               unmute()
+       }
+
+       def unmute() {
+               musicPlayers[0].unmute()
+       }
+
        def nextTrack(LinkedHashMap metaData) {
                nextTrack()
        }
+
        def nextTrack() {
-               if (status != "play") {
-                       this.status = "play"
-               }
-               this.trackNumber = this.trackNumber+1
                musicPlayers[0].nextTrack()
        }
+
        def pause(LinkedHashMap metaData) {
                pause()
        }
+
        def pause() {
-               if (status != "pause") {
-                       this.status = "pause"
-                       musicPlayers[0].pause()                 
-               }
+               musicPlayers[0].pause()
        }
+
        def play(LinkedHashMap metaData) {
                play()
        }
+
        def play() {
-               if (status != "play") {
-                       this.status = "play"
-                       musicPlayers[0].play()
-               }
+               musicPlayers[0].play()
        }
+
        def playTrack(LinkedHashMap metaData) {
                playTrack("someTrack")
        }
-       def playTrackAndResume(String trackData, int duration) {
-               playTrack(trackData)
-               if (duration != this.duration) {
-                       this.duration = duration
-  &nbs