//Global variables for files
+@Field File globalObjects = new File("Extractor/globalObjects.groovy")
@Field File extractedObjectsApp1 = new File("Extractor/App1/extractedObjectsApp1.groovy")
@Field File extractedObjectsApp2 = new File("Extractor/App2/extractedObjectsApp2.groovy")
@Field File extractedObjectsConstructorApp1 = new File("Extractor/App1/extractedObjectsConstructorApp1.groovy")
//Empty the files
if (App == "App1") {
+ globalObjects.write("")
extractedObjectsApp1.write("")
extractedObjectsConstructorApp1.write("")
} else if (App == "App2") {
if (metaData.containsKey('options')) {
println "Options: "+metaData['options']
}
+ def contains = 0
switch(metaData['type']) {
case "capability.lock":
+ globalObjects.eachLine { line ->
+ if(line.contains('"lockObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def lockObject = new Locks(sendEvent, 1)\n")
+
if (lockObjects == 0) {
lockObject0 = metaData['name']
this[lockObject0] = new Locks({}, 1)
}
break
case "capability.alarm":
+ globalObjects.eachLine { line ->
+ if(line.contains('"alarmObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def alarmObject = new Alarms(sendEvent, 1)\n")
+
if (alarmObjects == 0) {
alarmObject0 = metaData['name']
this[alarmObject0] = new Alarms({}, 1)
}
break
case "capability.battery":
+ globalObjects.eachLine { line ->
+ if(line.contains('"batteryObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def batteryObject = new Batteries(sendEvent, 1)\n")
+
if (batteryObjects == 0) {
batteryObject0 = metaData['name']
this[batteryObject0] = new Batteries({}, 1)
}
break
case "capability.beacon":
+ globalObjects.eachLine { line ->
+ if(line.contains('"beaconSensorObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def beaconSensorObject = new BeaconSensors(sendEvent, 1)\n")
+
if (beaconSensorObjects == 0) {
beaconSensorObject0 = metaData['name']
this[beaconSensorObject0] = new BeaconSensors({}, 1)
}
break
case "capability.carbonMonoxideDetector":
+ globalObjects.eachLine { line ->
+ if(line.contains('"carbonMonoxideDetectorObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def carbonMonoxideDetectorObject = new CarbonMonoxideDetectors(sendEvent, 1)\n")
+
if (carbonMonoxideDetectorObjects == 0) {
carbonMonoxideDetectorObject0 = metaData['name']
this[carbonMonoxideDetectorObject0] = new CarbonMonoxideDetectors({}, 1)
}
break
case "capability.colorControl":
+ globalObjects.eachLine { line ->
+ if(line.contains('"colorControlObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def colorControlObject = new ColorControls(sendEvent, 1)\n")
+
if (colorControlObjects == 0) {
colorControlObject0 = metaData['name']
this[colorControlObject0] = new ColorControls({}, 1)
}
break
case "capability.contactSensor":
+ globalObjects.eachLine { line ->
+ if(line.contains('"contactObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def contactObject = new ContactSensors(sendEvent, 1)\n")
+
if (contactObjects == 0) {
contactObject0 = metaData['name']
this[contactObject0] = new ContactSensors({}, 1)
}
break
case "capability.doorControl":
+ globalObjects.eachLine { line ->
+ if(line.contains('"doorControlObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def doorControlObject = new DoorControls(sendEvent, 1)\n")
+
if (doorControlObjects == 0) {
doorControlObject0 = metaData['name']
this[doorControlObject0] = new DoorControls({}, 1)
}
break
case "capability.energyMeter":
+ globalObjects.eachLine { line ->
+ if(line.contains('"energyMeterObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def energyMeterObject = new EnergyMeters(sendEvent, 1)\n")
+
if (energyMeterObjects == 0) {
energyMeterObject0 = metaData['name']
this[energyMeterObject0] = new EnergyMeters({}, 1)
}
break
case "capability.illuminanceMeasurement":
+ globalObjects.eachLine { line ->
+ if(line.contains('"illuminanceMeasurementObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def illuminanceMeasurementObject = new IlluminanceMeasurements(sendEvent, 1)\n")
+
if (illuminanceMeasurementObjects == 0) {
illuminanceMeasurementObject0 = metaData['name']
this[illuminanceMeasurementObject0] = new IlluminanceMeasurements({}, 1)
}
break
case "capability.accelerationSensor":
+ globalObjects.eachLine { line ->
+ if(line.contains('"accelerationSensorObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def accelerationSensorObject = new AccelerationSensors(sendEvent, 1)\n")
+
if (accelerationSensorObjects == 0) {
accelerationSensorObject0 = metaData['name']
this[accelerationSensorObject0] = new AccelerationSensors({}, 1)
}
break
case "capability.motionSensor":
+ globalObjects.eachLine { line ->
+ if(line.contains('"motionSensorObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def motionSensorObject = new MotionSensors(sendEvent, 1)\n")
+
if (motionSensorObjects == 0) {
motionSensorObject0 = metaData['name']
this[motionSensorObject0] = new MotionSensors({}, 1)
}
break
case "capability.musicPlayer":
+ globalObjects.eachLine { line ->
+ if(line.contains('"musicPlayerObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def musicPlayerObject = new MusicPlayers(sendEvent, 1)\n")
+
if (musicPlayerObjects == 0) {
musicPlayerObject0 = metaData['name']
this[musicPlayerObject0] = new MusicPlayers({}, 1)
}
break
case "capability.powerMeter":
+ globalObjects.eachLine { line ->
+ if(line.contains('"powerMeterObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def powerMeterObject = new PowerMeters(sendEvent, 1)\n")
+
if (powerMeterObjects == 0) {
powerMeterObject0 = metaData['name']
this[powerMeterObject0] = new PowerMeters({}, 1)
}
break
case "capability.presenceSensor":
+ globalObjects.eachLine { line ->
+ if(line.contains('"presenceSensorObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def presenceSensorObject = new PresenceSensors(sendEvent, 1)\n")
+
if (presenceSensorObjects == 0) {
presenceSensorObject0 = metaData['name']
this[presenceSensorObject0] = new PresenceSensors({}, 1)
}
break
case "capability.relativeHumidityMeasurement":
+ globalObjects.eachLine { line ->
+ if(line.contains('"humidityMeasurementObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def humidityMeasurementObject = new RelativeHumidityMeasurements(sendEvent, 1)\n")
+
if (humidityMeasurementObjects == 0) {
humidityMeasurementObject0 = metaData['name']
this[humidityMeasurementObject0] = new RelativeHumidityMeasurements({}, 1)
}
break
case "capability.relaySwitch":
+ globalObjects.eachLine { line ->
+ if(line.contains('"relaySwitchObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def relaySwitchObject = new RelaySwitches(sendEvent, 1)\n")
+
if (relaySwitchObjects == 0) {
relaySwitchObject0 = metaData['name']
this[relaySwitchObject0] = new RelaySwitches({}, 1)
}
break
case "capability.sleepSensor":
+ globalObjects.eachLine { line ->
+ if(line.contains('"sleepSensorObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def sleepSensorObject = new SleepSensors(sendEvent, 1)\n")
+
if (sleepSensorObjects == 0) {
sleepSensorObject0 = metaData['name']
this[sleepSensorObject0] = new SleepSensors({}, 1)
}
break
case "capability.smokeDetector":
+ globalObjects.eachLine { line ->
+ if(line.contains('"smokeDetectorObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def smokeDetectorObject = new SmokeDetectors(sendEvent, 1)\n")
+
if (smokeDetectorObjects == 0) {
smokeDetectorObject0 = metaData['name']
this[smokeDetectorObject0] = new SmokeDetectors({}, 1)
}
break
case "capability.stepSensor":
+ globalObjects.eachLine { line ->
+ if(line.contains('"stepSensorObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def stepSensorObject = new StepSensors(sendEvent, 1)\n")
+
if (stepSensorObjects == 0) {
stepSensorObject0 = metaData['name']
this[stepSensorObject0] = new StepSensors({}, 1)
extractedObjectsConstructorApp2.append(metaData['name']+" = obj.stepSensorObject\n")
}
break
- case "capability.switch":
+ case "capability.switch":
+ globalObjects.eachLine { line ->
+ if(line.contains('"switchObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def switchObject = new Switches(sendEvent, 1)\n")
+
if (switchObjects == 0) {
switchObject0 = metaData['name']
this[switchObject0] = new Switches({}, 1)
}
break
case "capability.switchLevel":
+ globalObjects.eachLine { line ->
+ if(line.contains('"switchLevelObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def switchLevelObject = new SwitchLevels(sendEvent, 1)\n")
+
if (switchLevelObjects == 0) {
switchLevelObject0 = metaData['name']
this[switchLevelObject0] = new SwitchLevels({}, 1)
}
break
case "capability.temperatureMeasurement":
+ globalObjects.eachLine { line ->
+ if(line.contains('"temperatureMeasurementObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def temperatureMeasurementObject = new TemperatureMeasurements(sendEvent, 1)\n")
+
if (temperatureMeasurementObjects == 0) {
temperatureMeasurementObject0 = metaData['name']
this[temperatureMeasurementObject0] = new TemperatureMeasurements({}, 1)
}
break
case "capability.thermostat":
+ globalObjects.eachLine { line ->
+ if(line.contains('thermostatObject')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def thermostatObject = new Thermostats(sendEvent, 1)\n")
+
if (thermostatObjects == 0) {
thermostatObject0 = metaData['name']
this[thermostatObject0] = new Thermostats({}, 1)
}
break
case "capability.valve":
+ globalObjects.eachLine { line ->
+ if(line.contains('"valveObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def valveObject = new Valves(sendEvent, 1)\n")
+
if (valveObjects == 0) {
valveObject0 = metaData['name']
this[valveObject0] = new Valves({}, 1)
}
break
case "capability.speechSynthesis":
+ globalObjects.eachLine { line ->
+ if(line.contains('"speechSynthesisObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def speechSynthesisObject = new SpeechSynthesises(sendEvent, 1)\n")
+
if (speechSynthesisObjects == 0) {
speechSynthesisObject0 = metaData['name']
this[speechSynthesisObject0] = new SpeechSynthesises({}, 1)
}
break
case "capability.waterSensor":
+ globalObjects.eachLine { line ->
+ if(line.contains('"waterSensorObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def waterSensorObject = new WaterSensors(sendEvent, 1)\n")
+
if (waterSensorObjects == 0) {
waterSensorObject0 = metaData['name']
this[waterSensorObject0] = new WaterSensors({}, 1)
}
break
case "capability.touchSensor":
+ globalObjects.eachLine { line ->
+ if(line.contains('"touchSensorObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def touchSensorObject = new NfcTouch(sendEvent, 1)\n")
+
if (touchSensorObjects == 0) {
touchSensorObject0 = metaData['name']
this[touchSensorObject0] = new NfcTouch({}, 1)
}
break
case "capability.imageCapture":
+ contains = globalObjects.eachLine { line ->
+ if(line.contains('"imageCaptureObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def imageCaptureObject = new ImageCaptures(sendEvent, 1)\n")
+
if (imageCaptureObjects == 0) {
imageCaptureObject0 = metaData['name']
this[imageCaptureObject0] = new ImageCaptures({}, 1)
}
break
case "device.mobilePresence":
+ contains = globalObjects.eachLine { line ->
+ if(line.contains('"mobilePresenceObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def mobilePresenceObject = new MobilePresences(sendEvent, 1)\n")
+
if (mobilePresenceObjects == 0) {
mobilePresenceObject0 = metaData['name']
this[mobilePresenceObject0] = new MobilePresences({}, 1)
}
break
case "device.aeonKeyFob":
+ contains = globalObjects.eachLine { line ->
+ if(line.contains('"aeonKeyFobObject"')){
+ contains = 1
+ }
+ }
+
+ if (contains == 0)
+ globalObjects.append("@Field def aeonKeyFobObject = new AeonKeyFobs(sendEvent, 1)\n")
+
if (aeonKeyFobObjects == 0) {
aeonKeyFobObject0 = metaData['name']
this[aeonKeyFobObject0] = new AeonKeyFobs({}, 1)
}
break
case "mode":
- def randomVariable = Math.abs(new Random().nextInt() % 3)
+ //def randomVariable = Math.abs(new Random().nextInt() % 3)
def modes = ["away", "home", "night"]
- def userInput = modes[randomVariable]
+ def userInput = modes[0]
if (modeVariables == 0) {
mode0 = metaData['name']
}
break
case "decimal":
- def userInput = Math.abs(new Random().nextInt() % 60) + 40
-
+ //def userInput = Math.abs(new Random().nextInt() % 60) + 40
+ def userInput = 50
+
if (decimalVariables == 0) {
decimal0 = metaData['name']
this[decimal0] = userInput
break
case "text":
def userInput = "This is just a text!"
-
+
if (textVariables == 0) {
text0 = metaData['name']
this[text0] = userInput
}
break
case "number":
- def userInput = Math.abs(new Random().nextInt() % 60) + 40
-
+ //def userInput = Math.abs(new Random().nextInt() % 60) + 40
+ def userInput = 50
+
if (numberVariables == 0) {
number0 = metaData['name']
this[number0] = userInput
}
break
case "bool":
- def userInput = Math.abs(new Random().nextInt() % 2)
-
+ //def userInput = Math.abs(new Random().nextInt() % 2)
+ def userInput = true
+
if (boolVariables == 0) {
bool0 = metaData['name']
this[bool0] = userInput
else
extractedObjectsConstructorApp2.append("END: \"END\"]\n")
}
+ def line
+ File GlobalVariablesBothApps = new File("GlobalVariables/GlobalVariablesBothApps.groovy")
+ GlobalVariablesBothApps.write("")
+ GlobalVariablesBothApps.append("//Creating Global variables for both apps\n")
+ GlobalVariablesBothApps.append("@Field def sendEvent = {eventDataMap -> eventHandler(eventDataMap)}\n")
+ GlobalVariablesBothApps.append("@Field def locationObject = new LocationVar(sendEvent)\n")
+ GlobalVariablesBothApps.append("@Field def appObject = new Touched(sendEvent, 0)\n")
+
+ globalObjects.withReader { reader ->
+ while ((line = reader.readLine()) != null) {
+ GlobalVariablesBothApps.append(line)
+ GlobalVariablesBothApps.append("\n")
+ }
+ }
}
}
-//Create a global variable for send event
-@Field def sendEvent = {eventDataMap ->
- eventHandler(eventDataMap)
- }
-//Object for location
-@Field def locationObject = new LocationVar(sendEvent)
-//Object for touch to call function
-@Field def appObject = new Touched(sendEvent, 0)
-//Create a global list for events
-//@Field def evt = []
-//Global Object for class Touch Sensor!
-@Field def touchSensorObject = new NfcTouch(sendEvent, 1)
-//Global Object for class switch!
-@Field def switchObject = new Switches(sendEvent, 1)
-//Global Object for class lock!
-@Field def lockObject = new Locks(sendEvent, 1)
-//Global Object for class door control!
-@Field def doorControlObject = new DoorControls(sendEvent, 1)
-//Global Object for class contact sensor!
-@Field def contactObject = new ContactSensors(sendEvent, 1)
-//Global Object for class presence sensor!
-@Field def presenceSensorObject = new PresenceSensors(sendEvent, 1)
-//Global Object for class thermostat!
-@Field def thermostatObject = new Thermostats(sendEvent, 1)
-//Global Object for class aeon key fob!
-@Field def aeonKeyFobObject = new AeonKeyFobs(sendEvent, 1)
-//Global Object for class music player!
-@Field def musicPlayerObject = new MusicPlayers(sendEvent, 1)
-//Global Object for class motion sensor!
-@Field def motionSensorObject = new MotionSensors(sendEvent, 1)
-//Global Object for class image capture!
-@Field def imageCaptureObject = new ImageCaptures(sendEvent, 1)
-//Global Object for class smoke detector!
-@Field def smokeDetectorObject = new SmokeDetectors(sendEvent, 1)
-//Global Object for class alarm!
-@Field def alarmObject = new Alarms(sendEvent, 1)
-//Global Object for class speech synthesis!
-@Field def speechSynthesisObject = new SpeechSynthesises(sendEvent, 1)
-//Global Object for class acceleration sensor!
-@Field def accelerationSensorObject = new AccelerationSensors(sendEvent, 1)
-//Global Object for class Battery!
-@Field def batteryObject = new Batteries(sendEvent, 1)
-//Global Object for class beacon sensor!
-@Field def beaconSensorObject = new BeaconSensors(sendEvent, 1)
-//Global Object for class carbon monoxide!
-@Field def carbonMonoxideDetectorObject = new CarbonMonoxideDetectors(sendEvent, 1)
-//Global Object for class color control!
-@Field def colorControlObject = new ColorControls(sendEvent, 1)
-//Global Object for class energy meter!
-@Field def energyMeterObject = new EnergyMeters(sendEvent, 1)
-//Global Object for class illuminance measurement!
-@Field def illuminanceMeasurementObject = new IlluminanceMeasurements(sendEvent, 1)
-//Global Object for class power meter!
-@Field def powerMeterObject = new PowerMeters(sendEvent, 1)
-//Global Object for class humidity measurement!
-@Field def humidityMeasurementObject = new RelativeHumidityMeasurements(sendEvent, 1)
-//Global Object for class relay switch!
-@Field def relaySwitchObject = new RelaySwitches(sendEvent, 1)
-//Global Object for class sleep sensor!
-@Field def sleepSensorObject = new SleepSensors(sendEvent, 1)
-//Global Object for class step sensor!
-@Field def stepSensorObject = new StepSensors(sendEvent, 1)
-//Global Object for class switch level!
-@Field def switchLevelObject = new SwitchLevels(sendEvent, 1)
-//Global Object for class temperature measurement!
-@Field def temperatureMeasurementObject = new TemperatureMeasurements(sendEvent, 1)
-//Global Object for class water sensor!
-@Field def waterSensorObject = new WaterSensors(sendEvent, 1)
-//Global Object for class valves!
-@Field def valveObject = new Valves(sendEvent, 1)
-//Global Object for class mobile presence!
-@Field def mobilePresenceObject = new MobilePresences(sendEvent, 1)