+++ /dev/null
-////////////////////
-@Field App
-App = "App2"
-////////////////////////////////////////
-//import libraries
-import groovy.transform.Field
-
-
-//import classes
-//Importing Classes
-import ContactSensor.ContactSensor
-import ContactSensor.ContactSensors
-import DoorControl.DoorControl
-import DoorControl.DoorControls
-import Lock.Lock
-import Lock.Locks
-import Thermostat.Thermostat
-import Thermostat.Thermostats
-import Switch.Switch
-import Switch.Switches
-import PresenceSensor.PresenceSensor
-import PresenceSensor.PresenceSensors
-import Logger.Logger
-import Location.LocationVar
-import Location.Phrase
-import appTouch.Touched
-import NfcTouch.NfcTouch
-import AeonKeyFob.AeonKeyFob
-import AeonKeyFob.AeonKeyFobs
-import MusicPlayer.MusicPlayer
-import MusicPlayer.MusicPlayers
-import MotionSensor.MotionSensor
-import MotionSensor.MotionSensors
-import ImageCapture.ImageCapture
-import ImageCapture.ImageCaptures
-import SmokeDetector.SmokeDetector
-import SmokeDetector.SmokeDetectors
-import Alarm.Alarm
-import Alarm.Alarms
-import SpeechSynthesis.SpeechSynthesis
-import SpeechSynthesis.SpeechSynthesises
-import AccelerationSensor.AccelerationSensor
-import AccelerationSensor.AccelerationSensors
-import Battery.Battery
-import Battery.Batteries
-import BeaconSensor.BeaconSensor
-import BeaconSensor.BeaconSensors
-import CarbonMonoxideDetector.CarbonMonoxideDetector
-import CarbonMonoxideDetector.CarbonMonoxideDetectors
-import ColorControl.ColorControl
-import ColorControl.ColorControls
-import EnergyMeter.EnergyMeter
-import EnergyMeter.EnergyMeters
-import IlluminanceMeasurement.IlluminanceMeasurement
-import IlluminanceMeasurement.IlluminanceMeasurements
-import PowerMeter.PowerMeter
-import PowerMeter.PowerMeters
-import RelativeHumidityMeasurement.RelativeHumidityMeasurement
-import RelativeHumidityMeasurement.RelativeHumidityMeasurements
-import RelaySwitch.RelaySwitch
-import RelaySwitch.RelaySwitches
-import SleepSensor.SleepSensor
-import SleepSensor.SleepSensors
-import StepSensor.StepSensor
-import StepSensor.StepSensors
-import SwitchLevel.SwitchLevel
-import SwitchLevel.SwitchLevels
-import TemperatureMeasurement.TemperatureMeasurement
-import TemperatureMeasurement.TemperatureMeasurements
-import WaterSensor.WaterSensor
-import WaterSensor.WaterSensors
-import Valve.Valve
-import Valve.Valves
-import MobilePresence.MobilePresence
-import MobilePresence.MobilePresences
-import Timer.SimulatedTimer
-
-//GlobalVariables
-@Field def location = new LocationVar()
-//Settings variable defined to settings on purpose
-@Field def settings = [app: "app"]
-//Global variable for state[mode]
-@Field def state = [home:[],away:[],night:[]]
-//Create a global logger object for methods
-@Field def log = new Logger()
-//Create a global variable for optional property
-@Field def optional = false //by default for now
-
-
-//Global variables for files
-@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")
-@Field File extractedObjectsConstructorApp2 = new File("Extractor/App2/extractedObjectsConstructorApp2.groovy")
-
-
-//Empty the files
-if (App == "App1") {
- extractedObjectsApp1.write("")
- extractedObjectsConstructorApp1.write("")
-} else if (App == "App2") {
- extractedObjectsApp2.write("")
- extractedObjectsConstructorApp2.write("")
-}
-
-
-
-//Some of methods-May be needed even in install
-/////////////////////////////////////////////////////////////////////
-def timeToday(String time, Object timeZone) {
- def timeOfDay = new Date()
- def _inputTime = time.split(':')
- def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60+1564191100415
- timeOfDay.time = inputTime
- return timeOfDay
-}
-
-
-
-//Global objects
-//Global Object for class Touch Sensor!
-@Field touchSensorObjects = 0
-@Field def touchSensorObject0
-@Field def touchSensorObject1
-@Field def touchSensorObject2
-//Global Object for class switch!
-@Field switchObjects = 0
-@Field def switchObject0
-@Field def switchObject1
-@Field def switchObject2
-//Global Object for class lock!
-@Field lockObjects = 0
-@Field def lockObject0
-@Field def lockObject1
-@Field def lockObject2
-//Global Object for class door control!
-@Field doorControlObjects = 0
-@Field def doorControlObject0
-@Field def doorControlObject1
-@Field def doorControlObject2
-//Global Object for class contact sensor!
-@Field contactObjects = 0
-@Field def contactObject0
-@Field def contactObject1
-@Field def contactObject2
-//Global Object for class presence sensor!
-@Field presenceSensorObjects = 0
-@Field def presenceSensorObject0
-@Field def presenceSensorObject1
-@Field def presenceSensorObject2
-//Global Object for class thermostat!
-@Field thermostatObjects = 0
-@Field def thermostatObject0
-@Field def thermostatObject1
-@Field def thermostatObject2
-//Global Object for class music player!
-@Field musicPlayerObjects = 0
-@Field def musicPlayerObject0
-@Field def musicPlayerObject1
-@Field def musicPlayerObject2
-//Global Object for class aeon key fob!
-@Field aeonKeyFobObjects = 0
-@Field def aeonKeyFobObject0
-@Field def aeonKeyFobObject1
-@Field def aeonKeyFobObject2
-//Global Object for class motion sensor!
-@Field motionSensorObjects = 0
-@Field def motionSensorObject0
-@Field def motionSensorObject1
-@Field def motionSensorObject2
-//Global Object for class image capture!
-@Field imageCaptureObjects = 0
-@Field def imageCaptureObject0
-@Field def imageCaptureObject1
-@Field def imageCaptureObject2
-//Global Object for class smoke detector!
-@Field smokeDetectorObjects = 0
-@Field def smokeDetectorObject0
-@Field def smokeDetectorObject1
-@Field def smokeDetectorObject2
-//Global Object for class alarm!
-@Field alarmObjects = 0
-@Field def alarmObject0
-@Field def alarmObject1
-@Field def alarmObject2
-//Global Object for class speech synthesis!
-@Field speechSynthesisObjects = 0
-@Field def speechSynthesisObject0
-@Field def speechSynthesisObject1
-@Field def speechSynthesisObject2
-//Global Object for class acceleration sensor!
-@Field accelerationSensorObjects = 0
-@Field def accelerationSensorObject0
-@Field def accelerationSensorObject1
-@Field def accelerationSensorObject2
-//Global Object for class battery!
-@Field batteryObjects = 0
-@Field def batteryObject0
-@Field def batteryObject1
-@Field def batteryObject2
-//Global Object for class beacon sensor!
-@Field beaconSensorObjects = 0
-@Field def beaconSensorObject0
-@Field def beaconSensorObject1
-@Field def beaconSensorObject2
-//Global Object for class carbon monoxide detector!
-@Field carbonMonoxideDetectorObjects = 0
-@Field def carbonMonoxideDetectorObject0
-@Field def carbonMonoxideDetectorObject1
-@Field def carbonMonoxideDetectorObject2
-//Global Object for class color control!
-@Field colorControlObjects = 0
-@Field def colorControlObject0
-@Field def colorControlObject1
-@Field def colorControlObject2
-//Global Object for class energy meter!
-@Field energyMeterObjects = 0
-@Field def energyMeterObject0
-@Field def energyMeterObject1
-@Field def energyMeterObject2
-//Global Object for class energy meter!
-@Field illuminanceMeasurementObjects = 0
-@Field def illuminanceMeasurementObject0
-@Field def illuminanceMeasurementObject1
-@Field def illuminanceMeasurementObject2
-//Global Object for class power meter!
-@Field powerMeterObjects = 0
-@Field def powerMeterObject0
-@Field def powerMeterObject1
-@Field def powerMeterObject2
-//Global Object for class power meter!
-@Field humidityMeasurementObjects = 0
-@Field def humidityMeasurementObject0
-@Field def humidityMeasurementObject1
-@Field def humidityMeasurementObject2
-//Global Object for class relay switch!
-@Field relaySwitchObjects = 0
-@Field def relaySwitchObject0
-@Field def relaySwitchObject1
-@Field def relaySwitchObject2
-//Global Object for class sleep sensor!
-@Field sleepSensorObjects = 0
-@Field def sleepSensorObject0
-@Field def sleepSensorObject1
-@Field def sleepSensorObject2
-//Global Object for class sleep sensor!
-@Field stepSensorObjects = 0
-@Field def stepSensorObject0
-@Field def stepSensorObject1
-@Field def stepSensorObject2
-//Global Object for class switch level!
-@Field switchLevelObjects = 0
-@Field def switchLevelObject0
-@Field def switchLevelObject1
-@Field def switchLevelObject2
-//Global Object for class temperature measurement!
-@Field temperatureMeasurementObjects = 0
-@Field def temperatureMeasurementObject0
-@Field def temperatureMeasurementObject1
-@Field def temperatureMeasurementObject2
-//Global Object for class temperature measurement!
-@Field waterSensorObjects = 0
-@Field def waterSensorObject0
-@Field def waterSensorObject1
-@Field def waterSensorObject2
-//Global Object for class valve!
-@Field valveObjects = 0
-@Field def valveObject0
-@Field def valveObject1
-@Field def valveObject2
-//Global Object for class valve!
-@Field mobilePresenceObjects = 0
-@Field def mobilePresenceObject0
-@Field def mobilePresenceObject1
-@Field def mobilePresenceObject2
-
-
-
-//Global variables
-//For mode
-@Field modeVariables = 0
-@Field mode0
-@Field mode1
-@Field mode2
-@Field mode3
-@Field mode4
-@Field mode5
-//For number
-@Field numberVariables = 0
-@Field number0
-@Field number1
-@Field number2
-@Field number3
-@Field number4
-@Field number5
-//For decimal
-@Field decimalVariables = 0
-@Field decimal0
-@Field decimal1
-@Field decimal2
-@Field decimal3
-@Field decimal4
-@Field decimal5
-//For time
-@Field timeVariables = 0
-@Field time0
-@Field time1
-@Field time2
-@Field time3
-@Field time4
-@Field time5
-//For enum
-@Field enumVariables = 0
-@Field enum0
-@Field enum1
-@Field enum2
-@Field enum3
-@Field enum4
-@Field enum5
-//For phone
-@Field phoneVariables = 0
-@Field phone0
-@Field phone1
-@Field phone2
-@Field phone3
-@Field phone4
-@Field phone5
-//For contact
-@Field contactVariables = 0
-@Field contact0
-@Field contact1
-@Field contact2
-@Field contact3
-@Field contact4
-@Field contact5
-//For text
-@Field textVariables = 0
-@Field textVariable0
-@Field textVariable1
-@Field textVariable2
-@Field textVariable3
-@Field textVariable4
-@Field textVariable5
-//For boolean
-@Field boolVariables = 0
-@Field boolVariable0
-@Field boolVariable1
-@Field boolVariable2
-@Field boolVariable3
-@Field boolVariable4
-@Field boolVariable5
-
-
-/////Input Methods/////
-//input "",""
-def input(String name, String type) {
- LinkedHashMap metaData = []
- metaData.put('name',name)
- metaData.put('type',type)
- input(metaData)
-}
-
-//input "","",linkedHashMap
-def input(LinkedHashMap metaData, String name, String type) {
- metaData.put('name',name)
- metaData.put('type',type)
- input(metaData)
-}
-
-//input "", "", linkedHashMap, Closure
-def input(LinkedHashMap metaData, String name, String type, Closure Input) {
- metaData.put('name',name)
- metaData.put('type',type)
- input(metaData)
- find(Input)
-}
-
-//input linkedHashMap
-def input(LinkedHashMap metaData) {
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('options')) {
- println "Options: "+metaData['options']
- }
- switch(metaData['type']) {
- case "capability.lock":
- if (lockObjects == 0) {
- lockObject0 = metaData['name']
- this[lockObject0] = new Locks({}, 1)
- } else if (lockObjects == 1) {
- lockObject1 = metaData['name']
- this[lockObject1] = new Locks({}, 1)
- } else if (lockObjects == 2) {
- lockObject2 = metaData['name']
- this[lockObject2] = new Locks({}, 1)
- }
-
- lockObjects=lockObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class lock!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.lockObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class lock!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.lockObject\n")
- }
- break
- case "capability.alarm":
- if (alarmObjects == 0) {
- alarmObject0 = metaData['name']
- this[alarmObject0] = new Alarms({}, 1)
- } else if (alarmObjects == 1) {
- alarmObject1 = metaData['name']
- this[alarmObject1] = new Alarms({}, 1)
- } else if (alarmObjects == 2) {
- alarmObject2 = metaData['name']
- this[alarmObject2] = new Alarms({}, 1)
- }
-
- alarmObjects=alarmObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class alarm!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.alarmObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class alarm!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.alarmObject\n")
- }
- break
- case "capability.battery":
- if (batteryObjects == 0) {
- batteryObject0 = metaData['name']
- this[batteryObject0] = new Batteries({}, 1)
- } else if (batteryObjects == 1) {
- batteryObject1 = metaData['name']
- this[batteryObject1] = new Batteries({}, 1)
- } else if (batteryObjects == 2) {
- batteryObject2 = metaData['name']
- this[batteryObject2] = new Batteries({}, 1)
- }
-
- batteryObjects=batteryObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class Battery!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.batteryObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class Battery!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.batteryObject\n")
- }
- break
- case "capability.beacon":
- if (beaconSensorObjects == 0) {
- beaconSensorObject0 = metaData['name']
- this[beaconSensorObject0] = new BeaconSensors({}, 1)
- } else if (beaconSensorObjects == 1) {
- beaconSensorObject1 = metaData['name']
- this[beaconSensorObject1] = new BeaconSensors({}, 1)
- } else if (beaconSensorObjects == 2) {
- beaconSensorObject2 = metaData['name']
- this[beaconSensorObject2] = new BeaconSensors({}, 1)
- }
-
- beaconSensorObjects=beaconSensorObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class beacon sensor!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.beaconSensorObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class beacon sensor!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.beaconSensorObject\n")
- }
- break
- case "capability.carbonMonoxideDetector":
- if (carbonMonoxideDetectorObjects == 0) {
- carbonMonoxideDetectorObject0 = metaData['name']
- this[carbonMonoxideDetectorObject0] = new CarbonMonoxideDetectors({}, 1)
- } else if (carbonMonoxideDetectorObjects == 1) {
- carbonMonoxideDetectorObject1 = metaData['name']
- this[carbonMonoxideDetectorObject1] = new CarbonMonoxideDetectors({}, 1)
- } else if (carbonMonoxideDetectorObjects == 2) {
- carbonMonoxideDetectorObject2 = metaData['name']
- this[carbonMonoxideDetectorObject2] = new CarbonMonoxideDetectors({}, 1)
- }
-
- carbonMonoxideDetectorObjects=carbonMonoxideDetectorObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class carbon monoxide detector!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.carbonMonoxideDetectorObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class carbon monoxide detector!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.carbonMonoxideDetectorObject\n")
- }
- break
- case "capability.colorControl":
- if (colorControlObjects == 0) {
- colorControlObject0 = metaData['name']
- this[colorControlObject0] = new ColorControls({}, 1)
- } else if (colorControlObjects == 1) {
- colorControlObject1 = metaData['name']
- this[colorControlObject1] = new ColorControls({}, 1)
- } else if (colorControlObjects == 2) {
- colorControlObject2 = metaData['name']
- this[colorControlObject2] = new ColorControls({}, 1)
- }
-
- colorControlObjects=colorControlObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class color control!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.colorControlObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class color control!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.colorControlObject\n")
- }
- break
- case "capability.contactSensor":
- if (contactObjects == 0) {
- contactObject0 = metaData['name']
- this[contactObject0] = new ContactSensors({}, 1)
- } else if (contactObjects == 1) {
- contactObject1 = metaData['name']
- this[contactObject1] = new ContactSensors({}, 1)
- } else if (contactObjects == 2) {
- contactObject2 = metaData['name']
- this[contactObject2] = new ContactSensors({}, 1)
- }
-
- contactObjects=contactObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class contactSensor!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.contactObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class contactSensor!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.contactObject\n")
- }
- break
- case "capability.doorControl":
- if (doorControlObjects == 0) {
- doorControlObject0 = metaData['name']
- this[doorControlObject0] = new DoorControls({}, 1)
- } else if (doorControlObjects == 1) {
- doorControlObject1 = metaData['name']
- this[doorControlObject1] = new DoorControls({}, 1)
- } else if (doorControlObjects == 2) {
- doorControlObject2 = metaData['name']
- this[doorControlObject2] = new DoorControls({}, 1)
- }
-
- doorControlObjects=doorControlObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class door control!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.doorControlObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class door control!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.doorControlObject\n")
- }
- break
- case "capability.energyMeter":
- if (energyMeterObjects == 0) {
- energyMeterObject0 = metaData['name']
- this[energyMeterObject0] = new EnergyMeters({}, 1)
- } else if (energyMeterObjects == 1) {
- energyMeterObject1 = metaData['name']
- this[energyMeterObject1] = new EnergyMeters({}, 1)
- } else if (energyMeterObjects == 2) {
- energyMeterObject2 = metaData['name']
- this[energyMeterObject2] = new EnergyMeters({}, 1)
- }
-
- energyMeterObjects=energyMeterObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class energy meter!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.energyMeterObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class energy meter!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.energyMeterObject\n")
- }
- break
- case "capability.illuminanceMeasurement":
- if (illuminanceMeasurementObjects == 0) {
- illuminanceMeasurementObject0 = metaData['name']
- this[illuminanceMeasurementObject0] = new IlluminanceMeasurements({}, 1)
- } else if (illuminanceMeasurementObjects == 1) {
- illuminanceMeasurementObject1 = metaData['name']
- this[illuminanceMeasurementObject1] = new IlluminanceMeasurements({}, 1)
- } else if (illuminanceMeasurementObjects == 2) {
- illuminanceMeasurementObject2 = metaData['name']
- this[illuminanceMeasurementObject2] = new IlluminanceMeasurements({}, 1)
- }
-
- illuminanceMeasurementObjects=illuminanceMeasurementObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class illuminance measurement!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.illuminanceMeasurementObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class illuminance measurement!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.illuminanceMeasurementObject\n")
- }
- break
- case "capability.accelerationSensor":
- if (accelerationSensorObjects == 0) {
- accelerationSensorObject0 = metaData['name']
- this[accelerationSensorObject0] = new AccelerationSensors({}, 1)
- } else if (accelerationSensorObjects == 1) {
- accelerationSensorObject1 = metaData['name']
- this[accelerationSensorObject1] = new AccelerationSensors({}, 1)
- } else if (accelerationSensorObjects == 2) {
- accelerationSensorObject2 = metaData['name']
- this[accelerationSensorObject2] = new AccelerationSensors({}, 1)
- }
-
- accelerationSensorObjects=accelerationSensorObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class Acceleration Sensor!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.accelerationSensorObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class Acceleration Sensor!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.accelerationSensorObject\n")
- }
- break
- case "capability.motionSensor":
- if (motionSensorObjects == 0) {
- motionSensorObject0 = metaData['name']
- this[motionSensorObject0] = new MotionSensors({}, 1)
- } else if (motionSensorObjects == 1) {
- motionSensorObject1 = metaData['name']
- this[motionSensorObject1] = new MotionSensors({}, 1)
- } else if (motionSensorObjects == 2) {
- motionSensorObject2 = metaData['name']
- this[motionSensorObject2] = new MotionSensors({}, 1)
- }
-
- motionSensorObjects=motionSensorObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class Motion Sensor!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.motionSensorObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class Motion Sensor!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.motionSensorObject\n")
- }
- break
- case "capability.musicPlayer":
- if (musicPlayerObjects == 0) {
- musicPlayerObject0 = metaData['name']
- this[musicPlayerObject0] = new MusicPlayers({}, 1)
- } else if (musicPlayerObjects == 1) {
- musicPlayerObject1 = metaData['name']
- this[musicPlayerObject1] = new MusicPlayers({}, 1)
- } else if (musicPlayerObjects == 2) {
- musicPlayerObject2 = metaData['name']
- this[musicPlayerObject2] = new MusicPlayers({}, 1)
- }
-
- musicPlayerObjects=musicPlayerObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class music player!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.musicPlayerObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class music player!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.musicPlayerObject\n")
- }
- break
- case "capability.powerMeter":
- if (powerMeterObjects == 0) {
- powerMeterObject0 = metaData['name']
- this[powerMeterObject0] = new PowerMeters({}, 1)
- } else if (powerMeterObjects == 1) {
- powerMeterObject1 = metaData['name']
- this[powerMeterObject1] = new PowerMeters({}, 1)
- } else if (powerMeterObjects == 2) {
- powerMeterObject2 = metaData['name']
- this[powerMeterObject2] = new PowerMeters({}, 1)
- }
-
- powerMeterObjects=powerMeterObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class power meter!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.powerMeterObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class power meter!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.powerMeterObject\n")
- }
- break
- case "capability.presenceSensor":
- if (presenceSensorObjects == 0) {
- presenceSensorObject0 = metaData['name']
- this[presenceSensorObject0] = new PresenceSensors({}, 1)
- } else if (presenceSensorObjects == 1) {
- presenceSensorObject1 = metaData['name']
- this[presenceSensorObject1] = new PresenceSensors({}, 1)
- } else if (presenceSensorObjects == 2) {
- presenceSensorObject2 = metaData['name']
- this[presenceSensorObject2] = new PresenceSensors({}, 1)
- }
-
- presenceSensorObjects=presenceSensorObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class presence sensor!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.presenceSensorObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class presence sensor!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.presenceSensorObject\n")
- }
- break
- case "capability.relativeHumidityMeasurement":
- if (humidityMeasurementObjects == 0) {
- humidityMeasurementObject0 = metaData['name']
- this[humidityMeasurementObject0] = new RelativeHumidityMeasurements({}, 1)
- } else if (humidityMeasurementObjects == 1) {
- humidityMeasurementObject1 = metaData['name']
- this[humidityMeasurementObject1] = new RelativeHumidityMeasurements({}, 1)
- } else if (humidityMeasurementObjects == 2) {
- humidityMeasurementObject2 = metaData['name']
- this[humidityMeasurementObject2] = new RelativeHumidityMeasurements({}, 1)
- }
-
- humidityMeasurementObjects=humidityMeasurementObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class humidity measurement!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.humidityMeasurementObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class humidity measurement!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.humidityMeasurementObject\n")
- }
- break
- case "capability.relaySwitch":
- if (relaySwitchObjects == 0) {
- relaySwitchObject0 = metaData['name']
- this[relaySwitchObject0] = new RelaySwitches({}, 1)
- } else if (relaySwitchObjects == 1) {
- relaySwitchObject1 = metaData['name']
- this[relaySwitchObject1] = new RelaySwitches({}, 1)
- } else if (relaySwitchObjects == 2) {
- relaySwitchObject2 = metaData['name']
- this[relaySwitchObject2] = new RelaySwitches({}, 1)
- }
-
- relaySwitchObjects=relaySwitchObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class relay switch!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.relaySwitchObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class relay switch!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.relaySwitchObject\n")
- }
- break
- case "capability.sleepSensor":
- if (sleepSensorObjects == 0) {
- sleepSensorObject0 = metaData['name']
- this[sleepSensorObject0] = new SleepSensors({}, 1)
- } else if (sleepSensorObjects == 1) {
- sleepSensorObject1 = metaData['name']
- this[sleepSensorObject1] = new SleepSensors({}, 1)
- } else if (sleepSensorObjects == 2) {
- sleepSensorObject2 = metaData['name']
- this[sleepSensorObject2] = new SleepSensors({}, 1)
- }
-
- sleepSensorObjects=sleepSensorObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class sleep sensor!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.sleepSensorObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class sleep sensor!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.sleepSensorObject\n")
- }
- break
- case "capability.smokeDetector":
- if (smokeDetectorObjects == 0) {
- smokeDetectorObject0 = metaData['name']
- this[smokeDetectorObject0] = new SmokeDetectors({}, 1)
- } else if (smokeDetectorObjects == 1) {
- smokeDetectorObject1 = metaData['name']
- this[smokeDetectorObject1] = new SmokeDetectors({}, 1)
- } else if (smokeDetectorObjects == 2) {
- smokeDetectorObject2 = metaData['name']
- this[smokeDetectorObject2] = new SmokeDetectors({}, 1)
- }
-
- smokeDetectorObjects=smokeDetectorObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class smoke detector!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.smokeDetectorObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class smoke detector!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.smokeDetectorObject\n")
- }
- break
- case "capability.stepSensor":
- if (stepSensorObjects == 0) {
- stepSensorObject0 = metaData['name']
- this[stepSensorObject0] = new StepSensors({}, 1)
- } else if (stepSensorObjects == 1) {
- stepSensorObject1 = metaData['name']
- this[stepSensorObject1] = new StepSensors({}, 1)
- } else if (stepSensorObjects == 2) {
- stepSensorObject2 = metaData['name']
- this[stepSensorObject2] = new StepSensors({}, 1)
- }
-
- stepSensorObjects=stepSensorObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class step sensor!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.stepSensorObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class step sensor!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.stepSensorObject\n")
- }
- break
- case "capability.switch":
- if (switchObjects == 0) {
- switchObject0 = metaData['name']
- this[switchObject0] = new Switches({}, 1)
- } else if (switchObjects == 1) {
- switchObject1 = metaData['name']
- this[switchObject1] = new Switches({}, 1)
- } else if (switchObjects == 2) {
- switchObject2 = metaData['name']
- this[switchObject2] = new Switches({}, 1)
- }
-
- switchObjects=switchObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class switch!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.switchObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class switch!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.switchObject\n")
- }
- break
- case "capability.switchLevel":
- if (switchLevelObjects == 0) {
- switchLevelObject0 = metaData['name']
- this[switchLevelObject0] = new SwitchLevels({}, 1)
- } else if (switchLevelObjects == 1) {
- switchLevelObject1 = metaData['name']
- this[switchLevelObject1] = new SwitchLevels({}, 1)
- } else if (switchLevelObjects == 2) {
- switchLevelObject2 = metaData['name']
- this[switchLevelObject2] = new SwitchLevels({}, 1)
- }
-
- switchLevelObjects=switchLevelObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class switch level!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.switchLevelObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class switch level!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.switchLevelObject\n")
- }
- break
- case "capability.temperatureMeasurement":
- if (temperatureMeasurementObjects == 0) {
- temperatureMeasurementObject0 = metaData['name']
- this[temperatureMeasurementObject0] = new TemperatureMeasurements({}, 1)
- } else if (temperatureMeasurementObjects == 1) {
- temperatureMeasurementObject1 = metaData['name']
- this[temperatureMeasurementObject1] = new TemperatureMeasurements({}, 1)
- } else if (temperatureMeasurementObjects == 2) {
- temperatureMeasurementObject2 = metaData['name']
- this[temperatureMeasurementObject2] = new TemperatureMeasurements({}, 1)
- }
-
- temperatureMeasurementObjects=temperatureMeasurementObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class temperature measurement!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.temperatureMeasurementObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class temperature measurement!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.temperatureMeasurementObject\n")
- }
- break
- case "capability.thermostat":
- if (thermostatObjects == 0) {
- thermostatObject0 = metaData['name']
- this[thermostatObject0] = new Thermostats({}, 1)
- } else if (thermostatObjects == 1) {
- thermostatObject1 = metaData['name']
- this[thermostatObject1] = new Thermostats({}, 1)
- } else if (thermostatObjects == 2) {
- thermostatObject2 = metaData['name']
- this[thermostatObject2] = new Thermostats({}, 1)
- }
-
- thermostatObjects=thermostatObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class thermostat!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.thermostatObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class thermostat!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.thermostatObject\n")
- }
- break
- case "capability.valve":
- if (valveObjects == 0) {
- valveObject0 = metaData['name']
- this[valveObject0] = new Valves({}, 1)
- } else if (valveObjects == 1) {
- valveObject1 = metaData['name']
- this[valveObject1] = new Valves({}, 1)
- } else if (valveObjects == 2) {
- valveObject2 = metaData['name']
- this[valveObject2] = new Valves({}, 1)
- }
-
- valveObjects=valveObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class valve!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.valveObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class valve!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.valveObject\n")
- }
- break
- case "capability.speechSynthesis":
- if (speechSynthesisObjects == 0) {
- speechSynthesisObject0 = metaData['name']
- this[speechSynthesisObject0] = new SpeechSynthesises({}, 1)
- } else if (speechSynthesisObjects == 1) {
- speechSynthesisObject1 = metaData['name']
- this[speechSynthesisObject1] = new SpeechSynthesises({}, 1)
- } else if (speechSynthesisObjects == 2) {
- speechSynthesisObject2 = metaData['name']
- this[speechSynthesisObject2] = new SpeechSynthesises({}, 1)
- }
-
- speechSynthesisObjects=speechSynthesisObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class speech synthesis!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.speechSynthesisObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class speech synthesis!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.speechSynthesisObject\n")
- }
- break
- case "capability.waterSensor":
- if (waterSensorObjects == 0) {
- waterSensorObject0 = metaData['name']
- this[waterSensorObject0] = new WaterSensors({}, 1)
- } else if (waterSensorObjects == 1) {
- waterSensorObject1 = metaData['name']
- this[waterSensorObject1] = new WaterSensors({}, 1)
- } else if (waterSensorObjects == 2) {
- waterSensorObject2 = metaData['name']
- this[waterSensorObject2] = new WaterSensors({}, 1)
- }
-
- waterSensorObjects=waterSensorObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class water sensor!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.waterSensorObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class water sensor!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.waterSensorObject\n")
- }
- break
- case "capability.touchSensor":
- if (touchSensorObjects == 0) {
- touchSensorObject0 = metaData['name']
- this[touchSensorObject0] = new NfcTouch({}, 1)
- } else if (touchSensorObjects == 1) {
- touchSensorObject1 = metaData['name']
- this[touchSensorObject1] = new NfcTouch({}, 1)
- } else if (touchSensorObjects == 2) {
- touchSensorObject2 = metaData['name']
- this[touchSensorObject2] = new NfcTouch({}, 1)
- }
-
- touchSensorObjects=touchSensorObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class Touch Sensor!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.touchSensorObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class Touch Sensor!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.touchSensorObject\n")
- }
- break
- case "capability.imageCapture":
- if (imageCaptureObjects == 0) {
- imageCaptureObject0 = metaData['name']
- this[imageCaptureObject0] = new ImageCaptures({}, 1)
- } else if (imageCaptureObjects == 1) {
- imageCaptureObject1 = metaData['name']
- this[imageCaptureObject1] = new ImageCaptures({}, 1)
- } else if (imageCaptureObjects == 2) {
- imageCaptureObject2 = metaData['name']
- this[imageCaptureObject2] = new ImageCaptures({}, 1)
- }
-
- imageCaptureObjects=imageCaptureObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class Image Capture!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.imageCaptureObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class Image Capture!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.imageCaptureObject\n")
- }
- break
- case "device.mobilePresence":
- if (mobilePresenceObjects == 0) {
- mobilePresenceObject0 = metaData['name']
- this[mobilePresenceObject0] = new MobilePresences({}, 1)
- } else if (mobilePresenceObjects == 1) {
- mobilePresenceObject1 = metaData['name']
- this[mobilePresenceObject1] = new MobilePresences({}, 1)
- } else if (mobilePresenceObjects == 2) {
- mobilePresenceObject2 = metaData['name']
- this[mobilePresenceObject2] = new MobilePresences({}, 1)
- }
-
- mobilePresenceObjects=mobilePresenceObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class mobile presence!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.mobilePresenceObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class mobile presence!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.mobilePresenceObject\n")
- }
- break
- case "device.aeonKeyFob":
- if (aeonKeyFobObjects == 0) {
- aeonKeyFobObject0 = metaData['name']
- this[aeonKeyFobObject0] = new AeonKeyFobs({}, 1)
- } else if (aeonKeyFobObjects == 1) {
- aeonKeyFobObject1 = metaData['name']
- this[aeonKeyFobObject1] = new AeonKeyFobs({}, 1)
- } else if (aeonKeyFobObjects == 2) {
- aeonKeyFobObject2 = metaData['name']
- this[aeonKeyFobObject2] = new AeonKeyFobs({}, 1)
- }
-
- aeonKeyFobObjects=aeonKeyFobObjects+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class aeon key fob!\n")
- extractedObjectsApp1.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp1.append(metaData['name']+" = obj.aeonKeyFobObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class aeon key fob!\n")
- extractedObjectsApp2.append("def "+metaData['name']+"\n")
- extractedObjectsConstructorApp2.append(metaData['name']+" = obj.aeonKeyFobObject\n")
- }
- break
- case "mode":
- def randomVariable = Math.abs(new Random().nextInt() % 3)
- def modes = ["away", "home", "night"]
- def userInput = modes[randomVariable]
-
- if (modeVariables == 0) {
- mode0 = metaData['name']
- this[mode0] = userInput
- } else if (modeVariables == 1) {
- mode1 = metaData['name']
- this[mode1] = userInput
- } else if (modeVariables == 2) {
- mode2 = metaData['name']
- this[mode2] = userInput
- } else if (modeVariables == 3) {
- mode3 = metaData['name']
- this[mode3] = userInput
- } else if (modeVariables == 4) {
- mode4 = metaData['name']
- this[mode4] = userInput
- } else if (modeVariables == 5) {
- mode5 = metaData['name']
- this[mode5] = userInput
- }
-
- modeVariables=modeVariables+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for mode!\n")
- extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for mode!\n")
- extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
- }
- break
- case "decimal":
- def userInput = Math.abs(new Random().nextInt() % 60) + 40
-
- if (decimalVariables == 0) {
- decimal0 = metaData['name']
- this[decimal0] = userInput
- } else if (decimalVariables == 1) {
- decimal1 = metaData['name']
- this[decimal1] = userInput
- } else if (decimalVariables == 2) {
- decimal2 = metaData['name']
- this[decimal2] = userInput
- } else if (decimalVariables == 3) {
- decimal3 = metaData['name']
- this[decimal3] = userInput
- } else if (decimalVariables == 4) {
- decimal4 = metaData['name']
- this[decimal4] = userInput
- } else if (decimalVariables == 5) {
- decimal5 = metaData['name']
- this[decimal5] = userInput
- }
-
- decimalVariables=decimalVariables+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for decimal number!\n")
- extractedObjectsApp1.append("def "+metaData['name']+" = "+userInput+"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for decimal number!\n")
- extractedObjectsApp2.append("def "+metaData['name']+" = "+userInput+"\n")
- }
- break
- case "text":
- def userInput = "This is just a text!"
-
- if (textVariables == 0) {
- text0 = metaData['name']
- this[text0] = userInput
- } else if (textVariables == 1) {
- text1 = metaData['name']
- this[text1] = userInput
- } else if (textVariables == 2) {
- text2 = metaData['name']
- this[text2] = userInput
- } else if (textVariables == 3) {
- text3 = metaData['name']
- this[text3] = userInput
- } else if (textVariables == 4) {
- text4 = metaData['name']
- this[text4] = userInput
- } else if (textVariables == 5) {
- text5 = metaData['name']
- this[text5] = userInput
- }
-
- textVariables=textVariables+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for text!\n")
- extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for text!\n")
- extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
- }
- break
- case "number":
- def userInput = Math.abs(new Random().nextInt() % 60) + 40
-
- if (numberVariables == 0) {
- number0 = metaData['name']
- this[number0] = userInput
- } else if (numberVariables == 1) {
- number1 = metaData['name']
- this[number1] = userInput
- } else if (numberVariables == 2) {
- number2 = metaData['name']
- this[number2] = userInput
- } else if (numberVariables == 3) {
- number3 = metaData['name']
- this[number3] = userInput
- } else if (numberVariables == 4) {
- number4 = metaData['name']
- this[number4] = userInput
- } else if (numberVariables == 5) {
- number5 = metaData['name']
- this[number5] = userInput
- }
-
- numberVariables=numberVariables+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for number!\n")
- extractedObjectsApp1.append("def "+metaData['name']+" = "+userInput+"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for number!\n")
- extractedObjectsApp2.append("def "+metaData['name']+" = "+userInput+"\n")
- }
- break
- case "time":
- def userInput = "15:00"
-
- if (timeVariables == 0) {
- time0 = metaData['name']
- this[time0] = userInput
- } else if (timeVariables == 1) {
- time1 = metaData['name']
- this[time1] = userInput
- } else if (timeVariables == 2) {
- time2 = metaData['name']
- this[time2] = userInput
- } else if (timeVariables == 3) {
- time3 = metaData['name']
- this[time3] = userInput
- } else if (timeVariables == 4) {
- time4 = metaData['name']
- this[time4] = userInput
- } else if (timeVariables == 5) {
- time5 = metaData['name']
- this[time5] = userInput
- }
-
- timeVariables=timeVariables+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for time!\n")
- extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for time!\n")
- extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
- }
- break
- case "enum":
- if (metaData['options'] != null)
- modes = metaData['options']
- else // If it is not named 'options' then it is captured as 'metadata'
- modes = metaData['metadata']
- def userInput = modes[0]
-
- if (enumVariables == 0) {
- enum0 = metaData['name']
- this[enum0] = userInput
- } else if (enumVariables == 1) {
- enum1 = metaData['name']
- this[enum1] = userInput
- } else if (enumVariables == 2) {
- enum2 = metaData['name']
- this[enum2] = userInput
- } else if (enumVariables == 3) {
- enum3 = metaData['name']
- this[enum3] = userInput
- } else if (enumVariables == 4) {
- enum4 = metaData['name']
- this[enum4] = userInput
- } else if (enumVariables == 5) {
- enum5 = metaData['name']
- this[enum5] = userInput
- }
-
- enumVariables=enumVariables+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for enum!\n")
- extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for enum!\n")
- extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
- }
- break
- case "bool":
- def userInput = Math.abs(new Random().nextInt() % 2)
-
- if (boolVariables == 0) {
- bool0 = metaData['name']
- this[bool0] = userInput
- } else if (boolVariables == 1) {
- bool1 = metaData['name']
- this[bool1] = userInput
- } else if (boolVariables == 2) {
- bool2 = metaData['name']
- this[bool2] = userInput
- } else if (boolVariables == 3) {
- bool3 = metaData['name']
- this[bool3] = userInput
- } else if (boolVariables == 4) {
- bool4 = metaData['name']
- this[bool4] = userInput
- } else if (boolVariables == 5) {
- bool5 = metaData['name']
- this[bool5] = userInput
- }
-
- boolVariables=boolVariables+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for boolean!\n")
- extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for boolean!\n")
- extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
- }
- break
- case "phone":
- def userInput = 9495379373
-
- if (phoneVariables == 0) {
- phone0 = metaData['name']
- this[phone0] = userInput
- } else if (phoneVariables == 1) {
- phone1 = metaData['name']
- this[phone1] = userInput
- } else if (phoneVariables == 2) {
- phone2 = metaData['name']
- this[phone2] = userInput
- } else if (phoneVariables == 3) {
- phone3 = metaData['name']
- this[phone3] = userInput
- } else if (phoneVariables == 4) {
- phone4 = metaData['name']
- this[phone4] = userInput
- } else if (phoneVariables == 5) {
- phone5 = metaData['name']
- this[phone5] = userInput
- }
-
- phoneVariables=phoneVariables+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for phone!\n")
- extractedObjectsApp1.append("def "+metaData['name']+" = "+userInput+"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for phone!\n")
- extractedObjectsApp2.append("def "+metaData['name']+" = "+userInput+"\n")
- }
- break
- case "contact":
- def userInput = "AJ"
-
- if (contactVariables == 0) {
- contact0 = metaData['name']
- this[contact0] = userInput
- } else if (contactVariables == 1) {
- contact1 = metaData['name']
- this[contact1] = userInput
- } else if (contactVariables == 2) {
- contact2 = metaData['name']
- this[contact2] = userInput
- } else if (contactVariables == 3) {
- contact3 = metaData['name']
- this[contact3] = userInput
- } else if (contactVariables == 4) {
- contact4 = metaData['name']
- this[contact4] = userInput
- } else if (contactVariables == 5) {
- contact5 = metaData['name']
- this[contact5] = userInput
- }
-
- contactVariables=contactVariables+1
-
- settings.put(metaData['name'], metaData['name'])
-
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for contact!\n")
- extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for contact!\n")
- extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
- }
- break
- default:
- break
- }
-}
-
-def label(LinkedHashMap metaData) {
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('options')) {
- println "Options: "+metaData['options']
- }
-
- println("//IGNORE--ForMobileUse//")
-}
-
-def mode(LinkedHashMap metaData) {
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('options')) {
- println "Options: "+metaData['options']
- }
-
- println("//IGNORE--ForMobileUse//")
-}
-
-def href(LinkedHashMap metaData) {
- println("//IGNORE--some data//")
-}
-
-def href(LinkedHashMap metaData, String name) {
- println("//IGNORE--some data//")
-}
-/////Input Methods/////
-
-
-/////MethodsForExtraction/////
-def definition(LinkedHashMap metaData) {
- println("///Just some information///")
-}
-
-def preferences(Closure inputData) {
- find(inputData) //Run the closure to extract pages/sections/inputMethods
- if (App == "App1") {
- extractedObjectsConstructorApp1.append("//Global variable for settings!\n")
- extractedObjectsConstructorApp1.append("settings = $settings\n")
- } else {
- extractedObjectsConstructorApp2.append("//Global variable for settings!\n")
- extractedObjectsConstructorApp2.append("settings = $settings\n")
- }
-}
-
-def page(LinkedHashMap metaData, Closure inputData) {
- if (metaData.containsKey('name'))
- println(metaData['name'])
- if (metaData.containsKey('title'))
- println(metaData['title'])
-
- find(inputData) //Run the closure to extract sections/inputMethods
-}
-
-def page(LinkedHashMap metaData) {
- def nameOfFunction = metaData['name']
- "$nameOfFunction"() //Call the page
-}
-
-def dynamicPage(LinkedHashMap metaData, Closure inputData) {
- if (metaData.containsKey('name'))
- println(metaData['name'])
- if (metaData.containsKey('title'))
- println(metaData['title'])
-
- find(inputData) //Run the closure to extract sections/inputMethods
-}
-
-def paragraph(String paragraphText) {
- println(paragraphText)
-}
-
-def section(String title, Closure inputData) {
- println(title)
- find(inputData) //Run the closure to extract inputMethods
-}
-
-def section(Closure inputData) {
- find(inputData) //Run the closure to extract inputMethods
-}
-
-def section(LinkedHashMap metaData, Closure inputData) {
- find(inputData) //Run the closure to extract inputMethods
-}
-
-def mappings(Closure inputData) {
- println("//IGNORE--some data//")
-}
-/////MethodsForExtraction/////
-
-
-
-/**
- * Beacon Control
- *
- * Copyright 2014 Physical Graph Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
- * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
- * for the specific language governing permissions and limitations under the License.
- *
- */
-definition(
- name: "Beacon Control",
- category: "SmartThings Internal",
- namespace: "smartthings",
- author: "SmartThings",
- description: "Execute a Hello, Home phrase, turn on or off some lights, and/or lock or unlock your door when you enter or leave a monitored region",
- iconUrl: "https://s3.amazonaws.com/smartapp-icons/MiscHacking/mindcontrol.png",
- iconX2Url: "https://s3.amazonaws.com/smartapp-icons/MiscHacking/mindcontrol@2x.png"
-)
-
-preferences {
- page(name: "timeIntervalInput", title: "Only during a certain time") {
- section {
- input "starting", "time", title: "Starting", required: false
- input "ending", "time", title: "Ending", required: false
- }
- }
-
- page(name: "mainPage")
-}
-
-def mainPage() {
- dynamicPage(name: "mainPage", install: true, uninstall: true) {
-
- section("Where do you want to watch?") {
- input name: "beacons", type: "capability.beacon", title: "Select your beacon(s)",
- multiple: true, required: true
- }
-
- section("Who do you want to watch for?") {
- input name: "phones", type: "device.mobilePresence", title: "Select your phone(s)",
- multiple: true, required: true
- }
-
- section("What do you want to do on arrival?") {
- input name: "arrivalPhrase", type: "enum", title: "Execute a phrase",
- options: listPhrases(), required: false
- input "arrivalOnSwitches", "capability.switch", title: "Turn on some switches",
- multiple: true, required: false
- input "arrivalOffSwitches", "capability.switch", title: "Turn off some switches",
- multiple: true, required: false
- input "arrivalLocks", "capability.lock", title: "Unlock the door",
- multiple: true, required: false
- }
-
- section("What do you want to do on departure?") {
- input name: "departPhrase", type: "enum", title: "Execute a phrase",
- options: listPhrases(), required: false
- input "departOnSwitches", "capability.switch", title: "Turn on some switches",
- multiple: true, required: false
- input "departOffSwitches", "capability.switch", title: "Turn off some switches",
- multiple: true, required: false
- input "departLocks", "capability.lock", title: "Lock the door",
- multiple: true, required: false
- }
-
- section("Do you want to be notified?") {
- input "pushNotification", "bool", title: "Send a push notification"
- input "phone", "phone", title: "Send a text message", description: "Tap to enter phone number",
- required: false
- }
-
- section {
- label title: "Give your automation a name", description: "e.g. Goodnight Home, Wake Up"
- }
-
- def timeLabel = timeIntervalLabel()
- section(title: "More options", hidden: hideOptionsSection(), hideable: true) {
- href "timeIntervalInput", title: "Only during a certain time",
- description: timeLabel ?: "Tap to set", state: timeLabel ? "complete" : "incomplete"
-
- input "days", "enum", title: "Only on certain days of the week", multiple: true, required: false,
- options: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
-
- input "modes", "mode", title: "Only when mode is", multiple: true, required: false
- }
- }
-}
-
-// Lifecycle management
-def installed() {
- log.debug "<beacon-control> Installed with settings: ${settings}"
- initialize()
-}
-
-def updated() {
- log.debug "<beacon-control> Updated with settings: ${settings}"
- unsubscribe()
- initialize()
-}
-
-def initialize() {
- subscribe(beacons, "presence", beaconHandler)
-}
-
-// Event handlers
-def beaconHandler(evt) {
- log.debug "<beacon-control> beaconHandler: $evt"
-
- if (allOk) {
- def data = new groovy.json.JsonSlurper().parseText(evt.data)
- // removed logging of device names. can be added back for debugging
- //log.debug "<beacon-control> data: $data - phones: " + phones*.deviceNetworkId
-
- def beaconName = getBeaconName(evt)
- // removed logging of device names. can be added back for debugging
- //log.debug "<beacon-control> beaconName: $beaconName"
-
- def phoneName = getPhoneName(data)
- // removed logging of device names. can be added back for debugging
- //log.debug "<beacon-control> phoneName: $phoneName"
- if (phoneName != null) {
- def action = data.presence == "1" ? "arrived" : "left"
- def msg = "$phoneName has $action ${action == 'arrived' ? 'at ' : ''}the $beaconName"
-
- if (action == "arrived") {
- msg = arriveActions(msg)
- }
- else if (action == "left") {
- msg = departActions(msg)
- }
- log.debug "<beacon-control> msg: $msg"
-
- if (pushNotification || phone) {
- def options = [
- method: (pushNotification && phone) ? "both" : (pushNotification ? "push" : "sms"),
- phone: phone
- ]
- sendNotification(msg, options)
- }
- }
- }
-}
-
-// Helpers
-private arriveActions(msg) {
- if (arrivalPhrase || arrivalOnSwitches || arrivalOffSwitches || arrivalLocks) msg += ", so"
-
- if (arrivalPhrase) {
- log.debug "<beacon-control> executing: $arrivalPhrase"
- executePhrase(arrivalPhrase)
- msg += " ${prefix('executed')} $arrivalPhrase."
- }
- if (arrivalOnSwitches) {
- log.debug "<beacon-control> turning on: $arrivalOnSwitches"
- arrivalOnSwitches.on()
- msg += " ${prefix('turned')} ${list(arrivalOnSwitches)} on."
- }
- if (arrivalOffSwitches) {
- log.debug "<beacon-control> turning off: $arrivalOffSwitches"
- arrivalOffSwitches.off()
- msg += " ${prefix('turned')} ${list(arrivalOffSwitches)} off."
- }
- if (arrivalLocks) {
- log.debug "<beacon-control> unlocking: $arrivalLocks"
- arrivalLocks.unlock()
- msg += " ${prefix('unlocked')} ${list(arrivalLocks)}."
- }
- msg
-}
-
-private departActions(msg) {
- if (departPhrase || departOnSwitches || departOffSwitches || departLocks) msg += ", so"
-
- if (departPhrase) {
- log.debug "<beacon-control> executing: $departPhrase"
- executePhrase(departPhrase)
- msg += " ${prefix('executed')} $departPhrase."
- }
- if (departOnSwitches) {
- log.debug "<beacon-control> turning on: $departOnSwitches"
- departOnSwitches.on()
- msg += " ${prefix('turned')} ${list(departOnSwitches)} on."
- }
- if (departOffSwitches) {
- log.debug "<beacon-control> turning off: $departOffSwitches"
- departOffSwitches.off()
- msg += " ${prefix('turned')} ${list(departOffSwitches)} off."
- }
- if (departLocks) {
- log.debug "<beacon-control> unlocking: $departLocks"
- departLocks.lock()
- msg += " ${prefix('locked')} ${list(departLocks)}."
- }
- msg
-}
-
-private prefix(word) {
- def result
- def index = settings.prefixIndex == null ? 0 : settings.prefixIndex + 1
- switch (index) {
- case 0:
- result = "I $word"
- break
- case 1:
- result = "I also $word"
- break
- case 2:
- result = "And I $word"
- break
- default:
- result = "And $word"
- break
- }
-
- settings.prefixIndex = index
- log.trace "prefix($word'): $result"
- result
-}
-
-private listPhrases() {
- location.helloHome.getPhrases().label
-}
-
-private executePhrase(phraseName) {
- if (phraseName) {
- location.helloHome.execute(phraseName)
- log.debug "<beacon-control> executed phrase: $phraseName"
- }
-}
-
-private getBeaconName(evt) {
- def beaconName = beacons.find { b -> b.id == evt.deviceId }
- return beaconName
-}
-
-private getPhoneName(data) {
- def phoneName = phones.find { phone ->
- // Work around DNI bug in data
- def pParts = phone.deviceNetworkId.split('\\|')
- def dParts = data.dni.split('\\|')
- pParts[0] == dParts[0]
- }
- return phoneName
-}
-
-private hideOptionsSection() {
- (starting || ending || days || modes) ? false : true
-}
-
-private getAllOk() {
- modeOk && daysOk && timeOk
-}
-
-private getModeOk() {
- def result = !modes || modes.contains(location.mode)
- log.trace "<beacon-control> modeOk = $result"
- result
-}
-
-private getDaysOk() {
- def result = true
- if (days) {
- def df = new java.text.SimpleDateFormat("EEEE")
- if (location.timeZone) {
- df.setTimeZone(location.timeZone)
- }
- else {
- df.setTimeZone(TimeZone.getTimeZone("America/New_York"))
- }
- def day = df.format(new Date())
- result = days.contains(day)
- }
- log.trace "<beacon-control> daysOk = $result"
- result
-}
-
-private getTimeOk() {
- def result = true
- if (starting && ending) {
- def currTime = now()
- def start = timeToday(starting, location?.timeZone).time
- def stop = timeToday(ending, location?.timeZone).time
- result = start < stop ? currTime >= start && currTime <= stop : currTime <= stop || currTime >= start
- }
- log.trace "<beacon-control> timeOk = $result"
- result
-}
-
-private hhmm(time, fmt = "h:mm a") {
- def t = timeToday(time, location.timeZone)
- def f = new java.text.SimpleDateFormat(fmt)
- f.setTimeZone(location.timeZone ?: timeZone(time))
- f.format(t)
-}
-
-private timeIntervalLabel() {
- (starting && ending) ? hhmm(starting) + "-" + hhmm(ending, "h:mm a z") : ""
-}
-
-private list(Object names) {
- return names[0]
-}
+++ /dev/null
-//Infrastructure for SmartThings Application
-//Importing Libraries
-import groovy.transform.Field
-import groovy.json.JsonSlurper
-
-//Importing Classes
-import ContactSensor.ContactSensor
-import ContactSensor.ContactSensors
-import DoorControl.DoorControl
-import DoorControl.DoorControls
-import Lock.Lock
-import Lock.Locks
-import Thermostat.Thermostat
-import Thermostat.Thermostats
-import Switch.Switch
-import Switch.Switches
-import PresenceSensor.PresenceSensor
-import PresenceSensor.PresenceSensors
-import Logger.Logger
-import Location.LocationVar
-import Location.Phrase
-import appTouch.Touched
-import NfcTouch.NfcTouch
-import AeonKeyFob.AeonKeyFob
-import AeonKeyFob.AeonKeyFobs
-import MusicPlayer.MusicPlayer
-import MusicPlayer.MusicPlayers
-import MotionSensor.MotionSensor
-import MotionSensor.MotionSensors
-import ImageCapture.ImageCapture
-import ImageCapture.ImageCaptures
-import SmokeDetector.SmokeDetector
-import SmokeDetector.SmokeDetectors
-import Alarm.Alarm
-import Alarm.Alarms
-import SpeechSynthesis.SpeechSynthesis
-import SpeechSynthesis.SpeechSynthesises
-import AccelerationSensor.AccelerationSensor
-import AccelerationSensor.AccelerationSensors
-import Battery.Battery
-import Battery.Batteries
-import BeaconSensor.BeaconSensor
-import BeaconSensor.BeaconSensors
-import CarbonMonoxideDetector.CarbonMonoxideDetector
-import CarbonMonoxideDetector.CarbonMonoxideDetectors
-import ColorControl.ColorControl
-import ColorControl.ColorControls
-import EnergyMeter.EnergyMeter
-import EnergyMeter.EnergyMeters
-import IlluminanceMeasurement.IlluminanceMeasurement
-import IlluminanceMeasurement.IlluminanceMeasurements
-import PowerMeter.PowerMeter
-import PowerMeter.PowerMeters
-import RelativeHumidityMeasurement.RelativeHumidityMeasurement
-import RelativeHumidityMeasurement.RelativeHumidityMeasurements
-import RelaySwitch.RelaySwitch
-import RelaySwitch.RelaySwitches
-import SleepSensor.SleepSensor
-import SleepSensor.SleepSensors
-import StepSensor.StepSensor
-import StepSensor.StepSensors
-import SwitchLevel.SwitchLevel
-import SwitchLevel.SwitchLevels
-import TemperatureMeasurement.TemperatureMeasurement
-import TemperatureMeasurement.TemperatureMeasurements
-import WaterSensor.WaterSensor
-import WaterSensor.WaterSensors
-import Valve.Valve
-import Valve.Valves
-import MobilePresence.MobilePresence
-import MobilePresence.MobilePresences
-import Event.Event
-import AtomicState.AtomicState
-import Timer.SimulatedTimer
-
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
-//Global eventHandler
-/////////////////////////////////////////////////////////////////////
-def eventHandler(LinkedHashMap eventDataMap) {
- def value = eventDataMap["value"]
- def name = eventDataMap["name"]
- def deviceId = eventDataMap["deviceId"]
- def descriptionText = eventDataMap["descriptionText"]
- def displayed = eventDataMap["displayed"]
- def linkText = eventDataMap["linkText"]
- def isStateChange = eventDataMap["isStateChange"]
- def unit = eventDataMap["unit"]
- def data = eventDataMap["data"]
-
- for (int i = 0;i < app2.eventList.size();i++) {
- if (app2.eventList[i] == name) {
- def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
- app2.functionList[i](event)
- }
- }
-
- for (int i = 0;i < app1.eventList.size();i++) {
- if (app1.eventList[i] == name) {
- def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
- app1.functionList[i](event)
- }
- }
-}
-
-//GlobalVariables for both Apps
-//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 AtomicState!
-@Field def atomicState = new AtomicState()
-//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)
-
-//Application #1
-class App1 {
- def reference
- def location
- def app
- def atomicState
-
- //Extracted objects for App1
- //Object for class lock!
- def lock1
- //Object for class contactSensor!
- def contact
- //Global variable for number!
- def minutesLater = 70
- //Global variable for number!
- def secondsLater = 93
- //Global variable for contact!
- def recipients = "AJ"
- //Global variable for phone!
- def phoneNumber = 9495379373
-
- //Extracted objects for functions for App1
- //Global Object for functions in subscribe method!
- def installed = this.&installed
- //Global Object for functions in subscribe method!
- def updated = this.&updated
- //Global Object for functions in subscribe method!
- def initialize = this.&initialize
- //Global Object for functions in subscribe method!
- def lockDoor = this.&lockDoor
- //Global Object for functions in subscribe method!
- def unlockDoor = this.&unlockDoor
- //Global Object for functions in subscribe method!
- def doorHandler = this.&doorHandler
-
- App1(Object obj) {
- reference = obj
- location = obj.locationObject
- app = obj.appObject
- atomicState = obj.atomicState
- lock1 = obj.lockObject
- contact = obj.contactObject
- //Global variable for settings!
- settings = [app:app, lock1:lock1, contact:contact, minutesLater:minutesLater, secondsLater:secondsLater, recipients:recipients, phoneNumber:phoneNumber]
- }
- //Global variables for each app
- //Global variable for state[mode]
- def state = [home:[],away:[],night:[]]
- //Create a global logger object for methods
- def log = new Logger()
- //Create a global variable for Functions in Subscribe method
- def functionList = []
- //Create a global variable for Objects in Subscribe method
- def objectList = []
- //Create a global variable for Events in Subscribe method
- def eventList = []
- //Create a global list for function schedulers
- def timersFuncList = []
- //Create a global list for timer schedulers
- def timersList = []
- //Create a global variable for settings
- def settings
- //Zip code
- def zipCode = 92617
-
- //Methods
- /////////////////////////////////////////////////////////////////////
- def setLocationMode(String mode) {
- location.mode = mode
- }
-
- /////////////////////////////////////////////////////////////////////
- ////subscribe(obj, func)
- def subscribe(Object obj, Closure FunctionToCall) {
- if (obj == app) {
- objectList.add(obj)
- eventList.add("Touched")
- functionList.add(FunctionToCall)
- } else if (obj == location) {
- objectList.add(obj)
- eventList.add("Location")
- functionList.add(FunctionToCall)
- }
- }
- ////subscribe(obj, event, func)
- def subscribe(Object obj, String event, Closure FunctionToCall) {
- objectList.add(obj)
- eventList.add(event)
- functionList.add(FunctionToCall)
- }
- ////subscribe(obj, event, func, data)
- def subscribe(Object obj, String event, Closure FunctionToCall, LinkedHashMap metaData) {
- objectList.add(obj)
- eventList.add(event)
- functionList.add(FunctionToCall)
- }
- /////////////////////////////////////////////////////////////////////
- ////runIn(time, func)
- def runIn(int seconds, Closure functionToCall) {
- if (timersFuncList.contains(functionToCall)) {
- timersList[timersFuncList.indexOf(functionToCall)].cancel()
- def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds*0, functionToCall)
- } else {
- timersFuncList.add(functionToCall)
- timersList.add(new SimulatedTimer())
- def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds*0, functionToCall)
- }
- }
-
- def runIn(int seconds, Closure functionToCall, LinkedHashMap metaData) {
- runIn(seconds, functionToCall)
- }
-
- def runIn(int seconds, String nameOfFunction, LinkedHashMap metaData) {
- runIn(seconds, nameOfFunction)
- }
-
- def runIn(int seconds, String nameOfFunction) {
- timersFuncList.add(nameOfFunction)
- timersList.add(new SimulatedTimer())
- def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(seconds*1000*0) {
- "$nameOfFunction"()
- }
- }
- /////////////////////////////////////////////////////////////////////
- ////unschedule(func)
- def unschedule(Closure functionToUnschedule) {
- for (int i = 0;i < timersFuncList.size();i++) {
- if (timersFuncList[i] == functionToUnschedule) {
- if (timersList != null)
- timersList[i].cancel()
- }
- }
- }
-
-
- def unschedule() {
- for (int i = 0;i < timersFuncList.size();i++) {
- if (timersList != null)
- timersList[i].cancel()
- }
- }
- /////////////////////////////////////////////////////////////////////
- ////sendNotificationToContacts(text, recipients)
- def sendNotificationToContacts(String text, String recipients) {
- for (int i = 0;i < recipients.size();i++) {
- for (int j = 0;j < location.contacts.size();j++) {
- if (recipients[i] == location.contacts[j]) {
- println("Sending \""+text+"\" to "+location.phoneNumbers[j].toString())
- }
- }
- }
- }
- /////////////////////////////////////////////////////////////////////
- ////sendSms(phone, text)
- def sendSms(long phoneNumber, String text) {
- println("Sending \""+text+"\" to "+phoneNumber.toString())
- }
-
- def sendSMS(long phoneNumber, String text) {
- println("Sending \""+text+"\" to "+phoneNumber.toString())
- }
- /////////////////////////////////////////////////////////////////////
- ////sendPush(text)
- def sendPush(String text) {
- println(text)
- }
- /////////////////////////////////////////////////////////////////////
- ////schedule(time, nameOfFunction as String)
- def schedule(String time, String nameOfFunction) {
- def _inputTime = time.split(':')
- Date date = new Date()
- def _currentTime = date.format("HH:mm:ss").split(':')
-
- //Convert input time and current time to minutes
- def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
- def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
- def delay
-
- if (inputTime < currentTime) {
- delay = 24*60*60-inputTime+currentTime
- } else {
- delay = inputTime-currentTime
- }
-
- timersFuncList.add(nameOfFunction)
- timersList.add(new SimulatedTimer())
- def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*1000*0) {
- "$nameOfFunction"()
- }
- }
- ////schedule(time, nameOfFunction as Closure)
- def schedule(String time, Closure nameOfFunction) {
- def _inputTime = time.split(':')
- Date date = new Date()
- def _currentTime = date.format("HH:mm:ss").split(':')
-
- //Convert input time and current time to minutes
- def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
- def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
- def delay
-
- if (inputTime < currentTime) {
- delay = 24*60*60-inputTime+currentTime
- } else {
- delay = inputTime-currentTime
- }
-
- if (timersFuncList.contains(nameOfFunction)) {
- timersList[timersFuncList.indexOf(nameOfFunction)].cancel()
- def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*0, nameOfFunction)
- } else {
- timersFuncList.add(nameOfFunction)
- timersList.add(new SimulatedTimer())
- def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*0, nameOfFunction)
- }
- }
- /////////////////////////////////////////////////////////////////////
- def now() {
- return System.currentTimeMillis()
- }
- /////////////////////////////////////////////////////////////////////
- def getTemperatureScale() {
- return 'F' //Celsius for now
- }
-
- /////////////////////////////////////////////////////////////////////
- def getSunriseAndSunset(LinkedHashMap metaData) {
- def sunRiseSetInfo = [sunrise:[time:1563800160000],sunset:[time:1563850740000]]
- return sunRiseSetInfo
- }
- /////////////////////////////////////////////////////////////////////
- def httpPostJson(LinkedHashMap metaData, Closure inputData) {
- inputData(metaData)
- }
- /////////////////////////////////////////////////////////////////////
- def runEvery15Minutes(Closure inputData) {
- inputData()
- }
- /////////////////////////////////////////////////////////////////////
- def timeToday(String time, Object timeZone) {
- def timeOfDay = new Date()
- def _inputTime = time.split(':')
- def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60+1564191100415
- timeOfDay.time = inputTime
- return timeOfDay
- }
- /////////////////////////////////////////////////////////////////////
- def sendNotification(String text, LinkedHashMap metaData) {
- println("Sending \""+text+"\" to "+metaData.phone.toString())
- }
- /////////////////////////////////////////////////////////////////////
- def canSchedule() {
- return true
- }
-
- def installed(){
- initialize()
- }
-
- def updated(){
- unsubscribe()
- unschedule()
- initialize()
- }
-
- def initialize(){
- log.debug "Settings: ${settings}"
- subscribe(lock1, "lock", doorHandler, [filterEvents: false])
- subscribe(lock1, "unlock", doorHandler, [filterEvents: false])
- subscribe(contact, "contact.open", doorHandler)
- subscribe(contact, "contact.closed", doorHandler)
- }
-
- def lockDoor(){
- log.debug "Locking the door."
- lock1.lock()
- if(location.contactBookEnabled) {
- if ( recipients ) {
- log.debug ( "Sending Push Notification..." )
- sendNotificationToContacts( "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!", recipients)
- }
- }
- if (phoneNumber) {
- log.debug("Sending text message...")
- sendSms( phoneNumber, "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!")
- }
- }
-
- def unlockDoor(){
- log.debug "Unlocking the door."
- lock1.unlock()
- if(location.contactBookEnabled) {
- if ( recipients ) {
- log.debug ( "Sending Push Notification..." )
- sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!", recipients)
- }
- }
- if ( phoneNumber ) {
- log.debug("Sending text message...")
- sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!")
- }
- }
-
- def doorHandler(evt){
- if ((contact.latestValue("contact") == "open") && (evt.value == "locked")) { // If the door is open and a person locks the door then...
- //def delay = (secondsLater) // runIn uses seconds
- runIn( secondsLater, unlockDoor ) // ...schedule (in minutes) to unlock... We don't want the door to be closed while the lock is engaged.
- }
- else if ((contact.latestValue("contact") == "open") && (evt.value == "unlocked")) { // If the door is open and a person unlocks it then...
- unschedule( unlockDoor ) // ...we don't need to unlock it later.
- }
- else if ((contact.latestValue("contact") == "closed") && (evt.value == "locked")) { // If the door is closed and a person manually locks it then...
- unschedule( lockDoor ) // ...we don't need to lock it later.
- }
- else if ((contact.latestValue("contact") == "closed") && (evt.value == "unlocked")) { // If the door is closed and a person unlocks it then...
- //def delay = (minutesLater * 60) // runIn uses seconds
- runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
- }
- else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "open")) { // If a person opens an unlocked door...
- unschedule( lockDoor ) // ...we don't need to lock it later.
- }
- else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "closed")) { // If a person closes an unlocked door...
- //def delay = (minutesLater * 60) // runIn uses seconds
- runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
- }
- else { //Opening or Closing door when locked (in case you have a handle lock)
- log.debug "Unlocking the door."
- lock1.unlock()
- if(location.contactBookEnabled) {
- if ( recipients ) {
- log.debug ( "Sending Push Notification..." )
- sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!", recipients)
- }
- }
- if ( phoneNumber ) {
- log.debug("Sending text message...")
- sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!")
- }
- }
- }
-}
-
-
-//Application #2
-class App2 {
- def reference
- def location
- def app
- def atomicState
-
- //Extracted objects for App2
- //Global variable for time!
- def starting = "15:00"
- //Global variable for time!
- def ending = "15:00"
- //Object for class beacon sensor!
- def beacons
- //Object for class mobile presence!
- def phones
- //Global variable for enum!
- def arrivalPhrase = "Good Night!"
- //Object for class switch!
- def arrivalOnSwitches
- //Object for class switch!
- def arrivalOffSwitches
- //Object for class lock!
- def arrivalLocks
- //Global variable for enum!
- def departPhrase = "Good Night!"
- //Object for class switch!
- def departOnSwitches
- //Object for class switch!
- def departOffSwitches
- //Object for class lock!
- def departLocks
- //Global variable for boolean!
- def pushNotification = "0"
- //Global variable for phone!
- def phone = 9495379373
- //Global variable for enum!
- def days = "Monday"
- //Global variable for mode!
- def modes = "night"
-
- //Extracted objects for functions for App2
- //Global Object for functions in subscribe method!
- def mainPage = this.&mainPage
- //Global Object for functions in subscribe method!
- def installed = this.&installed
- //Global Object for functions in subscribe method!
- def updated = this.&updated
- //Global Object for functions in subscribe method!
- def initialize = this.&initialize
- //Global Object for functions in subscribe method!
- def beaconHandler = this.&beaconHandler
- //Global Object for functions in subscribe method!
- def arriveActions = this.&arriveActions
- //Global Object for functions in subscribe method!
- def departActions = this.&departActions
- //Global Object for functions in subscribe method!
- def prefix = this.&prefix
- //Global Object for functions in subscribe method!
- def listPhrases = this.&listPhrases
- //Global Object for functions in subscribe method!
- def executePhrase = this.&executePhrase
- //Global Object for functions in subscribe method!
- def getBeaconName = this.&getBeaconName
- //Global Object for functions in subscribe method!
- def getPhoneName = this.&getPhoneName
- //Global Object for functions in subscribe method!
- def hideOptionsSection = this.&hideOptionsSection
- //Global Object for functions in subscribe method!
- def getAllOk = this.&getAllOk
- //Global Object for functions in subscribe method!
- def getModeOk = this.&getModeOk
- //Global Object for functions in subscribe method!
- def getDaysOk = this.&getDaysOk
- //Global Object for functions in subscribe method!
- def getTimeOk = this.&getTimeOk
- //Global Object for functions in subscribe method!
- def hhmm = this.&hhmm
- //Global Object for functions in subscribe method!
- def timeIntervalLabel = this.&timeIntervalLabel
- //Global Object for functions in subscribe method!
- def list = this.&list
-
- App2(Object obj) {
- reference = obj
- location = obj.locationObject
- app = obj.appObject
- atomicState = obj.atomicState
- beacons = obj.beaconSensorObject
- phones = obj.mobilePresenceObject
- arrivalOnSwitches = obj.switchObject
- arrivalOffSwitches = obj.switchObject
- arrivalLocks = obj.lockObject
- departOnSwitches = obj.switchObject
- departOffSwitches = obj.switchObject
- departLocks = obj.lockObject
- //Global variable for settings!
- settings = [app:app, starting:starting, ending:ending, beacons:beacons, phones:phones, arrivalPhrase:arrivalPhrase, arrivalOnSwitches:arrivalOnSwitches, arrivalOffSwitches:arrivalOffSwitches, arrivalLocks:arrivalLocks, departPhrase:departPhrase, departOnSwitches:departOnSwitches, departOffSwitches:departOffSwitches, departLocks:departLocks, pushNotification:pushNotification, phone:phone, days:days, modes:modes]
- }
- //Global variables for each app
- //Global variable for state[mode]
- def state = [home:[],away:[],night:[]]
- //Create a global logger object for methods
- def log = new Logger()
- //Create a global variable for Functions in Subscribe method
- def functionList = []
- //Create a global variable for Objects in Subscribe method
- def objectList = []
- //Create a global variable for Events in Subscribe method
- def eventList = []
- //Create a global list for function schedulers
- def timersFuncList = []
- //Create a global list for timer schedulers
- def timersList = []
- //Create a global variable for settings
- def settings
- //Zip code
- def zipCode = 92617
-
- //Methods
- /////////////////////////////////////////////////////////////////////
- def setLocationMode(String mode) {
- location.mode = mode
- }
-
- /////////////////////////////////////////////////////////////////////
- ////subscribe(obj, func)
- def subscribe(Object obj, Closure FunctionToCall) {
- if (obj == app) {
- objectList.add(obj)
- eventList.add("Touched")
- functionList.add(FunctionToCall)
- } else if (obj == location) {
- objectList.add(obj)
- eventList.add("Location")
- functionList.add(FunctionToCall)
- }
- }
- ////subscribe(obj, event, func)
- def subscribe(Object obj, String event, Closure FunctionToCall) {
- objectList.add(obj)
- eventList.add(event)
- functionList.add(FunctionToCall)
- }
- ////subscribe(obj, event, func, data)
- def subscribe(Object obj, String event, Closure FunctionToCall, LinkedHashMap metaData) {
- objectList.add(obj)
- eventList.add(event)
- functionList.add(FunctionToCall)
- }
- /////////////////////////////////////////////////////////////////////
- ////runIn(time, func)
- def runIn(int seconds, Closure functionToCall) {
- if (timersFuncList.contains(functionToCall)) {
- timersList[timersFuncList.indexOf(functionToCall)].cancel()
- def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds*0, functionToCall)
- } else {
- timersFuncList.add(functionToCall)
- timersList.add(new SimulatedTimer())
- def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds*0, functionToCall)
- }
- }
-
- def runIn(int seconds, Closure functionToCall, LinkedHashMap metaData) {
- runIn(seconds, functionToCall)
- }
-
- def runIn(int seconds, String nameOfFunction, LinkedHashMap metaData) {
- runIn(seconds, nameOfFunction)
- }
-
- def runIn(int seconds, String nameOfFunction) {
- timersFuncList.add(nameOfFunction)
- timersList.add(new SimulatedTimer())
- def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(seconds*1000*0) {
- "$nameOfFunction"()
- }
- }
- /////////////////////////////////////////////////////////////////////
- ////unschedule(func)
- def unschedule(Closure functionToUnschedule) {
- for (int i = 0;i < timersFuncList.size();i++) {
- if (timersFuncList[i] == functionToUnschedule) {
- if (timersList != null)
- timersList[i].cancel()
- }
- }
- }
-
-
- def unschedule() {
- for (int i = 0;i < timersFuncList.size();i++) {
- if (timersList != null)
- timersList[i].cancel()
- }
- }
- /////////////////////////////////////////////////////////////////////
- ////sendNotificationToContacts(text, recipients)
- def sendNotificationToContacts(String text, String recipients) {
- for (int i = 0;i < recipients.size();i++) {
- for (int j = 0;j < location.contacts.size();j++) {
- if (recipients[i] == location.contacts[j]) {
- println("Sending \""+text+"\" to "+location.phoneNumbers[j].toString())
- }
- }
- }
- }
- /////////////////////////////////////////////////////////////////////
- ////sendSms(phone, text)
- def sendSms(long phoneNumber, String text) {
- println("Sending \""+text+"\" to "+phoneNumber.toString())
- }
-
- def sendSMS(long phoneNumber, String text) {
- println("Sending \""+text+"\" to "+phoneNumber.toString())
- }
- /////////////////////////////////////////////////////////////////////
- ////sendPush(text)
- def sendPush(String text) {
- println(text)
- }
- /////////////////////////////////////////////////////////////////////
- ////schedule(time, nameOfFunction as String)
- def schedule(String time, String nameOfFunction) {
- def _inputTime = time.split(':')
- Date date = new Date()
- def _currentTime = date.format("HH:mm:ss").split(':')
-
- //Convert input time and current time to minutes
- def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
- def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
- def delay
-
- if (inputTime < currentTime) {
- delay = 24*60*60-inputTime+currentTime
- } else {
- delay = inputTime-currentTime
- }
-
- timersFuncList.add(nameOfFunction)
- timersList.add(new SimulatedTimer())
- def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*1000*0) {
- "$nameOfFunction"()
- }
- }
- ////schedule(time, nameOfFunction as Closure)
- def schedule(String time, Closure nameOfFunction) {
- def _inputTime = time.split(':')
- Date date = new Date()
- def _currentTime = date.format("HH:mm:ss").split(':')
-
- //Convert input time and current time to minutes
- def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
- def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
- def delay
-
- if (inputTime < currentTime) {
- delay = 24*60*60-inputTime+currentTime
- } else {
- delay = inputTime-currentTime
- }
-
- if (timersFuncList.contains(nameOfFunction)) {
- timersList[timersFuncList.indexOf(nameOfFunction)].cancel()
- def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*0, nameOfFunction)
- } else {
- timersFuncList.add(nameOfFunction)
- timersList.add(new SimulatedTimer())
- def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*0, nameOfFunction)
- }
- }
- /////////////////////////////////////////////////////////////////////
- def now() {
- return System.currentTimeMillis()
- }
- /////////////////////////////////////////////////////////////////////
- def getTemperatureScale() {
- return 'F' //Celsius for now
- }
-
- /////////////////////////////////////////////////////////////////////
- def getSunriseAndSunset(LinkedHashMap metaData) {
- def sunRiseSetInfo = [sunrise:[time:1563800160000],sunset:[time:1563850740000]]
- return sunRiseSetInfo
- }
- /////////////////////////////////////////////////////////////////////
- def httpPostJson(LinkedHashMap metaData, Closure inputData) {
- inputData(metaData)
- }
- /////////////////////////////////////////////////////////////////////
- def runEvery15Minutes(Closure inputData) {
- inputData()
- }
- /////////////////////////////////////////////////////////////////////
- def timeToday(String time, Object timeZone) {
- def timeOfDay = new Date()
- def _inputTime = time.split(':')
- def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60+1564191100415
- timeOfDay.time = inputTime
- return timeOfDay
- }
- /////////////////////////////////////////////////////////////////////
- def sendNotification(String text, LinkedHashMap metaData) {
- println("Sending \""+text+"\" to "+metaData.phone.toString())
- }
- /////////////////////////////////////////////////////////////////////
- def canSchedule() {
- return true
- }
-
- def mainPage() {
- dynamicPage(name: "mainPage", install: true, uninstall: true) {
-
- section("Where do you want to watch?") {
- input name: "beacons", type: "capability.beacon", title: "Select your beacon(s)",
- multiple: true, required: true
- }
-
- section("Who do you want to watch for?") {
- input name: "phones", type: "device.mobilePresence", title: "Select your phone(s)",
- multiple: true, required: true
- }
-
- section("What do you want to do on arrival?") {
- input name: "arrivalPhrase", type: "enum", title: "Execute a phrase",
- options: listPhrases(), required: false
- input "arrivalOnSwitches", "capability.switch", title: "Turn on some switches",
- multiple: true, required: false
- input "arrivalOffSwitches", "capability.switch", title: "Turn off some switches",
- multiple: true, required: false
- input "arrivalLocks", "capability.lock", title: "Unlock the door",
- multiple: true, required: false
- }
-
- section("What do you want to do on departure?") {
- input name: "departPhrase", type: "enum", title: "Execute a phrase",
- options: listPhrases(), required: false
- input "departOnSwitches", "capability.switch", title: "Turn on some switches",
- multiple: true, required: false
- input "departOffSwitches", "capability.switch", title: "Turn off some switches",
- multiple: true, required: false
- input "departLocks", "capability.lock", title: "Lock the door",
- multiple: true, required: false
- }
-
- section("Do you want to be notified?") {
- input "pushNotification", "bool", title: "Send a push notification"
- input "phone", "phone", title: "Send a text message", description: "Tap to enter phone number",
- required: false
- }
-
- section {
- label title: "Give your automation a name", description: "e.g. Goodnight Home, Wake Up"
- }
-
- def timeLabel = timeIntervalLabel()
- section(title: "More options", hidden: hideOptionsSection(), hideable: true) {
- href "timeIntervalInput", title: "Only during a certain time",
- description: timeLabel ?: "Tap to set", state: timeLabel ? "complete" : "incomplete"
-
- input "days", "enum", title: "Only on certain days of the week", multiple: true, required: false,
- options: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
-
- input "modes", "mode", title: "Only when mode is", multiple: true, required: false
- }
- }
- }
-
- // Lifecycle management
- def installed() {
- log.debug "<beacon-control> Installed with settings: ${settings}"
- initialize()
- }
-
- def updated() {
- log.debug "<beacon-control> Updated with settings: ${settings}"
- unsubscribe()
- initialize()
- }
-
- def initialize() {
- subscribe(beacons, "presence", beaconHandler)
- }
-
- // Event handlers
- def beaconHandler(evt) {
- log.debug "<beacon-control> beaconHandler: $evt"
-
- if (allOk) {
- def data = new groovy.json.JsonSlurper().parseText(evt.data)
- // removed logging of device names. can be added back for debugging
- //log.debug "<beacon-control> data: $data - phones: " + phones*.deviceNetworkId
-
- def beaconName = getBeaconName(evt)
- // removed logging of device names. can be added back for debugging
- //log.debug "<beacon-control> beaconName: $beaconName"
-
- def phoneName = getPhoneName(data)
- // removed logging of device names. can be added back for debugging
- //log.debug "<beacon-control> phoneName: $phoneName"
- if (phoneName != null) {
- def action = data.presence == "1" ? "arrived" : "left"
- def msg = "$phoneName has $action ${action == 'arrived' ? 'at ' : ''}the $beaconName"
-
- if (action == "arrived") {
- msg = arriveActions(msg)
- }
- else if (action == "left") {
- msg = departActions(msg)
- }
- log.debug "<beacon-control> msg: $msg"
-
- if (pushNotification || phone) {
- def options = [
- method: (pushNotification && phone) ? "both" : (pushNotification ? "push" : "sms"),
- phone: phone
- ]
- sendNotification(msg, options)
- }
- }
- }
- }
-
- // Helpers
- private arriveActions(msg) {
- if (arrivalPhrase || arrivalOnSwitches || arrivalOffSwitches || arrivalLocks) msg += ", so"
-
- if (arrivalPhrase) {
- log.debug "<beacon-control> executing: $arrivalPhrase"
- executePhrase(arrivalPhrase)
- msg += " ${prefix('executed')} $arrivalPhrase."
- }
- if (arrivalOnSwitches) {
- log.debug "<beacon-control> turning on: $arrivalOnSwitches"
- arrivalOnSwitches.on()
- msg += " ${prefix('turned')} ${list(arrivalOnSwitches)} on."
- }
- if (arrivalOffSwitches) {
- log.debug "<beacon-control> turning off: $arrivalOffSwitches"
- arrivalOffSwitches.off()
- msg += " ${prefix('turned')} ${list(arrivalOffSwitches)} off."
- }
- if (arrivalLocks) {
- log.debug "<beacon-control> unlocking: $arrivalLocks"
- arrivalLocks.unlock()
- msg += " ${prefix('unlocked')} ${list(arrivalLocks)}."
- }
- msg
- }
-
- private departActions(msg) {
- if (departPhrase || departOnSwitches || departOffSwitches || departLocks) msg += ", so"
-
- if (departPhrase) {
- log.debug "<beacon-control> executing: $departPhrase"
- executePhrase(departPhrase)
- msg += " ${prefix('executed')} $departPhrase."
- }
- if (departOnSwitches) {
- log.debug "<beacon-control> turning on: $departOnSwitches"
- departOnSwitches.on()
- msg += " ${prefix('turned')} ${list(departOnSwitches)} on."
- }
- if (departOffSwitches) {
- log.debug "<beacon-control> turning off: $departOffSwitches"
- departOffSwitches.off()
- msg += " ${prefix('turned')} ${list(departOffSwitches)} off."
- }
- if (departLocks) {
- log.debug "<beacon-control> unlocking: $departLocks"
- departLocks.lock()
- msg += " ${prefix('locked')} ${list(departLocks)}."
- }
- msg
- }
-
- private prefix(word) {
- def result
- def index = settings.prefixIndex == null ? 0 : settings.prefixIndex + 1
- switch (index) {
- case 0:
- result = "I $word"
- break
- case 1:
- result = "I also $word"
- break
- case 2:
- result = "And I $word"
- break
- default:
- result = "And $word"
- break
- }
-
- settings.prefixIndex = index
- log.trace "prefix($word'): $result"
- result
- }
-
- private listPhrases() {
- location.helloHome.getPhrases().label
- }
-
- private executePhrase(phraseName) {
- if (phraseName) {
- location.helloHome.execute(phraseName)
- log.debug "<beacon-control> executed phrase: $phraseName"
- }
- }
-
- private getBeaconName(evt) {
- def beaconName = beacons.find { b -> b.id == evt.deviceId }
- return beaconName
- }
-
- private getPhoneName(data) {
- def phoneName = phones.find { phone ->
- // Work around DNI bug in data
- def pParts = phone.deviceNetworkId.split('\\|')
- def dParts = data.dni.split('\\|')
- pParts[0] == dParts[0]
- }
- return phoneName
- }
-
- private hideOptionsSection() {
- (starting || ending || days || modes) ? false : true
- }
-
- private getAllOk() {
- modeOk && daysOk && timeOk
- }
-
- private getModeOk() {
- def result = !modes || modes.contains(location.mode)
- log.trace "<beacon-control> modeOk = $result"
- result
- }
-
- private getDaysOk() {
- def result = true
- if (days) {
- def df = new java.text.SimpleDateFormat("EEEE")
- if (location.timeZone) {
- df.setTimeZone(location.timeZone)
- }
- else {
- df.setTimeZone(TimeZone.getTimeZone("America/New_York"))
- }
- def day = df.format(new Date())
- result = days.contains(day)
- }
- log.trace "<beacon-control> daysOk = $result"
- result
- }
-
- private getTimeOk() {
- def result = true
- if (starting && ending) {
- def currTime = now()
- def start = timeToday(starting, location?.timeZone).time
- def stop = timeToday(ending, location?.timeZone).time
- result = start < stop ? currTime >= start && currTime <= stop : currTime <= stop || currTime >= start
- }
- log.trace "<beacon-control> timeOk = $result"
- result
- }
-
- private hhmm(time, fmt = "h:mm a") {
- def t = timeToday(time, location.timeZone)
- def f = new java.text.SimpleDateFormat(fmt)
- f.setTimeZone(location.timeZone ?: timeZone(time))
- f.format(t)
- }
-
- private timeIntervalLabel() {
- (starting && ending) ? hhmm(starting) + "-" + hhmm(ending, "h:mm a z") : ""
- }
-
- private list(Object names) {
- return names[0]
- }
-}
-
-@Field def app1
-@Field def app2
-def initOrder = Verify.getBoolean()
-if (initOrder) {
- app1 = new App1(this)
- app2 = new App2(this)
-} else {
- app2 = new App2(this)
- app1 = new App1(this)
-}
-
-def installOrder = Verify.getBoolean()
-if (installOrder) {
- app1.installed()
- app2.installed()
-} else {
- app2.installed()
- app1.installed()
-}
-
-while(true) {
- def eventNumber = Verify.getInt(0,4)
- switch(eventNumber) {
- case 0:
- lockObject.setValue([name: "lock", value: "locked", deviceId: "lockID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- break
- case 1:
- lockObject.setValue([name: "unlock", value: "unlocked ", deviceId: "lockID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- break
- case 2:
- contactObject.setValue([name: "contact.open", value: "open", deviceId: "contactSensorID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- break
- case 3:
- contactObject.setValue([name: "contact.closed", value: "closed", deviceId: "contactSensorID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- break
- case 4:
- def event = Verify.getInt(0,1)
- if (event == 0) {
- presenceSensorObject.setValue([name: "presence", value: "present", deviceId: "presenceSensorID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"1","dni":"mobile0"}'])
- } else {
- presenceSensorObject.setValue([name: "presence", value: "not present", deviceId: "presenceSensorID0", descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"0","dni":"mobile0"}'])
- }
- break
- }
-}