-//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()
}
}
//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
}
}
//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")
}
}
//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))
}
}
//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()
}
}
//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
}
}
//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
}
}
//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
- }
- }
-
}
//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()
}
}
//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
}
}
//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")
}
}
//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))
}
}
//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()
}
}
//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
}
}
//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
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()
}
}
//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
}
}
//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()
}
}
//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
}
}
//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()
}
}
//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
}
}
//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()
}
}
//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
}
}
//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()
}
}
//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
}
}
public class Event {
private String deviceId
- private String value
+ private Object value
private String linkText
private String displayName
private boolean displayed
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
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()
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
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")
//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
- }
- }
-
}
//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
}
}
//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()
}
}
//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() {
}
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
}
}
//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()
+ }
}
//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()
}
+
}
//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
}
}
//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()
}
}
//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
}
}
//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]
- }
}
//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!")
- }
-
+ }
}
-//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()
}
}
-//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
}
}
//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()
}
}
//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
- }
- }
- def playTrackAndResume(String trackData, int duration, int level) {
- playTrackAndResume(trackData, duration)
- if (level != this.level) {
- this.level = level
- }
- }
- def playSoundAndTrack(String trackData, int duration, int trackNumber, int level) {
- playTrackAndResume(trackData, duration)
- if (level != this.level) {
- this.level = level
- }
- if (trackNumber!= this.trackNumber) {
- this.trackNumber = trackNumber
- }
- }
- def playTrackAtVolume(String trackData, int level) {
- playTrack(trackData)
- if (level != this.level) {
- this.level = level
- }
- }
+
def playTrack(String trackToPlay) {
- if (status != "play") {
- this.status = "play"
- }
musicPlayers[0].playTrack(trackToPlay)
}
+
def previousTrack(LinkedHashMap metaData) {
previousTrack()
}
+
def previousTrack() {
- if (status != "play") {
- this.status = "play"
- }
- if (this.trackNumber != 1)
- this.trackNumber = this.trackNumber-1
musicPlayers[0].previousTrack()
}
+
def restoreTrack(LinkedHashMap metaData) {
restoreTrack()
}
+
def restoreTrack(String trackToRestore) {
musicPlayers[0].restoreTrack(trackToRestore)
}
+
def resumeTrack(LinkedHashMap metaData) {
resumeTrack()
}
+
def resumeTrack(String trackToResume) {
- if (status != "play") {
- this.status = "play"
- }
musicPlayers[0].resumeTrack(trackToResume)
}
+
def setLevel(LinkedHashMap metaData) {
setLevel()
}
+
def setLevel(int level) {
- if (level != this.level) {
- this.level = level
- musicPlayers[0].setLevel(level)
- }
+ musicPlayers[0].setLevel(level)
}
+
def setTrack(LinkedHashMap metaData) {
setTrack()
}
+
def setTrack(String trackToSet) {
- if (status != "play") {
- this.status = "play"
- }
musicPlayers[0].setTrack(trackToSet)
}
+
def stop(LinkedHashMap metaData) {
stop()
}
+
def stop() {
- if (status != "stop") {
- this.status = "stop"
- musicPlayers[0].stop()
- }
- }
- def statesSince(String info, Date dateObj, LinkedHashMap map) {
- return musicPlayers[0].statesSince()
- }
- def playText(LinkedHashMap metaData) {
- playText()
+ musicPlayers[0].stop()
}
- def playText(String text) {
- if (status != "play") {
- this.status = "play"
- }
- musicPlayers[0].playText(text)
+
+ // Methods to return values
+ def getCurrentLevel() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(musicPlayers[0].getCurrentLevel())
+ return tmpValues
}
- def currentValue(String deviceFeature) {
- musicPlayers[0].currentValue(deviceFeature)
+ def getCurrentMute() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(musicPlayers[0].getCurrentMute())
+ return tmpValues
+ }
+
+ def getCurrentStatus() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(musicPlayers[0].getCurrentStatus())
+ return tmpValues
}
- def latestValue(String deviceFeature) {
- musicPlayers[0].latestValue(deviceFeature)
+ def getCurrentTrackData() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(musicPlayers[0].getCurrentTrackData())
+ return tmpValues
}
- def getAt(int ix) {
- musicPlayers[ix]
+ def getCurrentTrackDescription() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(musicPlayers[0].getCurrentTrackDescription())
+ return tmpValues
}
}
//Create a class for Touch sensor
package NfcTouch
+import SmartThing.SmartThing
-public class NfcTouch{
- def sendEvent
- private int isTouched
- private String displayName = "NfcTouch0"
+public class NfcTouch extends SmartThing {
+ // id, label, and display name of the device
+ StringBuilder id = new StringBuilder()
+ StringBuilder label = new StringBuilder()
+ StringBuilder displayName = new StringBuilder()
- NfcTouch(Closure sendEvent, int isTouched) {
- this.sendEvent = sendEvent
- this.isTouched = isTouched
- }
+ NfcTouch(Closure sendEvent) {
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- println("NFC is Touched!")
- this.isTouched = 1 //Do we need this?
- sendEvent(eventDataMap)
+ // Initialization
+ id.append("nfcSensorID0")
+ label.append("nfcSensor")
+ displayName.append("nfcSensor0")
}
}
//Create a class for power meter
package PowerMeter
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
-public class PowerMeter {
- private String id
- private String label
- private String displayName
- private int power
- private int currentPower
+public class PowerMeter 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 currentPower = new MutableInteger()
+ // Maps from features to values
+ HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
- PowerMeter(String id, String label, String displayName, int power) {
+ PowerMeter(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentPower) {
+ deviceIntValuesMap = deviceIntValueSmartThing
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
+
+ // Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.power = power
- }
+ this.currentPower = currentPower
- //By Model Checker
- def setValue(String value) {
- println("the power is changed to $value!")
- this.power = value.toInteger()
- this.currentPower = value.toInteger()
+ deviceIntValuesMap.put("power", currentPower)
}
- def currentValue(String deviceFeature) {
- if (deviceFeature == "power") {
- return power
- }
+ // Methods to return values
+ def getCurrentPower() {
+ return currentPower.getValue()
}
-
- def latestValue(String deviceFeature) {
- if (deviceFeature == "power") {
- return power
- }
- }
-
}
//Create a class for power meter
package PowerMeter
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
-public class PowerMeters {
- private int deviceNumbers
- private List powerMeters
- def sendEvent
+public class PowerMeters extends SmartThings {
+ List powerMeters = new ArrayList()
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private String id = "powerMeterID0"
- private String label = "powerMeter0"
- private String displayName = "powerMeter0"
- private int power = 50
- private int currentPower = 50
+ PowerMeters(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ powerMeters = smartThings
-
- PowerMeters(Closure sendEvent, int deviceNumbers, boolean init) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.powerMeters = []
+ // Initialization
+ StringBuilder id = new StringBuilder("powerMeterID0")
+ StringBuilder label = new StringBuilder("powerMeter")
+ StringBuilder displayName = new StringBuilder("powerMeter0")
+ MutableInteger power = new MutableInteger()
- if (init) {
- this.power = 50
- this.currentPower = 50
- } else {
- this.power = 60
- this.currentPower = 60
- }
- powerMeters.add(new PowerMeter(id, label, displayName, this.power))
- }
-
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["value"].toInteger() != powerMeters[0].power) {
- this.power = eventDataMap["value"].toInteger()
- this.currentPower = eventDataMap["value"].toInteger()
- powerMeters[0].setValue(eventDataMap["value"])
- sendEvent(eventDataMap)
- }
- }
-
- //Methods for closures
- def count(Closure Input) {
- powerMeters.count(Input)
- }
- def size() {
- powerMeters.size()
- }
- def each(Closure Input) {
- powerMeters.each(Input)
- }
- def find(Closure Input) {
- powerMeters.find(Input)
- }
- def sort(Closure Input) {
- powerMeters.sort(Input)
- }
- def collect(Closure Input) {
- powerMeters.collect(Input)
- }
-
-
- def currentValue(String deviceFeature) {
- powerMeters[0].currentValue(deviceFeature)//It is called if we have only one device
- }
+ if (init)
+ power.setValue(50)
+ else
+ power.setValue(60)
- def latestValue(String deviceFeature) {
- powerMeters[0].latestValue(deviceFeature)//It is called if we have only one device
+ powerMeters.add(new PowerMeter(sendEvent, id, label, displayName, power))
}
- def getAt(int ix) {
- powerMeters[ix]
+ // Methods to return values
+ def getCurrentPower() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(powerMeters[0].getCurrentPower())
+ return tmpValues
}
}
-//Create a class for presence sensor
+// Create a class for presence sensor
package PresenceSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
+public class PresenceSensor 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>()
+ // Possible values for eventsSince method
+ List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
-public class PresenceSensor {
- private String id
- private String label
- private String displayName
- private String presence
- private String currentPresence
- private String presenceLatestValue
+ PresenceSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentPresence) {
+ deviceValuesMap = deviceValueSmartThing
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
+ possibleValuesSmartThings = possibleValues
- PresenceSensor(String id, String label, String displayName, String presence, String presenceLatestValue) {
+ // Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.presence = presence
- this.currentPresence = presence
- this.presenceLatestValue = presenceLatestValue
- }
+ this.currentPresence = currentPresence
+ possibleValues.add("present")
+ possibleValues.add("not present")
- def setValue(String value) {
- println("the presence sensor with id:$id is triggered to $value!")
- this.presenceLatestValue = value
- this.presence = value
- this.currentPresence = value
- }
-
- def statesSince() {
- eventsSince()
- }
-
- def statesSince(String info, Date dateObj) {
- statesSince()
- }
-
- def eventsSince(Date dateObj) {
- eventsSince()
- }
-
- def eventsSince() {
- def evtActive = [[name: "presence", value: "present", deviceId: "motionSensorID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
- def evtInactive = [[name: "presence", value: "not present", 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) {
- return [rawDateCreated: [time: System.currentTimeMillis()]]
- }
-
- def currentValue(String deviceFeature) {
- if (deviceFeature == "presence") {
- return presence
- }
+ deviceValuesMap.put("presence", currentPresence)
}
- def latestValue(String deviceFeature) {
- if (deviceFeature == "presence") {
- return presenceLatestValue
- }
+ // Methods to return values
+ def getCurrentPresence() {
+ return currentPresence.toString()
}
}
-//Create a class for presence sensor
+// Create a class for presence sensor
package PresenceSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
-public class PresenceSensors {
- private int deviceNumbers
- private List presenceSensors
- def sendEvent
+public class PresenceSensors extends SmartThings {
+ List presenceSensors = new ArrayList()
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private String id = "presenceSensorID0"
- private String label = "presenceSensor0"
- private String displayName = "presenceSensor0"
- private String presence = "not present"
- private String currentPresence = "not present"
- private String presenceLatestValue = "not present"
+ PresenceSensors(Closure sendEvent, boolean init) {
+ presenceSensors = smartThings
-
- PresenceSensors(Closure sendEvent, int deviceNumbers, boolean init) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.presenceSensors = []
+ // Initialization
+ StringBuilder id = new StringBuilder("presenceSensorID0")
+ StringBuilder label = new StringBuilder("presence")
+ StringBuilder displayName = new StringBuilder("presenceSensor0")
+ 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"
- }
- presenceSensors.add(new PresenceSensor(id, label, displayName, this.presence, this.presenceLatestValue))
- }
-
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["value"] != presenceSensors[0].presence) {
- this.presenceLatestValue = eventDataMap["value"]
- this.presence = eventDataMap["value"]
- this.currentPresence = eventDataMap["value"]
- presenceSensors[0].setValue(eventDataMap["value"])
- sendEvent(eventDataMap)
- }
- }
-
- //Methods for closures
- def count(Closure Input) {
- presenceSensors.count(Input)
- }
- def size() {
- presenceSensors.size()
- }
- def each(Closure Input) {
- presenceSensors.each(Input)
- }
- def find(Closure Input) {
- presenceSensors.find(Input)
- }
- def sort(Closure Input) {
- presenceSensors.sort(Input)
- }
- def collect(Closure Input) {
- presenceSensors.collect(Input)
- }
-
- def currentState(String deviceFeature) {
- presenceSensors[0].currentState(deviceFeature)
- }
-
- def currentValue(String deviceFeature) {
- presenceSensors[0].currentValue(deviceFeature)//It is called if we have only one device
- }
-
- def latestValue(String deviceFeature) {
- presenceSensors[0].latestValue(deviceFeature)//It is called if we have only one device
- }
-
- def statesSince(String info, Date dateObj) {
- return presenceSensors[0].statesSince()
- }
+ if (init)
+ presence.append("not present")
+ else
+ presence.append("present")
- def eventsSince(Date dateObj) {
- return presenceSensors[0].statesSince()
+ presenceSensors.add(new PresenceSensor(sendEvent, id, label, displayName, presence))
}
- def getAt(int ix) {
- presenceSensors[ix]
+ // Methods to return values
+ def getCurrentPresence() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(presenceSensors[0].getCurrentPresence())
+ return tmpValues
}
}
//Create a class for relative humidity measurement
package RelativeHumidityMeasurement
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
+public class RelativeHumidityMeasurement 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 currentHumidity = new MutableInteger()
+ // Maps from features to values
+ HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
-public class RelativeHumidityMeasurement {
- private String id
- private String label
- private String displayName
- private int humidity
- private int currentHumidity
+ RelativeHumidityMeasurement(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentHumidity) {
+ deviceIntValuesMap = deviceIntValueSmartThing
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
- RelativeHumidityMeasurement(String id, String label, String displayName, int humidity) {
+ // Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.humidity = humidity
- }
-
- def eventsSince() {
- def evtHumidity = [[name: "humidity", value: this.humidity.toString(), deviceId: "humidityMeasurementID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
- def init = Verify.getInt(0,1)
- def evtToSend = []
- if (init == 0) {//return empty set
- return evtToSend
- } else if (init == 1) {//send one open event
- evtHumidity.each{
- evtToSend.add(it)
- }
- return evtToSend
- }
- }
-
- //By Model Checker
- def setValue(String value) {
- println("the humidity is changed to $value!")
- this.humidity = value.toInteger()
- this.currentHumidity = value.toInteger()
- }
+ this.currentHumidity = currentHumidity
- def currentValue(String deviceFeature) {
- if (deviceFeature == "humidity") {
- return humidity
- }
+ deviceIntValuesMap.put("humidity", currentHumidity)
}
- def latestValue(String deviceFeature) {
- if (deviceFeature == "humidity") {
- return humidity
- }
+ // Methods to return values
+ def getCurrentHumidity() {
+ return currentHumidity.getValue()
}
}
//Create a class for relative humidity measurement
package RelativeHumidityMeasurement
-import Timer.SimulatedTimer
-
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
-public class RelativeHumidityMeasurements {
- private int deviceNumbers
- private List humidityMeasurements
- def sendEvent
-
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private String id = "humidityMeasurementID0"
- private String label = "humidityMeasurement0"
- private String displayName = "humidityMeasurement0"
- private int humidity = 50
- private int currentHumidity = 50
-
-
- RelativeHumidityMeasurements(Closure sendEvent, int deviceNumbers, boolean init) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.humidityMeasurements = []
-
- if (init) {
- this.humidity = 50
- this.currentHumidity = 50
- } else {
- this.humidity = 60
- this.currentHumidity = 60
- }
- humidityMeasurements.add(new RelativeHumidityMeasurement(id, label, displayName, this.humidity))
- }
-
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["value"].toInteger() != humidityMeasurements[0].humidity) {
- this.humidity = eventDataMap["value"].toInteger()
- this.currentHumidity = eventDataMap["value"].toInteger()
- humidityMeasurements[0].setValue(eventDataMap["value"])
- sendEvent(eventDataMap)
- }
- }
-
- def eventsSince(Date dateObj) {
- return humidityMeasurements[0].eventsSince()
- }
-
- //Methods for closures
- def count(Closure Input) {
- humidityMeasurements.count(Input)
- }
- def size() {
- humidityMeasurements.size()
- }
- def each(Closure Input) {
- humidityMeasurements.each(Input)
- }
- def find(Closure Input) {
- humidityMeasurements.find(Input)
- }
- def sort(Closure Input) {
- humidityMeasurements.sort(Input)
- }
- def collect(Closure Input) {
- humidityMeasurements.collect(Input)
- }
-
-
- def currentValue(String deviceFeature) {
- humidityMeasurements[0].currentValue(deviceFeature)//It is called if we have only one device
- }
-
- def latestValue(String deviceFeature) {
- humidityMeasurements[0].latestValue(deviceFeature)//It is called if we have only one device
- }
-
- def getAt(int ix) {
- humidityMeasurements[ix]
+import SmartThing.SmartThings
+
+public class RelativeHumidityMeasurements extends SmartThings {
+ List humidityMeasurements = new ArrayList()
+
+ RelativeHumidityMeasurements(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ humidityMeasurements = smartThings
+
+ // Initialization
+ StringBuilder id = new StringBuilder("humidityID0")
+ StringBuilder label = new StringBuilder("humidity")
+ StringBuilder displayName = new StringBuilder("humidity0")
+ MutableInteger humidity = new MutableInteger()
+
+ if (init)
+ humidity.setValue(50)
+ else
+ humidity.setValue(60)
+
+ humidityMeasurements.add(new RelativeHumidityMeasurement(sendEvent, id, label, displayName, humidity))
+ }
+
+ // Methods to return values
+ def getCurrentHumidity() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(humidityMeasurements[0].getCurrentHumidity())
+ return tmpValues
}
}
//Create a class for relay switch device
package RelaySwitch
-import Timer.SimulatedTimer
-
-public class RelaySwitch {
- private String id
- private String label
- private String displayName
- private String switchState
- private String currentSwitch
- private String switchLatestValue
- def sendEvent
- def timers
-
-
- RelaySwitch(Closure sendEvent, String id, String label, String displayName, String switchState, String currentSwitch, String switchLatestValue) {
- this.sendEvent = sendEvent
- this.timers = new SimulatedTimer()
- this.currentSwitch = currentSwitch
+import SmartThing.SmartThing
+
+public class RelaySwitch 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 currentSwitch = new StringBuilder()
+ // Maps from features to values
+ HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+
+ RelaySwitch(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentSwitch) {
+ deviceValuesMap = deviceValueSmartThing
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
+
+ // Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.switchState = switchState
- this.switchLatestValue = switchLatestValue
+ this.currentSwitch = currentSwitch
+
+ deviceValuesMap.put("switch", currentSwitch)
}
- //By Apps
+ // Methods to set values
def on() {
- if (switchState != "on") {
- println("the relay switch with id:$id is on!")
- this.switchLatestValue = "on"
- this.switchState = "on"
- this.currentSwitch = "on"
- sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ action(currentSwitch, "on", "switch")
}
def on(LinkedHashMap metaData) {
- if (switchState != "on") {
- def task = timers.runAfter(metaData["delay"]) {
- println("the relay switch with id:$id is on!")
- this.switchLatestValue = "on"
- this.switchState = "on"
- this.currentSwitch = "on"
- sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
+ on()
}
def off() {
- if (switchState != "off") {
- println("the relay switch with id:$id is off!")
- this.switchLatestValue = "off"
- this.switchState = "off"
- this.currentSwitch = "off"
- sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ action(currentSwitch, "off", "switch")
}
def off(LinkedHashMap metaData) {
- if (switchState != "off") {
- def task = timers.runAfter(metaData["delay"]) {
- println("the relay switch with id:$id is off!")
- this.switchLatestValue = "off"
- this.switchState = "off"
- this.currentSwitch = "off"
- sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
+ off()
}
- //By Model Checker
- def setValue(String value) {
- println("the relay switch with id:$id is $value!")
- this.switchLatestValue = value
- this.switchState = value
- this.currentSwitch = value
- }
-
- def currentValue(String deviceFeature) {
- if (deviceFeature == "switch") {
- return switchState
+ 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 relay switch 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 == "switch") {
- return switchLatestValue
- }
+ // Methods to return values
+ def getCurrentSwitch() {
+ return currentSwitch.toString()
}
}
//Create a class for relay switch device
package RelaySwitch
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
-public class RelaySwitches {
- int deviceNumbers
- List relaySwitches
- def timers
- def sendEvent
+public class RelaySwitches extends SmartThings {
+ List relaySwitches = new ArrayList()
- //If we have only one device
- private String id = "relaySwitchID0"
- private String label = "relaySwitch0"
- private String displayName = "relaySwitch0"
- private String switchState = "off"
- private String currentSwitch = "off"
- private String switchLatestValue = "off"
+ RelaySwitches(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ relaySwitches = smartThings
- RelaySwitches(Closure sendEvent, int deviceNumbers, boolean init) {
- this.sendEvent = sendEvent
- this.timers = new SimulatedTimer()
- this.deviceNumbers = deviceNumbers
- this.relaySwitches = []
+ // Initialization
+ StringBuilder id = new StringBuilder("relaySwitchID0")
+ StringBuilder label = new StringBuilder("relaySwitch")
+ StringBuilder displayName = new StringBuilder("relaySwitch0")
+ StringBuilder currentSwitch = new StringBuilder()
- if (init) {
- this.switchState = "off"
- this.currentSwitch = "off"
- this.switchLatestValue = "off"
- } else {
- this.switchState = "on"
- this.currentSwitch = "on"
- this.switchLatestValue = "on"
- }
- relaySwitches.add(new RelaySwitch(sendEvent, id, label, displayName, this.switchState, this.currentSwitch, this.switchLatestValue))
- }
+ if (init)
+ currentSwitch.append("off")
+ else
+ currentSwitch.append("on")
- //Methods for closures
- def count(Closure Input) {
- relaySwitches.count(Input)
- }
- def size() {
- relaySwitches.size()
- }
- def each(Closure Input) {
- relaySwitches.each(Input)
- }
- def find(Closure Input) {
- relaySwitches.find(Input)
- }
- def sort(Closure Input) {
- relaySwitches.sort(Input)
- }
- def collect(Closure Input) {
- relaySwitches.collect(Input)
+ relaySwitches.add(new RelaySwitch(sendEvent, id, label, displayName, currentSwitch))
}
- //By Apps
+ // Methods to set values
def on() {
- if (switchState != "on") {
- switchLatestValue = "on"
- switchState = "on"
- currentSwitch = "on"
- relaySwitches[0].on()
- }
+ relaySwitches[0].on()
}
def on(LinkedHashMap metaData) {
- if (switchState != "on") {
- def task = timers.runAfter(metaData["delay"]) {
- switchLatestValue = "on"
- switchState = "on"
- currentSwitch = "on"
- relaySwitches[0].on()
- }
- }
+ on()
}
def off() {
- if (switchState != "off") {
- switchLatestValue = "off"
- switchState = "off"
- currentSwitch = "off"
- relaySwitches[0].off()
- }
+ relaySwitches[0].off()
}
def off(LinkedHashMap metaData) {
- if (switchState != "off") {
- def task = timers.runAfter(metaData["delay"]) {
- switchLatestValue = "off"
- switchState = "off"
- currentSwitch = "off"
- relaySwitches[0].off()
- }
- }
- }
-
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["value"] != relaySwitches[0].switchState) {
- this.switchState = eventDataMap["value"]
- this.switchLatestValue = eventDataMap["value"]
- relaySwitches[0].setValue(eventDataMap["value"])
- sendEvent(eventDataMap)
- }
- }
-
-
- def currentValue(String deviceFeature) {
- relaySwitches[0].currentValue(deviceFeature)
- }
-
- def latestValue(String deviceFeature) {
- relaySwitches[0].latestValue(deviceFeature)
+ off()
}
- def getAt(int ix) {
- relaySwitches[ix]
+ // Methods to return values
+ def getCurrentSwitch() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(relaySwitches[0].getCurrentSwitch())
+ return tmpValues
}
}
//Create a class for sleep sensor
package SleepSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
-public class SleepSensor {
- private String id
- private String label
- private String displayName
- private String sleeping
+public class SleepSensor 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 currentSleeping = new StringBuilder()
+ // Maps from features to values
+ HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
- SleepSensor(String id, String label, String displayName, String sleeping) {
+ SleepSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentSleeping) {
+ deviceValuesMap = deviceValueSmartThing
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
+
+ // Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.sleeping = sleeping
+ this.currentSleeping = currentSleeping
+
+ deviceValuesMap.put("sleeping", currentSleeping)
}
- //By Model Checker
- def setValue(String value) {
- println("the sleeping state is changed to $value!")
- this.sleeping = value
+ // Methods to return values
+ def getCurrentSleeping() {
+ return currentSleeping.toString()
}
}
//Create a class for sleep sensor
package SleepSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
-public class SleepSensors {
- private int deviceNumbers
- private List sleepSensors
- def sendEvent
+public class SleepSensors extends SmartThings {
+ List sleepSensors = new ArrayList()
+
+ SleepSensors(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ sleepSensors = smartThings
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private String id = "sleepSensorID0"
- private String label = "sleepSensor0"
- private String displayName = "sleepSensor0"
- private String sleeping = "sleeping"
+ // Initialization
+ StringBuilder id = new StringBuilder("sleepSensorID0")
+ StringBuilder label = new StringBuilder("sleepSensor")
+ StringBuilder displayName = new StringBuilder("sleepSensor0")
+ StringBuilder sleeping = new StringBuilder()
-
- SleepSensors(Closure sendEvent, int deviceNumbers, boolean init) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.sleepSensors = []
+ if (init)
+ sleeping.append("sleeping")
+ else
+ sleeping.append("not sleeping")
- if (init) {
- this.sleeping = "sleeping"
- } else {
- this.sleeping = "not sleeping"
- }
- sleepSensors.add(new SleepSensor(id, label, displayName, this.sleeping))
+ sleepSensors.add(new SleepSensor(sendEvent, id, label, displayName, sleeping))
}
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["value"] != sleepSensors[0].sleeping) {
- this.sleeping = eventDataMap["value"]
- sleepSensors[0].setValue(eventDataMap["value"])
- sendEvent(eventDataMap)
- }
- }
-
- //Methods for closures
- def count(Closure Input) {
- sleepSensors.count(Input)
- }
- def size() {
- sleepSensors.size()
- }
- def each(Closure Input) {
- sleepSensors.each(Input)
- }
- def find(Closure Input) {
- sleepSensors.find(Input)
- }
- def sort(Closure Input) {
- sleepSensors.sort(Input)
- }
- def collect(Closure Input) {
- sleepSensors.collect(Input)
- }
-
- def getAt(int ix) {
- sleepSensors[ix]
+ // Methods to return values
+ def getCurrentSleeping() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(sleepSensors[0].getCurrentSleeping())
+ return tmpValues
}
}
//Create a class for smoke detector
package SmokeDetector
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
-public class SmokeDetector {
- private String id
- private String label
- private String displayName
- private String smoke
- private String currentSmokeValue
- private String smokeLatestValue
- private String carbonMonoxide
- private String currentCarbonMonoxideValue
- private String carbonMonoxideLatestValue
- private int battery
- private int batteryLatestValue
+public class SmokeDetector 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 currentSmoke = new StringBuilder()
+ // Maps from features to values
+ HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
- SmokeDetector(String id, String label, String displayName, String smoke, String smokeLatestValue, String carbonMonoxide, String carbonMonoxideLatestValue, int battery) {
+ SmokeDetector(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentSmoke) {
+ deviceValuesMap = deviceValueSmartThing
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
+
+ // Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.smoke = smoke
- this.currentSmokeValue = smoke
- this.smokeLatestValue = smokeLatestValue
- this.carbonMonoxide = carbonMonoxide
- this.currentCarbonMonoxideValue = currentCarbonMonoxideValue
- this.carbonMonoxideLatestValue = carbonMonoxideLatestValue
- this.battery = battery
- this.batteryLatestValue = battery
- }
-
- def setValue(String value, String name) {
- if (name.contains("smoke")) {
- println("the smoke value of smoke detector with id:$id is triggered to $value!")
- this.smokeLatestValue = value
- this.smoke = value
- this.currentSmokeValue = value
- } else if (name.contains("carbonMonoxide")) {
- println("the carbonMonoxide value of smoke detector with id:$id is triggered to $value!")
- this.carbonMonoxideLatestValue = value
- this.carbonMonoxide = value
- this.currentCarbonMonoxideValue = value
- } else if (name.contains("battery")) {
- println("the battery value of smoke detector with id:$id is triggered to $value!")
- this.batteryLatestValue = value.toInteger()
- this.battery = value.toInteger()
- }
-
- }
+ this.currentSmoke = currentSmoke
-
- def currentValue(String deviceFeature) {
- if (deviceFeature == "smoke") {
- return currentSmokeValue
- } else if (deviceFeature == "carbonMonoxide") {
- return currentCarbonMonoxideValue
- } else if (deviceFeature == "battery") {
- return battery
- }
+ deviceValuesMap.put("smoke", currentSmoke)
}
- def latestValue(String deviceFeature) {
- if (deviceFeature == "smoke") {
- return smokeLatestValue
- } else if (deviceFeature == "carbonMonoxide") {
- return carbonMonoxideLatestValue
- } else if (deviceFeature == "battery") {
- return batteryLatestValue
- }
+ // Methods to return values
+ def getCurrentSmoke() {
+ return currentSmoke.toString()
}
}
//Create a class for smoke detector
package SmokeDetector
-import Timer.SimulatedTimer
-
-public class SmokeDetectors {
- private int deviceNumbers
- private List smokeDetectors
- def sendEvent
-
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private String id = "smokeDetectorID0"
- private String label = "smokeDetector0"
- private String displayName = "smokeDetector0"
- private String smoke = "clear"
- private String currentSmokeValue = "clear"
- private String smokeLatestValue = "clear"
- private String carbonMonoxide = "clear"
- private String currentCarbonMonoxideValue = "clear"
- private String carbonMonoxideLatestValue = "clear"
- private int battery = 50
- private int batteryValue = 50
- private int batteryLatestValue = 50
+import SmartThing.SmartThings
+public class SmokeDetectors extends SmartThings {
+ List smokeDetectors = new ArrayList()
- SmokeDetectors(Closure sendEvent, int deviceNumbers, boolean init) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.smokeDetectors = []
-
- if (init) {
- this.currentSmokeValue = "clear"
- this.smokeLatestValue = "clear"
- this.carbonMonoxide = "clear"
- this.currentCarbonMonoxideValue = "clear"
- this.carbonMonoxideLatestValue = "clear"
- this.battery = 50
- this.batteryValue = 50
- this.batteryLatestValue = 50
- } else {
- this.currentSmokeValue = "detected"
- this.smokeLatestValue = "detected"
- this.carbonMonoxide = "detected"
- this.currentCarbonMonoxideValue = "detected"
- this.carbonMonoxideLatestValue = "detected"
- this.battery = 60
- this.batteryValue = 60
- this.batteryLatestValue = 60
- }
- smokeDetectors.add(new SmokeDetector(id, label, displayName, this.currentSmokeValue, this.smokeLatestValue, this.carbonMonoxide, this.carbonMonoxideLatestValue, this.battery))
- }
-
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["name"].contains("smoke")) {
- if (eventDataMap["value"] != smokeDetectors[0].currentSmokeValue) {
- this.smokeLatestValue = eventDataMap["value"]
- this.smoke = eventDataMap["value"]
- this.currentSmokeValue = eventDataMap["value"]
- smokeDetectors[0].setValue(eventDataMap["value"], eventDataMap["name"])
- sendEvent(eventDataMap)
- }
- } else if (eventDataMap["name"].contains("carbonMonoxide")) {
- if (eventDataMap["value"] != smokeDetectors[0].currentCarbonMonoxideValue) {
- this.carbonMonoxideLatestValue = eventDataMap["value"]
- this.carbonMonoxide = eventDataMap["value"]
- this.currentCarbonMonoxideValue = eventDataMap["value"]
- smokeDetectors[0].setValue(eventDataMap["value"], eventDataMap["name"])
- sendEvent(eventDataMap)
- }
- } else if (eventDataMap["name"].contains("battery")) {
- if (eventDataMap["value"].toInteger() != smokeDetectors[0].battery) {
- this.battery = eventDataMap["value"].toInteger()
- this.batteryLatestValue = eventDataMap["value"].toInteger()
- smokeDetectors[0].setValue(eventDataMap["value"], eventDataMap["name"])
- sendEvent(eventDataMap)
- }
- }
- }
-
- //Methods for closures
- def count(Closure Input) {
- smokeDetectors.count(Input)
- }
- def size() {
- smokeDetectors.size()
- }
- def each(Closure Input) {
- smokeDetectors.each(Input)
- }
- def find(Closure Input) {
- smokeDetectors.find(Input)
- }
- def sort(Closure Input) {
- smokeDetectors.sort(Input)
- }
- def collect(Closure Input) {
- smokeDetectors.collect(Input)
- }
+ SmokeDetectors(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ smokeDetectors = smartThings
+ // Initialization
+ StringBuilder id = new StringBuilder("smokeDetectorID0")
+ StringBuilder label = new StringBuilder("smokeDetector")
+ StringBuilder displayName = new StringBuilder("smokeDetector0")
+ StringBuilder smoke = new StringBuilder()
- def currentValue(String deviceFeature) {
- smokeDetectors[0].currentValue(deviceFeature)//It is called if we have only one device
- }
+ if (init)
+ smoke.append("clear")
+ else
+ smoke.append("detected")
- def latestValue(String deviceFeature) {
- smokeDetectors[0].latestValue(deviceFeature)//It is called if we have only one device
+ smokeDetectors.add(new SmokeDetector(sendEvent, id, label, displayName, smoke))
}
- def getAt(int ix) {
- smokeDetectors[ix]
+ // Methods to return values
+ def getCurrentSmoke() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(smokeDetectors[0].getCurrentSmoke())
+ return tmpValues
}
}
//Create a class for speech synthesis
package SpeechSynthesis
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
-public class SpeechSynthesis {
- private String id
- private String label
- private String displayName
- private int level
- private boolean oneUser
+public class SpeechSynthesis 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()
+ // Maps from features to values
+ HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+ SpeechSynthesis(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentLevel) {
+ deviceIntValuesMap = deviceIntValueSmartThing
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
- SpeechSynthesis(String id, String label, String displayName, int level, boolean oneUser) {
+ // Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.level = level
- this.oneUser = oneUser
+ this.currentLevel = currentLevel
+
+ deviceIntValuesMap.put("level", currentLevel)
}
- def setLevel(int level) {
- if (level != this.level) {
- println("The level of speech synthesis with id:$id is changed to $level")
- this.level = level
+ // Methods to set values
+ def setLevel(int newValue) {
+ if (!currentLevel.getValue().equals(newValue)) {
+ String tmpID = id.toString()
+ currentLevel.setValue(newValue)
+ println("The level of speech synthesis with id:$tmpID is changed to $currentLevel")
}
}
def speak(String message) {
- println("Speech synthesis with id:$id, SPEAKING:\"$message\"!")
- // As a conflict variable
- if (oneUser) {
- this.oneUser = false
- } else {
- this.oneUser = true
- }
+ String tmpID = id.toString()
+ println("Speech synthesis with id:$tmpID, SPEAKING:\"$message\"!")
+ }
+
+ // Methods to return values
+ def getCurrentLevel() {
+ return currentLevel.getValue()
}
}
//Create a class for speech synthesis
package SpeechSynthesis
-import Timer.SimulatedTimer
-
-public class SpeechSynthesises {
- private int deviceNumbers
- private List speechSynthesises
- def sendEvent
-
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private String id = "speechSynthesisID0"
- private String label = "speechSynthesis0"
- private String displayName = "speechSynthesis0"
- private int level = 50
- private boolean oneUser = true
+import SmartThing.SmartThings
+public class SpeechSynthesises extends SmartThings {
+ List speechSynthesises = new ArrayList()
- SpeechSynthesises(Closure sendEvent, int deviceNumbers, boolean init) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.speechSynthesises = []
+ SpeechSynthesises(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ speechSynthesises = smartThings
- if (init) {
- this.level = 50
- this.oneUser = true
- } else {
- this.level = 60
- this.oneUser = false
- }
- speechSynthesises.add(new SpeechSynthesis(id, label, displayName, this.level, this.oneUser))
- }
+ // Initialization
+ StringBuilder id = new StringBuilder("speechSynthesisID0")
+ StringBuilder label = new StringBuilder("speechSynthesis")
+ StringBuilder displayName = new StringBuilder("speechSynthesis0")
+ MutableInteger level = new MutableInteger()
- //Methods for closures
- def count(Closure Input) {
- speechSynthesises.count(Input)
- }
- def size() {
- speechSynthesises.size()
- }
- def each(Closure Input) {
- speechSynthesises.each(Input)
- }
- def find(Closure Input) {
- speechSynthesises.find(Input)
- }
- def sort(Closure Input) {
- speechSynthesises.sort(Input)
- }
- def collect(Closure Input) {
- speechSynthesises.collect(Input)
+ if (init)
+ level.setValue(50)
+ else
+ level.setValue(60)
+
+ speechSynthesises.add(new SpeechSynthesis(sendEvent, id, label, displayName, level))
}
+ // Methods to set values
def setLevel(int level) {
- if (level != this.level) {
- this.level = level
- speechSynthesises[0].setLevel(level)
- }
+ speechSynthesises[0].setLevel(level)
}
def speak(String message) {
speechSynthesises[0].speak(message)
- // As a conflict variable
- if (oneUser) {
- this.oneUser = false
- } else {
- this.oneUser = true
- }
}
- def getAt(int ix) {
- speechSynthesises[ix]
+ // Methods to return values
+ def getCurrentLevel() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(speechSynthesises[0].getCurrentLevel())
+ return tmpValues
}
+
}
//Create a class for step sensor
package StepSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
-public class StepSensor {
- private String id
- private String label
- private String displayName
- private int goal
- private int steps
+public class StepSensor 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 currentGoal = new MutableInteger()
+ MutableInteger currentSteps = new MutableInteger()
+ // Maps from features to values
+ HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
- StepSensor(String id, String label, String displayName, int steps, int goal) {
+ StepSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentSteps, MutableInteger currentGoal) {
+ deviceIntValuesMap = deviceIntValueSmartThing
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
+
+ // Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.steps = steps
- this.goal = goal
- }
+ this.currentSteps = currentSteps
+ this.currentGoal = currentGoal
- //By Model Checker
- def setValue(String value, String name) {
- if (name == "steps") {
- println("the number of steps is changed to $value!")
- this.steps = value.toInteger()
- } else if (name == "goal") {
- println("the goal is changed to $value!")
- this.goal = value.toInteger()
- }
+ deviceIntValuesMap.put("steps", currentSteps)
+ deviceIntValuesMap.put("goal", currentGoal)
}
- def currentValue(String deviceFeature) {
- if (deviceFeature == "steps")
- return steps
- else if (deviceFeature == "goal")
- return goal
+ // Methods to return values
+ def getCurrentSteps() {
+ return currentSteps.getValue()
}
- def latestValue(String deviceFeature) {
- if (deviceFeature == "steps")
- return steps
- else if (deviceFeature == "goal")
- return goal
+ def getCurrentGoal() {
+ return currentGoal.getValue()
}
}
//Create a class for step sensor
package StepSensor
-import Timer.SimulatedTimer
-
-public class StepSensors {
- private int deviceNumbers
- private List stepSensors
- def sendEvent
-
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private String id = "stepSensorID0"
- private String label = "stepSensor0"
- private String displayName = "stepSensor0"
- private int goal = 1000
- private int steps = 0
+import SmartThing.SmartThings
+public class StepSensors extends SmartThings {
+ List stepSensors = new ArrayList()
- StepSensors(Closure sendEvent, int deviceNumbers, boolean init) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.stepSensors = []
+ StepSensors(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ stepSensors = smartThings
+
+ // Initialization
+ StringBuilder id = new StringBuilder("stepSensorID0")
+ StringBuilder label = new StringBuilder("stepSensor")
+ StringBuilder displayName = new StringBuilder("stepSensor0")
+ MutableInteger steps = new MutableInteger()
+ MutableInteger goal = new MutableInteger()
if (init) {
- this.goal = 50
- this.steps = 35
+ goal.setValue(50)
+ steps.setValue(35)
} else {
- this.goal = 40
- this.steps = 60
- }
- stepSensors.add(new StepSensor(id, label, displayName, this.steps, this.goal))
- }
-
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["name"] == "steps") {
- if (eventDataMap["value"].toInteger() != stepSensors[0].steps) {
- this.steps = eventDataMap["value"].toInteger()
- stepSensors[0].setValue(eventDataMap["value"], "steps")
- sendEvent(eventDataMap)
- }
- } else if (eventDataMap["name"] == "goal") {
- if (eventDataMap["value"].toInteger() != stepSensors[0].goal) {
- this.goal = eventDataMap["value"].toInteger()
- stepSensors[0].setValue(eventDataMap["value"], "goal")
- sendEvent(eventDataMap)
- }
+ goal.setValue(40)
+ steps.setValue(60)
}
- }
-
- //Methods for closures
- def count(Closure Input) {
- stepSensors.count(Input)
- }
- def size() {
- stepSensors.size()
- }
- def each(Closure Input) {
- stepSensors.each(Input)
- }
- def find(Closure Input) {
- stepSensors.find(Input)
- }
- def sort(Closure Input) {
- stepSensors.sort(Input)
- }
- def collect(Closure Input) {
- stepSensors.collect(Input)
- }
-
- def currentValue(String deviceFeature) {
- stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device
+ stepSensors.add(new StepSensor(sendEvent, id, label, displayName, steps, goal))
}
- def latestValue(String deviceFeature) {
- stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device
+ // Methods to return values
+ def getCurrentSteps() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(stepSensors[0].getCurrentSteps())
+ return tmpValues
}
- def getAt(int ix) {
- stepSensors[ix]
+ def getCurrentGoal() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(stepSensors[0].getCurrentGoal())
+ return tmpValues
}
}
//Create a class for switch device
package Switch
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
+public class Switch 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 currentSwitch = 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>();
+ Switch(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentSwitch) {
+ deviceValuesMap = deviceValueSmartThing
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
+ possibleValuesSmartThings = possibleValues
-public class Switch {
- private String id
- private String label
- private String displayName
- private String switchState
- private String currentSwitch
- private int currentLevel
- private String switchLatestValue
- def sendEvent
- def timers
-
-
- Switch(Closure sendEvent, String id, String label, String displayName, String switchState, String currentSwitch, int currentLevel, String switchLatestValue) {
- this.sendEvent = sendEvent
- this.timers = new SimulatedTimer()
- this.currentSwitch = currentSwitch
- this.currentLevel = currentLevel
+ // Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.switchState = switchState
- this.switchLatestValue = switchLatestValue
- }
-
- def eventsSince() {
- def evtOn = [[name: "switch", value: "on", deviceId: "switchID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
- def evtOff = [[name: "switch", value: "off", deviceId: "switchID0", 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
- evtOn.each{
- evtToSend.add(it)
- }
- return evtToSend
- } else if (init == 2) {//send two open events
- evtOn.each{
- evtToSend.add(it)
- }
- evtOn.each{
- evtToSend.add(it)
- }
- return evtToSend
- } else if (init == 3) {//send one closed event
- evtOff.each{
- evtToSend.add(it)
- }
- return evtToSend
- } else if (init == 4) {//send two closed events
- evtOff.each{
- evtToSend.add(it)
- }
- evtOff.each{
- evtToSend.add(it)
- }
- return evtToSend
- }
- }
+ this.currentSwitch = currentSwitch
+ possibleValues.add("on")
+ possibleValues.add("off")
- //By Apps
- def setLevel(int level) {
- if (this.currentLevel != level) {
- println("the switch with id:$id is setted to level $level!")
- this.currentLevel = level
- sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ deviceValuesMap.put("switch", currentSwitch)
}
+ // Methods to set values
def on() {
- if (this.switchState != "on") {
- println("the switch with id:$id is on!")
- this.switchLatestValue = "on"
- this.switchState = "on"
- this.currentSwitch = "on"
- sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ action(currentSwitch, "on", "switch")
}
def on(LinkedHashMap metaData) {
- if (this.switchState != "on") {
- def task = timers.runAfter(metaData["delay"]) {
- println("the switch with id:$id is on!")
- this.switchLatestValue = "on"
- this.switchState = "on"
- this.currentSwitch = "on"
- sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
+ on()
}
def off() {
- if (this.switchState != "off") {
- println("the switch with id:$id is off!")
- this.switchLatestValue = "off"
- this.switchState = "off"
- this.currentSwitch = "off"
- sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ action(currentSwitch, "off", "switch")
}
def off(LinkedHashMap metaData) {
- if (this.switchState != "off") {
- def task = timers.runAfter(metaData["delay"]) {
- println("the switch with id:$id is off!")
- this.switchLatestValue = "off"
- this.switchState = "off"
- this.currentSwitch = "off"
- sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
+ off()
}
- //By Model Checker
- def setValue(String value) {
- println("the switch with id:$id is $value!")
- this.switchLatestValue = value
- this.switchState = value
- this.currentSwitch = value
- }
-
- def currentValue(String deviceFeature) {
- if (deviceFeature == "switch") {
- return switchState
+ 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:$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 == "switch") {
- return switchLatestValue
- }
+ // Methods to return values
+ def getCurrentSwitch() {
+ return currentSwitch.toString()
}
}
//Create a class for switch device
package Switch
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
+public class Switches extends SmartThings {
+ List switches = new ArrayList()
+ Switches(Closure sendEvent, boolean init) {
+ switches = smartThings
-public class Switches {
- int deviceNumbers
- List switches
- def timers
- def sendEvent
+ // Initialization
+ StringBuilder id = new StringBuilder("switchID0")
+ StringBuilder label = new StringBuilder("switch")
+ StringBuilder displayName = new StringBuilder("switch0")
+ StringBuilder currentSwitch = new StringBuilder()
- //If we have only one device
- private String id = "switchID0"
- private String label = "switch0"
- private String displayName = "switch0"
- private String switchState = "off"
- private String currentSwitch = "off"
- private int currentLevel = 50
- private String switchLatestValue = "off"
+ if (init)
+ currentSwitch.append("off")
+ else
+ currentSwitch.append("on")
- Switches(Closure sendEvent, int deviceNumbers, boolean init) {
- this.sendEvent = sendEvent
- this.timers = new SimulatedTimer()
- this.deviceNumbers = deviceNumbers
- this.switches = []
-
- if (init) {
- this.switchState = "off"
- this.currentSwitch = "off"
- this.switchLatestValue = "off"
- this.currentLevel = 50
- } else {
- this.switchState = "on"
- this.currentSwitch = "on"
- this.switchLatestValue = "on"
- this.currentLevel = 60
- }
- switches.add(new Switch(sendEvent, id, label, displayName, this.switchState, this.currentSwitch, this.currentLevel, this.switchLatestValue))
- }
-
- //Methods for closures
- def count(Closure Input) {
- switches.count(Input)
- }
- def size() {
- switches.size()
- }
- def each(Closure Input) {
- switches.each(Input)
- }
- def eachWithIndex(Closure Input) {
- switches.eachWithIndex(Input)
- }
- def find(Closure Input) {
- switches.find(Input)
- }
- def sort(Closure Input) {
- switches.sort(Input)
- }
- def collect(Closure Input) {
- switches.collect(Input)
- }
-
- //By Apps
- def eventsSince(Date dateObj, LinkedHashMap metaData) {
- return switches[0].eventsSince()
- }
-
- def setLevel(int level) {
- currentLevel = level
- switches[0].setLevel(level)
+ switches.add(new Switch(sendEvent, id, label, displayName, currentSwitch))
}
+ // Methods to set values
def on() {
- switchLatestValue = "on"
- switchState = "on"
- currentSwitch = "on"
switches[0].on()
}
def on(LinkedHashMap metaData) {
- def task = timers.runAfter(metaData["delay"]) {
- switchLatestValue = "on"
- switchState = "on"
- currentSwitch = "on"
- switches[0].on()
- }
+ on()
}
def off() {
- switchLatestValue = "off"
- switchState = "off"
- currentSwitch = "off"
switches[0].off()
}
def off(LinkedHashMap metaData) {
- def task = timers.runAfter(metaData["delay"]) {
- switchLatestValue = "off"
- switchState = "off"
- currentSwitch = "off"
- switches[0].off()
- }
- }
-
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["value"] != switches[0].switchState) {
- this.switchState = eventDataMap["value"]
- this.switchLatestValue = eventDataMap["value"]
- switches[0].setValue(eventDataMap["value"])
- sendEvent(eventDataMap)
- }
- }
-
-
- def currentValue(String deviceFeature) {
- switches[0].currentValue(deviceFeature)
- }
-
- def latestValue(String deviceFeature) {
- switches[0].latestValue(deviceFeature)
+ off()
}
- def getAt(int ix) {
- switches[ix]
+ // Methods to return values
+ def getCurrentSwitch() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(switches[0].getCurrentSwitch())
+ return tmpValues
}
}
//Create a class for switch level
package SwitchLevel
-import Timer.SimulatedTimer
-
-public class SwitchLevel {
- private String id
- private String label
- private String displayName
- private String switchState
- private String currentSwitch
- private int level
- private int currentLevel
- private int rate
- private int currentRate
- private int hue
- private int currentHue
- private int saturation
- private int currentSaturation
- private String switchLatestValue
- def sendEvent
- def timers
+import SmartThing.SmartThing
+
+public class SwitchLevel 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()
+ // Maps from features to values
+ HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
-
- SwitchLevel(Closure sendEvent, String id, String label, String displayName, int level, int hue, int saturation, String switchState, String switchLatestValue) {
- this.sendEvent = sendEvent
- this.timers = new SimulatedTimer()
+ SwitchLevel(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentLevel) {
+ 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.rate = level
- this.currentRate = level
- this.hue = hue
- this.currentHue = hue
- this.saturation = saturation
- this.currentSaturation = saturation
- this.switchState = switchState
- this.currentSwitch = switchState
- this.switchLatestValue = switchLatestValue
- }
-
- //By Apps
- def setColor(LinkedHashMap metaData) {
- if ((this.level != metaData["level"]) || (this.hue != metaData["hue"]) || (this.saturation != metaData["saturation"])) {
- this.level = metaData["level"]
- this.currentLevel = metaData["level"]
- this.rate = metaData["level"]
- this.currentRate = metaData["level"]
- this.hue = metaData["hue"]
- this.currentHue = metaData["hue"]
- this.saturation = metaData["saturation"]
- this.currentSaturation = metaData["saturation"]
- println("the switch with id:$id is setted to level $level and hue to $hue and saturation to $saturation!")
- sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- def setLevel(String level) {
- def newLevel = level.toInteger()
- setLevel(newLevel)
- }
-
- def setLevel(int level) {
- if (this.level != level) {
- println("the switch with id:$id is setted to level $level!")
- this.level = level
- this.currentLevel = level
- this.rate = level
- this.currentRate = level
- sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- def setLevel(long level) {
- if (this.level != level) {
- println("the switch with id:$id is setted to level $level!")
- this.level = level
- this.currentLevel = level
- this.rate = level
- this.currentRate = level
- sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- def on() {
- if (this.switchState != "on") {
- println("the switch with id:$id is on!")
- this.switchLatestValue = "on"
- this.switchState = "on"
- this.currentSwitch = "on"
- sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- def on(LinkedHashMap metaData) {
- if (this.switchState != "on") {
- def task = timers.runAfter(metaData["delay"]) {
- println("the switch with id:$id is on!")
- this.switchLatestValue = "on"
- this.switchState = "on"
- this.currentSwitch = "on"
- sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
- }
+ this.currentLevel = currentLevel
- def off() {
- if (this.switchState != "off") {
- println("the switch with id:$id is off!")
- this.switchLatestValue = "off"
- this.switchState = "off"
- this.currentSwitch = "off"
- sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ deviceIntValuesMap.put("level", currentLevel)
}
- def off(LinkedHashMap metaData) {
- if (this.switchState != "off") {
- def task = timers.runAfter(metaData["delay"]) {
- println("the switch with id:$id is off!")
- this.switchLatestValue = "off"
- this.switchState = "off"
- this.currentSwitch = "off"
- sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
+ // Methods to set values
+ def setLevel(String newValue) {
+ setLevel(newValue.toInteger())
}
- //By Model Checker
- def setValue(String value, String name) {
- if (name == "switch") {
- println("the switch with id:$id is $value!")
- this.switchLatestValue = value
- this.switchState = value
- this.currentSwitch = value
- } else if (name == "level") {
- println("the switch with id:$id is setted to level $value!")
- this.level = value.toInteger()
- this.currentLevel = value.toInteger()
- this.rate = value.toInteger()
- this.currentRate = value.toInteger()
- }
+ def setLevel(long newValue) {
+ setLevel((int) newValue) {
}
-
- def currentValue(String deviceFeature) {
- if (deviceFeature == "level") {
- return level
- } else if (deviceFeature == "switch") {
- return switchState
+ def setLevel(int newValue) {
+ if (!currentLevel.getValue().equals(newValue)) {
+ String tmpID = id.toString()
+ variable.setValue(newValue)
+ println("the switch with id:$tmpID is setted to level $level!")
+ sendEvent([name: "level", value: newValue, deviceId: tmpID, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
}
}
-
- def latestValue(String deviceFeature) {
- if (deviceFeature == "level") {
- return level
- } else if (deviceFeature == "switch") {
- return switchState
- }
+
+ // Methods to return values
+ def getCurrentLevel() {
+ return currentLevel.getValue()
}
}
//Create a class for switch level
package SwitchLevel
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
-public class SwitchLevels {
- int deviceNumbers
- List switchLevels
- def timers
- def sendEvent
+public class SwitchLevels extends SmartThings {
+ List switchLevels = new ArrayList()
- //If we have only one device
- private String id = "switchLevelID0"
- private String label = "switchLevel0"
- private String displayName = "switchLevel0"
- private int level = 50
- private int currentLevel = 50
- private int rate = 50
- private int currentRate = 50
- private int hue = 30
- private int currentHue = 30
- private int saturation = 70
- private int currentSaturation = 70
- private String switchState = "on"
- private String currentSwitch = "on"
- private String switchLatestValue = "on"
+ SwitchLevels(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ switchLevels = smartThings
- SwitchLevels(Closure sendEvent, int deviceNumbers, boolean init) {
- this.sendEvent = sendEvent
- this.timers = new SimulatedTimer()
- this.deviceNumbers = deviceNumbers
- this.switchLevels = []
+ // Initialization
+ StringBuilder id = new StringBuilder("switchLevelID0")
+ StringBuilder label = new StringBuilder("switchLevel")
+ StringBuilder displayName = new StringBuilder("switchLevel0")
+ MutableInteger level = new MutableInteger()
- if (init) {
- this.level = 50
- this.currentLevel = 50
- this.rate = 50
- this.currentRate = 50
- this.hue = 30
- this.currentHue = 30
- this.saturation = 70
- this.currentSaturation = 70
- this.switchState = "off"
- this.currentSwitch = "off"
- this.switchLatestValue = "off"
- } else {
- this.level = 60
- this.currentLevel = 60
- this.rate = 60
- this.currentRate = 60
- this.hue = 50
- this.currentHue = 50
- this.saturation = 90
- this.currentSaturation = 90
- this.switchState = "on"
- this.currentSwitch = "on"
- this.switchLatestValue = "on"
- }
- switchLevels.add(new SwitchLevel(sendEvent, id, label, displayName, this.level, this.hue, this.saturation, this.switchState, this.switchLatestValue))
- }
-
- //Methods for closures
- def count(Closure Input) {
- switchLevels.count(Input)
- }
- def size() {
- switchLevels.size()
- }
- def each(Closure Input) {
- switchLevels.each(Input)
- }
- def find(Closure Input) {
- switchLevels.find(Input)
- }
- def sort(Closure Input) {
- switchLevels.sort(Input)
- }
- def collect(Closure Input) {
- switchLevels.collect(Input)
- }
+ if (init)
+ level.setValue(50)
+ else
+ level.setValue(60)
- //By Apps
- def setColor(LinkedHashMap metaData) {
- if ((this.level != metaData["level"]) || (this.hue != metaData["hue"]) || (this.saturation != metaData["saturation"])) {
- this.level = metaData["level"]
- this.currentLevel = metaData["level"]
- this.rate = metaData["level"]
- this.currentRate = metaData["level"]
- this.hue = metaData["hue"]
- this.currentHue = metaData["hue"]
- this.saturation = metaData["saturation"]
- this.currentSaturation = metaData["saturation"]
- switchLevels[0].setColor(metaData)
- }
- }
-
- def setLevel(String level) {
- def newLevel = level.toInteger()
- setLevel(newLevel)
+ switchLevels.add(new SwitchLevel(sendEvent, id, label, displayName, level))
}
- def setLevel(int level) {
- if (this.level != level) {
- switchLevels[0].setLevel(level)
- this.level = level
- this.currentLevel = level
- this.rate = level
- this.currentRate = level
- }
- }
-
- def setLevel(long level) {
- if (this.level != level) {
- switchLevels[0].setLevel(level)
- this.level = level
- this.rate = level
- this.currentLevel = level
- this.currentRate = level
- }
+ // Methods to set values
+ def setLevel(String newValue) {
+ setLevel(newValue.toInteger())
}
- def on() {
- switchLatestValue = "on"
- switchState = "on"
- currentSwitch = "on"
- switchLevels[0].on()
+ def setLevel(long newValue) {
+ setLevel((int) newValue)
}
- def on(LinkedHashMap metaData) {
- def task = timers.runAfter(metaData["delay"]) {
- switchLatestValue = "on"
- switchState = "on"
- currentSwitch = "on"
- switchLevels[0].on()
- }
- }
-
- def off() {
- switchLatestValue = "off"
- switchState = "off"
- currentSwitch = "off"
- switchLevels[0].off()
- }
-
- def off(LinkedHashMap metaData) {
- def task = timers.runAfter(metaData["delay"]) {
- switchLatestValue = "off"
- switchState = "off"
- currentSwitch = "off"
- switchLevels[0].off()
- }
- }
-
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["name"] == "switch") {
- if (eventDataMap["value"] != switchLevels[0].switchState) {
- this.switchState = eventDataMap["value"]
- this.switchLatestValue = eventDataMap["value"]
- this.currentSwitch = eventDataMap["value"]
- switchLevels[0].setValue(eventDataMap["value"], "switch")
- sendEvent(eventDataMap)
- }
- } else if (eventDataMap["name"] == "level") {
- if (eventDataMap["value"].toInteger() != switchLevels[0].level) {
- this.level = eventDataMap["value"].toInteger()
- this.currentLevel = eventDataMap["value"].toInteger()
- this.currentRate = eventDataMap["value"].toInteger()
- this.rate = eventDataMap["value"].toInteger()
- switchLevels[0].setValue(eventDataMap["value"], "level")
- sendEvent(eventDataMap)
- }
- }
- }
-
- def currentValue(String deviceFeature) {
- switchLevels[0].currentValue(deviceFeature)
- }
-
- def latestValue(String deviceFeature) {
- switchLevels[0].latestValue(deviceFeature)
+ def setLevel(int newValue) {
+ switchLevels[0].setLevel(newValue)
}
-
- def getAt(int ix) {
- switchLevels[ix]
+ // Methods to return values
+ def getCurrentLevel() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(switchLevels[0].getCurrentLevel())
+ return tmpValues
}
}
//Create a class for temperature measurement
package TemperatureMeasurement
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
+public class TemperatureMeasurement 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 currentTemperature = new MutableInteger()
+ // Maps from features to values
+ HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
-public class TemperatureMeasurement {
- private String id
- private String label
- private String displayName
- private int temperature
- private int currentTemperature
+ TemperatureMeasurement(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentTemperature) {
+ deviceIntValuesMap = deviceIntValueSmartThing
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
- TemperatureMeasurement(String id, String label, String displayName, int temperature) {
+ // Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.temperature = temperature
- this.currentTemperature = temperature
- }
+ this.currentTemperature = currentTemperature
- def eventsSince() {
- def evtTemp = [[name: "temperature", value: this.temperature.toString(), deviceId: "temperatureMeasurementID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
- def init = Verify.getInt(0,1)
- def evtToSend = []
- if (init == 0) {//return empty set
- return evtToSend
- } else if (init == 1) {//send one open event
- evtTemp.each{
- evtToSend.add(it)
- }
- return evtToSend
- }
+ deviceIntValuesMap.put("temperature", currentTemperature)
}
- //By Model Checker
- def setValue(String value) {
- println("the temperature is changed to $value!")
- this.temperature = value.toInteger()
- this.currentTemperature = value.toInteger()
+ // Methods to return values
+ def getCurrentTemperature() {
+ return currentTemperature.getValue()
}
}
//Create a class for temperature measurement
package TemperatureMeasurement
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
+public class TemperatureMeasurements extends SmartThings {
+ List temperatureMeasurements = new ArrayList()
-public class TemperatureMeasurements {
- private int deviceNumbers
- private List temperatureMeasurements
- def sendEvent
+ TemperatureMeasurements(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ temperatureMeasurements = smartThings
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private String id = "temperatureMeasurementID0"
- private String label = "temperatureMeasurement0"
- private String displayName = "temperatureMeasurement0"
- private int temperature = 40
- private int currentTemperature = 40
+ // Initialization
+ StringBuilder id = new StringBuilder("temperatureMeasurementID0")
+ StringBuilder label = new StringBuilder("temperature")
+ StringBuilder displayName = new StringBuilder("temperatureMeasurement0")
+ MutableInteger temperature = new MutableInteger()
- TemperatureMeasurements(Closure sendEvent, int deviceNumbers, boolean init) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.temperatureMeasurements = []
+ if (init)
+ temperature.setValue(40)
+ else
+ temperature.setValue(60)
- if (init) {
- this.temperature = 40
- this.currentTemperature = 40
- } else {
- this.temperature = 60
- this.currentTemperature = 60
- }
- temperatureMeasurements.add(new TemperatureMeasurement(id, label, displayName, this.temperature))
+ temperatureMeasurements.add(new TemperatureMeasurement(sendEvent, id, label, displayName, temperature))
}
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["value"].toInteger() != temperatureMeasurements[0].temperature) {
- this.temperature = eventDataMap["value"].toInteger()
- this.currentTemperature = eventDataMap["value"].toInteger()
- temperatureMeasurements[0].setValue(eventDataMap["value"])
- sendEvent(eventDataMap)
- }
- }
-
- def eventsSince(Date dateObj) {
- return temperatureMeasurements[0].eventsSince()
- }
-
- //Methods for closures
- def count(Closure Input) {
- temperatureMeasurements.count(Input)
- }
- def size() {
- temperatureMeasurements.size()
- }
- def each(Closure Input) {
- temperatureMeasurements.each(Input)
- }
- def find(Closure Input) {
- temperatureMeasurements.find(Input)
- }
- def sort(Closure Input) {
- temperatureMeasurements.sort(Input)
- }
- def collect(Closure Input) {
- temperatureMeasurements.collect(Input)
- }
-
- def getAt(int ix) {
- temperatureMeasurements[ix]
+ // Methods to return values
+ def getCurrentTemperature() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(temperatureMeasurements[0].getCurrentTemperature())
+ return tmpValues
}
}
//Create a class for thermostat device
package Thermostat
-import Timer.SimulatedTimer
-
-public class Thermostat {
- private String id
- private String label
- private String displayName
- private int temperature
- private int currentTemperature
- private int currentCoolingSetpoint
- private int currentHeatingSetpoint
- private int coolingSetpoint
- private int latestCoolingSetPoint
- private int thermostatSetpoint
- private int latestThermostatSetPoint
- private int heatingSetpoint
- private int latestHeatingSetPoint
- private List coolingSetpointRange
- private List thermostatSetpointRange
- private List heatingSetpointRange
- private List supportedThermostatFanModes
- private List supportedThermostatModes
- private String thermostatOperatingState
- private String thermostatFanMode
- private String thermostatMode
- private String currentThermostatMode
- private String climateName
- private String thermostatLatestMode
- private String thermostatLatestOperatingState
- private String thermostatLatestFanMode
- def sendEvent
- def timers
-
-
- Thermostat(Closure sendEvent, String id, String label, String displayName, int temperature, int currentCoolingSetpoint, int currentHeatingSetpoint, int coolingSetpoint,
- int thermostatSetpoint, int heatingSetpoint, List coolingSetpointRange, List thermostatSetpointRange, List heatingSetpointRange,
- List supportedThermostatFanModes, List supportedThermostatModes, String thermostatOperatingState, String thermostatFanMode, String thermostatMode,
- String climateName, String thermostatLatestMode, String thermostatLatestOperatingState, String thermostatLatestFanMode, int latestCoolingSetPoint,
- int latestThermostatSetPoint, int latestHeatingSetPoint) {
+import SmartThing.SmartThing
+
+class Thermostat 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 currentTemperature = new MutableInteger()
+ MutableInteger currentCoolingSetpoint = new MutableInteger()
+ MutableInteger currentHeatingSetpoint = new MutableInteger()
+ MutableInteger currentThermostatSetPoint = new MutableInteger()
+ // Features with string values
+ StringBuilder currentThermostatOperatingState = new StringBuilder()
+ StringBuilder currentThermostatFanMode = new StringBuilder()
+ StringBuilder currentThermostatMode = new StringBuilder()
+ StringBuilder currentClimateName = new StringBuilder()
+ // Maps from features to values
+ HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+
+ Thermostat(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentTemperature, MutableInteger currentCoolingSetpoint,
+ MutableInteger currentHeatingSetpoint, MutableInteger currentThermostatSetPoint, StringBuilder currentThermostatOperatingState, StringBuilder currentThermostatFanMode,
+ StringBuilder currentThermostatMode, StringBuilder currentClimateName) {
+ deviceValuesMap = deviceValueSmartThing
+ deviceIntValuesMap = deviceIntValueSmartThing
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
+
+ // Initialization
this.id = id
this.label = label
- this.sendEvent = sendEvent
- this.temperature = temperature
+ this.displayName = displayName
this.currentTemperature = currentTemperature
this.currentCoolingSetpoint = currentCoolingSetpoint
this.currentHeatingSetpoint = currentHeatingSetpoint
- this.coolingSetpoint = coolingSetpoint
- this.thermostatSetpoint = thermostatSetpoint
- this.heatingSetpoint = heatingSetpoint
- this.coolingSetpointRange = coolingSetpointRange
- this.thermostatSetpointRange = thermostatSetpointRange
- this.heatingSetpointRange = heatingSetpointRange
- this.supportedThermostatFanModes = supportedThermostatFanModes
- this.supportedThermostatModes = supportedThermostatModes
- this.thermostatOperatingState = thermostatOperatingState
- this.thermostatFanMode = thermostatFanMode
- this.thermostatMode = thermostatMode
- this.currentThermostatMode = thermostatMode
- this.climateName = climateName
- this.thermostatLatestMode = thermostatLatestMode
- this.thermostatLatestOperatingState = thermostatLatestOperatingState
- this.thermostatLatestFanMode = thermostatLatestFanMode
- this.latestHeatingSetPoint = latestHeatingSetPoint
- this.latestThermostatSetPoint = latestThermostatSetPoint
- this.latestCoolingSetPoint = latestCoolingSetPoint
- }
-
+ this.currentThermostatSetPoint = currentThermostatSetPoint
+ this.currentThermostatOperatingState = currentThermostatOperatingState
+ this.currentThermostatFanMode = currentThermostatFanMode
+ this.currentThermostatMode = currentThermostatMode
+ this.currentClimateName = currentClimateName
- //By Apps
- def setCoolingSetpoint(int coolingSetpoint) {
- if (this.coolingSetpoint != coolingSetpoint) {
- this.latestCoolingSetPoint = coolingSetpoint
- this.coolingSetpoint = coolingSetpoint
- this.currentCoolingSetpoint = coolingSetpoint
- println("Cooling set point for the thermostat with id:$id is changed to $coolingSetpoint!")
- sendEvent([name: "coolingSetpoint", value: "$coolingSetpoint", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ deviceValuesMap.put("temperature", currentTemperature)
+ deviceValuesMap.put("thermostatOperatingState", currentThermostatOperatingState)
+ deviceValuesMap.put("thermostatFanMode", currentThermostatFanMode)
+ deviceValuesMap.put("thermostatMode", currentThermostatMode)
+ deviceIntValuesMap.put("coolingSetpoint", currentCoolingSetpoint)
+ deviceIntValuesMap.put("heatingSetpoint", currentHeatingSetpoint)
+ deviceIntValuesMap.put("thermostatSetpoint", currentThermostatSetPoint)
}
- def setCoolingSetpoint(String coolingSetpoint) {
- setCoolingSetpoint(coolingSetpoint.toInteger())
+ // Methods to set values
+ def setCoolingSetpoint(int newValue) {
+ action(this.currentCoolingSetpoint, newValue, "coolingSetpoint")
}
- def setHeatingSetpoint(int heatingSetpoint) {
- if (this.heatingSetpoint != heatingSetpoint) {
- this.latestHeatingSetPoint = heatingSetpoint
- this.heatingSetpoint = heatingSetpoint
- this.currentHeatingSetpoint = heatingSetpoint
- println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
- sendEvent([name: "heatingSetpoint", value: "$heatingSetpoint", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ def setCoolingSetpoint(String newValue) {
+ setCoolingSetpoint(newValue.toInteger())
}
- def setHeatingSetpoint(String heatingSetpoint) {
- setHeatingSetpoint(heatingSetpoint.toInteger())
+ def setHeatingSetpoint(int newValue) {
+ action(this.currentHeatingSetpoint, newValue, "heatingSetpoint")
}
- def setSchedule() {
- //Not implemented yet
+ def setHeatingSetpoint(String newValue) {
+ setHeatingSetpoint(newValue.toInteger())
}
- def setThermostatFanMode(String thermostatFanMode) {
- if (this.thermostatFanMode != thermostatFanMode) {
- this.thermostatLatestFanMode = thermostatFanMode
- this.thermostatFanMode = thermostatFanMode
- println("Fan mode of the thermostat with id:$id is changed to $thermostatFanMode!")
- sendEvent([name: "thermostatFanMode", value: "$thermostatFanMode", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ def setThermostatFanMode(String newValue) {
+ action(this.currentThermostatFanMode, newValue, "thermostatFanMode")
}
- def setThermostatMode(String thermostatMode) {
- if (this.thermostatMode != thermostatMode) {
- this.thermostatLatestMode =thermostatMode
- this.thermostatMode = thermostatMode
- this.currentThermostatMode = thermostatMode
- println("Mode of the thermostat with id:$id is changed to $thermostatMode!")
- sendEvent([name: "thermostatMode", value: "$thermostatMode", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ def setThermostatMode(String newValue) {
+ action(this.currentThermostatMode, newValue, "thermostatMode")
}
def cool() {
- if (this.thermostatMode != "cool") {
- this.thermostatLatestMode = "cool"
- this.thermostatMode = "cool"
- this.currentThermostatMode = "cool"
- println("Mode of the thermostat with id:$id is changed to cool!")
- sendEvent([name: "thermostatMode", value: "cool", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ action(this.currentThermostatMode, "cool", "thermostatMode")
}
def heat() {
- if (this.thermostatMode != "heat") {
- this.thermostatLatestMode = "heat"
- this.thermostatMode = "heat"
- this.currentThermostatMode = "heat"
- println("Mode of the thermostat with id:$id is changed to heat!")
- sendEvent([name: "thermostatMode", value: "heat", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ action(this.currentThermostatMode, "heat", "thermostatMode")
}
def auto() {
- if (this.thermostatMode != "auto") {
- this.thermostatLatestMode = "auto"
- this.thermostatMode = "auto"
- this.currentThermostatMode = "auto"
- println("Mode of the thermostat with id:$id is changed to auto!")
- sendEvent([name: "thermostatMode", value: "auto", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ action(this.currentThermostatMode, "auto", "thermostatMode")
}
def emergencyHeat() {
- if (this.thermostatMode != "emergencyHeat") {
- this.thermostatLatestMode = "emergencyHeat"
- this.thermostatMode = "emergencyHeat"
- this.currentThermostatMode = "emergencyHeat"
- println("Mode of the thermostat with id:$id is changed to emergencyHeat!")
- sendEvent([name: "thermostatMode", value: "emergencyHeat", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ action(this.currentThermostatMode, "emergencyHeat", "thermostatMode")
}
def off() {
- if (this.thermostatMode != "off") {
- this.thermostatLatestMode = "off"
- this.thermostatMode = "off"
- this.currentThermostatMode = "off"
- println("Mode of the thermostat with id:$id is changed to off!")
- sendEvent([name: "thermostatMode", value: "off", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ action(this.currentThermostatMode, "off", "thermostatMode")
}
- def setClimate(String info, String givenClimateName) {
- if (this.climateName != givenClimateName) {
- this.climateName = givenClimateName
- println("Climate name of the thermostat with id:$id is changed to $givenClimateName!")
- }
+ def setClimate(String info, String newValue) {
+ action(currentClimateName, newValue, "climateName")
}
def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
- if ((this.heatingSetpoint != heatingSetpoint) || (this.coolingSetpoint != coolingSetpoint)) {
- this.coolingSetpoint = coolingSetpoint
- this.currentCoolingSetpoint = currentCoolingSetpoint
- println("Cooling set point for the thermostat with id:$id is changed to $coolingSetpoint!")
- this.heatingSetpoint = heatingSetpoint
- this.currentHeatingSetpoint = currentHeatingSetpoint
- println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
- sendEvent([name: "heatingSetpoint", value: "$heatingSetpoint", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- sendEvent([name: "coolingSetpoint", value: "$coolingSetpoint", deviceId: this.id, descriptionText: "",
+ setHeatingSetpoint(heatingSetpoint)
+ setCoolingSetpoint(coolingSetpoint)
+ }
+
+ 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 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"}'])
}
}
- //By Model Checker
- def setValue(String value, String name) {
- if ((name == "temperature") && (value.toInteger() != this.temperature)) {
- println("the temperature is $value!")
- this.temperature = value.toInteger()
- this.currentTemperature = value.toInteger()
- } else if ((name == "heatingSetpoint") && (value.toInteger() != this.heatingSetpoint)) {
- println("the heating set point of the thermostat with id:$id is $value!")
- this.latestHeatingSetPoint = value.toInteger()
- this.heatingSetpoint = value.toInteger()
- } else if ((name == "coolingSetpoint") && (value.toInteger() != this.coolingSetpoint)) {
- println("the cooling set point of the thermostat with id:$id is $value!")
- this.latestCoolingSetPoint = value.toInteger()
- this.coolingSetpoint = value.toInteger()
- } else if ((name == "thermostatSetpoint") && (value.toInteger() != this.thermostatSetpoint)) {
- println("the set point of the thermostat with id:$id is $value!")
- this.latestThermostatSetPoint = value.toInteger()
- this.thermostatSetpoint = value.toInteger()
- } else if ((name == "thermostatMode") && (value != this.thermostatMode)) {
- println("the mode of the thermostat with id:$id is $value!")
- this.thermostatLatestMode = value
- this.thermostatMode = value
- } else if ((name == "thermostatFanMode") && (value != this.thermostatFanMode)) {
- println("the fan mode of the thermostat with id:$id is $value!")
- this.thermostatLatestFanMode = value
- this.thermostatFanMode = value
- } else if ((name == "thermostatOperatingState") && (value != this.thermostatOperatingState)) {
- println("the operating state of the thermostat with id:$id is $value!")
- this.thermostatLatestOperatingState = value
- this.thermostatOperatingState = value
+ 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 currentValue(String deviceFeature) {
- if (deviceFeature == "thermostatMode")
- return thermostatMode
- else if (deviceFeature == "thermostatOperatingState")
- return thermostatOperatingState
- else if (deviceFeature == "thermostatFanMode")
- return thermostatFanMode
- else if (deviceFeature == "heatingSetpoint")
- return heatingSetpoint
- else if (deviceFeature == "coolingSetpoint")
- return coolingSetpoint
- else if (deviceFeature == "thermostatSetpoint")
- return thermostatSetpoint
+ // Methods to return values
+ def getCurrentTemperature() {
+ return currentTemperature.getValue()
}
- def latestValue(String deviceFeature) {
- if (deviceFeature == "thermostatMode")
- return thermostatLatestMode
- else if (deviceFeature == "thermostatOperatingState")
- return thermostatLatestOperatingState
- else if (deviceFeature == "thermostatFanMode")
- return thermostatLatestFanMode
- else if (deviceFeature == "heatingSetpoint")
- return latestHeatingSetPoint
- else if (deviceFeature == "coolingSetpoint")
- return latestCoolingSetPoint
- else if (deviceFeature == "thermostatSetpoint")
- return latestThermostatSetPoint
+ def getCurrentCoolingSetpoint() {
+ return currentCoolingSetpoint.getValue()
+ }
+
+ def getCurrentHeatingSetpoint() {
+ return currentHeatingSetpoint.getValue()
}
+ def getCurrentThermostatSetPoint() {
+ return currentThermostatSetPoint.getValue()
+ }
+
+ def getCurrentThermostatOperatingState() {
+ return currentThermostatOperatingState.toString()
+ }
+
+ def getCurrentThermostatFanMode() {
+ return currentThermostatFanMode.toString()
+ }
+
+ def getCurrentThermostatMode() {
+ return currentThermostatMode.toString()
+ }
+
+ def getCurrentClimateName() {
+ return currentClimateName.toString()
+ }
}
//Create a class for thermostat device
package Thermostat
-import Timer.SimulatedTimer
-
-public class Thermostats{
- int deviceNumbers
- List thermostats
- def sendEvent
- def timers
-
- //When we have only one device
- private String id = "thermostatID0"
- private String label = "thermostat0"
- private String displayName = "thermostat0"
- private int temperature = 66
- private int currentTemperature = 66
- private int currentCoolingSetpoint = 70
- private int currentHeatingSetpoint = 50
- private int coolingSetpoint = 70
- private int thermostatSetpoint = 60
- private int heatingSetpoint = 50
- private coolingSetpointRange = [70, 90]
- private thermostatSetpointRange = [50, 70]
- private heatingSetpointRange = [20, 50]
- private supportedThermostatFanModes = ["auto", "fanCirculate", "circulate", "fanOn", "on"]
- private supportedThermostatModes = ["auto", "cool", "emergencyHeat", "heat", "off"]
- private String thermostatOperatingState = "cooling"
- private String thermostatFanMode = "off"
- private String thermostatMode = "off"
- private String currentThermostatMode = "off"
- private String climateName = ""
- private String thermostatLatestMode = "off"
- private String thermostatLatestOperatingState = "cooling"
- private String thermostatLatestFanMode = "off"
- private int latestCoolingSetPoint = 70
- private int latestThermostatSetPoint = 60
- private int latestHeatingSetPoint = 50
-
-
- Thermostats(Closure sendEvent, int deviceNumbers, boolean init) {
- this.sendEvent = sendEvent
- this.timers = new SimulatedTimer()
- this.deviceNumbers = deviceNumbers
- this.thermostats = []
+import SmartThing.SmartThings
+
+class Thermostats extends SmartThings {
+ List thermostats = new ArrayList()
+
+ Thermostats(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ thermostats = smartThings
+
+ // Initialization
+ StringBuilder id = new StringBuilder("thermostatID0")
+ StringBuilder label = new StringBuilder("thermostat")
+ StringBuilder displayName = new StringBuilder("thermostat0")
+ StringBuilder climateName = new StringBuilder("climateName")
+ StringBuilder thermostatOperatingState = new StringBuilder()
+ StringBuilder thermostatFanMode = new StringBuilder()
+ StringBuilder thermostatMode = new StringBuilder()
+ MutableInteger temperature = new MutableInteger()
+ MutableInteger coolingSetpoint = new MutableInteger()
+ MutableInteger heatingSetpoint = new MutableInteger()
+ MutableInteger thermostatSetpoint = new MutableInteger()
if (init) {
- this.temperature = 60
- this.currentTemperature = 60
- this.currentCoolingSetpoint = 70
- this.coolingSetpoint = 70
- this.currentHeatingSetpoint = 35
- this.heatingSetpoint = 35
- this.thermostatSetpoint = 50
- this.thermostatFanMode = "off"
- this.thermostatLatestFanMode = "off"
- this.thermostatMode = "off"
- this.currentThermostatMode = "off"
- this.thermostatLatestMode = "off"
+ temperature.setValue(60)
+ coolingSetpoint.setValue(70)
+ heatingSetpoint.setValue(35)
+ thermostatSetpoint.setValue(50)
+ thermostatOperatingState.append("off")
+ thermostatFanMode.append("off")
+ thermostatMode.append("off")
} else {
- this.temperature = 66
- this.currentTemperature = 66
- this.currentCoolingSetpoint = 80
- this.coolingSetpoint = 80
- this.currentHeatingSetpoint = 50
- this.heatingSetpoint = 50
- this.thermostatSetpoint = 60
- this.thermostatFanMode = "circulate"
- this.thermostatLatestFanMode = "circulate"
- this.thermostatMode = "auto"
- this.currentThermostatMode = "auto"
- this.thermostatLatestMode = "auto"
+ temperature.setValue(66)
+ coolingSetpoint.setValue(80)
+ heatingSetpoint.setValue(50)
+ thermostatSetpoint.setValue(60)
+ thermostatOperatingState.append("heating")
+ thermostatFanMode.append("circulate")
+ thermostatMode.append("auto")
}
- thermostats.add(new Thermostat(sendEvent, id, label, displayName, this.temperature, this.currentCoolingSetpoint,
- this.currentHeatingSetpoint, this.coolingSetpoint, this.thermostatSetpoint, this.heatingSetpoint, this.coolingSetpointRange,
- this.thermostatSetpointRange, this.heatingSetpointRange, this.supportedThermostatFanModes, this.supportedThermostatModes,
- this.thermostatOperatingState, this.thermostatFanMode, this.thermostatMode, this.climateName,
- this.thermostatLatestMode, this.thermostatLatestOperatingState, this.thermostatLatestFanMode, this.latestCoolingSetPoint,
- this.latestThermostatSetPoint, this.latestHeatingSetPoint))
- }
- //Methods for closures
- def count(Closure Input) {
- thermostats.count(Input)
- }
- def size() {
- thermostats.size()
- }
- def each(Closure Input) {
- thermostats.each(Input)
- }
- def find(Closure Input) {
- thermostats.find(Input)
- }
- def sort(Closure Input) {
- thermostats.sort(Input)
- }
- def collect(Closure Input) {
- thermostats.collect(Input)
+ thermostats.add(new Thermostat(sendEvent, id, label, displayName, temperature, coolingSetpoint,
+ heatingSetpoint, thermostatSetpoint, thermostatOperatingState,
+ thermostatFanMode, thermostatMode, climateName))
}
- //By Apps
+ // Methods to set values
def setCoolingSetpoint(int coolingSetpoint) {
- if (coolingSetpoint != this.coolingSetpoint) {
- this.latestCoolingSetPoint = coolingSetpoint
- this.currentCoolingSetpoint = coolingSetpoint
- this.coolingSetpoint = coolingSetpoint
- thermostats[0].setCoolingSetpoint(coolingSetpoint)
- }
+ thermostats[0].setCoolingSetpoint(coolingSetpoint)
}
def setCoolingSetpoint(String coolingSetpoint) {
}
def setHeatingSetpoint(int heatingSetpoint) {
- if (heatingSetpoint != this.heatingSetpoint) {
- this.latestHeatingSetPoint = heatingSetpoint
- this.currentHeatingSetpoint = heatingSetpoint
- this.heatingSetpoint = heatingSetpoint
- thermostats[0].setHeatingSetpoint(heatingSetpoint)
- }
+ thermostats[0].setHeatingSetpoint(heatingSetpoint)
}
def setHeatingSetpoint(String heatingSetpoint) {
setHeatingSetpoint(heatingSetpoint.toInteger())
}
- def setSchedule() {
- //Not implemented yet
- }
-
def setThermostatFanMode(String thermostatFanMode) {
- if (thermostatFanMode != this.thermostatFanMode) {
- this.thermostatLatestFanMode = thermostatFanMode
- this.thermostatFanMode = thermostatFanMode
- thermostats[0].setThermostatFanMode(thermostatFanMode)
- }
+ thermostats[0].setThermostatFanMode(thermostatFanMode)
}
def setThermostatMode(String thermostatMode) {
- if (thermostatMode != this.thermostatMode) {
- this.thermostatLatestMode = thermostatMode
- this.thermostatMode = thermostatMode
- this.currentThermostatMode = thermostatMode
- thermostats[0].setThermostatMode(thermostatMode)
- }
+ thermostats[0].setThermostatMode(thermostatMode)
+ }
+
+ def setClimate(String info, String givenClimateName) {
+ thermostats[0].setClimate(info, givenClimateName)
+ }
+
+ def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
+ setCoolingSetpoint(coolingSetpoint)
+ setHeatingSetpoint(heatingSetpoint)
}
def cool() {
- if (thermostatMode != "cool") {
- this.thermostatLatestMode = "cool"
- this.thermostatMode = "cool"
- this.currentThermostatMode = "cool"
- thermostats[0].cool()
- }
+ thermostats[0].cool()
}
def heat() {
- if (thermostatMode != "heat") {
- this.thermostatLatestMode = "heat"
- this.thermostatMode = "heat"
- this.currentThermostatMode = "heat"
- thermostats[0].heat()
- }
+ thermostats[0].heat()
}
def auto() {
- if (thermostatMode != "auto") {
- this.thermostatLatestMode = "auto"
- this.thermostatMode = "auto"
- this.currentThermostatMode = "auto"
- thermostats[0].auto()
- }
+ thermostats[0].auto()
}
def emergencyHeat() {
- if (thermostatMode != "emergencyHeat") {
- this.thermostatLatestMode = "emergencyHeat"
- this.thermostatMode = "emergencyHeat"
- this.currentThermostatMode = "emergencyHeat"
- thermostats[0].emergencyHeat()
- }
+ thermostats[0].emergencyHeat()
}
def off() {
- if (thermostatMode != "off") {
- this.thermostatLatestMode = "off"
- this.thermostatMode = "off"
- this.currentThermostatMode = "off"
- thermostats[0].off()
- }
+ thermostats[0].off()
}
- def setClimate(String info, String givenClimateName) {
- if (givenClimateName != climateName) {
- this.climateName = givenClimateName
- thermostats[0].setClimate(info, givenClimateName)
- }
+ // Methods to return values
+ def getCurrentTemperature() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(thermostats[0].getCurrentTemperature())
+ return tmpValues
}
- def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
- if ((coolingSetpoint != this.coolingSetpoint) || (heatingSetpoint != this.heatingSetpoint)) {
- this.currentCoolingSetpoint = coolingSetpoint
- this.coolingSetpoint = coolingSetpoint
- this.currentHeatingSetpoint = heatingSetpoint
- this.heatingSetpoint = heatingSetpoint
- this.latestCoolingSetPoint = coolingSetpoint
- this.latestHeatingSetPoint = heatingSetpoint
- thermostats[0].setHold(info1, coolingSetpoint, heatingSetpoint, info2, info3)
- }
+ def getCurrentCoolingSetpoint() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(thermostats[0].getCurrentCoolingSetpoint())
+ return tmpValues
+ }
+
+ def getCurrentHeatingSetpoint() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(thermostats[0].getCurrentHeatingSetpoint())
+ return tmpValues
}
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["name"] == "temperature") {
- if (eventDataMap["value"].toInteger() != thermostats[0].temperature) {
- this.temperature = eventDataMap["value"].toInteger()
- this.currentTemperature = eventDataMap["value"].toInteger()
- thermostats[0].setValue(eventDataMap["value"], "temperature")
- sendEvent(eventDataMap)
- }
- } else if (eventDataMap["name"] == "heatingSetpoint") {
- if (eventDataMap["value"].toInteger() != thermostats[0].heatingSetpoint) {
- this.latestHeatingSetPoint = eventDataMap["value"].toInteger()
- this.heatingSetpoint = eventDataMap["value"].toInteger()
- thermostats[0].setValue(eventDataMap["value"], "heatingSetpoint")
- sendEvent(eventDataMap)
- }
- } else if (eventDataMap["name"] == "coolingSetpoint") {
- if (eventDataMap["value"].toInteger() != thermostats[0].coolingSetpoint) {
- this.latestCoolingSetPoint = eventDataMap["value"].toInteger()
- this.coolingSetpoint = eventDataMap["value"].toInteger()
- thermostats[0].setValue(eventDataMap["value"], "coolingSetpoint")
- sendEvent(eventDataMap)
- }
- } else if (eventDataMap["name"] == "thermostatSetpoint") {
- if (eventDataMap["value"].toInteger() != thermostats[0].thermostatSetpoint) {
- this.latestThermostatSetPoint = eventDataMap["value"].toInteger()
- this.thermostatSetpoint = eventDataMap["value"].toInteger()
- thermostats[0].setValue(eventDataMap["value"], "thermostatSetpoint")
- sendEvent(eventDataMap)
- }
- } else if (eventDataMap["name"] == "thermostatMode") {
- if (eventDataMap["value"] != thermostats[0].thermostatMode) {
- this.thermostatLatestMode = eventDataMap["value"]
- this.thermostatMode = eventDataMap["value"]
- this.currentThermostatMode = eventDataMap["value"]
- thermostats[0].setValue(eventDataMap["value"], "thermostatMode")
- sendEvent(eventDataMap)
- }
- } else if (eventDataMap["name"] == "thermostatFanMode") {
- if (eventDataMap["value"] != thermostats[0].thermostatFanMode) {
- this.thermostatLatestFanMode = eventDataMap["value"]
- this.thermostatFanMode = eventDataMap["value"]
- thermostats[0].setValue(eventDataMap["value"], "thermostatFanMode")
- sendEvent(eventDataMap)
- }
- } else if (eventDataMap["name"] == "thermostatOperatingState") {
- if (eventDataMap["value"] != thermostats[0].thermostatOperatingState) {
- this.thermostatLatestOperatingState = eventDataMap["value"]
- this.thermostatOperatingState = eventDataMap["value"]
- thermostats[0].setValue(eventDataMap["value"], "thermostatOperatingState")
- sendEvent(eventDataMap)
- }
- }
+ def getCurrentThermostatSetPoint() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(thermostats[0].getCurrentThermostatSetPoint())
+ return tmpValues
}
- def currentValue(String deviceFeature) {
- thermostats[0].currentValue(deviceFeature)
+ def getCurrentThermostatOperatingState() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(thermostats[0].getCurrentThermostatOperatingState())
+ return tmpValues
}
- def latestValue(String deviceFeature) {
- thermostats[0].latestValue(deviceFeature)
+ def getCurrentThermostatFanMode() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(thermostats[0].getCurrentThermostatFanMode())
+ return tmpValues
}
- def getAt(int ix) {
- thermostats[ix]
+ def getCurrentThermostatMode() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(thermostats[0].getCurrentThermostatMode())
+ return tmpValues
}
-}
+ def getCurrentClimateName() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(thermostats[0].getCurrentClimateName())
+ return tmpValues
+ }
+}
//Create a class for three axis
package ThreeAxis
-import Timer.SimulatedTimer
-import groovy.json.JsonSlurper
-
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
public class ThreeAxis {
- private String id
- private String label
- private String displayName
- private LinkedHashMap threeAxis
+ // id, label, and display name of the device
+ StringBuilder id = new StringBuilder()
+ StringBuilder label = new StringBuilder()
+ StringBuilder displayName = new StringBuilder()
+ // Other variables
+ def sendEvent
+ LinkedHashMap currentThreeAxis
+
- ThreeAxis(String id, String label, String displayName, LinkedHashMap threeAxis) {
+ ThreeAxis(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, LinkedHashMap currentThreeAxis) {
+ // Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.threeAxis = threeAxis
+ this.currentThreeAxis = currentThreeAxis
+ this.sendEvent = sendEvent
}
+ // Methods to set values
def setValue(LinkedHashMap eventDataMap) {
- threeAxis = new groovy.json.JsonSlurper().parseText(eventDataMap["value"])
- println("the three axis of cube is chagned to $threeAxis!")
+ def tmpID = id.toString()
+ currentThreeAxis = new groovy.json.JsonSlurper().parseText(eventDataMap["value"])
+ println("the three axis with id:$tmpID of cube is chagned to $currentThreeAxis!")
+ sendEvent(eventDataMap)
+ }
+
+ // Methods to return values
+ def getCurrentThreeAxis() {
+ return currentThreeAxis
}
def currentState(String deviceFeature) {
currentValue(deviceFeature)
}
- def currentValue(String deviceFeature) {
- if (deviceFeature == "threeAxis" || deviceFeature == "status")
- return threeAxis
+ def latestValue(String deviceFeature) {
+ currentValue(deviceFeature)
}
- def latestValue(String deviceFeature) {
+ def currentValue(String deviceFeature) {
if (deviceFeature == "threeAxis" || deviceFeature == "status")
- return threeAxis
+ return currentThreeAxis
}
}
//Create a class for three axis
package ThreeAxis
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
-public class ThreeAxises {
- private int deviceNumbers
- private List threeAxises
- def sendEvent
-
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private String id = "threeAxisID0"
- private String label = "threeAxis0"
- private String displayName = "threeAxis0"
- private LinkedHashMap threeAxis = [x:0, y:0, z:0]
-
-
- ThreeAxises(Closure sendEvent, int deviceNumbers, boolean init) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.threeAxises = []
+public class ThreeAxises extends SmartThings {
+ List threeAxises = new ArrayList()
- if (init) {
- this.threeAxis = [x:0, y:0, z:0]
- } else {
- this.threeAxis = [x:1, y:2, z:3]
- }
- threeAxises.add(new ThreeAxis(id, label, displayName, threeAxis))
- }
+ ThreeAxises(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ threeAxises = smartThings
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- threeAxises[0].setValue(eventDataMap)
- sendEvent(eventDataMap)
- }
+ // Initialization
+ StringBuilder id = new StringBuilder("threeAxisID0")
+ StringBuilder label = new StringBuilder("threeAxis")
+ StringBuilder displayName = new StringBuilder("threeAxis0")
+ LinkedHashMap threeAxis
- //Methods for closures
- def count(Closure Input) {
- threeAxises.count(Input)
- }
- def size() {
- threeAxises.size()
- }
- def each(Closure Input) {
- threeAxises.each(Input)
- }
- def sort(Closure Input) {
- threeAxises.sort(Input)
- }
- def find(Closure Input) {
- threeAxises.find(Input)
- }
- def collect(Closure Input) {
- threeAxises.collect(Input)
- }
-
- def currentState(String deviceFeature) {
- threeAxises[0].currentValue(deviceFeature)
- }
-
- def currentValue(String deviceFeature) {
- threeAxises[0].currentValue(deviceFeature)
- }
+ if (init)
+ threeAxis = [x:0, y:0, z:0]
+ else
+ threeAxis = [x:1, y:2, z:3]
- def latestValue(String deviceFeature) {
- threeAxises[0].latestValue(deviceFeature)
+ threeAxises.add(new ThreeAxis(sendEvent, id, label, displayName, threeAxis))
}
- def getAt(int ix) {
- threeAxises[ix]
+ // Methods to return values
+ def getCurrentThreeAxis() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(threeAxises[0].getCurrentThreeAxis())
+ return tmpValues
}
}
//Create a class for valve
package Valve
-import Timer.SimulatedTimer
-
-public class Valve {
- private String id
- private String label
- private String displayName
- private String valve
- private String valveLatestValue
- def sendEvent
- def timers
-
-
- Valve(Closure sendEvent, String id, String label, String displayName, String valve, String valveLatestValue) {
- this.sendEvent = sendEvent
- this.timers = new SimulatedTimer()
+import SmartThing.SmartThing
+
+public class Valve 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 currentValve = new StringBuilder()
+ // Maps from features to values
+ HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+
+ Valve(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentValve) {
+ deviceValuesMap = deviceValueSmartThing
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
+
+ // Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.valve = valve
- this.valveLatestValue = valveLatestValue
+ this.currentValve = currentValve
+
+ deviceValuesMap.put("valve", currentValve)
}
- //By Apps
+ // Methods to set values
def open() {
- if (valve != "open") {
- println("the valve with id:$id is open!")
- this.valveLatestValue = "open"
- this.valve = "open"
- sendEvent([name: "contact", value: "open", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ action(currentValve, "open", "contact")
}
def open(LinkedHashMap metaData) {
- if (valve != "open") {
- def task = timers.runAfter(metaData["delay"]) {
- println("the valve with id:$id is open!")
- this.valveLatestValue = "open"
- this.valve = "open"
- sendEvent([name: "contact", value: "open", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
+ open()
}
def close() {
- if (valve != "closed") {
- println("the valve with id:$id is closed!")
- this.valveLatestValue = "closed"
- this.valve = "closed"
- sendEvent([name: "contact", value: "closed", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
+ action(currentValve, "closed", "contact")
}
def close(LinkedHashMap metaData) {
- if (valve != "closed") {
- def task = timers.runAfter(metaData["delay"]) {
- println("the valve with id:$id is closed!")
- this.valveLatestValue = "closed"
- this.valve = "closed"
- sendEvent([name: "contact", value: "closed", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
- }
-
- //By Model Checker
- def setValue(String value) {
- println("the valve with id:$id is $value!")
- this.valveLatestValue = value
- this.valve = value
+ close()
}
- def currentValue(String deviceFeature) {
- if (deviceFeature == "valve") {
- return valve
+ 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 valve with id:$tmpID is $newValue!")
+ sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
}
}
- def latestValue(String deviceFeature) {
- if (deviceFeature == "valve") {
- return valveLatestValue
- }
+ // Methods to return values
+ def getCurrentValve() {
+ return currentValve.toString()
}
}
//Create a class for valve
package Valve
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
-public class Valves {
- int deviceNumbers
- List valves
- def timers
- def sendEvent
+public class Valves extends SmartThings {
+ List valves = new ArrayList()
- //If we have only one device
- private String id = "ValveID0"
- private String label = "Valve0"
- private String displayName = "Valve0"
- private String valve = "closed"
- private String valveLatestValue = "closed"
+ Valves(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ valves = smartThings
- Valves(Closure sendEvent, int deviceNumbers, boolean init) {
- this.sendEvent = sendEvent
- this.timers = new SimulatedTimer()
- this.deviceNumbers = deviceNumbers
- this.valves = []
+ // Initialization
+ StringBuilder id = new StringBuilder("valveID0")
+ StringBuilder label = new StringBuilder("valve")
+ StringBuilder displayName = new StringBuilder("valve0")
+ StringBuilder valve = new StringBuilder()
- if (init) {
- this.valve = "closed"
- this.valveLatestValue = "closed"
- } else {
- this.valve = "open"
- this.valveLatestValue = "open"
- }
- valves.add(new Valve(sendEvent, id, label, displayName, this.valve, this.valveLatestValue))
- }
+ if (init)
+ valve.append("closed")
+ else
+ valve.append("open")
- //Methods for closures
- def count(Closure Input) {
- valves.count(Input)
- }
- def size() {
- valves.size()
- }
- def each(Closure Input) {
- valves.each(Input)
- }
- def find(Closure Input) {
- valves.find(Input)
- }
- def sort(Closure Input) {
- valves.sort(Input)
- }
- def collect(Closure Input) {
- valves.collect(Input)
+ valves.add(new Valve(sendEvent, id, label, displayName, valve))
}
- //By Apps
+ // Methods to set values
def open() {
- if (valve != "open") {
- this.valve = "open"
- this.valveLatestValue = "open"
- valves[0].open()
- }
+ valves[0].open()
}
def open(LinkedHashMap metaData) {
- if (valve != "open") {
- def task = timers.runAfter(metaData["delay"]) {
- this.valve = "open"
- this.valveLatestValue = "open"
- valves[0].open()
- }
- }
+ open()
}
- def close() {
- if (valve != "closed") {
- this.valve = "closed"
- this.valveLatestValue = "closed"
- valves[0].close()
- }
+ def close() {
+ valves[0].close()
}
def close(LinkedHashMap metaData) {
- if (valve != "closed") {
- def task = timers.runAfter(metaData["delay"]) {
- this.valve = "closed"
- this.valveLatestValue = "closed"
- valves[0].close()
- }
- }
+ close()
}
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["value"] != valves[0].valve) {
- this.valve = eventDataMap["value"]
- valves[0].setValue(eventDataMap["value"])
- }
+ // Methods to return values
+ def getCurrentValve() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(valves[0].getCurrentValve())
+ return tmpValues
}
-
- def currentValue(String deviceFeature) {
- valves[0].currentValue(deviceFeature)
- }
-
- def latestValue(String deviceFeature) {
- valves[0].latestValue(deviceFeature)
- }
-
- def getAt(int ix) {
- valves[ix]
- }
}
//Create a class for water sensor
package WaterSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
-public class WaterSensor {
- private String id
- private String label
- private String displayName
- private String water
+public class WaterSensor 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 currentWater = new StringBuilder()
+ // Maps from features to values
+ HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
- WaterSensor(String id, String label, String displayName, String water) {
+ WaterSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentWater) {
+ deviceValuesMap = deviceValueSmartThing
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
+
+ // Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.water = water
+ this.currentWater = currentWater
+
+ deviceValuesMap.put("water", currentWater)
}
- //By Model Checker
- def setValue(String value) {
- println("the water state is changed to $value!")
- this.water = value
+ // Methods to return values
+ def getCurrentWater() {
+ return currentWater.toString()
}
}
//Create a class for water sensor
package WaterSensor
-import Timer.SimulatedTimer
-
-public class WaterSensors {
- private int deviceNumbers
- private List waterSensors
- def sendEvent
-
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private String id = "waterSensorID0"
- private String label = "waterSensor0"
- private String displayName = "waterSensor0"
- private String water = "dry"
+import SmartThing.SmartThings
+public class WaterSensors extends SmartThings {
+ List waterSensors = new ArrayList()
- WaterSensors(Closure sendEvent, int deviceNumbers, boolean init) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.waterSensors = []
+ WaterSensors(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ waterSensors = smartThings
- if (init) {
- this.water = "dry"
- } else {
- this.water = "wet"
- }
- waterSensors.add(new WaterSensor(id, label, displayName, this.water))
- }
+ // Initialization
+ StringBuilder id = new StringBuilder("waterSensorID0")
+ StringBuilder label = new StringBuilder("waterSensor")
+ StringBuilder displayName = new StringBuilder("waterSensor0")
+ StringBuilder water = new StringBuilder()
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- if (eventDataMap["value"] != waterSensors[0].water) {
- this.water = eventDataMap["value"]
- waterSensors[0].setValue(eventDataMap["value"])
- sendEvent(eventDataMap)
- }
- }
+ if (init)
+ water.append("dry")
+ else
+ water.append("wet")
- //Methods for closures
- def count(Closure Input) {
- waterSensors.count(Input)
- }
- def size() {
- waterSensors.size()
- }
- def each(Closure Input) {
- waterSensors.each(Input)
+ waterSensors.add(new WaterSensor(sendEvent, id, label, displayName, water))
}
- def find(Closure Input) {
- waterSensors.find(Input)
- }
- def sort(Closure Input) {
- waterSensors.sort(Input)
- }
- def collect(Closure Input) {
- waterSensors.collect(Input)
- }
-
- def getAt(int ix) {
- waterSensors[ix]
+
+ // Methods to return values
+ def getCurrentWater() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(waterSensors[0].getCurrentWater())
+ return tmpValues
}
}
-01-control-lights-and-locks-with-contact-sensor.groovy
-beacon-control.groovy
+#01-control-lights-and-locks-with-contact-sensor.groovy
+#beacon-control.groovy
big-turn-off.groovy
-big-turn-on.groovy
-control-switch-with-contact-sensor.groovy
-double-tap.groovy
-energy-saver.groovy
-gentle-wake-up.groovy
-good-night.groovy
-humidity-alert.groovy
-jenkins-notifier.groovy
-make-it-so.groovy
-monitor-on-sense.groovy
-nfc-tag-toggle.groovy
-once-a-day.groovy
-power-allowance.groovy
-rise-and-shine.groovy
+#big-turn-on.groovy
+#control-switch-with-contact-sensor.groovy
+#double-tap.groovy
+#energy-saver.groovy
+#gentle-wake-up.groovy
+#good-night.groovy
+#humidity-alert.groovy
+#jenkins-notifier.groovy
+#make-it-so.groovy
+#monitor-on-sense.groovy
+#nfc-tag-toggle.groovy
+#once-a-day.groovy
+#power-allowance.groovy
+#rise-and-shine.groovy
smart-turn-it-on.groovy
-sunrise-sunset.groovy
-the-big-switch.groovy
-turn-it-on-for-5-minutes.groovy
-BetterLaundryMonitor.groovy
-garage-switch.groovy
-loft.groovy
+#sunrise-sunset.groovy
+#the-big-switch.groovy
+#turn-it-on-for-5-minutes.groovy
+#BetterLaundryMonitor.groovy
+#garage-switch.groovy
+#loft.groovy
//Create a class for Touch sensor
package appTouch
+import SmartThing.SmartThing
-public class Touched{
- def sendEvent
- private String id
- private int isTouched
- private String label
- private String name
+public class Touched extends SmartThing {
+ // id, label, and display name of the device
+ StringBuilder id = new StringBuilder()
+ StringBuilder label = new StringBuilder()
+ StringBuilder displayName = new StringBuilder()
+ Touched(Closure sendEvent) {
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
- Touched(Closure sendEvent, int isTouched) {
- this.sendEvent = sendEvent
- this.isTouched = isTouched
- this.label = "app0"
- this.id = "appID0"
- this.name = "app0"
- }
-
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- println("The application is Touched!")
- this.isTouched = 1 //Do we need this?
- sendEvent(eventDataMap)
+ // Initialization
+ id.append("appTouchID0")
+ label.append("appTouch")
+ displayName.append("appTouch0")
}
}