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 acceleration
private String currentAcceleration
private String accelerationLatestValue
- private List states = []
- private List timeOfStates = []
AccelerationSensor(String id, String label, String displayName, String acceleration, String accelerationLatestValue) {
this.id = id
this.accelerationLatestValue = value
this.acceleration = value
this.currentAcceleration = value
- this.states.add(value)
- this.timeOfStates.add(System.currentTimeMillis())
}
- def statesSince(String info, Date dateObj) {
- def List happenedStates = []
- def sinceThen = dateObj.time
- for (int i = 0;i < timeOfStates.size();i++) {
- if (timeOfStates[i]>=sinceThen)
- happenedStates.add(states[i])
+ def statesSince() {
+ def evtActive = [[name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
+ [name: "acceleration.active", 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"}'],
+ [name: "acceleration.inactive", 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"}'],
+ [name: "acceleration.active", 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"}'],
+ [name: "acceleration.inactive", 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
}
- return happenedStates
}
}
}
+ //methods
+ def eventsSince(Date dateObj) {
+ return accelerationSensors[0].eventsSince()
+ }
+
+ def statesSince(String info, Date dateObj) {
+ return accelerationSensors[0].statesSince()
+ }
+
//Methods for closures
def count(Closure Input) {
accelerationSensors.count(Input)
accelerationSensors[0].latestValue(deviceFeature)//It is called if we have only one device
}
- def statesSince(String info, Date dateObj) {
- return accelerationSensors[0].statesSince(info, dateObj)
- }
-
def getAt(int ix) {
accelerationSensors[ix]
}
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) {
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
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)) {
//methods
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: "",
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 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: "",
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: "",
private String label = "colorControl0"
private String displayName = "colorControl0"
private String color = "red"
+ private String currentColor = "red"
private String currentSwitch = "off"
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
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"] == "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
def setColor(String color) {
if (color != this.color) {
+ this.currentColor = color
this.color = color
colorControls[0].setColor(color)
}
def setHue(int hue) {
if (hue != this.hue) {
- this.hue = hue
+ this.hue = hue
+ this.currentHue = hue
colorControls[0].setHue(hue)
}
}
def setSaturation(int 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)
}
private String unit
private String data
private int integerValue
+ private double doubleValue
private List integerValues = ["battery", "hue", "saturation", "energy", "level", "temperature",
"heatingSetpoint", "coolingSetpoint", "thermostatSetpoint", "illuminance"]
this.unit = unit
this.data = data
this.displayed = displayed
- if (integerValues.contains(name))
+ if (integerValues.contains(name)) {
this.integerValue = value.toInteger()
+ this.doubleValue = Double.parseDouble(value);
+ }
}
}
import Valve.Valves
import MobilePresence.MobilePresence
import MobilePresence.MobilePresences
+import ColorTemperature.ColorTemperature
+import ColorTemperature.ColorTemperatures
+import Button.Button
+import Button.Buttons
import Timer.SimulatedTimer
//GlobalVariables
@Field def sleepSensorObject0
@Field def sleepSensorObject1
@Field def sleepSensorObject2
-//Global Object for class sleep sensor!
+//Global Object for class step sensor!
@Field stepSensorObjects = 0
@Field def stepSensorObject0
@Field def stepSensorObject1
@Field def temperatureMeasurementObject0
@Field def temperatureMeasurementObject1
@Field def temperatureMeasurementObject2
-//Global Object for class temperature measurement!
+//Global Object for class water sensor!
@Field waterSensorObjects = 0
@Field def waterSensorObject0
@Field def waterSensorObject1
@Field def valveObject0
@Field def valveObject1
@Field def valveObject2
-//Global Object for class valve!
+//Global Object for class mobile presence!
@Field mobilePresenceObjects = 0
@Field def mobilePresenceObject0
@Field def mobilePresenceObject1
@Field def mobilePresenceObject2
-
+//Global Object for class color temperature!
+@Field colorTemperatureObjects = 0
+@Field def colorTemperatureObject0
+@Field def colorTemperatureObject1
+@Field def colorTemperatureObject2
+//Global Object for class button!
+@Field buttonObjects = 0
+@Field def buttonObject0
+@Field def buttonObject1
+@Field def buttonObject2
//Global variables
extractedObjectsConstructorApp2.append(metaData['name']+" = obj.alarmObject\n")
}
break
+ case "capability.button":
+ globalObjects.eachLine { line ->
+ if(line.contains("buttonObject")){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def buttonObject = new Buttons(sendEvent, 1)\n")
+
+ if (buttonObjects == 0) {
+ buttonObject0 = metaData['name']
+ this[buttonObject0] = new Buttons({}, 1)
+ } else if (buttonObjects == 1) {
+ buttonObject1 = metaData['name']
+ this[buttonObject1] = new Buttons({}, 1)
+ } else if (buttonObjects == 2) {
+ buttonObject2 = metaData['name']
+ this[buttonObject2] = new Buttons({}, 1)
+ }
+
+ buttonObjects=buttonObjects+1
+
+ settings.put(metaData['name'], new Buttons({}, 1))
+
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class Button!\n")
+ extractedObjectsApp1.append("def "+metaData['name']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['name']+" = obj.buttonObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class Button!\n")
+ extractedObjectsApp2.append("def "+metaData['name']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['name']+" = obj.buttonObject\n")
+ }
+ break
case "capability.battery":
globalObjects.eachLine { line ->
if(line.contains("batteryObject")){
extractedObjectsConstructorApp2.append(metaData['name']+" = obj.carbonMonoxideDetectorObject\n")
}
break
+ case "capability.colorTemperature":
+ globalObjects.eachLine { line ->
+ if(line.contains("colorTemperatureObject")){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def colorTemperatureObject = new ColorTemperatures(sendEvent, 1)\n")
+
+ if (colorTemperatureObjects == 0) {
+ colorTemperatureObject0 = metaData['name']
+ this[colorTemperatureObject0] = new ColorTemperatures({}, 1)
+ } else if (colorTemperatureObjects == 1) {
+ colorTemperatureObject1 = metaData['name']
+ this[colorTemperatureObject1] = new ColorTemperatures({}, 1)
+ } else if (colorTemperatureObjects == 2) {
+ colorTemperatureObject2 = metaData['name']
+ this[colorTemperatureObject2] = new ColorTemperatures({}, 1)
+ }
+
+ colorTemperatureObjects=colorTemperatureObjects+1
+
+ settings.put(metaData['name'], new ColorTemperatures({}, 1))
+
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class color temperature!\n")
+ extractedObjectsApp1.append("def "+metaData['name']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['name']+" = obj.colorTemperatureObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class color control!\n")
+ extractedObjectsApp2.append("def "+metaData['name']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['name']+" = obj.colorTemperatureObject\n")
+ }
+ break
case "capability.colorControl":
globalObjects.eachLine { line ->
if(line.contains("colorControlObject")){
this.rate = value.toInteger()
}
}
+
+
+ def currentValue(String deviceFeature) {
+ if (deviceFeature == "level") {
+ return level
+ } else if (deviceFeature == "switch") {
+ return switchState
+ }
+ }
+
+ def latestValue(String deviceFeature) {
+ if (deviceFeature == "level") {
+ return level
+ } else if (deviceFeature == "switch") {
+ return switchState
+ }
+ }
}
}
}
+ def currentValue(String deviceFeature) {
+ switchLevels[0].currentValue(deviceFeature)
+ }
+
+ def latestValue(String deviceFeature) {
+ switchLevels[0].latestValue(deviceFeature)
+ }
+
+
def getAt(int ix) {
switchLevels[ix]
}
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
switchObject.setValue([name: "switch", value: "on", deviceId: "switchID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+switchObject.setValue([name: "switch.off", value: "off", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+switchObject.setValue([name: "switch.on", value: "on", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
/////
/*events*/
//
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
colorControlObject.setValue([name: "switch", value: "off", deviceId: "colorControlID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "switch.on", value: "on", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "switch.off", value: "off", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
colorControlObject.setValue([name: "colorTemperature", value: "50", deviceId: "colorControlID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
/*events*/
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
relaySwitchObject.setValue([name: "switch", value: "on", deviceId: "relaySwitchID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+relaySwitchObject.setValue([name: "switch.off", value: "off", deviceId: "relaySwitchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+relaySwitchObject.setValue([name: "switch.on", value: "on", deviceId: "relaySwitchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
/////
/*events*/
//
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
switchLevelObject.setValue([name: "switch", value: "off", deviceId: "switchLevelID0", descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+switchLevelObject.setValue([name: "switch.on", value: "on", deviceId: "switchLevelID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+switchLevelObject.setValue([name: "switch.off", value: "off", deviceId: "switchLevelID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
/////
/*events*/
//
/////
/*events*/
//
+-------------------------------------------------------------------------------
+
+
+//For color temperature:
+int colorTemperature
+String switchState
+/*events*/
+colorTemperatureObject.setValue([name: "switch", value: "off", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorTemperatureObject.setValue([name: "switch", value: "on", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorTemperatureObject.setValue([name: "switch.off", value: "off", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorTemperatureObject.setValue([name: "switch.on", value: "on", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorTemperatureObject.setValue([name: "colorTemperature", value: "13000", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+/////
+/*events*/
+//
+-------------------------------------------------------------------------------
+
+
+//For button:
+String button
+/*events*/
+buttonObject.setValue([name: "button", value: "held", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"buttonNumber": 1}'])
+buttonObject.setValue([name: "button", value: "push", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"buttonNumber": 1}'])
+/////
+/*events*/
+//
+