--- /dev/null
+//Create a class for contact sensor
+package ContactSensor
+import Timer.SimulatedTimer
+
+public class ContactSensor {
+ private int id
+ private String label
+ private String displayName
+ private String contactState
+ private String contactLatestValue
+
+ ContactSensor(int id, String label, String displayName, String contactState, String contactLatestValue) {
+ this.id = id
+ this.label = label
+ this.displayName = displayName
+ this.contactState = contactState
+ this.contactLatestValue = contactLatestValue
+ }
+
+ def setValue(String value) {
+ this.contactLatestValue = contactState
+ println("the contact sensor with id:$id is triggered to $value!")
+ this.contactState = value
+ }
+
+ def currentValue(String deviceFeature) {
+ if (deviceFeature == "contact") {
+ return contactState
+ }
+ }
+
+ def latestValue(String deviceFeature) {
+ if (deviceFeature == "contact") {
+ return contactLatestValue
+ }
+ }
+}
--- /dev/null
+//Create a class for contact sensor
+package ContactSensor
+import Timer.SimulatedTimer
+
+public class ContactSensors {
+ private int deviceNumbers
+ private List contacts
+ def sendEvent
+
+ //For one device(We cannot have obj.id)-> We should have obj[0].id
+ private int id = 10
+ private String label = "contactSensor"
+ private String displayName = "contactSensor"
+ private String contactState = "closed"
+ private String contactLatestValue = "closed"
+
+
+ ContactSensors(Closure sendEvent, int deviceNumbers) {
+ this.sendEvent = sendEvent
+ this.deviceNumbers = deviceNumbers
+ this.contacts = []
+
+ for (int i = 0;i < deviceNumbers;i++) {
+ contacts.add(new ContactSensor(i+10, label+i.toString(), displayName+i.toString(), this.contactState, this.contactLatestValue))
+ }
+ }
+
+ //Methods for closures
+ def count(Closure Input) {
+ contacts.count(Input)
+ }
+ def size() {
+ contacts.size()
+ }
+ def each(Closure Input) {
+ contacts.each(Input)
+ }
+
+ //By Model Checker
+ def setValue(LinkedHashMap eventDataMap) {
+ contacts[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
+ if (deviceNumbers == 1)
+ this.contactLatestValue = contacts[eventDataMap["deviceId"]].contactLatestValue
+ this.contactState = contacts[eventDataMap["deviceId"]].contactState
+ sendEvent(eventDataMap)
+ }
+
+ def currentValue(String deviceFeature) {
+ if (deviceNumbers == 1)
+ contacts[0].currentValue(deviceFeature)//It is called if we have only one device
+ else
+ contacts*.currentValue(deviceFeature)
+ }
+
+ def latestValue(String deviceFeature) {
+ if (deviceNumbers == 1)
+ contacts[0].latestValue(deviceFeature)//It is called if we have only one device
+ else
+ contacts*.latestValue(deviceFeature)
+ }
+
+ def getAt(int ix) {
+ contacts[ix]
+ }
+}
+++ /dev/null
-//Create a class for contact sensor
-package ContactSensor
-import Timer.SimulatedTimer
-
-public class Contacting {
- private int deviceNumbers
- private List contacts
- def sendEvent
-
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private int id = 0
- private String displayName = "contact0"
- private String contactState = "closed"
- private String contactLatestValue = "closed"
-
-
- Contacting(Closure sendEvent, int deviceNumbers) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.contacts = []
-
-
- if (deviceNumbers == 1) {
- contacts = [new Contacts(this.id, this.displayName, this.contactState, this.contactLatestValue)]
- } else if (deviceNumbers == 2) {
- contacts = [new Contacts(0, "contact0", "closed", "closed"), new Contacts(1, "contact1", "closed", "closed")]
- } else if (deviceNumbers == 3) {
- contacts = [new Contacts(0, "contact0", "closed", "closed"), new Contacts(1, "contact1", "closed", "closed")
- ,new Contacts(2, "contact2", "closed", "closed")]
- }
- }
-
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- contacts[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
- if (deviceNumbers == 1)
- this.contactLatestValue = contacts[eventDataMap["deviceId"]].contactLatestValue
- this.contactState = contacts[eventDataMap["deviceId"]].contactState
- sendEvent(eventDataMap)
- }
-
- def currentValue(String deviceFeature) {
- if (deviceNumbers == 1)
- contacts[0].currentValue(deviceFeature)//It is called if we have only one device
- else
- contacts*.currentValue(deviceFeature)
- }
-
- def latestValue(String deviceFeature) {
- if (deviceNumbers == 1)
- contacts[0].latestValue(deviceFeature)//It is called if we have only one device
- else
- contacts*.latestValue(deviceFeature)
- }
-
- def getAt(int ix) {
- contacts[ix]
- }
-}
+++ /dev/null
-//Create a class for contact sensor
-package ContactSensor
-import Timer.SimulatedTimer
-
-public class Contacts {
- private int id
- private String displayName
- private String contactState
- private String contactLatestValue
-
- Contacts(int id, String displayName, String contactState, String contactLatestValue) {
- this.id = id
- this.displayName = displayName
- this.contactState = contactState
- this.contactLatestValue = contactLatestValue
- }
-
- def setValue(String value) {
- this.contactLatestValue = contactState
- println("the contact sensor with id:$id is triggered to $value!")
- this.contactState = value
- }
-
- def currentValue(String deviceFeature) {
- if (deviceFeature == "contact") {
- return contactState
- }
- }
-
- def latestValue(String deviceFeature) {
- if (deviceFeature == "contact") {
- return contactLatestValue
- }
- }
-}
--- /dev/null
+//Create a class for door control device
+package DoorControl
+import Timer.SimulatedTimer
+
+public class DoorControl {
+ private int id
+ private String label
+ private String displayName
+ private String doorState
+ private String doorLatestValue
+ def sendEvent
+ def timers
+
+
+ DoorControl(Closure sendEvent, int id, String label, String displayName, String doorState, String doorLatestValue) {
+ this.sendEvent = sendEvent
+ this.timers = new SimulatedTimer()
+ this.id = id
+ this.label = label
+ this.displayName = displayName
+ this.doorState = doorState
+ }
+
+ //By Apps
+ def open() {
+ println("the door with id:$id is open!")
+ this.doorLatestValue = this.doorState
+ this.doorState = "open"
+ sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+
+ def open(LinkedHashMap metaData) {
+ def task = timers.runAfter(metaData["delay"]) {
+ println("the door with id:$id is open!")
+ this.doorLatestValue = this.doorState
+ this.doorState = "open"
+ sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+ }
+
+ def close() {
+ println("the door with id:$id is closed!")
+ this.doorLatestValue = this.doorState
+ this.doorState = "closed"
+ sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+
+ def close(LinkedHashMap metaData) {
+ def task = timers.runAfter(metaData["delay"]) {
+ println("the door with id:$id is closed!")
+ this.doorLatestValue = this.doorState
+ this.doorState = "closed"
+ sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+ }
+
+ //By Model Checker
+ def setValue(String value) {
+ println("the door with id:$id is $value!")
+ this.doorLatestValue = this.doorState
+ this.doorState = value
+ }
+
+ def currentValue(String deviceFeature) {
+ if (deviceFeature == "status") {
+ return doorState
+ }
+ }
+
+ def latestValue(String deviceFeature) {
+ if (deviceFeature == "status") {
+ return doorLatestValue
+ }
+ }
+}
--- /dev/null
+//Create a class for door control device
+package DoorControl
+import Timer.SimulatedTimer
+
+public class DoorControls {
+ int deviceNumbers
+ List doorControls
+ def timers
+ def sendEvent
+
+ //If we have only one device
+ private int id = 40
+ private String label = "DoorControl"
+ private String displayName = "DoorControl"
+ private String doorState = "closed"
+ private String doorLatestValue = "closed"
+
+ DoorControls(Closure sendEvent, int deviceNumbers) {
+ this.sendEvent = sendEvent
+ this.timers = new SimulatedTimer()
+ this.deviceNumbers = deviceNumbers
+ this.doorControls = []
+ for (int i = 0;i < deviceNumbers;i++) {
+ doorControls.add(new DoorControl(sendEvent, i+60, label+i.toString(), displayName+i.toString(), this.doorState, this.doorLatestValue))
+ }
+ }
+
+ //Methods for closures
+ def count(Closure Input) {
+ doorControls.count(Input)
+ }
+ def size() {
+ doorControls.size()
+ }
+ def each(Closure Input) {
+ doorControls.each(Input)
+ }
+
+ //By Apps
+ def open() {
+ doorControls*.on()
+ }
+
+ def open(LinkedHashMap metaData) {
+ def task = timers.runAfter(metaData["delay"]) {
+ doorControls*.on()
+ }
+ }
+
+ def close() {
+ doorControls*.off()
+ }
+
+ def close(LinkedHashMap metaData) {
+ def task = timers.runAfter(metaData["delay"]) {
+ doorControls*.off()
+ }
+ }
+
+ //By Model Checker
+ def setValue(LinkedHashMap eventDataMap) {
+ doorControls[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
+ if (deviceNumbers == 1)
+ this.doorState = doorControls[eventDataMap["deviceId"]].doorState
+ sendEvent(eventDataMap)
+ }
+
+
+ def currentValue(String deviceFeature) {
+ if (deviceNumbers == 1)
+ doorControls[0].currentValue(deviceFeature)
+ else
+ doorControls*.currentValue(deviceFeature)
+ }
+
+ def latestValue(String deviceFeature) {
+ if (deviceNumbers == 1)
+ doorControls[0].latestValue(deviceFeature)
+ else
+ doorControls*.latestValue(deviceFeature)
+ }
+
+ def getAt(int ix) {
+ doorControls[ix]
+ }
+}
-//////////
+////////////////
definition(
- name: "Enhanced Auto Lock Door",
- namespace: "Lock Auto Super Enhanced",
- author: "Arnaud",
- description: "Automatically locks a specific door after X minutes when closed and unlocks it when open after X seconds.",
- category: "Safety & Security",
- iconUrl: "http://www.gharexpert.com/mid/4142010105208.jpg",
- iconX2Url: "http://www.gharexpert.com/mid/4142010105208.jpg"
-)
+ name: "NFC Tag Toggle",
+ namespace: "smartthings",
+ author: "SmartThings",
+ description: "Allows toggling of a switch, lock, or garage door based on an NFC Tag touch event",
+ category: "SmartThings Internal",
+ iconUrl: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor.png",
+ iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor@2x.png",
+ iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor@2x.png")
-preferences{
- section("Select the door lock:") {
- input "lock1", "capability.lock", required: true
- }
- section("Select the door contact sensor:") {
- input "contact", "capability.contactSensor", required: true
- }
- section("Automatically lock the door when closed...") {
- input "minutesLater", "number", title: "Delay (in minutes):", required: true
- }
- section("Automatically unlock the door when open...") {
- input "secondsLater", "number", title: "Delay (in seconds):", required: true
- }
- section( "Notifications" ) {
- input("recipients", "contact", title: "Send notifications to", required: false) {
- input "phoneNumber", "phone", title: "Warn with text message (optional)", description: "Phone Number", required: false
+
+preferences {
+ page(name: "pageOne", title: "Device selection", uninstall: true, nextPage: "pageTwo") {
+ section("Select an NFC tag") {
+ input "tag", "capability.touchSensor", title: "NFC Tag"
+ }
+ section("Select devices to control") {
+ input "switch1", "capability.switch", title: "Light or switch", required: false, multiple: true
+ input "lock", "capability.lock", title: "Lock", required: false, multiple: true
+ input "garageDoor", "capability.doorControl", title: "Garage door controller", required: false, multiple: true
}
}
+
+ page(name: "pageTwo", title: "Master devices", install: true, uninstall: true)
}
-def installed(){
- initialize()
+def pageTwo() {
+ dynamicPage(name: "pageTwo") {
+ section("If set, the state of these devices will be toggled each time the tag is touched, " +
+ "e.g. a light that's on will be turned off and one that's off will be turned on, " +
+ "other devices of the same type will be set to the same state as their master device. " +
+ "If no master is designated then the majority of devices of the same type will be used " +
+ "to determine whether to turn on or off the devices.") {
+
+ if (switch1 || masterSwitch) {
+ input "masterSwitch", "enum", title: "Master switch", options: switch1.collect{[(it.id): it.displayName]}, required: false
+ }
+ if (lock || masterLock) {
+ input "masterLock", "enum", title: "Master lock", options: lock.collect{[(it.id): it.displayName]}, required: false
+ }
+ if (garageDoor || masterDoor) {
+ input "masterDoor", "enum", title: "Master door", options: garageDoor.collect{[(it.id): it.displayName]}, required: false
+ }
+ }
+ section([mobileOnly:true]) {
+ label title: "Assign a name", required: false
+ mode title: "Set for specific mode(s)", required: false
+ }
+ }
}
-def updated(){
- unsubscribe()
- unschedule()
- initialize()
+def installed() {
+ log.debug "Installed with settings: ${settings}"
+
+ 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 updated() {
+ log.debug "Updated with settings: ${settings}"
+
+ unsubscribe()
+ initialize()
}
-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 initialize() {
+ subscribe tag, "nfcTouch", touchHandler
+ subscribe app, touchHandler
}
-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)
- }
+private currentStatus(devices, master, attribute) {
+ log.trace "currentStatus($devices, $master, $attribute)"
+ def result = null
+ if (master) {
+ result = devices.find{it.id == master}?.currentValue(attribute)
}
- if ( phoneNumber ) {
- log.debug("Sending text message...")
- sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!")
+ else {
+ def map = [:]
+ devices.each {
+ def value = it.currentValue(attribute)
+ map[value] = (map[value] ?: 0) + 1
+ log.trace "$it.displayName: $value"
+ }
+ log.trace map
+ result = map.collect{it}.sort{it.value}[-1].key
}
+ log.debug "$attribute = $result"
+ result
}
-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.
+def touchHandler(evt) {
+ log.trace "touchHandler($evt.descriptionText)"
+ if (switch1) {
+ def status = currentStatus(switch1, masterSwitch, "switch")
+ switch1.each {
+ if (status == "on") {
+ it.off()
+ }
+ else {
+ it.on()
+ }
+ }
}
- 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 (lock) {
+ def status = currentStatus(lock, masterLock, "lock")
+ lock.each {
+ if (status == "locked") {
+ lock.unlock()
+ }
+ else {
+ lock.lock()
}
}
- if ( phoneNumber ) {
- log.debug("Sending text message...")
- sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!")
+ }
+
+ if (garageDoor) {
+ def status = currentStatus(garageDoor, masterDoor, "status")
+ garageDoor.each {
+ if (status == "open") {
+ it.close()
+ }
+ else {
+ it.open()
+ }
}
}
}
//Global Object for functions in subscribe method!
+def pageTwo = this.&pageTwo
+//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
+def currentStatus = this.¤tStatus
//Global Object for functions in subscribe method!
-def doorHandler = this.&doorHandler
+def touchHandler = this.&touchHandler
+//Object for class Touch Sensor!
+def tag
+//Object for class switch!
+def switch1
//Object for class lock!
-def lock1
-//Object for class contactSensor!
-def contact
-//Global variable for number!
-def minutesLater = 1
-//Global variable for number!
-def secondsLater = 10
-//Global variable for contact!
-def recipients = "AJ"
-//Global variable for phone!
-def phoneNumber = 9495379373
+def lock
+//Object for class door control!
+def garageDoor
+//Global variable for enum!
+def masterSwitch = "40"
+//Global variable for enum!
+def masterLock = "20"
+//Global variable for enum!
+def masterDoor = "40"
-lock1 = obj.lockObject
-contact = obj.contactObject
+tag = obj.touchSensorObject
+switch1 = obj.switchObject
+lock = obj.lockObject
+garageDoor = obj.doorControlObject
+++ /dev/null
-input"lock1","capability.lock",required:true,"App1"
-input"contact","capability.contactSensor",required:true,"App1"
-input"minutesLater","number",title:"Delay(inminutes):",required:true,"App1"
-input"secondsLater","number",title:"Delay(inseconds):",required:true,"App1"
-input("recipients","contact",title:"Sendnotificationsto",required:false,"App1")
-input"phoneNumber","phone",title:"Warnwithtextmessage(optional)",description:"PhoneNumber",required:false,"App1"
//Object for class lock!
def lock1
//Global variable for mode!
-def newMode = "away"
+def newMode = "home"
//Global variable for number!
-def waitfor = 4
+def waitfor = 10
+++ /dev/null
-input"switchesoff","capability.switch",multiple:true,required:true,"App2"
-input"switcheson","capability.switch",multiple:true,required:false,"App2"
-input"lock1","capability.lock",multiple:true,"App2"
-input"newMode","mode",title:"Mode?","App2"
-input"waitfor","number",title:"Offafter(default120)",required:true,"App2"
--- /dev/null
+////////////////////////////////////////
+//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 Timer.SimulatedTimer
+
+
+@Field App //Default
+
+
+//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("")
+}
+
+
+
+
+
+//Global objects
+//Global Object for class Touch Sensor!
+@Field def touchSensorObject
+//Global Object for class switch!
+@Field def switchObject
+//Global Object for class lock!
+@Field def lockObject
+//Global Object for class door control!
+@Field def doorControlObject
+//Global Object for class contact sensor!
+@Field def contactObject
+//Global Object for class presence sensor!
+@Field def presenceSensorObject
+//Global Object for class thermostat!
+@Field def thermostatObject
+
+
+//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 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
+
+
+
+/////Input Methods/////
+//input "",""
+def input(String name, String type) {
+ switch(type) {
+ case "capability.lock":
+ lockObject = name
+ this[lockObject] = new Locks({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class lock!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.lockObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class lock!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.lockObject\n")
+ }
+ break
+ case "capability.alarm":
+ break
+ case "capability.battery":
+ break
+ case "capability.beacon":
+ break
+ case "capability.carbonMonoxideDetector":
+ break
+ case "capability.colorControl":
+ break
+ case "capability.contactSensor":
+ contactObject = name
+ this[contactObject] = new ContactSensors({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class contactSensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.contactObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class contactSensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.contactObject\n")
+ }
+ break
+ case "capability.doorControl":
+ doorControlObject = name
+ this[doorControlObject] = new DoorControls({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class door control!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.doorControlObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class door control!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.doorControlObject\n")
+ }
+ break
+ case "capability.energyMeter":
+ break
+ case "capability.illuminanceMeasurement":
+ break
+ case "capability.accelerationSensor":
+ break
+ case "capability.motionSensor":
+ break
+ case "capability.musicPlayer":
+ break
+ case "capability.powerMeter":
+ break
+ case "capability.presenceSensor":
+ presenceSensorObject = name
+ this[presenceSensorObject] = new PresenceSensors({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class presence sensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.presenceSensorObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class presence sensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.presenceSensorObject\n")
+ }
+ break
+ case "capability.relativeHumidityMeasurement":
+ break
+ case "capability.relaySwitch":
+ break
+ case "capability.sleepSensor":
+ break
+ case "capability.smokeDetector":
+ break
+ case "capability.stepSensor":
+ break
+ case "capability.switch":
+ switchObject = name
+ this[switchObject] = new Switches({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class switch!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.switchObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class switch!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.switchObject\n")
+ }
+ break
+ case "capability.switchLevel":
+ break
+ case "capability.temperatureMeasurement":
+ break
+ case "capability.thermostat":
+ thermostatObject = name
+ this[thermostatObject] = new Thermostats({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class thermostat!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.thermostatObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class thermostat!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.thermostatObject\n")
+ }
+ break
+ case "capability.valve":
+ break
+ case "capability.waterSensor":
+ break
+ case "capability.touchSensor":
+ touchSensorObject = name
+ this[touchSensorObject] = new NfcTouch({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class Touch Sensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.touchSensorObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class Touch Sensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.touchSensorObject\n")
+ }
+ break
+ case "capability.imageCapture":
+ break
+ case "device.mobilePresence":
+ break
+ case "device.aeonKeyFob":
+ break
+ case "mode":
+ def userInput = System.console().readLine 'Enter the mode:'
+
+ if (modeVariables == 0) {
+ mode0 = name
+ this[mode0] = userInput
+ } else if (modeVariables == 1) {
+ mode1 = name
+ this[mode1] = userInput
+ } else if (modeVariables == 2) {
+ mode2 = name
+ this[mode2] = userInput
+ } else if (modeVariables == 3) {
+ mode3 = name
+ this[mode3] = userInput
+ } else if (modeVariables == 4) {
+ mode4 = name
+ this[mode4] = userInput
+ } else if (modeVariables == 5) {
+ mode5 = name
+ this[mode5] = userInput
+ }
+
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for mode!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for mode!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "decimal":
+ break
+ case "text":
+ break
+ case "number":
+ def userInput = System.console().readLine 'Enter the number:'
+
+ if (numberVariables == 0) {
+ number0 = name
+ this[number0] = userInput
+ } else if (numberVariables == 1) {
+ number1 = name
+ this[number1] = userInput
+ } else if (numberVariables == 2) {
+ number2 = name
+ this[number2] = userInput
+ } else if (numberVariables == 3) {
+ number3 = name
+ this[number3] = userInput
+ } else if (numberVariables == 4) {
+ number4 = name
+ this[number4] = userInput
+ } else if (numberVariables == 5) {
+ number5 = name
+ this[number5] = userInput
+ }
+
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for number!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for number!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "time":
+ def userInput = System.console().readLine 'Enter the time:'
+
+ if (timeVariables == 0) {
+ time0 = name
+ this[time0] = userInput
+ } else if (timeVariables == 1) {
+ time1 = name
+ this[time1] = userInput
+ } else if (timeVariables == 2) {
+ time2 = name
+ this[time2] = userInput
+ } else if (timeVariables == 3) {
+ time3 = name
+ this[time3] = userInput
+ } else if (timeVariables == 4) {
+ time4 = name
+ this[time4] = userInput
+ } else if (timeVariables == 5) {
+ time5 = name
+ this[time5] = userInput
+ }
+
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for time!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for time!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "enum":
+ def userInput = System.console().readLine 'Enter the enum:'
+
+ if (enumVariables == 0) {
+ enum0 = name
+ this[enum0] = userInput
+ } else if (enumVariables == 1) {
+ enum1 = name
+ this[enum1] = userInput
+ } else if (enumVariables == 2) {
+ enum2 = name
+ this[enum2] = userInput
+ } else if (enumVariables == 3) {
+ enum3 = name
+ this[enum3] = userInput
+ } else if (enumVariables == 4) {
+ enum4 = name
+ this[enum4] = userInput
+ } else if (enumVariables == 5) {
+ enum5 = name
+ this[enum5] = userInput
+ }
+
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for enum!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for enum!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "bool":
+ break
+ case "phone":
+ def userInput = System.console().readLine 'Enter the phone:'
+
+ if (phoneVariables == 0) {
+ phone0 = name
+ this[phone0] = userInput
+ } else if (phoneVariables == 1) {
+ phone1 = name
+ this[phone1] = userInput
+ } else if (phoneVariables == 2) {
+ phone2 = name
+ this[phone2] = userInput
+ } else if (phoneVariables == 3) {
+ phone3 = name
+ this[phone3] = userInput
+ } else if (phoneVariables == 4) {
+ phone4 = name
+ this[phone4] = userInput
+ } else if (phoneVariables == 5) {
+ phone5 = name
+ this[phone5] = userInput
+ }
+
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for phone!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for phone!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "contact":
+ def userInput = System.console().readLine 'Enter the name of the contact:'
+
+ if (contactVariables == 0) {
+ contact0 = name
+ this[contact0] = userInput
+ } else if (contactVariables == 1) {
+ contact1 = name
+ this[contact1] = userInput
+ } else if (contactVariables == 2) {
+ contact2 = name
+ this[contact2] = userInput
+ } else if (contactVariables == 3) {
+ contact3 = name
+ this[contact3] = userInput
+ } else if (contactVariables == 4) {
+ contact4 = name
+ this[contact4] = userInput
+ } else if (contactVariables == 5) {
+ contact5 = name
+ this[contact5] = userInput
+ }
+
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for contact!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for contact!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ default:
+ break
+ }
+}
+
+//input "","",linkedHashMap
+def input(LinkedHashMap metaData, String name, String type) {
+ switch(type) {
+ case "capability.lock":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ lockObject = name
+ this[lockObject] = new Locks({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class lock!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.lockObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class lock!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.lockObject\n")
+ }
+ break
+ case "capability.alarm":
+ break
+ case "capability.battery":
+ break
+ case "capability.beacon":
+ break
+ case "capability.carbonMonoxideDetector":
+ break
+ case "capability.colorControl":
+ break
+ case "capability.contactSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ contactObject = name
+ this[contactObject] = new ContactSensors({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class contactSensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.contactObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class contactSensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.contactObject\n")
+ }
+ break
+ case "capability.doorControl":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ doorControlObject = name
+ this[doorControlObject] = new DoorControls({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class door control!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.doorControlObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class door control!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.doorControlObject\n")
+ }
+ break
+ case "capability.energyMeter":
+ break
+ case "capability.illuminanceMeasurement":
+ break
+ case "capability.accelerationSensor":
+ break
+ case "capability.motionSensor":
+ break
+ case "capability.musicPlayer":
+ break
+ case "capability.powerMeter":
+ break
+ case "capability.presenceSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ presenceSensorObject = name
+ this[presenceSensorObject] = new PresenceSensors({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class presence sensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.presenceSensorObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class presence sensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.presenceSensorObject\n")
+ }
+ break
+ case "capability.relativeHumidityMeasurement":
+ break
+ case "capability.relaySwitch":
+ break
+ case "capability.sleepSensor":
+ break
+ case "capability.smokeDetector":
+ break
+ case "capability.stepSensor":
+ break
+ case "capability.switch":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ switchObject = name
+ this[switchObject] = new Switches({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class switch!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.switchObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class switch!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.switchObject\n")
+ }
+ break
+ case "capability.switchLevel":
+ break
+ case "capability.temperatureMeasurement":
+ break
+ case "capability.thermostat":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ thermostatObject = name
+ this[thermostatObject] = new Thermostats({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class thermostat!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.thermostatObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class thermostat!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.thermostatObject\n")
+ }
+ break
+ case "capability.valve":
+ break
+ case "capability.waterSensor":
+ break
+ case "capability.touchSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ touchSensorObject = name
+ this[touchSensorObject] = new NfcTouch({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class Touch Sensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.touchSensorObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class Touch Sensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.touchSensorObject\n")
+ }
+ break
+ case "capability.imageCapture":
+ break
+ case "device.mobilePresence":
+ break
+ case "device.aeonKeyFob":
+ break
+ case "mode":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ def userInput = System.console().readLine 'Enter the mode:'
+
+ if (modeVariables == 0) {
+ mode0 = name
+ this[mode0] = userInput
+ } else if (modeVariables == 1) {
+ mode1 = name
+ this[mode1] = userInput
+ } else if (modeVariables == 2) {
+ mode2 = name
+ this[mode2] = userInput
+ } else if (modeVariables == 3) {
+ mode3 = name
+ this[mode3] = userInput
+ } else if (modeVariables == 4) {
+ mode4 = name
+ this[mode4] = userInput
+ } else if (modeVariables == 5) {
+ mode5 = name
+ this[mode5] = userInput
+ }
+
+ modeVariables=modeVariables+1
+
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for mode!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for mode!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "decimal":
+ break
+ case "text":
+ break
+ case "number":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ def userInput = System.console().readLine 'Enter the number:'
+
+ if (numberVariables == 0) {
+ number0 = name
+ this[number0] = userInput
+ } else if (numberVariables == 1) {
+ number1 = name
+ this[number1] = userInput
+ } else if (numberVariables == 2) {
+ number2 = name
+ this[number2] = userInput
+ } else if (numberVariables == 3) {
+ number3 = name
+ this[number3] = userInput
+ } else if (numberVariables == 4) {
+ number4 = name
+ this[number4] = userInput
+ } else if (numberVariables == 5) {
+ number5 = name
+ this[number5] = userInput
+ }
+
+ numberVariables=numberVariables+1
+
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for number!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for number!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "time":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ def userInput = System.console().readLine 'Enter the time:'
+
+ if (timeVariables == 0) {
+ time0 = name
+ this[time0] = userInput
+ } else if (timeVariables == 1) {
+ time1 = name
+ this[time1] = userInput
+ } else if (timeVariables == 2) {
+ time2 = name
+ this[time2] = userInput
+ } else if (timeVariables == 3) {
+ time3 = name
+ this[time3] = userInput
+ } else if (timeVariables == 4) {
+ time4 = name
+ this[time4] = userInput
+ } else if (timeVariables == 5) {
+ time5 = name
+ this[time5] = userInput
+ }
+
+ timeVariables=timeVariables+1
+
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for time!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for time!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "enum":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ def userInput = System.console().readLine 'Enter the enum:'
+
+ if (enumVariables == 0) {
+ enum0 = name
+ this[enum0] = userInput
+ } else if (enumVariables == 1) {
+ enum1 = name
+ this[enum1] = userInput
+ } else if (enumVariables == 2) {
+ enum2 = name
+ this[enum2] = userInput
+ } else if (enumVariables == 3) {
+ enum3 = name
+ this[enum3] = userInput
+ } else if (enumVariables == 4) {
+ enum4 = name
+ this[enum4] = userInput
+ } else if (enumVariables == 5) {
+ enum5 = name
+ this[enum5] = userInput
+ }
+
+ enumVariables=enumVariables+1
+
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for enum!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for enum!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "bool":
+ break
+ case "phone":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ def userInput = System.console().readLine 'Enter the phone:'
+
+ if (phoneVariables == 0) {
+ phone0 = name
+ this[phone0] = userInput
+ } else if (phoneVariables == 1) {
+ phone1 = name
+ this[phone1] = userInput
+ } else if (phoneVariables == 2) {
+ phone2 = name
+ this[phone2] = userInput
+ } else if (phoneVariables == 3) {
+ phone3 = name
+ this[phone3] = userInput
+ } else if (phoneVariables == 4) {
+ phone4 = name
+ this[phone4] = userInput
+ } else if (phoneVariables == 5) {
+ phone5 = name
+ this[phone5] = userInput
+ }
+
+ phoneVariables=phoneVariables+1
+
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for phone!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for phone!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "contact":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ def userInput = System.console().readLine 'Enter the name of the contact:'
+
+ if (contactVariables == 0) {
+ contact0 = name
+ this[contact0] = userInput
+ } else if (contactVariables == 1) {
+ contact1 = name
+ this[contact1] = userInput
+ } else if (contactVariables == 2) {
+ contact2 = name
+ this[contact2] = userInput
+ } else if (contactVariables == 3) {
+ contact3 = name
+ this[contact3] = userInput
+ } else if (contactVariables == 4) {
+ contact4 = name
+ this[contact4] = userInput
+ } else if (contactVariables == 5) {
+ contact5 = name
+ this[contact5] = userInput
+ }
+
+ contactVariables=contactVariables+1
+
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for contact!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for contact!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ default:
+ break
+ }
+}
+//input linkedHashMap
+def input(LinkedHashMap metaData) {
+ switch(metaData['type']) {
+ case "capability.lock":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ lockObject = metaData['name']
+ this[lockObject] = new Locks({}, 1)
+ 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":
+ break
+ case "capability.battery":
+ break
+ case "capability.beacon":
+ break
+ case "capability.carbonMonoxideDetector":
+ break
+ case "capability.colorControl":
+ break
+ case "capability.contactSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ contactObject = metaData['name']
+ this[contactObject] = new ContactSensors({}, 1)
+ 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":
+ doorControlObject = metaData['name']
+ this[doorControlObject] = new DoorControls({}, 1)
+ 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":
+ break
+ case "capability.illuminanceMeasurement":
+ break
+ case "capability.accelerationSensor":
+ break
+ case "capability.motionSensor":
+ break
+ case "capability.musicPlayer":
+ break
+ case "capability.powerMeter":
+ break
+ case "capability.presenceSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ presenceSensorObject = metaData['name']
+ this[presenceSensorObject] = new PresenceSensors({}, 1)
+ 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":
+ break
+ case "capability.relaySwitch":
+ break
+ case "capability.sleepSensor":
+ break
+ case "capability.smokeDetector":
+ break
+ case "capability.stepSensor":
+ break
+ case "capability.switch":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ switchObject = metaData['name']
+ this[switchObject] = new Switches({}, 1)
+ 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":
+ break
+ case "capability.temperatureMeasurement":
+ break
+ case "capability.thermostat":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ thermostatObject = metaData['name']
+ this[thermostatObject] = new Thermostats({}, 1)
+ 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":
+ break
+ case "capability.waterSensor":
+ break
+ case "capability.touchSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ touchSensorObject = metaData['name']
+ this[touchSensorObject] = new NfcTouch({}, 1)
+ 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":
+ break
+ case "device.mobilePresence":
+ break
+ case "device.aeonKeyFob":
+ break
+ case "mode":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ def userInput = System.console().readLine 'Enter the mode:'
+
+ 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
+ }
+
+ 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":
+ break
+ case "text":
+ break
+ case "number":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ def userInput = System.console().readLine 'Enter the number:'
+
+ 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
+ }
+
+ 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":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ def userInput = System.console().readLine 'Enter the time:'
+
+ 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
+ }
+
+ 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.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ def userInput = System.console().readLine 'Enter the enum:'
+
+ 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
+ }
+
+ 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":
+ break
+ case "phone":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ def userInput = System.console().readLine 'Enter the phone:'
+
+ 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
+ }
+
+ 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":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ def userInput = System.console().readLine 'Enter the metaData['name'] of the contact:'
+
+ 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
+ }
+
+ 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//")
+}
+/////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
+}
+
+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 section(String title, Closure inputData) {
+ println(title)
+ find(inputData) //Run the closure to extract inputMethods
+}
+
+def section(LinkedHashMap metaData, Closure inputData) {
+ find(inputData) //Run the closure to extract inputMethods
+}
+/////MethodsForExtraction/////
+
if not c:
return "EOF"
-def ExtractMethods(F, inputMethodsFile, appName):
+def ExtractFunctions(F, appName):
Temp = GetToken(F)
- inputMethod = ""
while (Temp != "EOF"):
- #Extract the input methods
- if (Temp == "input"):
- inputMethod += Temp
- Temp = GetToken(F) #",(,input
- #input "","",linkedHashMap
- if (Temp == "\""):
- while (Temp!="input" and Temp!="}"):
- inputMethod += Temp
- Temp = GetToken(F)
- inputMethod += ",\""+appName+"\""
- #input ()
- elif (Temp == "("):
- while (Temp!=")"):
- inputMethod += Temp
- Temp = GetToken(F)
- inputMethod += ",\""+appName+"\")"
- #input linkedHashMap
- elif (Temp == "input"):
- while (Temp!="input" and Temp!="}"):
- inputMethod += Temp
- Temp = GetToken(F)
- inputMethod += ",\""+appName+"\""
- elif (Temp == "def"):
+ if (Temp == "def" or Temp == "private"):
Temp = GetToken(F)
NameofFunc = Temp
if (GetToken(F) != "="): #We have a function to create object for
extractedFunctionsApp2.write("//Global Object for functions in subscribe method!\n")
extractedFunctionsApp2.write("def %s = this.&" % NameofFunc)
extractedFunctionsApp2.write("%s\n" % NameofFunc)
- if (Temp!="input"):
- Temp=GetToken(F)
- if (inputMethod != ""):
- inputMethodsFile.write(inputMethod+"\n")
- inputMethod = ""
+ Temp = GetToken(F)
-#Extract the methods from App1 and store in inputMethodsFile
+#Extract objects to call functions from App1
F1 = open("Extractor/App1/App1.groovy", "r")
-inputMethodsFile1 = open("Extractor/App1/inputMethodsFile1.groovy", "w+")
extractedFunctionsApp1 = open("Extractor/App1/extractedFunctionsApp1.groovy", "w+")
-ExtractMethods(F1, inputMethodsFile1, "App1")
-inputMethodsFile1.close()
+ExtractFunctions(F1, "App1")
F1.close()
-#Extract the methods from App2 and store in inputMethodsFile
+#Extract objects to call functions from App2
F2 = open("Extractor/App2/App2.groovy", "r")
-inputMethodsFile2 = open("Extractor/App2/inputMethodsFile2.groovy", "w+")
extractedFunctionsApp2 = open("Extractor/App2/extractedFunctionsApp2.groovy", "w+")
-ExtractMethods(F2, inputMethodsFile2, "App2")
-inputMethodsFile2.close()
+ExtractFunctions(F2, "App2")
F2.close()
-#Save the extracted methods and methods functions in a same file
+#Save the extracted methods and app1 in a same file to extract information
extractorFile = open("Extractor/extractorFile.groovy", "w+")
-inputMethodsFile1 = open("Extractor/App1/inputMethodsFile1.groovy", "r")
-inputMethodsFile2 = open("Extractor/App2/inputMethodsFile2.groovy", "r")
-inputMethods = open("Extractor/inputMethods.groovy", "r")
-for line in inputMethods:
+Extractor = open("Extractor/Extractor.groovy", "r")
+F1 = open("Extractor/App1/App1.groovy", "r")
+
+extractorFile.write("////////////////////")
+extractorFile.write("@Field App\n")
+extractorFile.write("App = \"App1\"")
+extractorFile.write("\n")
+for line in Extractor:
extractorFile.write(line)
extractorFile.write("\n\n")
-for line in inputMethodsFile1:
- extractorFile.write(line)
-for line in inputMethodsFile2:
+for line in F1:
extractorFile.write(line)
extractorFile.close()
-inputMethodsFile1.close()
-inputMethodsFile2.close()
-inputMethods.close()
+Extractor.close()
+F1.close()
+#Run the file to extract the objects
+os.system("groovy Extractor/extractorFile.groovy")
+
+#Save the extracted methods and app2 in a same file to extract information
+extractorFile = open("Extractor/extractorFile.groovy", "w+")
+Extractor = open("Extractor/Extractor.groovy", "r")
+F2 = open("Extractor/App2/App2.groovy", "r")
+extractorFile.write("////////////////////")
+extractorFile.write("@Field App\n")
+extractorFile.write("App = \"App2\"")
+extractorFile.write("\n")
+for line in Extractor:
+ extractorFile.write(line)
+extractorFile.write("\n\n")
+for line in F2:
+ extractorFile.write(line)
#Run the file to extract the objects
+extractorFile.close()
+Extractor.close()
+F2.close()
os.system("groovy Extractor/extractorFile.groovy")
+
+
+
+
+////////////////////@Field App
+App = "App2"
////////////////////////////////////////
+//import libraries
import groovy.transform.Field
-@Field File outGlobal = new File("Extractor/outGlobal.groovy")
+
+
+//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 Timer.SimulatedTimer
+
+
+@Field App //Default
+
+
+//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
-outGlobal.write("")
-extractedObjectsApp1.write("")
-extractedObjectsApp2.write("")
-extractedObjectsConstructorApp1.write("")
-extractedObjectsConstructorApp2.write("")
+if (App == "App1") {
+ extractedObjectsApp1.write("")
+ extractedObjectsConstructorApp1.write("")
+} else if (App == "App2") {
+ extractedObjectsApp2.write("")
+ extractedObjectsConstructorApp2.write("")
+}
+
+
+
+
+
+//Global objects
+//Global Object for class Touch Sensor!
+@Field def touchSensorObject
+//Global Object for class switch!
+@Field def switchObject
+//Global Object for class lock!
+@Field def lockObject
+//Global Object for class door control!
+@Field def doorControlObject
+//Global Object for class contact sensor!
+@Field def contactObject
+//Global Object for class presence sensor!
+@Field def presenceSensorObject
+//Global Object for class thermostat!
+@Field def thermostatObject
+
+//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 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
-@Field lockIsSet = 0
-@Field contactIsSet = 0
-@Field switchIsSet = 0
+
+/////Input Methods/////
//input "",""
-def input(String name, String type, String App) {
+def input(String name, String type) {
switch(type) {
case "capability.lock":
- if (lockIsSet != 1) {
- lockIsSet = 1
- outGlobal.append("//Global Object for class lock!\n")
- outGlobal.append("@Field def lockObject = new Locking(sendEvent,1)\n")
- }
+ lockObject = name
+ this[lockObject] = new Locks({}, 1)
if (App == "App1") {
extractedObjectsApp1.append("//Object for class lock!\n")
extractedObjectsApp1.append("def "+name+"\n")
case "capability.colorControl":
break
case "capability.contactSensor":
- if (contactIsSet != 1) {
- contactIsSet = 1
- outGlobal.append("//Global Object for class contactSensor!\n")
- outGlobal.append("@Field def contactObject = new Contacting(sendEvent,1)\n")
- }
+ contactObject = name
+ this[contactObject] = new ContactSensors({}, 1)
if (App == "App1") {
extractedObjectsApp1.append("//Object for class contactSensor!\n")
extractedObjectsApp1.append("def "+name+"\n")
}
break
case "capability.doorControl":
+ doorControlObject = name
+ this[doorControlObject] = new DoorControls({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class door control!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.doorControlObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class door control!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.doorControlObject\n")
+ }
break
case "capability.energyMeter":
break
case "capability.powerMeter":
break
case "capability.presenceSensor":
+ presenceSensorObject = name
+ this[presenceSensorObject] = new PresenceSensors({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class presence sensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.presenceSensorObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class presence sensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.presenceSensorObject\n")
+ }
break
case "capability.relativeHumidityMeasurement":
break
case "capability.stepSensor":
break
case "capability.switch":
- if (switchIsSet != 1) {
- switchIsSet = 1
- outGlobal.append("//Global Object for class switch!\n")
- outGlobal.append("@Field def switchObject = new Switching(sendEvent,1)\n")
- }
+ switchObject = name
+ this[switchObject] = new Switches({}, 1)
if (App == "App1") {
extractedObjectsApp1.append("//Object for class switch!\n")
extractedObjectsApp1.append("def "+name+"\n")
case "capability.temperatureMeasurement":
break
case "capability.thermostat":
+ thermostatObject = name
+ this[thermostatObject] = new Thermostats({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class thermostat!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.thermostatObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class thermostat!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.thermostatObject\n")
+ }
break
case "capability.valve":
break
case "capability.waterSensor":
break
case "capability.touchSensor":
+ touchSensorObject = name
+ this[touchSensorObject] = new NfcTouch({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class Touch Sensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.touchSensorObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class Touch Sensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.touchSensorObject\n")
+ }
break
case "capability.imageCapture":
break
break
case "mode":
def userInput = System.console().readLine 'Enter the mode:'
+
+ if (modeVariables == 0) {
+ mode0 = name
+ this[mode0] = userInput
+ } else if (modeVariables == 1) {
+ mode1 = name
+ this[mode1] = userInput
+ } else if (modeVariables == 2) {
+ mode2 = name
+ this[mode2] = userInput
+ } else if (modeVariables == 3) {
+ mode3 = name
+ this[mode3] = userInput
+ } else if (modeVariables == 4) {
+ mode4 = name
+ this[mode4] = userInput
+ } else if (modeVariables == 5) {
+ mode5 = name
+ this[mode5] = userInput
+ }
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for mode!\n")
extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
break
case "number":
def userInput = System.console().readLine 'Enter the number:'
+
+ if (numberVariables == 0) {
+ number0 = name
+ this[number0] = userInput
+ } else if (numberVariables == 1) {
+ number1 = name
+ this[number1] = userInput
+ } else if (numberVariables == 2) {
+ number2 = name
+ this[number2] = userInput
+ } else if (numberVariables == 3) {
+ number3 = name
+ this[number3] = userInput
+ } else if (numberVariables == 4) {
+ number4 = name
+ this[number4] = userInput
+ } else if (numberVariables == 5) {
+ number5 = name
+ this[number5] = userInput
+ }
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for number!\n")
extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
break
case "time":
def userInput = System.console().readLine 'Enter the time:'
+
+ if (timeVariables == 0) {
+ time0 = name
+ this[time0] = userInput
+ } else if (timeVariables == 1) {
+ time1 = name
+ this[time1] = userInput
+ } else if (timeVariables == 2) {
+ time2 = name
+ this[time2] = userInput
+ } else if (timeVariables == 3) {
+ time3 = name
+ this[time3] = userInput
+ } else if (timeVariables == 4) {
+ time4 = name
+ this[time4] = userInput
+ } else if (timeVariables == 5) {
+ time5 = name
+ this[time5] = userInput
+ }
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for time!\n")
extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
break
case "enum":
def userInput = System.console().readLine 'Enter the enum:'
+
+ if (enumVariables == 0) {
+ enum0 = name
+ this[enum0] = userInput
+ } else if (enumVariables == 1) {
+ enum1 = name
+ this[enum1] = userInput
+ } else if (enumVariables == 2) {
+ enum2 = name
+ this[enum2] = userInput
+ } else if (enumVariables == 3) {
+ enum3 = name
+ this[enum3] = userInput
+ } else if (enumVariables == 4) {
+ enum4 = name
+ this[enum4] = userInput
+ } else if (enumVariables == 5) {
+ enum5 = name
+ this[enum5] = userInput
+ }
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for enum!\n")
extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
break
case "phone":
def userInput = System.console().readLine 'Enter the phone:'
+
+ if (phoneVariables == 0) {
+ phone0 = name
+ this[phone0] = userInput
+ } else if (phoneVariables == 1) {
+ phone1 = name
+ this[phone1] = userInput
+ } else if (phoneVariables == 2) {
+ phone2 = name
+ this[phone2] = userInput
+ } else if (phoneVariables == 3) {
+ phone3 = name
+ this[phone3] = userInput
+ } else if (phoneVariables == 4) {
+ phone4 = name
+ this[phone4] = userInput
+ } else if (phoneVariables == 5) {
+ phone5 = name
+ this[phone5] = userInput
+ }
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for phone!\n")
extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
break
case "contact":
def userInput = System.console().readLine 'Enter the name of the contact:'
+
+ if (contactVariables == 0) {
+ contact0 = name
+ this[contact0] = userInput
+ } else if (contactVariables == 1) {
+ contact1 = name
+ this[contact1] = userInput
+ } else if (contactVariables == 2) {
+ contact2 = name
+ this[contact2] = userInput
+ } else if (contactVariables == 3) {
+ contact3 = name
+ this[contact3] = userInput
+ } else if (contactVariables == 4) {
+ contact4 = name
+ this[contact4] = userInput
+ } else if (contactVariables == 5) {
+ contact5 = name
+ this[contact5] = userInput
+ }
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for contact!\n")
extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
}
//input "","",linkedHashMap
-def input(LinkedHashMap metaData, String name, String type, String App) {
+def input(LinkedHashMap metaData, String name, String type) {
switch(type) {
case "capability.lock":
if (metaData.containsKey('title')) {
println metaData['title']
}
- if (metaData.containsKey('multiple')) {
- if (metaData['multiple'] == true) {
- if (lockIsSet != 1) {
- lockIsSet = 1
- def count = System.console().readLine 'Enter the number of locks to control?(1,2, or 3)'
- outGlobal.append("//Global Object for class lock!\n")
- outGlobal.append("@Field def lockObject = new Locking(sendEvent, ")
- outGlobal.append(count+")\n")
- }
- }
- }
- if (lockIsSet != 1) {
- lockIsSet = 1
- outGlobal.append("//Global Object for class lock!\n")
- outGlobal.append("@Field def lockObject = new Locking(sendEvent,1)\n")
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
}
+ lockObject = name
+ this[lockObject] = new Locks({}, 1)
if (App == "App1") {
extractedObjectsApp1.append("//Object for class lock!\n")
extractedObjectsApp1.append("def "+name+"\n")
if (metaData.containsKey('title')) {
println metaData['title']
}
- if (metaData.containsKey('multiple')) {
- if (metaData['multiple'] == true) {
- if (contactIsSet != 1) {
- contactIsSet = 1
- def count = System.console().readLine 'Enter the number of contact sensors to control?(1,2, or 3)'
- outGlobal.append("//Global Object for class contactSensor!\n")
- outGlobal.append("@Field def contactObject = new Contacting(sendEvent, ")
- outGlobal.append(count+")\n")
- }
- }
- }
- if (contactIsSet != 1) {
- contactIsSet = 1
- outGlobal.append("//Global Object for class contactSensor!\n")
- outGlobal.append("@Field def contactObject = new Contacting(sendEvent,1)\n")
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
}
+ contactObject = name
+ this[contactObject] = new ContactSensors({}, 1)
if (App == "App1") {
extractedObjectsApp1.append("//Object for class contactSensor!\n")
extractedObjectsApp1.append("def "+name+"\n")
}
break
case "capability.doorControl":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ doorControlObject = name
+ this[doorControlObject] = new DoorControls({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class door control!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.doorControlObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class door control!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.doorControlObject\n")
+ }
break
case "capability.energyMeter":
break
case "capability.powerMeter":
break
case "capability.presenceSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ presenceSensorObject = name
+ this[presenceSensorObject] = new PresenceSensors({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class presence sensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.presenceSensorObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class presence sensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.presenceSensorObject\n")
+ }
break
case "capability.relativeHumidityMeasurement":
break
if (metaData.containsKey('title')) {
println metaData['title']
}
- if (metaData.containsKey('multiple')) {
- if (metaData['multiple'] == true) {
- if (switchIsSet != 1) {
- switchIsSet = 1
- def count = System.console().readLine 'Enter the number of switches to control?(1,2, or 3)'
- outGlobal.append("//Global Object for class switch!\n")
- outGlobal.append("@Field def switchObject = new Switching(sendEvent, ")
- outGlobal.append(count+")\n")
- }
- }
- }
- if (switchIsSet != 1) {
- switchIsSet = 1
- outGlobal.append("//Global Object for class switch!\n")
- outGlobal.append("@Field def switchObject = new Switching(sendEvent,1)\n")
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
}
+ switchObject = name
+ this[switchObject] = new Switches({}, 1)
if (App == "App1") {
extractedObjectsApp1.append("//Object for class switch!\n")
extractedObjectsApp1.append("def "+name+"\n")
case "capability.temperatureMeasurement":
break
case "capability.thermostat":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ thermostatObject = name
+ this[thermostatObject] = new Thermostats({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class thermostat!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.thermostatObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class thermostat!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.thermostatObject\n")
+ }
break
case "capability.valve":
break
case "capability.waterSensor":
break
case "capability.touchSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ touchSensorObject = name
+ this[touchSensorObject] = new NfcTouch({}, 1)
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class Touch Sensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.touchSensorObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class Touch Sensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.touchSensorObject\n")
+ }
break
case "capability.imageCapture":
break
println "Options: "+metaData['options']
}
def userInput = System.console().readLine 'Enter the mode:'
+
+ if (modeVariables == 0) {
+ mode0 = name
+ this[mode0] = userInput
+ } else if (modeVariables == 1) {
+ mode1 = name
+ this[mode1] = userInput
+ } else if (modeVariables == 2) {
+ mode2 = name
+ this[mode2] = userInput
+ } else if (modeVariables == 3) {
+ mode3 = name
+ this[mode3] = userInput
+ } else if (modeVariables == 4) {
+ mode4 = name
+ this[mode4] = userInput
+ } else if (modeVariables == 5) {
+ mode5 = name
+ this[mode5] = userInput
+ }
+
+ modeVariables=modeVariables+1
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for mode!\n")
extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
if (metaData.containsKey('options')) {
println "Options: "+metaData['options']
}
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
def userInput = System.console().readLine 'Enter the number:'
+
+ if (numberVariables == 0) {
+ number0 = name
+ this[number0] = userInput
+ } else if (numberVariables == 1) {
+ number1 = name
+ this[number1] = userInput
+ } else if (numberVariables == 2) {
+ number2 = name
+ this[number2] = userInput
+ } else if (numberVariables == 3) {
+ number3 = name
+ this[number3] = userInput
+ } else if (numberVariables == 4) {
+ number4 = name
+ this[number4] = userInput
+ } else if (numberVariables == 5) {
+ number5 = name
+ this[number5] = userInput
+ }
+
+ numberVariables=numberVariables+1
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for number!\n")
extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
if (metaData.containsKey('options')) {
println "Options: "+metaData['options']
}
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
def userInput = System.console().readLine 'Enter the time:'
+
+ if (timeVariables == 0) {
+ time0 = name
+ this[time0] = userInput
+ } else if (timeVariables == 1) {
+ time1 = name
+ this[time1] = userInput
+ } else if (timeVariables == 2) {
+ time2 = name
+ this[time2] = userInput
+ } else if (timeVariables == 3) {
+ time3 = name
+ this[time3] = userInput
+ } else if (timeVariables == 4) {
+ time4 = name
+ this[time4] = userInput
+ } else if (timeVariables == 5) {
+ time5 = name
+ this[time5] = userInput
+ }
+
+ timeVariables=timeVariables+1
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for time!\n")
extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
if (metaData.containsKey('options')) {
println "Options: "+metaData['options']
}
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
def userInput = System.console().readLine 'Enter the enum:'
+
+ if (enumVariables == 0) {
+ enum0 = name
+ this[enum0] = userInput
+ } else if (enumVariables == 1) {
+ enum1 = name
+ this[enum1] = userInput
+ } else if (enumVariables == 2) {
+ enum2 = name
+ this[enum2] = userInput
+ } else if (enumVariables == 3) {
+ enum3 = name
+ this[enum3] = userInput
+ } else if (enumVariables == 4) {
+ enum4 = name
+ this[enum4] = userInput
+ } else if (enumVariables == 5) {
+ enum5 = name
+ this[enum5] = userInput
+ }
+
+ enumVariables=enumVariables+1
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for enum!\n")
extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
if (metaData.containsKey('options')) {
println "Options: "+metaData['options']
}
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
def userInput = System.console().readLine 'Enter the phone:'
+
+ if (phoneVariables == 0) {
+ phone0 = name
+ this[phone0] = userInput
+ } else if (phoneVariables == 1) {
+ phone1 = name
+ this[phone1] = userInput
+ } else if (phoneVariables == 2) {
+ phone2 = name
+ this[phone2] = userInput
+ } else if (phoneVariables == 3) {
+ phone3 = name
+ this[phone3] = userInput
+ } else if (phoneVariables == 4) {
+ phone4 = name
+ this[phone4] = userInput
+ } else if (phoneVariables == 5) {
+ phone5 = name
+ this[phone5] = userInput
+ }
+
+ phoneVariables=phoneVariables+1
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for phone!\n")
extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
if (metaData.containsKey('options')) {
println "Options: "+metaData['options']
}
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
def userInput = System.console().readLine 'Enter the name of the contact:'
+
+ if (contactVariables == 0) {
+ contact0 = name
+ this[contact0] = userInput
+ } else if (contactVariables == 1) {
+ contact1 = name
+ this[contact1] = userInput
+ } else if (contactVariables == 2) {
+ contact2 = name
+ this[contact2] = userInput
+ } else if (contactVariables == 3) {
+ contact3 = name
+ this[contact3] = userInput
+ } else if (contactVariables == 4) {
+ contact4 = name
+ this[contact4] = userInput
+ } else if (contactVariables == 5) {
+ contact5 = name
+ this[contact5] = userInput
+ }
+
+ contactVariables=contactVariables+1
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for contact!\n")
extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
}
}
//input linkedHashMap
-def input(LinkedHashMap metaData, String App) {
+def input(LinkedHashMap metaData) {
switch(metaData['type']) {
case "capability.lock":
if (metaData.containsKey('title')) {
println metaData['title']
}
- if (metaData.containsKey('multiple')) {
- if (metaData['multiple'] == true) {
- if (lockIsSet != 1) {
- lockIsSet = 1
- def count = System.console().readLine 'Enter the number of locks to control?(1,2, or 3)'
- outGlobal.append("//Global Object for class lock!\n")
- outGlobal.append("@Field def lockObject = new Locking(sendEvent, ")
- outGlobal.append(count+")\n")
- }
- }
- }
- if (lockIsSet != 1) {
- lockIsSet = 1
- outGlobal.append("//Global Object for class lock!\n")
- outGlobal.append("@Field def lockObject = new Locking(sendEvent,1)\n")
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
}
+ lockObject = metaData['name']
+ this[lockObject] = new Locks({}, 1)
if (App == "App1") {
extractedObjectsApp1.append("//Object for class lock!\n")
- extractedObjectsApp1.append("def "+metaData['input']+"\n")
- extractedObjectsConstructorApp1.append(metaData['input']+" = obj.lockObject\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['input']+"\n")
- extractedObjectsConstructorApp2.append(metaData['input']+" = obj.lockObject\n")
+ extractedObjectsApp2.append("def "+metaData['name']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['name']+" = obj.lockObject\n")
}
break
case "capability.alarm":
if (metaData.containsKey('title')) {
println metaData['title']
}
- if (metaData.containsKey('multiple')) {
- if (metaData['multiple'] == true) {
- if (contactIsSet != 1) {
- contactIsSet = 1
- def count = System.console().readLine 'Enter the number of contact sensors to control?(1,2, or 3)'
- outGlobal.append("//Global Object for class contactSensor!\n")
- outGlobal.append("@Field def contactObject = new Contacting(sendEvent, ")
- outGlobal.append(count+")\n")
- }
- }
- }
- if (contactIsSet != 1) {
- contactIsSet = 1
- outGlobal.append("//Global Object for class contactSensor!\n")
- outGlobal.append("@Field def contactObject = new Contacting(sendEvent,1)\n")
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
}
+ contactObject = metaData['name']
+ this[contactObject] = new ContactSensors({}, 1)
if (App == "App1") {
extractedObjectsApp1.append("//Object for class contactSensor!\n")
- extractedObjectsApp1.append("def "+metaData['input']+"\n")
- extractedObjectsConstructorApp1.append(metaData['input']+" = obj.contactObject\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['input']+"\n")
- extractedObjectsConstructorApp2.append(metaData['input']+" = obj.contactObject\n")
+ extractedObjectsApp2.append("def "+metaData['name']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['name']+" = obj.contactObject\n")
}
break
case "capability.doorControl":
+ doorControlObject = metaData['name']
+ this[doorControlObject] = new DoorControls({}, 1)
+ 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":
break
case "capability.powerMeter":
break
case "capability.presenceSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ presenceSensorObject = metaData['name']
+ this[presenceSensorObject] = new PresenceSensors({}, 1)
+ 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":
break
if (metaData.containsKey('title')) {
println metaData['title']
}
- if (metaData.containsKey('multiple')) {
- if (metaData['multiple'] == true) {
- if (switchIsSet != 1) {
- switchIsSet = 1
- def count = System.console().readLine 'Enter the number of switches to control?(1,2, or 3)'
- outGlobal.append("//Global Object for class switch!\n")
- outGlobal.append("@Field def switchObject = new Switching(sendEvent, ")
- outGlobal.append(count+")\n")
- }
- }
- }
- if (switchIsSet != 1) {
- switchIsSet = 1
- outGlobal.append("//Global Object for class switch!\n")
- outGlobal.append("@Field def switchObject = new Switching(sendEvent,1)\n")
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
}
+ switchObject = metaData['name']
+ this[switchObject] = new Switches({}, 1)
if (App == "App1") {
extractedObjectsApp1.append("//Object for class switch!\n")
- extractedObjectsApp1.append("def "+metaData['input']+"\n")
- extractedObjectsConstructorApp1.append(metaData['input']+" = obj.switchObject\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['input']+"\n")
- extractedObjectsConstructorApp2.append(metaData['input']+" = obj.switchObject\n")
+ extractedObjectsApp2.append("def "+metaData['name']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['name']+" = obj.switchObject\n")
}
break
case "capability.switchLevel":
break
case "capability.temperatureMeasurement":
- break
+ break
case "capability.thermostat":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ thermostatObject = metaData['name']
+ this[thermostatObject] = new Thermostats({}, 1)
+ 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":
break
case "capability.waterSensor":
break
case "capability.touchSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ touchSensorObject = metaData['name']
+ this[touchSensorObject] = new NfcTouch({}, 1)
+ 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":
break
if (metaData.containsKey('options')) {
println "Options: "+metaData['options']
}
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
def userInput = System.console().readLine 'Enter the mode:'
+
+ 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
+ }
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for mode!\n")
- extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
} else {
extractedObjectsApp2.append("//Global variable for mode!\n")
- extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
}
break
case "decimal":
if (metaData.containsKey('options')) {
println "Options: "+metaData['options']
}
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
def userInput = System.console().readLine 'Enter the number:'
+
+ 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
+ }
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for number!\n")
- extractedObjectsApp1.append("def "+metaData['input']+" = "+userInput+"\n")
+ extractedObjectsApp1.append("def "+metaData['name']+" = "+userInput+"\n")
} else {
extractedObjectsApp2.append("//Global variable for number!\n")
- extractedObjectsApp2.append("def "+metaData['input']+" = "+userInput+"\n")
+ extractedObjectsApp2.append("def "+metaData['name']+" = "+userInput+"\n")
}
break
case "time":
if (metaData.containsKey('options')) {
println "Options: "+metaData['options']
}
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
def userInput = System.console().readLine 'Enter the time:'
+
+ 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
+ }
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for time!\n")
- extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
} else {
extractedObjectsApp2.append("//Global variable for time!\n")
- extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
}
break
case "enum":
if (metaData.containsKey('options')) {
println "Options: "+metaData['options']
}
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
def userInput = System.console().readLine 'Enter the enum:'
+
+ 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
+ }
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for enum!\n")
- extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
} else {
extractedObjectsApp2.append("//Global variable for enum!\n")
- extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
}
break
case "bool":
if (metaData.containsKey('options')) {
println "Options: "+metaData['options']
}
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
def userInput = System.console().readLine 'Enter the phone:'
+
+ 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
+ }
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for phone!\n")
- extractedObjectsApp1.append("def "+metaData['input']+" = "+userInput+"\n")
+ extractedObjectsApp1.append("def "+metaData['name']+" = "+userInput+"\n")
} else {
extractedObjectsApp2.append("//Global variable for phone!\n")
- extractedObjectsApp2.append("def "+metaData['input']+" = "+userInput+"\n")
+ extractedObjectsApp2.append("def "+metaData['name']+" = "+userInput+"\n")
}
break
case "contact":
if (metaData.containsKey('options')) {
println "Options: "+metaData['options']
}
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
+ def userInput = System.console().readLine 'Enter the metaData['name'] of the contact:'
+
+ 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
}
- def userInput = System.console().readLine 'Enter the name of the contact:'
+
if (App == "App1") {
extractedObjectsApp1.append("//Global variable for contact!\n")
- extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
} else {
extractedObjectsApp2.append("//Global variable for contact!\n")
- extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\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//")
+}
+/////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
+}
-input"lock1","capability.lock",required:true,"App1"
-input"contact","capability.contactSensor",required:true,"App1"
-input"minutesLater","number",title:"Delay(inminutes):",required:true,"App1"
-input"secondsLater","number",title:"Delay(inseconds):",required:true,"App1"
-input("recipients","contact",title:"Sendnotificationsto",required:false,"App1")
-input"phoneNumber","phone",title:"Warnwithtextmessage(optional)",description:"PhoneNumber",required:false,"App1"
-input"switchesoff","capability.switch",multiple:true,required:true,"App2"
-input"switcheson","capability.switch",multiple:true,required:false,"App2"
-input"lock1","capability.lock",multiple:true,"App2"
-input"newMode","mode",title:"Mode?","App2"
-input"waitfor","number",title:"Offafter(default120)",required:true,"App2"
+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 section(String title, Closure inputData) {
+ println(title)
+ find(inputData) //Run the closure to extract inputMethods
+}
+
+def section(LinkedHashMap metaData, Closure inputData) {
+ find(inputData) //Run the closure to extract inputMethods
+}
+/////MethodsForExtraction/////
+
+
+
+/////
+definition(
+ name: "Good Night House",
+ namespace: "charette.joseph@gmail.com",
+ author: "Joseph Charette",
+ description: "Some on, some off with delay for bedtime, Lock The Doors",
+ category: "Convenience",
+ iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
+ iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png"
+/**
+* Borrowed code from
+* Walk Gentle Into That Good Night
+*
+* Author: oneaccttorulethehouse@gmail.com
+* Date: 2014-02-01
+ */
+ )
+preferences {
+ section("When I touch the app turn these lights off…"){
+ input "switchesoff", "capability.switch", multiple: true, required:true
+ }
+ section("When I touch the app turn these lights on…"){
+ input "switcheson", "capability.switch", multiple: true, required:false
+ }
+ section("Lock theses locks...") {
+ input "lock1","capability.lock", multiple: true
+ }
+ section("And change to this mode...") {
+ input "newMode", "mode", title: "Mode?"
+ }
+ section("After so many seconds (optional)"){
+ input "waitfor", "number", title: "Off after (default 120)", required: true
+ }
+}
+
+
+def installed()
+{
+ log.debug "Installed with settings: ${settings}"
+ log.debug "Current mode = ${location.mode}"
+ subscribe(app, appTouch)
+}
+
+
+def updated()
+{
+ log.debug "Updated with settings: ${settings}"
+ log.debug "Current mode = ${location.mode}"
+ unsubscribe()
+ subscribe(app, appTouch)
+}
+
+def appTouch(evt) {
+ log.debug "changeMode, location.mode = $location.mode, newMode = $newMode, location.modes = $location.modes"
+ if (location.mode != newMode) {
+ setLocationMode(newMode)
+ log.debug "Changed the mode to '${newMode}'"
+ } else {
+ log.debug "New mode is the same as the old mode, leaving it be"
+ }
+ log.debug "appTouch: $evt"
+ lock1.lock()
+ switcheson.on()
+ def delay = (waitfor != null && waitfor != "") ? waitfor * 1000 : 120000
+ switchesoff.off(delay: delay)
+}
+++ /dev/null
-////////////////////////////////////////
-import groovy.transform.Field
-@Field File outGlobal = new File("Extractor/outGlobal.groovy")
-@Field File extractedObjectsApp1 = new File("Extractor/App1/extractedObjectsApp1.groovy")
-@Field File extractedObjectsApp2 = new File("Extractor/App2/extractedObjectsApp2.groovy")
-@Field File extractedObjectsConstructorApp1 = new File("Extractor/App1/extractedObjectsConstructorApp1.groovy")
-@Field File extractedObjectsConstructorApp2 = new File("Extractor/App2/extractedObjectsConstructorApp2.groovy")
-
-//Empty the files
-outGlobal.write("")
-extractedObjectsApp1.write("")
-extractedObjectsApp2.write("")
-extractedObjectsConstructorApp1.write("")
-extractedObjectsConstructorApp2.write("")
-
-
-@Field lockIsSet = 0
-@Field contactIsSet = 0
-@Field switchIsSet = 0
-
-//input "",""
-def input(String name, String type, String App) {
- switch(type) {
- case "capability.lock":
- if (lockIsSet != 1) {
- lockIsSet = 1
- outGlobal.append("//Global Object for class lock!\n")
- outGlobal.append("@Field def lockObject = new Locking(sendEvent,1)\n")
- }
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class lock!\n")
- extractedObjectsApp1.append("def "+name+"\n")
- extractedObjectsConstructorApp1.append(name+" = obj.lockObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class lock!\n")
- extractedObjectsApp2.append("def "+name+"\n")
- extractedObjectsConstructorApp2.append(name+" = obj.lockObject\n")
- }
- break
- case "capability.alarm":
- break
- case "capability.battery":
- break
- case "capability.beacon":
- break
- case "capability.carbonMonoxideDetector":
- break
- case "capability.colorControl":
- break
- case "capability.contactSensor":
- if (contactIsSet != 1) {
- contactIsSet = 1
- outGlobal.append("//Global Object for class contactSensor!\n")
- outGlobal.append("@Field def contactObject = new Contacting(sendEvent,1)\n")
- }
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class contactSensor!\n")
- extractedObjectsApp1.append("def "+name+"\n")
- extractedObjectsConstructorApp1.append(name+" = obj.contactObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class contactSensor!\n")
- extractedObjectsApp2.append("def "+name+"\n")
- extractedObjectsConstructorApp2.append(name+" = obj.contactObject\n")
- }
- break
- case "capability.doorControl":
- break
- case "capability.energyMeter":
- break
- case "capability.illuminanceMeasurement":
- break
- case "capability.accelerationSensor":
- break
- case "capability.motionSensor":
- break
- case "capability.musicPlayer":
- break
- case "capability.powerMeter":
- break
- case "capability.presenceSensor":
- break
- case "capability.relativeHumidityMeasurement":
- break
- case "capability.relaySwitch":
- break
- case "capability.sleepSensor":
- break
- case "capability.smokeDetector":
- break
- case "capability.stepSensor":
- break
- case "capability.switch":
- if (switchIsSet != 1) {
- switchIsSet = 1
- outGlobal.append("//Global Object for class switch!\n")
- outGlobal.append("@Field def switchObject = new Switching(sendEvent,1)\n")
- }
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class switch!\n")
- extractedObjectsApp1.append("def "+name+"\n")
- extractedObjectsConstructorApp1.append(name+" = obj.switchObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class switch!\n")
- extractedObjectsApp2.append("def "+name+"\n")
- extractedObjectsConstructorApp2.append(name+" = obj.switchObject\n")
- }
- break
- case "capability.switchLevel":
- break
- case "capability.temperatureMeasurement":
- break
- case "capability.thermostat":
- break
- case "capability.valve":
- break
- case "capability.waterSensor":
- break
- case "capability.touchSensor":
- break
- case "capability.imageCapture":
- break
- case "device.mobilePresence":
- break
- case "device.aeonKeyFob":
- break
- case "mode":
- def userInput = System.console().readLine 'Enter the mode:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for mode!\n")
- extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for mode!\n")
- extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
- }
- break
- case "decimal":
- break
- case "text":
- break
- case "number":
- def userInput = System.console().readLine 'Enter the number:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for number!\n")
- extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for number!\n")
- extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
- }
- break
- case "time":
- def userInput = System.console().readLine 'Enter the time:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for time!\n")
- extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for time!\n")
- extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
- }
- break
- case "enum":
- def userInput = System.console().readLine 'Enter the enum:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for enum!\n")
- extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for enum!\n")
- extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
- }
- break
- case "bool":
- break
- case "phone":
- def userInput = System.console().readLine 'Enter the phone:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for phone!\n")
- extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for phone!\n")
- extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
- }
- break
- case "contact":
- def userInput = System.console().readLine 'Enter the name of the contact:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for contact!\n")
- extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for contact!\n")
- extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
- }
- break
- default:
- break
- }
-}
-
-//input "","",linkedHashMap
-def input(LinkedHashMap metaData, String name, String type, String App) {
- switch(type) {
- case "capability.lock":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('multiple')) {
- if (metaData['multiple'] == true) {
- if (lockIsSet != 1) {
- lockIsSet = 1
- def count = System.console().readLine 'Enter the number of locks to control?(1,2, or 3)'
- outGlobal.append("//Global Object for class lock!\n")
- outGlobal.append("@Field def lockObject = new Locking(sendEvent, ")
- outGlobal.append(count+")\n")
- }
- }
- }
- if (lockIsSet != 1) {
- lockIsSet = 1
- outGlobal.append("//Global Object for class lock!\n")
- outGlobal.append("@Field def lockObject = new Locking(sendEvent,1)\n")
- }
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class lock!\n")
- extractedObjectsApp1.append("def "+name+"\n")
- extractedObjectsConstructorApp1.append(name+" = obj.lockObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class lock!\n")
- extractedObjectsApp2.append("def "+name+"\n")
- extractedObjectsConstructorApp2.append(name+" = obj.lockObject\n")
- }
- break
- case "capability.alarm":
- break
- case "capability.battery":
- break
- case "capability.beacon":
- break
- case "capability.carbonMonoxideDetector":
- break
- case "capability.colorControl":
- break
- case "capability.contactSensor":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('multiple')) {
- if (metaData['multiple'] == true) {
- if (contactIsSet != 1) {
- contactIsSet = 1
- def count = System.console().readLine 'Enter the number of contact sensors to control?(1,2, or 3)'
- outGlobal.append("//Global Object for class contactSensor!\n")
- outGlobal.append("@Field def contactObject = new Contacting(sendEvent, ")
- outGlobal.append(count+")\n")
- }
- }
- }
- if (contactIsSet != 1) {
- contactIsSet = 1
- outGlobal.append("//Global Object for class contactSensor!\n")
- outGlobal.append("@Field def contactObject = new Contacting(sendEvent,1)\n")
- }
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class contactSensor!\n")
- extractedObjectsApp1.append("def "+name+"\n")
- extractedObjectsConstructorApp1.append(name+" = obj.contactObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class contactSensor!\n")
- extractedObjectsApp2.append("def "+name+"\n")
- extractedObjectsConstructorApp2.append(name+" = obj.contactObject\n")
- }
- break
- case "capability.doorControl":
- break
- case "capability.energyMeter":
- break
- case "capability.illuminanceMeasurement":
- break
- case "capability.accelerationSensor":
- break
- case "capability.motionSensor":
- break
- case "capability.musicPlayer":
- break
- case "capability.powerMeter":
- break
- case "capability.presenceSensor":
- break
- case "capability.relativeHumidityMeasurement":
- break
- case "capability.relaySwitch":
- break
- case "capability.sleepSensor":
- break
- case "capability.smokeDetector":
- break
- case "capability.stepSensor":
- break
- case "capability.switch":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('multiple')) {
- if (metaData['multiple'] == true) {
- if (switchIsSet != 1) {
- switchIsSet = 1
- def count = System.console().readLine 'Enter the number of switches to control?(1,2, or 3)'
- outGlobal.append("//Global Object for class switch!\n")
- outGlobal.append("@Field def switchObject = new Switching(sendEvent, ")
- outGlobal.append(count+")\n")
- }
- }
- }
- if (switchIsSet != 1) {
- switchIsSet = 1
- outGlobal.append("//Global Object for class switch!\n")
- outGlobal.append("@Field def switchObject = new Switching(sendEvent,1)\n")
- }
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class switch!\n")
- extractedObjectsApp1.append("def "+name+"\n")
- extractedObjectsConstructorApp1.append(name+" = obj.switchObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class switch!\n")
- extractedObjectsApp2.append("def "+name+"\n")
- extractedObjectsConstructorApp2.append(name+" = obj.switchObject\n")
- }
- break
- case "capability.switchLevel":
- break
- case "capability.temperatureMeasurement":
- break
- case "capability.thermostat":
- break
- case "capability.valve":
- break
- case "capability.waterSensor":
- break
- case "capability.touchSensor":
- break
- case "capability.imageCapture":
- break
- case "device.mobilePresence":
- break
- case "device.aeonKeyFob":
- break
- case "mode":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('options')) {
- println "Options: "+metaData['options']
- }
- def userInput = System.console().readLine 'Enter the mode:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for mode!\n")
- extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for mode!\n")
- extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
- }
- break
- case "decimal":
- break
- case "text":
- break
- case "number":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('options')) {
- println "Options: "+metaData['options']
- }
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
- def userInput = System.console().readLine 'Enter the number:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for number!\n")
- extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for number!\n")
- extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
- }
- break
- case "time":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('options')) {
- println "Options: "+metaData['options']
- }
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
- def userInput = System.console().readLine 'Enter the time:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for time!\n")
- extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for time!\n")
- extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
- }
- break
- case "enum":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('options')) {
- println "Options: "+metaData['options']
- }
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
- def userInput = System.console().readLine 'Enter the enum:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for enum!\n")
- extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for enum!\n")
- extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
- }
- break
- case "bool":
- break
- case "phone":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('options')) {
- println "Options: "+metaData['options']
- }
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
- def userInput = System.console().readLine 'Enter the phone:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for phone!\n")
- extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for phone!\n")
- extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
- }
- break
- case "contact":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('options')) {
- println "Options: "+metaData['options']
- }
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
- def userInput = System.console().readLine 'Enter the name of the contact:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for contact!\n")
- extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for contact!\n")
- extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
- }
- break
- default:
- break
- }
-}
-//input linkedHashMap
-def input(LinkedHashMap metaData, String App) {
- switch(metaData['type']) {
- case "capability.lock":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('multiple')) {
- if (metaData['multiple'] == true) {
- if (lockIsSet != 1) {
- lockIsSet = 1
- def count = System.console().readLine 'Enter the number of locks to control?(1,2, or 3)'
- outGlobal.append("//Global Object for class lock!\n")
- outGlobal.append("@Field def lockObject = new Locking(sendEvent, ")
- outGlobal.append(count+")\n")
- }
- }
- }
- if (lockIsSet != 1) {
- lockIsSet = 1
- outGlobal.append("//Global Object for class lock!\n")
- outGlobal.append("@Field def lockObject = new Locking(sendEvent,1)\n")
- }
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class lock!\n")
- extractedObjectsApp1.append("def "+metaData['input']+"\n")
- extractedObjectsConstructorApp1.append(metaData['input']+" = obj.lockObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class lock!\n")
- extractedObjectsApp2.append("def "+metaData['input']+"\n")
- extractedObjectsConstructorApp2.append(metaData['input']+" = obj.lockObject\n")
- }
- break
- case "capability.alarm":
- break
- case "capability.battery":
- break
- case "capability.beacon":
- break
- case "capability.carbonMonoxideDetector":
- break
- case "capability.colorControl":
- break
- case "capability.contactSensor":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('multiple')) {
- if (metaData['multiple'] == true) {
- if (contactIsSet != 1) {
- contactIsSet = 1
- def count = System.console().readLine 'Enter the number of contact sensors to control?(1,2, or 3)'
- outGlobal.append("//Global Object for class contactSensor!\n")
- outGlobal.append("@Field def contactObject = new Contacting(sendEvent, ")
- outGlobal.append(count+")\n")
- }
- }
- }
- if (contactIsSet != 1) {
- contactIsSet = 1
- outGlobal.append("//Global Object for class contactSensor!\n")
- outGlobal.append("@Field def contactObject = new Contacting(sendEvent,1)\n")
- }
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class contactSensor!\n")
- extractedObjectsApp1.append("def "+metaData['input']+"\n")
- extractedObjectsConstructorApp1.append(metaData['input']+" = obj.contactObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class contactSensor!\n")
- extractedObjectsApp2.append("def "+metaData['input']+"\n")
- extractedObjectsConstructorApp2.append(metaData['input']+" = obj.contactObject\n")
- }
- break
- case "capability.doorControl":
- break
- case "capability.energyMeter":
- break
- case "capability.illuminanceMeasurement":
- break
- case "capability.accelerationSensor":
- break
- case "capability.motionSensor":
- break
- case "capability.musicPlayer":
- break
- case "capability.powerMeter":
- break
- case "capability.presenceSensor":
- break
- case "capability.relativeHumidityMeasurement":
- break
- case "capability.relaySwitch":
- break
- case "capability.sleepSensor":
- break
- case "capability.smokeDetector":
- break
- case "capability.stepSensor":
- break
- case "capability.switch":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('multiple')) {
- if (metaData['multiple'] == true) {
- if (switchIsSet != 1) {
- switchIsSet = 1
- def count = System.console().readLine 'Enter the number of switches to control?(1,2, or 3)'
- outGlobal.append("//Global Object for class switch!\n")
- outGlobal.append("@Field def switchObject = new Switching(sendEvent, ")
- outGlobal.append(count+")\n")
- }
- }
- }
- if (switchIsSet != 1) {
- switchIsSet = 1
- outGlobal.append("//Global Object for class switch!\n")
- outGlobal.append("@Field def switchObject = new Switching(sendEvent,1)\n")
- }
- if (App == "App1") {
- extractedObjectsApp1.append("//Object for class switch!\n")
- extractedObjectsApp1.append("def "+metaData['input']+"\n")
- extractedObjectsConstructorApp1.append(metaData['input']+" = obj.switchObject\n")
- } else {
- extractedObjectsApp2.append("//Object for class switch!\n")
- extractedObjectsApp2.append("def "+metaData['input']+"\n")
- extractedObjectsConstructorApp2.append(metaData['input']+" = obj.switchObject\n")
- }
- break
- case "capability.switchLevel":
- break
- case "capability.temperatureMeasurement":
- break
- case "capability.thermostat":
- break
- case "capability.valve":
- break
- case "capability.waterSensor":
- break
- case "capability.touchSensor":
- break
- case "capability.imageCapture":
- break
- case "device.mobilePresence":
- break
- case "device.aeonKeyFob":
- break
- case "mode":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('options')) {
- println "Options: "+metaData['options']
- }
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
- def userInput = System.console().readLine 'Enter the mode:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for mode!\n")
- extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for mode!\n")
- extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
- }
- break
- case "decimal":
- break
- case "text":
- break
- case "number":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('options')) {
- println "Options: "+metaData['options']
- }
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
- def userInput = System.console().readLine 'Enter the number:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for number!\n")
- extractedObjectsApp1.append("def "+metaData['input']+" = "+userInput+"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for number!\n")
- extractedObjectsApp2.append("def "+metaData['input']+" = "+userInput+"\n")
- }
- break
- case "time":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('options')) {
- println "Options: "+metaData['options']
- }
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
- def userInput = System.console().readLine 'Enter the time:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for time!\n")
- extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for time!\n")
- extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
- }
- break
- case "enum":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('options')) {
- println "Options: "+metaData['options']
- }
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
- def userInput = System.console().readLine 'Enter the enum:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for enum!\n")
- extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for enum!\n")
- extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
- }
- break
- case "bool":
- break
- case "phone":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('options')) {
- println "Options: "+metaData['options']
- }
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
- def userInput = System.console().readLine 'Enter the phone:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for phone!\n")
- extractedObjectsApp1.append("def "+metaData['input']+" = "+userInput+"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for phone!\n")
- extractedObjectsApp2.append("def "+metaData['input']+" = "+userInput+"\n")
- }
- break
- case "contact":
- if (metaData.containsKey('title')) {
- println metaData['title']
- }
- if (metaData.containsKey('options')) {
- println "Options: "+metaData['options']
- }
- if (metaData.containsKey('metadata')) {
- println "metaData: "+metaData['metadata']
- }
- def userInput = System.console().readLine 'Enter the name of the contact:'
- if (App == "App1") {
- extractedObjectsApp1.append("//Global variable for contact!\n")
- extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
- } else {
- extractedObjectsApp2.append("//Global variable for contact!\n")
- extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
- }
- break
- default:
- break
- }
-}
+++ /dev/null
-//Global Object for class lock!
-@Field def lockObject = new Locking(sendEvent,1)
-//Global Object for class contactSensor!
-@Field def contactObject = new Contacting(sendEvent,1)
-//Global Object for class switch!
-@Field def switchObject = new Switching(sendEvent, 1)
}
//Object for location
@Field def locationObject = new LocationVar()
-//Object for touch
+//Object for touch to call function
@Field def appObject = new Touched(sendEvent, 0)
//Create a global list for events
@Field def evt = []
+//Global Object for class Touch Sensor!
+@Field def touchSensorObject = new NfcTouch(sendEvent, 1)
+//Global Object for class switch!
+@Field def switchObject = new Switches(sendEvent, 1)
+//Global Object for class lock!
+@Field def lockObject = new Locks(sendEvent, 1)
+//Global Object for class door control!
+@Field def doorControlObject = new DoorControls(sendEvent, 1)
+//Global Object for class contact sensor!
+@Field def contactObject = new ContactSensors(sendEvent, 1)
+//Global Object for class presence sensor!
+@Field def presenceSensorObject = new PresenceSensors(sendEvent, 1)
+//Global Object for class thermostat!
+@Field def thermostatObject = new Thermostats(sendEvent, 1)
--- /dev/null
+//Create a class for lock device
+package Lock
+import Timer.SimulatedTimer
+
+public class Lock {
+ private int id
+ private String label
+ private String displayName
+ private String lockState
+ private String currentLock
+ private String lockLatestValue
+ def sendEvent
+ def timers
+
+
+ Lock(Closure sendEvent, int id, String label, String displayName, String lockState, String lockLatestValue) {
+ this.id = id
+ this.label = label
+ this.sendEvent = sendEvent
+ this.displayName = displayName
+ this.lockState = lockState
+ this.currentLock = lockState
+ this.lockLatestValue = lockLatestValue
+ this.timers = new SimulatedTimer()
+ }
+
+ //By Apps
+ def lock() {
+ println("the door with id:$id is locked!")
+ this.lockLatestValue = this.lockState
+ this.lockState = "locked"
+ this.currentLock = "locked"
+ sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+
+ def lock(LinkedHashMap metaData) {
+ def task = timers.runAfter(metaData["delay"]) {
+ println("the door with id:$id is locked!")
+ this.lockLatestValue = this.lockState
+ this.lockState = "locked"
+ this.currentLock = "locked"
+ sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+ }
+
+ def unlock() {
+ println("the door with id:$id is unlocked!")
+ this.lockLatestValue = this.lockState
+ this.lockState = "unlocked"
+ this.currentLock = "unlocked"
+ sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+
+ def unlock(LinkedHashMap metaData) {
+ def task = timers.runAfter(metaData["delay"]) {
+ println("the door with id:$id is locked!")
+ this.lockLatestValue = this.lockState
+ this.lockState = "locked"
+ this.currentLock = "locked"
+ sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+ }
+
+ //By Model Checker
+ def setValue(String value) {
+ println("the door with id:$id is $value!")
+ this.lockLatestValue = this.lockState
+ this.lockState = value
+ this.currentLock = value
+ }
+
+ def currentValue(String deviceFeature) {
+ if (deviceFeature == "lock") {
+ return lockState
+ }
+ }
+
+ def latestValue(String deviceFeature) {
+ if (deviceFeature == "lock") {
+ return lockLatestValue
+ }
+ }
+}
+++ /dev/null
-//Create a class for lock device
-package Lock
-import Timer.SimulatedTimer
-
-public class Locking{
- int deviceNumbers
- List locks
- def sendEvent
- def timers
-
- //When we have only one device
- private int id = 0
- private String displayName = "lock0"
- private String lockState = "locked"
- private String lockLatestValue = "locked"
-
- Locking(Closure sendEvent, int deviceNumbers) {
- this.sendEvent = sendEvent
- this.timers = new SimulatedTimer()
- this.deviceNumbers = deviceNumbers
- this.locks = []
- if (deviceNumbers == 1) {
- locks = [new Locks(sendEvent, this.id, this.displayName, this.lockState, this.lockLatestValue)]
- } else if (deviceNumbers == 2) {
- locks = [new Locks(sendEvent, 0, "lock0", "locked", "locked"), new Locks(sendEvent, 1, "lock1", "locked", "locked")]
- } else if (deviceNumbers == 3) {
- locks = [new Locks(sendEvent, 0, "lock0", "locked", "locked"), new Locks(sendEvent, 1, "lock1", "locked", "locked")
- ,new Locks(sendEvent, 2, "lock2", "locked", "locked")]
- }
- }
-
- //By Apps
- def lock() {
- locks*.lock()
- }
-
- def lock(LinkedHashMap metaData) {
- def task = timers.runAfter(metaData["delay"]) {
- locks*.lock()
- }
- }
-
- def unlock() {
- locks*.unlock()
- }
-
- def unlock(LinkedHashMap metaData) {
- def task = timers.runAfter(metaData["delay"]) {
- locks*.unlock()
- }
- }
-
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- locks[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
- if (deviceNumbers == 1)
- this.lockState = locks[eventDataMap["deviceId"]].lockState
- this.lockLatestValue = locks[eventDataMap["deviceId"]].lockLatestValue
- sendEvent(eventDataMap)
- }
-
- def currentValue(String deviceFeature) {
- if (deviceNumbers == 1)
- locks[0].currentValue(deviceFeature)
- else
- locks*.currentValue(deviceFeature)
- }
-
- def latestValue(String deviceFeature) {
- if (deviceNumbers == 1)
- locks[0].latestValue(deviceFeature)
- else
- locks*.latestValue(deviceFeature)
- }
-
- def getAt(int ix) {
- locks[ix]
- }
-}
-
package Lock
import Timer.SimulatedTimer
-public class Locks {
- private int id
- private String displayName
- private String lockState
- private String lockLatestValue
+public class Locks{
+ int deviceNumbers
+ List locks
def sendEvent
def timers
+ //When we have only one device
+ private int id = 20
+ private String label = "lock"
+ private String displayName = "lock"
+ private String lockState = "locked"
+ private String currentLock = "locked"
+ private String lockLatestValue = "locked"
- Locks(Closure sendEvent, int id, String displayName, String lockState, String lockLatestValue) {
- this.id = id
+ Locks(Closure sendEvent, int deviceNumbers) {
this.sendEvent = sendEvent
- this.displayName = displayName
- this.lockState = lockState
- this.lockLatestValue = lockLatestValue
this.timers = new SimulatedTimer()
+ this.deviceNumbers = deviceNumbers
+ this.locks = []
+ for (int i = 0;i < deviceNumbers;i++) {
+ locks.add(new Lock(sendEvent, i+20, label+i.toString(), displayName+i.toString(), this.lockState, this.lockLatestValue))
+ }
}
//By Apps
def lock() {
- println("the door with id:$id is locked!")
- this.lockLatestValue = this.lockState
- this.lockState = "locked"
- sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ locks*.lock()
}
def lock(LinkedHashMap metaData) {
def task = timers.runAfter(metaData["delay"]) {
- println("the door with id:$id is locked!")
- this.lockLatestValue = this.lockState
- this.lockState = "locked"
- sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ locks*.lock()
}
}
-
+
def unlock() {
- println("the door with id:$id is unlocked!")
- this.lockLatestValue = this.lockState
- this.lockState = "unlocked"
- sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ locks*.unlock()
}
+
def unlock(LinkedHashMap metaData) {
def task = timers.runAfter(metaData["delay"]) {
- println("the door with id:$id is locked!")
- this.lockLatestValue = this.lockState
- this.lockState = "locked"
- sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ locks*.unlock()
}
}
+ //Methods for closures
+ def count(Closure Input) {
+ locks.count(Input)
+ }
+ def size() {
+ locks.size()
+ }
+ def each(Closure Input) {
+ locks.each(Input)
+ }
+
//By Model Checker
- def setValue(String value) {
- println("the door with id:$id is $value!")
- this.lockLatestValue = this.lockState
- this.lockState = value
+ def setValue(LinkedHashMap eventDataMap) {
+ locks[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
+ if (deviceNumbers == 1)
+ this.lockState = locks[eventDataMap["deviceId"]].lockState
+ this.currentLock = locks[eventDataMap["deviceId"]].lockState
+ this.lockLatestValue = locks[eventDataMap["deviceId"]].lockLatestValue
+ sendEvent(eventDataMap)
}
-
+
def currentValue(String deviceFeature) {
- if (deviceFeature == "lock") {
- return lockState
- }
+ if (deviceNumbers == 1)
+ locks[0].currentValue(deviceFeature)
+ else
+ locks*.currentValue(deviceFeature)
}
def latestValue(String deviceFeature) {
- if (deviceFeature == "lock") {
- return lockLatestValue
- }
+ if (deviceNumbers == 1)
+ locks[0].latestValue(deviceFeature)
+ else
+ locks*.latestValue(deviceFeature)
+ }
+
+ def getAt(int ix) {
+ locks[ix]
}
}
+
/////////////////////////////////////////////////////////////////////
////subscribe(obj, func)
def subscribe(Object obj, Closure FunctionToCall) {
- objectList.add(obj)
- eventList.add("Touched")
- functionList.add(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) {
--- /dev/null
+//Create a class for Touch sensor
+package NfcTouch
+
+public class NfcTouch{
+ def sendEvent
+ private int isTouched
+
+ NfcTouch(Closure sendEvent, int isTouched) {
+ this.sendEvent = sendEvent
+ this.isTouched = isTouched
+ }
+
+ //By Model Checker
+ def setValue(LinkedHashMap eventDataMap) {
+ println("NFC is Touched!")
+ this.isTouched = 1 //Do we need this?
+ sendEvent(eventDataMap)
+ }
+}
--- /dev/null
+//Create a class for presence sensor
+package PresenceSensor
+import Timer.SimulatedTimer
+
+public class PresenceSensor {
+ private int id
+ private String label
+ private String displayName
+ private String presenceState
+ private String currentPresence
+ private String presenceLatestValue
+
+ PresenceSensor(int id, String label, String displayName, String presenceState, String presenceLatestValue) {
+ this.id = id
+ this.label = label
+ this.displayName = displayName
+ this.presenceState = presenceState
+ this.currentPresence = presenceState
+ this.presenceLatestValue = presenceLatestValue
+ }
+
+ def setValue(String value) {
+ this.presenceLatestValue = presenceState
+ println("the presence sensor with id:$id is triggered to $value!")
+ this.presenceState = value
+ this.currentPresence = value
+ }
+
+
+ def currentValue(String deviceFeature) {
+ if (deviceFeature == "presence") {
+ return presenceState
+ }
+ }
+
+ def latestValue(String deviceFeature) {
+ if (deviceFeature == "presence") {
+ return presenceLatestValue
+ }
+ }
+}
--- /dev/null
+//Create a class for presence sensor
+package PresenceSensor
+import Timer.SimulatedTimer
+
+public class PresenceSensors {
+ private int deviceNumbers
+ private List presenceSensors
+ def sendEvent
+
+ //For one device(We cannot have obj.id)-> We should have obj[0].id
+ private int id = 0
+ private String label = "presenceSensor"
+ private String displayName = "presenceSensor"
+ private String presenceState = "not present"
+ private String currentPresence = "not present"
+ private String presenceLatestValue = "not present"
+
+
+ PresenceSensors(Closure sendEvent, int deviceNumbers) {
+ this.sendEvent = sendEvent
+ this.deviceNumbers = deviceNumbers
+ this.presenceSensors = []
+
+ for (int i = 0;i < deviceNumbers;i++) {
+ presenceSensors.add(new PresenceSensor(i+30, label+i.toString(), displayName+i.toString(), this.presenceState, this.presenceLatestValue))
+ }
+ }
+
+ //By Model Checker
+ def setValue(LinkedHashMap eventDataMap) {
+ presenceSensors[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
+ if (deviceNumbers == 1)
+ this.presenceLatestValue = presenceSensors[eventDataMap["deviceId"]].presenceLatestValue
+ this.presenceState = presenceSensors[eventDataMap["deviceId"]].presenceState
+ this.currentPresence = presenceSensors[eventDataMap["deviceId"]].presenceState
+ sendEvent(eventDataMap)
+ }
+
+ //Methods for closures
+ def count(Closure Input) {
+ presenceSensors.count(Input)
+ }
+ def size() {
+ presenceSensors.size()
+ }
+ def each(Closure Input) {
+ presenceSensors.each(Input)
+ }
+
+
+ def currentValue(String deviceFeature) {
+ if (deviceNumbers == 1)
+ presenceSensors[0].currentValue(deviceFeature)//It is called if we have only one device
+ else
+ presenceSensors*.currentValue(deviceFeature)
+ }
+
+ def latestValue(String deviceFeature) {
+ if (deviceNumbers == 1)
+ presenceSensors[0].latestValue(deviceFeature)//It is called if we have only one device
+ else
+ presenceSensors*.latestValue(deviceFeature)
+ }
+
+ def getAt(int ix) {
+ presenceSensors[ix]
+ }
+}
#Files for both Apps
Out = open("main.groovy", "w+")
GlobalVariablesBothApps = open("GlobalVariables/"+"GlobalVariablesBothApps.groovy", "r")
-outGlobal = open("Extractor/"+"outGlobal.groovy", "r")
eventSimulator = open("eventSimulator/"+"eventSimulator.groovy", "r")
#For App1
Out.write("import groovy.transform.Field\n")
Out.write("\n")
Out.write("//Importing Classes\n")
-Out.write("import ContactSensor.Contacting\n")
-Out.write("import ContactSensor.Contacts\n")
-Out.write("import Lock.Locking\n")
+Out.write("import ContactSensor.ContactSensor\n")
+Out.write("import ContactSensor.ContactSensors\n")
+Out.write("import DoorControl.DoorControl\n")
+Out.write("import DoorControl.DoorControls\n")
+Out.write("import Lock.Lock\n")
Out.write("import Lock.Locks\n")
-Out.write("import Switch.Switching\n")
+Out.write("import Thermostat.Thermostat\n")
+Out.write("import Thermostat.Thermostats\n")
+Out.write("import Switch.Switch\n")
Out.write("import Switch.Switches\n")
+Out.write("import PresenceSensor.PresenceSensor\n")
+Out.write("import PresenceSensor.PresenceSensors\n")
Out.write("import Logger.Logger\n")
Out.write("import Location.LocationVar\n")
Out.write("import Location.Phrase\n")
Out.write("import appTouch.Touched\n")
+Out.write("import NfcTouch.NfcTouch\n")
Out.write("import Event.Event\n")
Out.write("import Timer.SimulatedTimer\n")
Out.write("\n")
for line in GlobalVariablesBothApps:
Out.write(line)
Out.write("\n")
-Out.write("//Extracted global objects for both Apps\n")
-for line in outGlobal:
- Out.write(line)
-Out.write("\n")
Out.write("//Application #1\n")
Out.write("class App1 {\n")
Out.write("\tdef reference\n")
Out.write("app2.installed()\n")
Out.write("\n")
for line in eventSimulator:
- Out.write("\t"+line)
+ Out.write(line)
Out.close()
--- /dev/null
+//Create a class for switch device
+package Switch
+import Timer.SimulatedTimer
+
+public class Switch {
+ private int id
+ private String label
+ private String displayName
+ private String switchState
+ private String currentSwitch
+ private int currentLevel
+ private String switchLatestValue
+ def sendEvent
+ def timers
+
+
+ Switch(Closure sendEvent, int id, String label, String displayName, String switchState, String currentSwitch, int currentLevel, String switchLatestValue) {
+ this.sendEvent = sendEvent
+ this.timers = new SimulatedTimer()
+ this.currentSwitch = currentSwitch
+ this.currentLevel = currentLevel
+ this.id = id
+ this.label = label
+ this.displayName = displayName
+ this.switchState = switchState
+ this.switchLatestValue = switchLatestValue
+ }
+
+ //By Apps
+ def setLevel(int level) {
+ println("the switch with id:$id is setted to level $level!")
+ this.currentLevel = level
+ }
+
+ def on() {
+ println("the switch with id:$id is on!")
+ this.switchLatestValue = this.switchState
+ this.switchState = "on"
+ this.currentSwitch = "on"
+ sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+
+ def on(LinkedHashMap metaData) {
+ def task = timers.runAfter(metaData["delay"]) {
+ println("the switch with id:$id is on!")
+ this.switchLatestValue = this.switchState
+ this.switchState = "on"
+ this.currentSwitch = "on"
+ sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+ }
+
+ def off() {
+ println("the switch with id:$id is off!")
+ this.switchLatestValue = this.switchState
+ this.switchState = "off"
+ this.currentSwitch = "off"
+ sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+
+ def off(LinkedHashMap metaData) {
+ def task = timers.runAfter(metaData["delay"]) {
+ println("the switch with id:$id is off!")
+ this.switchLatestValue = this.switchState
+ this.switchState = "off"
+ this.currentSwitch = "off"
+ sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+ }
+
+ //By Model Checker
+ def setValue(String value) {
+ println("the switch with id:$id is $value!")
+ this.switchLatestValue = this.switchState
+ this.switchState = value
+ this.currentSwitch = value
+ }
+
+ def currentValue(String deviceFeature) {
+ if (deviceFeature == "switch") {
+ return switchState
+ }
+ }
+
+ def latestValue(String deviceFeature) {
+ if (deviceFeature == "switch") {
+ return switchLatestValue
+ }
+ }
+}
import Timer.SimulatedTimer
public class Switches {
- private int id = 0
- private String displayName
- private String switchState
- private String switchLatestValue
- def sendEvent
+ int deviceNumbers
+ List switches
def timers
-
+ def sendEvent
- Switches(Closure sendEvent, int id, String displayName, String switchState, String switchLatestValue) {
+ //If we have only one device
+ private int id = 40
+ private String label = "switch"
+ private String displayName = "switch"
+ private String switchState = "off"
+ private String currentSwitch = "off"
+ private int currentLevel = 50
+ private String switchLatestValue = "off"
+
+ Switches(Closure sendEvent, int deviceNumbers) {
this.sendEvent = sendEvent
this.timers = new SimulatedTimer()
+ this.deviceNumbers = deviceNumbers
+ this.switches = []
+ for (int i = 0;i < deviceNumbers;i++) {
+ switches.add(new Switch(sendEvent, i+40, label+i.toString(), displayName+i.toString(), this.switchState, this.currentSwitch, this.currentLevel, this.switchLatestValue))
+ }
+ }
- this.id = id
- this.displayName = displayName
- this.switchState = switchState
- this.switchLatestValue = switchLatestValue
+ //Methods for closures
+ def count(Closure Input) {
+ switches.count(Input)
+ }
+ def size() {
+ switches.size()
+ }
+ def each(Closure Input) {
+ switches.each(Input)
}
//By Apps
+ def setLevel(int level) {
+ switches*.setLevel(level)
+ }
+
def on() {
- println("the switch with id:$id is on!")
- this.switchLatestValue = this.switchState
- this.switchState = "on"
- sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ switches*.on()
}
def on(LinkedHashMap metaData) {
def task = timers.runAfter(metaData["delay"]) {
- println("the switch with id:$id is on!")
- this.switchLatestValue = this.switchState
- this.switchState = "on"
- sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ switches*.on()
}
}
def off() {
- println("the switch with id:$id is off!")
- this.switchLatestValue = this.switchState
- this.switchState = "off"
- sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ switches*.off()
}
def off(LinkedHashMap metaData) {
def task = timers.runAfter(metaData["delay"]) {
- println("the switch with id:$id is off!")
- this.switchLatestValue = this.switchState
- this.switchState = "off"
- sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ switches*.off()
}
}
//By Model Checker
- def setValue(String value) {
- println("the switch with id:$id is $value!")
- this.switchLatestValue = this.switchState
- this.switchState = value
+ def setValue(LinkedHashMap eventDataMap) {
+ switches[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
+ if (deviceNumbers == 1)
+ this.switchState = switches[eventDataMap["deviceId"]].switchState
+ this.switchLatestValue = switches[eventDataMap["deviceId"]].switchLatestValue
+ sendEvent(eventDataMap)
}
-
+
+
def currentValue(String deviceFeature) {
- if (deviceFeature == "switch") {
- return switchState
- }
+ if (deviceNumbers == 1)
+ switches[0].currentValue(deviceFeature)
+ else
+ switches*.currentValue(deviceFeature)
}
def latestValue(String deviceFeature) {
- if (deviceFeature == "switch") {
- return switchLatestValue
- }
+ if (deviceNumbers == 1)
+ switches[0].latestValue(deviceFeature)
+ else
+ switches*.latestValue(deviceFeature)
+ }
+
+ def getAt(int ix) {
+ switches[ix]
}
}
+++ /dev/null
-//Create a class for switch device
-package Switch
-import Timer.SimulatedTimer
-
-public class Switching{
- int deviceNumbers
- List switches
- def timers
- def sendEvent
-
- //If we have only one device
- private int id = 0
- private String displayName = "switch0"
- private String switchState = "off"
- private String switchLatestValue = "off"
-
- Switching(Closure sendEvent, int deviceNumbers) {
- this.sendEvent = sendEvent
- this.timers = new SimulatedTimer()
- this.deviceNumbers = deviceNumbers
- this.switches = []
- if (deviceNumbers == 1) {
- switches = [new Switches(sendEvent, this.id, this.displayName, this.switchState, this.switchLatestValue)]
- } else if (deviceNumbers == 2) {
- switches = [new Switches(sendEvent, 0, "switch0", "off", "off"), new Switches(sendEvent, 1, "switch1", "off", "off")]
- } else if (deviceNumbers == 3) {
- switches = [new Switches(sendEvent, 0, "switch0", "off", "off"), new Switches(sendEvent, 1, "switch1", "off", "off")
- ,new Switches(sendEvent, 2, "switch2", "off", "off")]
- }
- }
-
- //By Apps
- def on() {
- switches*.on()
- }
-
- def on(LinkedHashMap metaData) {
- def task = timers.runAfter(metaData["delay"]) {
- switches*.on()
- }
- }
-
- def off() {
- switches*.off()
- }
-
- def off(LinkedHashMap metaData) {
- def task = timers.runAfter(metaData["delay"]) {
- switches*.off()
- }
- }
-
- //By Model Checker
- def setValue(LinkedHashMap eventDataMap) {
- switches[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
- if (deviceNumbers == 1)
- this.switchState = switches[eventDataMap["deviceId"]].switchState
- this.switchLatestValue = switches[eventDataMap["deviceId"]].switchLatestValue
- sendEvent(eventDataMap)
- }
-
-
- def currentValue(String deviceFeature) {
- if (deviceNumbers == 1)
- switches[0].currentValue(deviceFeature)
- else
- switches*.currentValue(deviceFeature)
- }
-
- def latestValue(String deviceFeature) {
- if (deviceNumbers == 1)
- switches[0].latestValue(deviceFeature)
- else
- switches*.latestValue(deviceFeature)
- }
-
- def getAt(int ix) {
- switches[ix]
- }
-}
--- /dev/null
+/////
+
+def preferences(Closure Input) {
+ find(Input)
+}
+
+def input(String Inp) {
+ println(Inp)
+}
+
+preferences {
+ def d = 1
+ if (d==1)
+ println "salam"
+ d=0
+ input "switch1"
+ if (d==0)
+ println "oyo"
+}
+
--- /dev/null
+//
+//import libraries
+import groovy.transform.Field
+
+//import classes
+public class Switches {
+ int deviceNumbers
+ List switches
+ def sendEvent
+
+ //If we have only one device
+ private int id = 40
+ private String label = "switch"
+ private String displayName = "switch"
+ private String switchState = "off"
+ private String currentSwitch = "off"
+ private int currentLevel = 50
+ private String switchLatestValue = "off"
+
+ Switches(Closure sendEvent, int deviceNumbers) {
+ this.sendEvent = sendEvent
+ this.deviceNumbers = deviceNumbers
+ this.switches = []
+ for (int i = 0;i < deviceNumbers;i++) {
+ switches.add(new Switch(sendEvent, i+40, label+i.toString(), displayName+i.toString(), this.switchState, this.currentSwitch, this.currentLevel, this.switchLatestValue))
+ }
+ }
+
+ //Methods for closures
+ def count(Closure Input) {
+ switches.count(Input)
+ }
+ def size() {
+ switches.size()
+ }
+ def each(Closure Input) {
+ switches.each(Input)
+ }
+
+ //By Apps
+ def setLevel(int level) {
+ switches*.setLevel(level)
+ }
+
+ def on() {
+ switches*.on()
+ }
+
+ def on(LinkedHashMap metaData) {
+ switches*.on()
+ }
+
+ def off() {
+ switches*.off()
+ }
+
+ def off(LinkedHashMap metaData) {
+ switches*.off()
+ }
+
+ //By Model Checker
+ def setValue(LinkedHashMap eventDataMap) {
+ switches[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
+ if (deviceNumbers == 1)
+ this.switchState = switches[eventDataMap["deviceId"]].switchState
+ this.switchLatestValue = switches[eventDataMap["deviceId"]].switchLatestValue
+ sendEvent(eventDataMap)
+ }
+
+
+ def currentValue(String deviceFeature) {
+ if (deviceNumbers == 1)
+ switches[0].currentValue(deviceFeature)
+ else
+ switches*.currentValue(deviceFeature)
+ }
+
+ def latestValue(String deviceFeature) {
+ if (deviceNumbers == 1)
+ switches[0].latestValue(deviceFeature)
+ else
+ switches*.latestValue(deviceFeature)
+ }
+
+ def getAt(int ix) {
+ switches[ix]
+ }
+}
+public class Switch {
+ private int id
+ private String label
+ private String displayName
+ private String switchState
+ private String currentSwitch
+ private int currentLevel
+ private String switchLatestValue
+ def sendEvent
+
+
+ Switch(Closure sendEvent, int id, String label, String displayName, String switchState, String currentSwitch, int currentLevel, String switchLatestValue) {
+ this.sendEvent = sendEvent
+ this.currentSwitch = currentSwitch
+ this.currentLevel = currentLevel
+ this.id = id
+ this.label = label
+ this.displayName = displayName
+ this.switchState = switchState
+ this.switchLatestValue = switchLatestValue
+ }
+
+ //By Apps
+ def setLevel(int level) {
+ println("the switch with id:$id is setted to level $level!")
+ this.currentLevel = level
+ }
+
+ def on() {
+ println("the switch with id:$id is on!")
+ this.switchLatestValue = this.switchState
+ this.switchState = "on"
+ this.currentSwitch = "on"
+ sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+
+ def on(LinkedHashMap metaData) {
+ println("the switch with id:$id is on!")
+ this.switchLatestValue = this.switchState
+ this.switchState = "on"
+ this.currentSwitch = "on"
+ sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+
+ def off() {
+ println("the switch with id:$id is off!")
+ this.switchLatestValue = this.switchState
+ this.switchState = "off"
+ this.currentSwitch = "off"
+ sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+
+ def off(LinkedHashMap metaData) {
+ println("the switch with id:$id is off!")
+ this.switchLatestValue = this.switchState
+ this.switchState = "off"
+ this.currentSwitch = "off"
+ sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ }
+
+ //By Model Checker
+ def setValue(String value) {
+ println("the switch with id:$id is $value!")
+ this.switchLatestValue = this.switchState
+ this.switchState = value
+ this.currentSwitch = value
+ }
+
+ def currentValue(String deviceFeature) {
+ if (deviceFeature == "switch") {
+ return switchState
+ }
+ }
+
+ def latestValue(String deviceFeature) {
+ if (deviceFeature == "switch") {
+ return switchLatestValue
+ }
+ }
+}
+
+@Field def switchObject
+
+//input "",""
+def input(String name, String type) {
+ switch(type) {
+ case "capability.lock":
+ break
+ case "capability.alarm":
+ break
+ case "capability.battery":
+ break
+ case "capability.beacon":
+ break
+ case "capability.carbonMonoxideDetector":
+ break
+ case "capability.colorControl":
+ break
+ case "capability.contactSensor":
+ break
+ case "capability.doorControl":
+ break
+ case "capability.energyMeter":
+ break
+ case "capability.illuminanceMeasurement":
+ break
+ case "capability.accelerationSensor":
+ break
+ case "capability.motionSensor":
+ break
+ case "capability.musicPlayer":
+ break
+ case "capability.powerMeter":
+ break
+ case "capability.presenceSensor":
+ break
+ case "capability.relativeHumidityMeasurement":
+ break
+ case "capability.relaySwitch":
+ break
+ case "capability.sleepSensor":
+ break
+ case "capability.smokeDetector":
+ break
+ case "capability.stepSensor":
+ break
+ case "capability.switch":
+ break
+ case "capability.switchLevel":
+ break
+ case "capability.temperatureMeasurement":
+ break
+ case "capability.thermostat":
+ break
+ case "capability.valve":
+ break
+ case "capability.waterSensor":
+ break
+ case "capability.touchSensor":
+ break
+ case "capability.imageCapture":
+ break
+ case "device.mobilePresence":
+ break
+ case "device.aeonKeyFob":
+ break
+ case "mode":
+ break
+ case "decimal":
+ break
+ case "text":
+ break
+ case "number":
+ break
+ case "time":
+ break
+ case "enum":
+ break
+ case "bool":
+ break
+ case "phone":
+ break
+ case "contact":
+ break
+ default:
+ break
+ }
+}
+
+//input "","",linkedHashMap
+def input(LinkedHashMap metaData, String name, String type) {
+ switch(type) {
+ case "capability.lock":
+ break
+ case "capability.alarm":
+ break
+ case "capability.battery":
+ break
+ case "capability.beacon":
+ break
+ case "capability.carbonMonoxideDetector":
+ break
+ case "capability.colorControl":
+ break
+ case "capability.contactSensor":
+ break
+ case "capability.doorControl":
+ break
+ case "capability.energyMeter":
+ break
+ case "capability.illuminanceMeasurement":
+ break
+ case "capability.accelerationSensor":
+ break
+ case "capability.motionSensor":
+ break
+ case "capability.musicPlayer":
+ break
+ case "capability.powerMeter":
+ break
+ case "capability.presenceSensor":
+ break
+ case "capability.relativeHumidityMeasurement":
+ break
+ case "capability.relaySwitch":
+ break
+ case "capability.sleepSensor":
+ break
+ case "capability.smokeDetector":
+ break
+ case "capability.stepSensor":
+ break
+ case "capability.switch":
+ break
+ case "capability.switchLevel":
+ break
+ case "capability.temperatureMeasurement":
+ break
+ case "capability.thermostat":
+ break
+ case "capability.valve":
+ break
+ case "capability.waterSensor":
+ break
+ case "capability.touchSensor":
+ break
+ case "capability.imageCapture":
+ break
+ case "device.mobilePresence":
+ break
+ case "device.aeonKeyFob":
+ break
+ case "mode":
+ break
+ case "decimal":
+ break
+ case "text":
+ break
+ case "number":
+ break
+ case "time":
+ break
+ case "enum":
+ break
+ case "bool":
+ break
+ case "phone":
+ break
+ case "contact":
+ break
+ default:
+ break
+ }
+}
+//input linkedHashMap
+def input(LinkedHashMap metaData) {
+ switch(metaData['type']) {
+ case "capability.lock":
+ break
+ case "capability.alarm":
+ break
+ case "capability.battery":
+ break
+ case "capability.beacon":
+ break
+ case "capability.carbonMonoxideDetector":
+ break
+ case "capability.colorControl":
+ break
+ case "capability.contactSensor":
+ break
+ case "capability.doorControl":
+ break
+ case "capability.energyMeter":
+ break
+ case "capability.illuminanceMeasurement":
+ break
+ case "capability.accelerationSensor":
+ break
+ case "capability.motionSensor":
+ break
+ case "capability.musicPlayer":
+ break
+ case "capability.powerMeter":
+ break
+ case "capability.presenceSensor":
+ break
+ case "capability.relativeHumidityMeasurement":
+ break
+ case "capability.relaySwitch":
+ break
+ case "capability.sleepSensor":
+ break
+ case "capability.smokeDetector":
+ break
+ case "capability.stepSensor":
+ break
+ case "capability.switch":
+ break
+ case "capability.switchLevel":
+ break
+ case "capability.temperatureMeasurement":
+ break
+ case "capability.thermostat":
+ break
+ case "capability.valve":
+ break
+ case "capability.waterSensor":
+ break
+ case "capability.touchSensor":
+ break
+ case "capability.imageCapture":
+ break
+ case "device.mobilePresence":
+ break
+ case "device.aeonKeyFob":
+ break
+ case "mode":
+ break
+ case "decimal":
+ break
+ case "text":
+ break
+ case "number":
+ break
+ case "time":
+ break
+ case "enum":
+ break
+ case "bool":
+ break
+ case "phone":
+ break
+ case "contact":
+ break
+ default:
+ break
+ }
+}
+
+def definition(LinkedHashMap metaData) {
+ println("///Just some information///")
+}
+
+def preferences(Closure inputData) {
+ find(inputData) //Run the closure to extract pages/sections/inputMethods
+}
+
+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 section(String title, Closure inputData) {
+ println(title)
+ find(inputData) //Run the closure to extract inputMethods
+ switchObject = "switch1"
+ this[switchObject] = new Switches({}, 1)
+ switch1.on()
+}
+
+
+////////////////
+definition(
+ name: "NFC Tag Toggle",
+ namespace: "smartthings",
+ author: "SmartThings",
+ description: "Allows toggling of a switch, lock, or garage door based on an NFC Tag touch event",
+ category: "SmartThings Internal",
+ iconUrl: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor.png",
+ iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor@2x.png",
+ iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor@2x.png")
+
+
+preferences {
+ page(name: "pageOne", title: "Device selection", uninstall: true, nextPage: "pageTwo") {
+ section("Select an NFC tag") {
+ input "tag", "capability.touchSensor", title: "NFC Tag"
+ }
+ section("Select devices to control") {
+ input "switch1", "capability.switch", title: "Light or switch", required: false, multiple: true
+ input "lock", "capability.lock", title: "Lock", required: false, multiple: true
+ input "garageDoor", "capability.doorControl", title: "Garage door controller", required: false, multiple: true
+ }
+ }
+
+ page(name: "pageTwo", title: "Master devices", install: true, uninstall: true)
+}
+
+switch1.on()
+
+def pageTwo() {
+ dynamicPage(name: "pageTwo") {
+ section("If set, the state of these devices will be toggled each time the tag is touched, " +
+ "e.g. a light that's on will be turned off and one that's off will be turned on, " +
+ "other devices of the same type will be set to the same state as their master device. " +
+ "If no master is designated then the majority of devices of the same type will be used " +
+ "to determine whether to turn on or off the devices.") {
+
+ if (switch1 || masterSwitch) {
+ input "masterSwitch", "enum", title: "Master switch", options: switch1.collect{[(it.id): it.displayName]}, required: false
+ }
+ if (lock || masterLock) {
+ input "masterLock", "enum", title: "Master lock", options: lock.collect{[(it.id): it.displayName]}, required: false
+ }
+ if (garageDoor || masterDoor) {
+ input "masterDoor", "enum", title: "Master door", options: garageDoor.collect{[(it.id): it.displayName]}, required: false
+ }
+ }
+ section([mobileOnly:true]) {
+ label title: "Assign a name", required: false
+ mode title: "Set for specific mode(s)", required: false
+ }
+ }
+}
+
+def installed() {
+ log.debug "Installed with settings: ${settings}"
+ initialize()
+}
+
+def updated() {
+ log.debug "Updated with settings: ${settings}"
+ unsubscribe()
+ initialize()
+}
+
+def initialize() {
+ subscribe tag, "nfcTouch", touchHandler
+ subscribe app, touchHandler
+}
+
+private currentStatus(devices, master, attribute) {
+ log.trace "currentStatus($devices, $master, $attribute)"
+ def result = null
+ if (master) {
+ result = devices.find{it.id == master}?.currentValue(attribute)
+ }
+ else {
+ def map = [:]
+ devices.each {
+ def value = it.currentValue(attribute)
+ map[value] = (map[value] ?: 0) + 1
+ log.trace "$it.displayName: $value"
+ }
+ log.trace map
+ result = map.collect{it}.sort{it.value}[-1].key
+ }
+ log.debug "$attribute = $result"
+ result
+}
+
+def touchHandler(evt) {
+ log.trace "touchHandler($evt.descriptionText)"
+ if (switch1) {
+ def status = currentStatus(switch1, masterSwitch, "switch")
+ switch1.each {
+ if (status == "on") {
+ it.off()
+ }
+ else {
+ it.on()
+ }
+ }
+ }
+
+ if (lock) {
+ def status = currentStatus(lock, masterLock, "lock")
+ lock.each {
+ if (status == "locked") {
+ lock.unlock()
+ }
+ else {
+ lock.lock()
+ }
+ }
+ }
+
+ if (garageDoor) {
+ def status = currentStatus(garageDoor, masterDoor, "status")
+ garageDoor.each {
+ if (status == "open") {
+ it.close()
+ }
+ else {
+ it.open()
+ }
+ }
+ }
+}
+
--- /dev/null
+//
+def S
+def S2
+def S1
+
+
+"$S"+"1" = "SALAM"
--- /dev/null
+////////////////////////////////////////
+import groovy.transform.Field
+@Field File outGlobal = new File("Extractor/outGlobal.groovy")
+@Field File extractedObjectsApp1 = new File("Extractor/App1/extractedObjectsApp1.groovy")
+@Field File extractedObjectsApp2 = new File("Extractor/App2/extractedObjectsApp2.groovy")
+@Field File extractedObjectsConstructorApp1 = new File("Extractor/App1/extractedObjectsConstructorApp1.groovy")
+@Field File extractedObjectsConstructorApp2 = new File("Extractor/App2/extractedObjectsConstructorApp2.groovy")
+
+
+//Empty the files
+outGlobal.write("")
+extractedObjectsApp1.write("")
+extractedObjectsApp2.write("")
+extractedObjectsConstructorApp1.write("")
+extractedObjectsConstructorApp2.write("")
+
+
+@Field lockIsSet = 0
+@Field contactIsSet = 0
+@Field switchIsSet = 0
+@Field presenceIsSet = 0
+@Field thermostatIsSet = 0
+@Field touchSensorIsSet = 0
+@Field doorControlIsSet = 0
+
+//input "",""
+def input(String name, String type, String App) {
+ switch(type) {
+ case "capability.lock":
+ if (lockIsSet != 1) {
+ lockIsSet = 1
+ outGlobal.append("//Global Object for class lock!\n")
+ outGlobal.append("@Field def lockObject = new Locks(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class lock!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.lockObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class lock!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.lockObject\n")
+ }
+ break
+ case "capability.alarm":
+ break
+ case "capability.battery":
+ break
+ case "capability.beacon":
+ break
+ case "capability.carbonMonoxideDetector":
+ break
+ case "capability.colorControl":
+ break
+ case "capability.contactSensor":
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ outGlobal.append("//Global Object for class contactSensor!\n")
+ outGlobal.append("@Field def contactObject = new ContactSensors(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class contactSensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.contactObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class contactSensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.contactObject\n")
+ }
+ break
+ case "capability.doorControl":
+ if (doorControlIsSet != 1) {
+ doorControlIsSet = 1
+ outGlobal.append("//Global Object for class door control!\n")
+ outGlobal.append("@Field def doorControlObject = new DoorControls(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class door control!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.doorControlObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class door control!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.doorControlObject\n")
+ }
+ break
+ case "capability.energyMeter":
+ break
+ case "capability.illuminanceMeasurement":
+ break
+ case "capability.accelerationSensor":
+ break
+ case "capability.motionSensor":
+ break
+ case "capability.musicPlayer":
+ break
+ case "capability.powerMeter":
+ break
+ case "capability.presenceSensor":
+ if (presenceIsSet != 1) {
+ presenceIsSet = 1
+ outGlobal.append("//Global Object for class presence sensor!\n")
+ outGlobal.append("@Field def presenceSensorObject = new PresenceSensors(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class presence sensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.presenceSensorObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class presence sensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.presenceSensorObject\n")
+ }
+ break
+ case "capability.relativeHumidityMeasurement":
+ break
+ case "capability.relaySwitch":
+ break
+ case "capability.sleepSensor":
+ break
+ case "capability.smokeDetector":
+ break
+ case "capability.stepSensor":
+ break
+ case "capability.switch":
+ if (switchIsSet != 1) {
+ switchIsSet = 1
+ outGlobal.append("//Global Object for class switch!\n")
+ outGlobal.append("@Field def switchObject = new Switches(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class switch!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.switchObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class switch!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.switchObject\n")
+ }
+ break
+ case "capability.switchLevel":
+ break
+ case "capability.temperatureMeasurement":
+ break
+ case "capability.thermostat":
+ if (thermostatIsSet != 1) {
+ thermostatIsSet = 1
+ outGlobal.append("//Global Object for class thermostat!\n")
+ outGlobal.append("@Field def thermostatObject = new Thermostats(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class thermostat!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.thermostatObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class thermostat!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.thermostatObject\n")
+ }
+ break
+ case "capability.valve":
+ break
+ case "capability.waterSensor":
+ break
+ case "capability.touchSensor":
+ if (touchSensorIsSet != 1) {
+ touchSensorIsSet = 1
+ outGlobal.append("//Global Object for class Touch Sensor!\n")
+ outGlobal.append("@Field def touchSensorObject = new NfcTouch(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class Touch Sensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.touchSensorObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class Touch Sensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.touchSensorObject\n")
+ }
+ break
+ case "capability.imageCapture":
+ break
+ case "device.mobilePresence":
+ break
+ case "device.aeonKeyFob":
+ break
+ case "mode":
+ def userInput = System.console().readLine 'Enter the mode:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for mode!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for mode!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "decimal":
+ break
+ case "text":
+ break
+ case "number":
+ def userInput = System.console().readLine 'Enter the number:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for number!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for number!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "time":
+ def userInput = System.console().readLine 'Enter the time:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for time!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for time!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "enum":
+ def userInput = System.console().readLine 'Enter the enum:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for enum!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for enum!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "bool":
+ break
+ case "phone":
+ def userInput = System.console().readLine 'Enter the phone:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for phone!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for phone!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "contact":
+ def userInput = System.console().readLine 'Enter the name of the contact:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for contact!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for contact!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ default:
+ break
+ }
+}
+
+//input "","",linkedHashMap
+def input(LinkedHashMap metaData, String name, String type, String App) {
+ switch(type) {
+ case "capability.lock":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (lockIsSet != 1) {
+ lockIsSet = 1
+ def count = System.console().readLine 'Enter the number of locks to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class lock!\n")
+ outGlobal.append("@Field def lockObject = new Locks(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (lockIsSet != 1) {
+ lockIsSet = 1
+ outGlobal.append("//Global Object for class lock!\n")
+ outGlobal.append("@Field def lockObject = new Locks(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class lock!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.lockObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class lock!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.lockObject\n")
+ }
+ break
+ case "capability.alarm":
+ break
+ case "capability.battery":
+ break
+ case "capability.beacon":
+ break
+ case "capability.carbonMonoxideDetector":
+ break
+ case "capability.colorControl":
+ break
+ case "capability.contactSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ def count = System.console().readLine 'Enter the number of contact sensors to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class contactSensor!\n")
+ outGlobal.append("@Field def contactObject = new ContactSensors(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ outGlobal.append("//Global Object for class contactSensor!\n")
+ outGlobal.append("@Field def contactObject = new ContactSensors(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class contactSensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.contactObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class contactSensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.contactObject\n")
+ }
+ break
+ case "capability.doorControl":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ def count = System.console().readLine 'Enter the number of doors to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class door control!\n")
+ outGlobal.append("@Field def doorControlObject = new DoorControls(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (doorControlIsSet != 1) {
+ doorControlIsSet = 1
+ outGlobal.append("//Global Object for class door control!\n")
+ outGlobal.append("@Field def doorControlObject = new DoorControls(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class door control!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.doorControlObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class door control!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.doorControlObject\n")
+ }
+ break
+ case "capability.energyMeter":
+ break
+ case "capability.illuminanceMeasurement":
+ break
+ case "capability.accelerationSensor":
+ break
+ case "capability.motionSensor":
+ break
+ case "capability.musicPlayer":
+ break
+ case "capability.powerMeter":
+ break
+ case "capability.presenceSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (presenceIsSet != 1) {
+ presenceIsSet = 1
+ def count = System.console().readLine 'Enter the number of presence sensors to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class presence sensor!\n")
+ outGlobal.append("@Field def presenceSensorObject = new PresenceSensors(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (presenceIsSet != 1) {
+ presenceIsSet = 1
+ outGlobal.append("//Global Object for class presence sensor!\n")
+ outGlobal.append("@Field def presenceSensorObject = new PresenceSensors(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class presence sensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.presenceSensorObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class presence sensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.presenceSensorObject\n")
+ }
+ break
+ case "capability.relativeHumidityMeasurement":
+ break
+ case "capability.relaySwitch":
+ break
+ case "capability.sleepSensor":
+ break
+ case "capability.smokeDetector":
+ break
+ case "capability.stepSensor":
+ break
+ case "capability.switch":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (switchIsSet != 1) {
+ switchIsSet = 1
+ def count = System.console().readLine 'Enter the number of switches to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class switch!\n")
+ outGlobal.append("@Field def switchObject = new Switches(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (switchIsSet != 1) {
+ switchIsSet = 1
+ outGlobal.append("//Global Object for class switch!\n")
+ outGlobal.append("@Field def switchObject = new Switches(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class switch!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.switchObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class switch!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.switchObject\n")
+ }
+ break
+ case "capability.switchLevel":
+ break
+ case "capability.temperatureMeasurement":
+ break
+ case "capability.thermostat":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (thermostatIsSet != 1) {
+ thermostatIsSet = 1
+ def count = System.console().readLine 'Enter the number of thermostats to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class thermostat!\n")
+ outGlobal.append("@Field def thermostatObject = new Thermostats(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (thermostatIsSet != 1) {
+ thermostatIsSet = 1
+ outGlobal.append("//Global Object for class thermostat!\n")
+ outGlobal.append("@Field def thermostatObject = new Thermostats(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class thermostat!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.thermostatObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class thermostat!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.thermostatObject\n")
+ }
+ break
+ case "capability.valve":
+ break
+ case "capability.waterSensor":
+ break
+ case "capability.touchSensor":
+ if (touchSensorIsSet != 1) {
+ touchSensorIsSet = 1
+ outGlobal.append("//Global Object for class Touch Sensor!\n")
+ outGlobal.append("@Field def touchSensorObject = new NfcTouch(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class Touch Sensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.touchSensorObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class Touch Sensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.touchSensorObject\n")
+ }
+ break
+ case "capability.imageCapture":
+ break
+ case "device.mobilePresence":
+ break
+ case "device.aeonKeyFob":
+ break
+ case "mode":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ def userInput = System.console().readLine 'Enter the mode:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for mode!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for mode!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "decimal":
+ break
+ case "text":
+ break
+ case "number":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the number:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for number!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for number!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "time":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the time:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for time!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for time!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "enum":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the enum:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for enum!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for enum!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "bool":
+ break
+ case "phone":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the phone:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for phone!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for phone!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "contact":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the name of the contact:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for contact!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for contact!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ default:
+ break
+ }
+}
+//input linkedHashMap
+def input(LinkedHashMap metaData, String App) {
+ switch(metaData['type']) {
+ case "capability.lock":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (lockIsSet != 1) {
+ lockIsSet = 1
+ def count = System.console().readLine 'Enter the number of locks to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class lock!\n")
+ outGlobal.append("@Field def lockObject = new Locks(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (lockIsSet != 1) {
+ lockIsSet = 1
+ outGlobal.append("//Global Object for class lock!\n")
+ outGlobal.append("@Field def lockObject = new Locks(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class lock!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['input']+" = obj.lockObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class lock!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['input']+" = obj.lockObject\n")
+ }
+ break
+ case "capability.alarm":
+ break
+ case "capability.battery":
+ break
+ case "capability.beacon":
+ break
+ case "capability.carbonMonoxideDetector":
+ break
+ case "capability.colorControl":
+ break
+ case "capability.contactSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ def count = System.console().readLine 'Enter the number of contact sensors to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class contactSensor!\n")
+ outGlobal.append("@Field def contactObject = new ContactSensors(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ outGlobal.append("//Global Object for class contactSensor!\n")
+ outGlobal.append("@Field def contactObject = new ContactSensors(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class contactSensor!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['input']+" = obj.contactObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class contactSensor!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['input']+" = obj.contactObject\n")
+ }
+ break
+ case "capability.doorControl":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ def count = System.console().readLine 'Enter the number of doors to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class door control!\n")
+ outGlobal.append("@Field def doorControlObject = new DoorControls(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (doorControlIsSet != 1) {
+ doorControlIsSet = 1
+ outGlobal.append("//Global Object for class door control!\n")
+ outGlobal.append("@Field def doorControlObject = new DoorControls(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class door control!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['input']+" = obj.doorControlObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class door control!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['input']+" = obj.doorControlObject\n")
+ }
+ break
+ case "capability.energyMeter":
+ break
+ case "capability.illuminanceMeasurement":
+ break
+ case "capability.accelerationSensor":
+ break
+ case "capability.motionSensor":
+ break
+ case "capability.musicPlayer":
+ break
+ case "capability.powerMeter":
+ break
+ case "capability.presenceSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (presenceIsSet != 1) {
+ presenceIsSet = 1
+ def count = System.console().readLine 'Enter the number of presence sensors to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class presence sensor!\n")
+ outGlobal.append("@Field def presenceSensorObject = new PresenceSensors(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (presenceIsSet != 1) {
+ presenceIsSet = 1
+ outGlobal.append("//Global Object for class presence sensor!\n")
+ outGlobal.append("@Field def presenceSensorObject = new PresenceSensors(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class presence sensor!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['input']+" = obj.presenceSensorObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class presence sensor!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['input']+" = obj.presenceSensorObject\n")
+ }
+ break
+ case "capability.relativeHumidityMeasurement":
+ break
+ case "capability.relaySwitch":
+ break
+ case "capability.sleepSensor":
+ break
+ case "capability.smokeDetector":
+ break
+ case "capability.stepSensor":
+ break
+ case "capability.switch":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (switchIsSet != 1) {
+ switchIsSet = 1
+ def count = System.console().readLine 'Enter the number of switches to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class switch!\n")
+ outGlobal.append("@Field def switchObject = new Switches(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (switchIsSet != 1) {
+ switchIsSet = 1
+ outGlobal.append("//Global Object for class switch!\n")
+ outGlobal.append("@Field def switchObject = new Switches(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class switch!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['input']+" = obj.switchObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class switch!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['input']+" = obj.switchObject\n")
+ }
+ break
+ case "capability.switchLevel":
+ break
+ case "capability.temperatureMeasurement":
+ break
+ case "capability.thermostat":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (thermostatIsSet != 1) {
+ thermostatIsSet = 1
+ def count = System.console().readLine 'Enter the number of thermostats to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class thermostat!\n")
+ outGlobal.append("@Field def thermostatObject = new Thermostats(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (thermostatIsSet != 1) {
+ thermostatIsSet = 1
+ outGlobal.append("//Global Object for class thermostat!\n")
+ outGlobal.append("@Field def thermostatObject = new Thermostats(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class thermostat!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['input']+" = obj.thermostatObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class thermostat!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['input']+" = obj.thermostatObject\n")
+ }
+ break
+ case "capability.valve":
+ break
+ case "capability.waterSensor":
+ break
+ case "capability.touchSensor":
+ if (touchSensorIsSet != 1) {
+ touchSensorIsSet = 1
+ outGlobal.append("//Global Object for class Touch Sensor!\n")
+ outGlobal.append("@Field def touchSensorObject = new NfcTouch(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class Touch Sensor!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['input']+" = obj.touchSensorObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class Touch Sensor!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['input']+" = obj.touchSensorObject\n")
+ }
+ break
+ case "capability.imageCapture":
+ break
+ case "device.mobilePresence":
+ break
+ case "device.aeonKeyFob":
+ break
+ case "mode":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the mode:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for mode!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for mode!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ }
+ break
+ case "decimal":
+ break
+ case "text":
+ break
+ case "number":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the number:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for number!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for number!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = "+userInput+"\n")
+ }
+ break
+ case "time":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the time:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for time!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for time!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ }
+ break
+ case "enum":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the enum:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for enum!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for enum!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ }
+ break
+ case "bool":
+ break
+ case "phone":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the phone:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for phone!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for phone!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = "+userInput+"\n")
+ }
+ break
+ case "contact":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the name of the contact:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for contact!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for contact!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ }
+ break
+ default:
+ break
+ }
+}
--- /dev/null
+//Create a class for thermostat device
+package Thermostat
+import Timer.SimulatedTimer
+
+public class Thermostat {
+ private int id
+ private String label
+ private String displayName
+ private int temperature
+ private int currentCoolingSetpoint
+ private int currentHeatingSetpoint
+ private int coolingSetpoint
+ private int thermostatSetpoint
+ private int heatingSetpoint
+ private List coolingSetpointRange
+ private List thermostatSetpointRange
+ private List heatingSetpointRange
+ private List supportedThermostatFanModes
+ private List supportedThermostatModes
+ private String thermostatOperatingState
+ private String thermostatFanMode
+ private String thermostatMode
+ def sendEvent
+ def timers
+
+
+ Thermostat(Closure sendEvent, int id, String label, String displayName, int temperature, int currentCoolingSetpoint, int currentHeatingSetpoint, int coolingSetpoint,
+ int thermostatSetpoint, int heatingSetpoint, List coolingSetpointRange, List thermostatSetpointRange, List heatingSetpointRange,
+ List supportedThermostatFanModes, List supportedThermostatModes, String thermostatOperatingState, String thermostatFanMode, String thermostatMode) {
+ this.id = id
+ this.label = label
+ this.sendEvent = sendEvent
+ this.temperature = temperature
+ this.currentCoolingSetpoint = currentCoolingSetpoint
+ this.currentHeatingSetpoint = currentHeatingSetpoint
+ this.coolingSetpoint = coolingSetpoint
+ this.thermostatSetpoint = thermostatSetpoint
+ this.heatingSetpoint = heatingSetpoint
+ this.coolingSetpointRange = coolingSetpointRange
+ this.thermostatSetpointRange = thermostatSetpointRange
+ this.heatingSetpointRange = heatingSetpointRange
+ this.supportedThermostatFanModes = supportedThermostatFanModes
+ this.supportedThermostatModes = supportedThermostatModes
+ this.thermostatOperatingState = thermostatOperatingState
+ this.thermostatFanMode = thermostatFanMode
+ this.thermostatMode = thermostatMode
+ }
+
+
+ //By Apps
+ def setCoolingSetpoint(int coolingSetpoint) {
+ this.coolingSetpoint = coolingSetpoint
+ this.currentCoolingSetpoint = currentCoolingSetpoint
+ println("Cooling set point for the thermostat with id:$id is changed to $coolingSetpoint!")
+ }
+
+ def setHeatingSetpoint(int heatingSetpoint) {
+ this.heatingSetpoint = heatingSetpoint
+ this.currentHeatingSetpoint = currentHeatingSetpoint
+ println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
+ }
+
+ def setSchedule() {
+ //Not implemented yet
+ }
+
+ def setThermostatFanMode(String thermostatFanMode) {
+ this.thermostatFanMode = thermostatFanMode
+ println("Fan mode of the thermostat with id:$id is changed to $thermostatFanMode!")
+ }
+
+ def setThermostatMode(String thermostatMode) {
+ this.thermostatMode = thermostatMode
+ println("Mode of the thermostat with id:$id is changed to $thermostatMode!")
+ }
+
+
+ //By Model Checker
+ /*def setValue(String value) {
+ println("the door with id:$id is $value!")
+ this.lockLatestValue = this.lockState
+ this.lockState = value
+ this.currentLock = value
+ }*/
+}
--- /dev/null
+//Create a class for thermostat device
+package Thermostat
+import Timer.SimulatedTimer
+
+public class Thermostats{
+ int deviceNumbers
+ List thermostats
+ def sendEvent
+ def timers
+
+ //When we have only one device
+ private int id = 50
+ private String label = "thermostat"
+ private String displayName = "thermostat"
+ private int temperature = 66
+ private int currentCoolingSetpoint = 70
+ private int currentHeatingSetpoint = 50
+ private int coolingSetpoint = 70
+ private int thermostatSetpoint = 60
+ private int heatingSetpoint = 50
+ private coolingSetpointRange = [70, 90]
+ private thermostatSetpointRange = [50, 70]
+ private heatingSetpointRange = [20, 50]
+ private supportedThermostatFanModes = ["auto", "fanCirculate", "circulate", "fanOn", "on"]
+ private supportedThermostatModes = ["auto", "cool", "emergencyHeat", "heat", "off"]
+ private String thermostatOperatingState = "cooling"
+ private String thermostatFanMode = "auto"
+ private String thermostatMode = "auto"
+
+ Thermostats(Closure sendEvent, int deviceNumbers) {
+ this.sendEvent = sendEvent
+ this.timers = new SimulatedTimer()
+ this.deviceNumbers = deviceNumbers
+ this.thermostats = []
+ for (int i = 0;i < deviceNumbers;i++) {
+ thermostats.add(new Thermostat(sendEvent, i+50, label+i.toString(), displayName+i.toString(), this.temperature, this.currentCoolingSetpoint,
+ this.currentHeatingSetpoint, this.coolingSetpoint, this.thermostatSetpoint, this.heatingSetpoint, this.coolingSetpointRange,
+ this.thermostatSetpointRange, this.heatingSetpointRange, this.supportedThermostatFanModes, this.supportedThermostatModes,
+ this.thermostatOperatingState, this.thermostatFanMode, this.thermostatMode))
+ }
+ }
+
+ //Methods for closures
+ def count(Closure Input) {
+ thermostats.count(Input)
+ }
+ def size() {
+ thermostats.size()
+ }
+ def each(Closure Input) {
+ thermostats.each(Input)
+ }
+
+ //By Apps
+ def setCoolingSetpoint(int coolingSetpoint) {
+ thermostats*.setCoolingSetpoint(coolingSetpoint)
+ }
+
+ def setHeatingSetpoint(int heatingSetpoint) {
+ thermostats*.setHeatingSetpoint(heatingSetpoint)
+ }
+
+ def setSchedule() {
+ //Not implemented yet
+ }
+
+ def setThermostatFanMode(String thermostatFanMode) {
+ thermostats*.setThermostatFanMode(thermostatFanMode)
+ }
+
+ def setThermostatMode(String thermostatMode) {
+ thermostats*.setThermostatMode(thermostatMode)
+ }
+
+
+ //By Model Checker(There is no event based on thermostat?)
+ /*def setValue(LinkedHashMap eventDataMap) {
+ thermostats[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
+ if (deviceNumbers == 1)
+ this.lockState = locks[eventDataMap["deviceId"]].lockState
+ this.currentLock = locks[eventDataMap["deviceId"]].lockState
+ this.lockLatestValue = locks[eventDataMap["deviceId"]].lockLatestValue
+ sendEvent(eventDataMap)
+ }*/
+
+ def getAt(int ix) {
+ locks[ix]
+ }
+}
+
-// Generate a random variable
-Random random = new Random(1131)
-int nextRandom = 10
+def events = [1,2,3,4,5,6,7]
+def list = events.permutations()
+int count = Verify.getInt(0,list.size()-1)
+println "COUNT: " + count
-// Touch events
-new Thread() {
- @Override
- public void run() {
- while(true) {
- appObject.setValue([name: "Touched", value: "Touched", deviceId: 0, descriptionText: "",
+list[count].each {
+ switch(it) {
+ case 1:
+ appObject.setValue([name: "Touched", value: "Touched", deviceId: 0, descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
- Thread.sleep(random.nextInt(nextRandom));
-
- }
- }
-}.start()
-
-// Lock events
-new Thread() {
-
- @Override
- public void run() {
- while(true) {
- lockObject.setValue([name: "lock", value: "locked", deviceId: 0, descriptionText: "",
+ println "1"
+ break
+ case 2:
+ lockObject.setValue([name: "lock0", value: "locked", deviceId: 0, descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
- Thread.sleep(random.nextInt(nextRandom));
- }
- }
-}.start()
-
-new Thread() {
-
- @Override
- public void run() {
- while(true) {
- lockObject.setValue([name: "unlock", value: "unlocked", deviceId: 0, descriptionText: "",
+ println " 2"
+ break
+ case 3:
+ lockObject.setValue([name: "lock0", value: "unlocked", deviceId: 0, descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
- Thread.sleep(random.nextInt(nextRandom));
- }
- }
-}.start()
-
-// Contact sensor events
-new Thread() {
-
- @Override
- public void run() {
- while(true) {
- contactObject.setValue([name: "contact.open", value: "open", deviceId: 0, descriptionText: "",
+ println " 3"
+ break
+ case 4:
+ contactObject.setValue([name: "contact0", value: "open", deviceId: 0, descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
- Thread.sleep(random.nextInt(nextRandom));
-
- }
- }
-}.start()
-
-new Thread() {
-
- @Override
- public void run() {
- while(true) {
- contactObject.setValue([name: "contact.closed", value: "closed", deviceId: 0, descriptionText: "",
+ println " 4"
+ break
+ case 5:
+ contactObject.setValue([name: "contact0", value: "closed", deviceId: 0, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ println " 5"
+ break
+ case 6:
+ switchObject.setValue([name: "switch0", value: "on", deviceId: 0, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ println " 6"
+ break
+ case 7:
+ switchObject.setValue([name: "switch0", value: "off", deviceId: 0, descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
- Thread.sleep(random.nextInt(nextRandom));
-
- }
- }
-}.start()
+ println " 7"
+ default:
+ break
+ }
+}
import groovy.transform.Field
//Importing Classes
-import ContactSensor.Contacting
-import ContactSensor.Contacts
-import Lock.Locking
+import ContactSensor.ContactSensor
+import ContactSensor.ContactSensors
+import DoorControl.DoorControl
+import DoorControl.DoorControls
+import Lock.Lock
import Lock.Locks
-import Switch.Switching
+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 Event.Event
import Timer.SimulatedTimer
}
//Object for location
@Field def locationObject = new LocationVar()
-//Object for touch
+//Object for touch to call function
@Field def appObject = new Touched(sendEvent, 0)
//Create a global list for events
@Field def evt = []
-
-//Extracted global objects for both Apps
-//Global Object for class lock!
-@Field def lockObject = new Locking(sendEvent,1)
-//Global Object for class contactSensor!
-@Field def contactObject = new Contacting(sendEvent,1)
+//Global Object for class Touch Sensor!
+@Field def touchSensorObject = new NfcTouch(sendEvent, 1)
//Global Object for class switch!
-@Field def switchObject = new Switching(sendEvent, 1)
+@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)
//Application #1
class App1 {
def app
//Extracted objects for App1
+ //Object for class Touch Sensor!
+ def tag
+ //Object for class switch!
+ def switch1
//Object for class lock!
- def lock1
- //Object for class contactSensor!
- def contact
- //Global variable for number!
- def minutesLater = 1
- //Global variable for number!
- def secondsLater = 10
- //Global variable for contact!
- def recipients = "AJ"
- //Global variable for phone!
- def phoneNumber = 9495379373
+ def lock
+ //Object for class door control!
+ def garageDoor
+ //Global variable for enum!
+ def masterSwitch = "40"
+ //Global variable for enum!
+ def masterLock = "20"
+ //Global variable for enum!
+ def masterDoor = "40"
//Extracted objects for functions for App1
//Global Object for functions in subscribe method!
+ def pageTwo = this.&pageTwo
+ //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
+ def currentStatus = this.¤tStatus
//Global Object for functions in subscribe method!
- def unlockDoor = this.&unlockDoor
- //Global Object for functions in subscribe method!
- def doorHandler = this.&doorHandler
+ def touchHandler = this.&touchHandler
App1(Object obj) {
reference = obj
location = obj.locationObject
app = obj.appObject
- lock1 = obj.lockObject
- contact = obj.contactObject
+ tag = obj.touchSensorObject
+ switch1 = obj.switchObject
+ lock = obj.lockObject
+ garageDoor = obj.doorControlObject
}
//Global variables for each app
//Settings variable defined to settings on purpose
/////////////////////////////////////////////////////////////////////
////subscribe(obj, func)
def subscribe(Object obj, Closure FunctionToCall) {
- objectList.add(obj)
- eventList.add("Touched")
- functionList.add(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) {
}
}
- def installed(){
- initialize()
+ def pageTwo() {
+ dynamicPage(name: "pageTwo") {
+ section("If set, the state of these devices will be toggled each time the tag is touched, " +
+ "e.g. a light that's on will be turned off and one that's off will be turned on, " +
+ "other devices of the same type will be set to the same state as their master device. " +
+ "If no master is designated then the majority of devices of the same type will be used " +
+ "to determine whether to turn on or off the devices.") {
+
+ if (switch1 || masterSwitch) {
+ input "masterSwitch", "enum", title: "Master switch", options: switch1.collect{[(it.id): it.displayName]}, required: false
+ }
+ if (lock || masterLock) {
+ input "masterLock", "enum", title: "Master lock", options: lock.collect{[(it.id): it.displayName]}, required: false
+ }
+ if (garageDoor || masterDoor) {
+ input "masterDoor", "enum", title: "Master door", options: garageDoor.collect{[(it.id): it.displayName]}, required: false
+ }
+ }
+ section([mobileOnly:true]) {
+ label title: "Assign a name", required: false
+ mode title: "Set for specific mode(s)", required: false
+ }
+ }
}
- def updated(){
- unsubscribe()
- unschedule()
- initialize()
+ def installed() {
+ log.debug "Installed with settings: ${settings}"
+
+ 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 updated() {
+ log.debug "Updated with settings: ${settings}"
+
+ unsubscribe()
+ initialize()
}
- 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 initialize() {
+ subscribe tag, "nfcTouch", touchHandler
+ subscribe app, touchHandler
}
- 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)
- }
+ private currentStatus(devices, master, attribute) {
+ log.trace "currentStatus($devices, $master, $attribute)"
+ def result = null
+ if (master) {
+ result = devices.find{it.id == master}?.currentValue(attribute)
}
- if ( phoneNumber ) {
- log.debug("Sending text message...")
- sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!")
+ else {
+ def map = [:]
+ devices.each {
+ def value = it.currentValue(attribute)
+ map[value] = (map[value] ?: 0) + 1
+ log.trace "$it.displayName: $value"
+ }
+ log.trace map
+ result = map.collect{it}.sort{it.value}[-1].key
}
+ log.debug "$attribute = $result"
+ result
}
- 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.
+ def touchHandler(evt) {
+ log.trace "touchHandler($evt.descriptionText)"
+ if (switch1) {
+ def status = currentStatus(switch1, masterSwitch, "switch")
+ switch1.each {
+ if (status == "on") {
+ it.off()
+ }
+ else {
+ it.on()
+ }
+ }
}
- 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 (lock) {
+ def status = currentStatus(lock, masterLock, "lock")
+ lock.each {
+ if (status == "locked") {
+ lock.unlock()
+ }
+ else {
+ lock.lock()
}
}
- if ( phoneNumber ) {
- log.debug("Sending text message...")
- sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!")
+ }
+
+ if (garageDoor) {
+ def status = currentStatus(garageDoor, masterDoor, "status")
+ garageDoor.each {
+ if (status == "open") {
+ it.close()
+ }
+ else {
+ it.open()
+ }
}
}
}
//Object for class lock!
def lock1
//Global variable for mode!
- def newMode = "away"
+ def newMode = "home"
//Global variable for number!
- def waitfor = 4
+ def waitfor = 10
//Extracted objects for functions for App2
//Global Object for functions in subscribe method!
/////////////////////////////////////////////////////////////////////
////subscribe(obj, func)
def subscribe(Object obj, Closure FunctionToCall) {
- objectList.add(obj)
- eventList.add("Touched")
- functionList.add(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) {
app1.installed()
app2.installed()
- // Generate a random variable
- Random random = new Random(1131)
- int nextRandom = 10
-
- // Touch events
- new Thread() {
- @Override
- public void run() {
- while(true) {
- appObject.setValue([name: "Touched", value: "Touched", deviceId: 0, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
- Thread.sleep(random.nextInt(nextRandom));
-
- }
- }
- }.start()
-
- // Lock events
- new Thread() {
-
- @Override
- public void run() {
- while(true) {
- lockObject.setValue([name: "lock", value: "locked", deviceId: 0, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
- Thread.sleep(random.nextInt(nextRandom));
- }
- }
- }.start()
-
- new Thread() {
-
- @Override
- public void run() {
- while(true) {
- lockObject.setValue([name: "unlock", value: "unlocked", deviceId: 0, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
- Thread.sleep(random.nextInt(nextRandom));
- }
- }
- }.start()
-
- // Contact sensor events
- new Thread() {
-
- @Override
- public void run() {
- while(true) {
- contactObject.setValue([name: "contact.open", value: "open", deviceId: 0, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
- Thread.sleep(random.nextInt(nextRandom));
-
- }
- }
- }.start()
-
- new Thread() {
-
- @Override
- public void run() {
- while(true) {
- contactObject.setValue([name: "contact.closed", value: "closed", deviceId: 0, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
- Thread.sleep(random.nextInt(nextRandom));
-
- }
- }
- }.start()
+def events = [1,2,3,4,5,6,7]
+def list = events.permutations()
+int count = Verify.getInt(0,list.size()-1)
+println "COUNT: " + count
+
+list[count].each {
+ switch(it) {
+ case 1:
+ appObject.setValue([name: "Touched", value: "Touched", deviceId: 0, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ println "1"
+ break
+ case 2:
+ lockObject.setValue([name: "lock0", value: "locked", deviceId: 0, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ println " 2"
+ break
+ case 3:
+ lockObject.setValue([name: "lock0", value: "unlocked", deviceId: 0, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ println " 3"
+ break
+ case 4:
+ contactObject.setValue([name: "contact0", value: "open", deviceId: 0, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ println " 4"
+ break
+ case 5:
+ contactObject.setValue([name: "contact0", value: "closed", deviceId: 0, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ println " 5"
+ break
+ case 6:
+ switchObject.setValue([name: "switch0", value: "on", deviceId: 0, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ println " 6"
+ break
+ case 7:
+ switchObject.setValue([name: "switch0", value: "off", deviceId: 0, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+ println " 7"
+ default:
+ break
+ }
+}