Commit #7: Events thread-based + new easier Extractor.py + our own Timer class
authoramiraj <amiraj.95@uci.edu>
Fri, 12 Jul 2019 00:24:02 +0000 (17:24 -0700)
committeramiraj <amiraj.95@uci.edu>
Fri, 12 Jul 2019 00:24:02 +0000 (17:24 -0700)
60 files changed:
ContactSensor/Contacting.groovy
ContactSensor/Contacts.groovy
Event/Event.groovy
Extractor/App1.groovy [deleted file]
Extractor/App1/App1.groovy [new file with mode: 0644]
Extractor/App1/extractedFunctionsApp1.groovy [new file with mode: 0644]
Extractor/App1/extractedObjectsApp1.groovy [new file with mode: 0644]
Extractor/App1/extractedObjectsConstructorApp1.groovy [new file with mode: 0644]
Extractor/App1/inputMethodsFile1.groovy [new file with mode: 0644]
Extractor/App2.groovy [deleted file]
Extractor/App2/App2.groovy [new file with mode: 0644]
Extractor/App2/extractedFunctionsApp2.groovy [new file with mode: 0644]
Extractor/App2/extractedObjectsApp2.groovy [new file with mode: 0644]
Extractor/App2/extractedObjectsConstructorApp2.groovy [new file with mode: 0644]
Extractor/App2/inputMethodsFile2.groovy [new file with mode: 0644]
Extractor/ExtractorScript.py
Extractor/extractedObjectsApp1.groovy [deleted file]
Extractor/extractedObjectsApp2.groovy [deleted file]
Extractor/extractedObjectsConstructorApp1.groovy [deleted file]
Extractor/extractedObjectsConstructorApp2.groovy [deleted file]
Extractor/extractorFile.groovy [new file with mode: 0644]
Extractor/inputMethods.groovy [new file with mode: 0644]
Extractor/outGlobal.groovy
Lock/Locking.groovy
Lock/Locks.groovy
Methods/eventHandler.groovy
Methods/runIn.groovy
Methods/schedule.groovy [new file with mode: 0644]
Methods/sendNotificationToContacts.groovy
Methods/sendPush.groovy [new file with mode: 0644]
Methods/unschedule.groovy
Runner.py
Switch/Switches.groovy
Switch/Switching.groovy
Timer/SimulatedTimer.groovy [new file with mode: 0644]
bin/main/App1.class [deleted file]
bin/main/App2.class [deleted file]
bin/main/ContactSensor/Contacting.class [deleted file]
bin/main/ContactSensor/Contacts.class [deleted file]
bin/main/Event/Event.class [deleted file]
bin/main/Location/LocationVar.class [deleted file]
bin/main/Location/Phrase.class [deleted file]
bin/main/Lock/Locking$_lock_closure1.class [deleted file]
bin/main/Lock/Locking$_unlock_closure2.class [deleted file]
bin/main/Lock/Locking.class [deleted file]
bin/main/Lock/Locks$_lock_closure1.class [deleted file]
bin/main/Lock/Locks$_unlock_closure2.class [deleted file]
bin/main/Lock/Locks.class [deleted file]
bin/main/Logger/Logger.class [deleted file]
bin/main/Switch/Switches$_off_closure2.class [deleted file]
bin/main/Switch/Switches$_on_closure1.class [deleted file]
bin/main/Switch/Switches.class [deleted file]
bin/main/Switch/Switching$_off_closure2.class [deleted file]
bin/main/Switch/Switching$_on_closure1.class [deleted file]
bin/main/Switch/Switching.class [deleted file]
bin/main/appTouch/Touched.class [deleted file]
bin/main/main$_closure1.class [deleted file]
bin/main/main.class [deleted file]
eventSimulator/eventSimulator.groovy [new file with mode: 0644]
main.groovy

index 9b293e877bffeb109d7f0e35c096e9b68f2f4852..a744889f438edb8cfbeb438579e13efe29e2d820 100644 (file)
@@ -1,17 +1,27 @@
 //Create a class for contact sensor
 package ContactSensor
+import Timer.SimulatedTimer
 
-public class Contacting{
+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(0, "contact0", "closed", "closed")]
+                       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) {
@@ -23,6 +33,9 @@ public class Contacting{
        //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)
        }
 
index 90bd008fa67312172798bba04f1dab6474f6877f..3796b6088000cd10c2ccdb221e748ce1c9779362 100644 (file)
@@ -1,28 +1,29 @@
 //Create a class for contact sensor
 package ContactSensor
+import Timer.SimulatedTimer
 
 public class Contacts {
        private int id
        private String displayName
-       private String contactCurrentValue
+       private String contactState
        private String contactLatestValue
 
-       Contacts(int id, String displayName, String contactCurrentValue, String contactLatestValue) {
+       Contacts(int id, String displayName, String contactState, String contactLatestValue) {
                this.id = id
                this.displayName = displayName
-               this.contactCurrentValue = contactCurrentValue
+               this.contactState = contactState
                this.contactLatestValue = contactLatestValue
        }
 
        def setValue(String value) {
-               this.contactLatestValue = contactCurrentValue
+               this.contactLatestValue = contactState
                println("the contact sensor with id:$id is triggered to $value!")
-               this.contactCurrentValue = value
+               this.contactState = value
        }
        
        def currentValue(String deviceFeature) {
                if (deviceFeature == "contact") {
-                       return contactCurrentValue
+                       return contactState
                }
        }
 
index a1d5e71d1b5b80f55eada67cf6dbe136254e1e3b..794dbca4387c59a98b08241e082f1ecba0e717f5 100644 (file)
@@ -11,18 +11,18 @@ public class Event {
        private String descriptionText
        private boolean isStateChange
        private String unit
-       private LinkedHashMap data
+       private ArrayList data
        
-       Event() {
-               this.deviceId = 0
-               this.linkText = ""
-               this.value = ""
-               this.displayName = ""
-               this.name = ""
-               this.descriptionText = ""
-               this.isStateChange = false
-               this.unit = ""
-               this.data = []
-               this.displayed = false
+       Event(String value, String name, int deviceId, String descriptionText, boolean displayed, String linkText, String displayName, boolean isStateChange, String unit, ArrayList data) {
+               this.deviceId = deviceId
+               this.linkText = linkText
+               this.value = value
+               this.displayName = displayName
+               this.name = name
+               this.descriptionText = descriptionText
+               this.isStateChange = isStateChange
+               this.unit = unit
+               this.data = data
+               this.displayed = displayed
        }
 }
diff --git a/Extractor/App1.groovy b/Extractor/App1.groovy
deleted file mode 100644 (file)
index 1c2c55f..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-//////////
-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"
-)
-
-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
-        }
-    }
-}
-
-def installed(){
-    initialize()
-}
-
-def updated(){
-    unsubscribe()
-    unschedule()
-    initialize()
-}
-
-def initialize(){
-    log.debug "Settings: ${settings}"
-    subscribe(lock1, "lock", doorHandler, [filterEvents: false])
-    subscribe(lock1, "unlock", doorHandler, [filterEvents: false])  
-    subscribe(contact, "contact.open", doorHandler)
-    subscribe(contact, "contact.closed", doorHandler)
-}
-
-def lockDoor(){
-    log.debug "Locking the door."
-    lock1.lock()
-    if(location.contactBookEnabled) {
-        if ( recipients ) {
-            log.debug ( "Sending Push Notification..." ) 
-            sendNotificationToContacts( "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!", recipients)
-        }
-    }
-    if (phoneNumber) {
-        log.debug("Sending text message...")
-        sendSms( phoneNumber, "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!")
-    }
-}
-
-def unlockDoor(){
-    log.debug "Unlocking the door."
-    lock1.unlock()
-    if(location.contactBookEnabled) {
-        if ( recipients ) {
-            log.debug ( "Sending Push Notification..." ) 
-            sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!", recipients)
-        }
-    }
-    if ( phoneNumber ) {
-        log.debug("Sending text message...")
-        sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!")
-    }
-}
-
-def doorHandler(evt){
-    if ((contact.latestValue("contact") == "open") && (evt.value == "locked")) { // If the door is open and a person locks the door then...  
-        //def delay = (secondsLater) // runIn uses seconds
-        runIn( secondsLater, unlockDoor )   // ...schedule (in minutes) to unlock...  We don't want the door to be closed while the lock is engaged. 
-    }
-    else if ((contact.latestValue("contact") == "open") && (evt.value == "unlocked")) { // If the door is open and a person unlocks it then...
-        unschedule( unlockDoor ) // ...we don't need to unlock it later.
-    }
-    else if ((contact.latestValue("contact") == "closed") && (evt.value == "locked")) { // If the door is closed and a person manually locks it then...
-        unschedule( lockDoor ) // ...we don't need to lock it later.
-    }   
-    else if ((contact.latestValue("contact") == "closed") && (evt.value == "unlocked")) { // If the door is closed and a person unlocks it then...
-       //def delay = (minutesLater * 60) // runIn uses seconds
-        runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
-    }
-    else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "open")) { // If a person opens an unlocked door...
-        unschedule( lockDoor ) // ...we don't need to lock it later.
-    }
-    else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "closed")) { // If a person closes an unlocked door...
-        //def delay = (minutesLater * 60) // runIn uses seconds
-        runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
-    }
-    else { //Opening or Closing door when locked (in case you have a handle lock)
-        log.debug "Unlocking the door."
-        lock1.unlock()
-        if(location.contactBookEnabled) {
-            if ( recipients ) {
-                log.debug ( "Sending Push Notification..." ) 
-                sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!", recipients)
-            }
-        }
-        if ( phoneNumber ) {
-            log.debug("Sending text message...")
-            sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!")
-        }
-    }
-}
diff --git a/Extractor/App1/App1.groovy b/Extractor/App1/App1.groovy
new file mode 100644 (file)
index 0000000..1c2c55f
--- /dev/null
@@ -0,0 +1,116 @@
+//////////
+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"
+)
+
+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
+        }
+    }
+}
+
+def installed(){
+    initialize()
+}
+
+def updated(){
+    unsubscribe()
+    unschedule()
+    initialize()
+}
+
+def initialize(){
+    log.debug "Settings: ${settings}"
+    subscribe(lock1, "lock", doorHandler, [filterEvents: false])
+    subscribe(lock1, "unlock", doorHandler, [filterEvents: false])  
+    subscribe(contact, "contact.open", doorHandler)
+    subscribe(contact, "contact.closed", doorHandler)
+}
+
+def lockDoor(){
+    log.debug "Locking the door."
+    lock1.lock()
+    if(location.contactBookEnabled) {
+        if ( recipients ) {
+            log.debug ( "Sending Push Notification..." ) 
+            sendNotificationToContacts( "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!", recipients)
+        }
+    }
+    if (phoneNumber) {
+        log.debug("Sending text message...")
+        sendSms( phoneNumber, "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!")
+    }
+}
+
+def unlockDoor(){
+    log.debug "Unlocking the door."
+    lock1.unlock()
+    if(location.contactBookEnabled) {
+        if ( recipients ) {
+            log.debug ( "Sending Push Notification..." ) 
+            sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!", recipients)
+        }
+    }
+    if ( phoneNumber ) {
+        log.debug("Sending text message...")
+        sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!")
+    }
+}
+
+def doorHandler(evt){
+    if ((contact.latestValue("contact") == "open") && (evt.value == "locked")) { // If the door is open and a person locks the door then...  
+        //def delay = (secondsLater) // runIn uses seconds
+        runIn( secondsLater, unlockDoor )   // ...schedule (in minutes) to unlock...  We don't want the door to be closed while the lock is engaged. 
+    }
+    else if ((contact.latestValue("contact") == "open") && (evt.value == "unlocked")) { // If the door is open and a person unlocks it then...
+        unschedule( unlockDoor ) // ...we don't need to unlock it later.
+    }
+    else if ((contact.latestValue("contact") == "closed") && (evt.value == "locked")) { // If the door is closed and a person manually locks it then...
+        unschedule( lockDoor ) // ...we don't need to lock it later.
+    }   
+    else if ((contact.latestValue("contact") == "closed") && (evt.value == "unlocked")) { // If the door is closed and a person unlocks it then...
+       //def delay = (minutesLater * 60) // runIn uses seconds
+        runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
+    }
+    else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "open")) { // If a person opens an unlocked door...
+        unschedule( lockDoor ) // ...we don't need to lock it later.
+    }
+    else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "closed")) { // If a person closes an unlocked door...
+        //def delay = (minutesLater * 60) // runIn uses seconds
+        runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
+    }
+    else { //Opening or Closing door when locked (in case you have a handle lock)
+        log.debug "Unlocking the door."
+        lock1.unlock()
+        if(location.contactBookEnabled) {
+            if ( recipients ) {
+                log.debug ( "Sending Push Notification..." ) 
+                sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!", recipients)
+            }
+        }
+        if ( phoneNumber ) {
+            log.debug("Sending text message...")
+            sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!")
+        }
+    }
+}
diff --git a/Extractor/App1/extractedFunctionsApp1.groovy b/Extractor/App1/extractedFunctionsApp1.groovy
new file mode 100644 (file)
index 0000000..b7e30e6
--- /dev/null
@@ -0,0 +1,12 @@
+//Global Object for functions in subscribe method!
+def installed = this.&installed
+//Global Object for functions in subscribe method!
+def updated = this.&updated
+//Global Object for functions in subscribe method!
+def initialize = this.&initialize
+//Global Object for functions in subscribe method!
+def lockDoor = this.&lockDoor
+//Global Object for functions in subscribe method!
+def unlockDoor = this.&unlockDoor
+//Global Object for functions in subscribe method!
+def doorHandler = this.&doorHandler
diff --git a/Extractor/App1/extractedObjectsApp1.groovy b/Extractor/App1/extractedObjectsApp1.groovy
new file mode 100644 (file)
index 0000000..be7bc9f
--- /dev/null
@@ -0,0 +1,12 @@
+//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
diff --git a/Extractor/App1/extractedObjectsConstructorApp1.groovy b/Extractor/App1/extractedObjectsConstructorApp1.groovy
new file mode 100644 (file)
index 0000000..2e3aa8e
--- /dev/null
@@ -0,0 +1,2 @@
+lock1 = obj.lockObject
+contact = obj.contactObject
diff --git a/Extractor/App1/inputMethodsFile1.groovy b/Extractor/App1/inputMethodsFile1.groovy
new file mode 100644 (file)
index 0000000..0310df4
--- /dev/null
@@ -0,0 +1,6 @@
+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"
diff --git a/Extractor/App2.groovy b/Extractor/App2.groovy
deleted file mode 100644 (file)
index 176a336..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- *  Good Night House
- *
- *  Copyright 2014 Joseph Charette
- *
- *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- *  in compliance with the License. You may obtain a copy of the License at:
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
- *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
- *  for the specific language governing permissions and limitations under the License.
- *
- */
-definition(
-    name: "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)
-}
diff --git a/Extractor/App2/App2.groovy b/Extractor/App2/App2.groovy
new file mode 100644 (file)
index 0000000..0af812f
--- /dev/null
@@ -0,0 +1,66 @@
+/////
+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)
+}
diff --git a/Extractor/App2/extractedFunctionsApp2.groovy b/Extractor/App2/extractedFunctionsApp2.groovy
new file mode 100644 (file)
index 0000000..6d9060e
--- /dev/null
@@ -0,0 +1,6 @@
+//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 appTouch = this.&appTouch
diff --git a/Extractor/App2/extractedObjectsApp2.groovy b/Extractor/App2/extractedObjectsApp2.groovy
new file mode 100644 (file)
index 0000000..7089b9b
--- /dev/null
@@ -0,0 +1,10 @@
+//Object for class switch!
+def switchesoff
+//Object for class switch!
+def switcheson
+//Object for class lock!
+def lock1
+//Global variable for mode!
+def newMode = "away"
+//Global variable for number!
+def waitfor = 4
diff --git a/Extractor/App2/extractedObjectsConstructorApp2.groovy b/Extractor/App2/extractedObjectsConstructorApp2.groovy
new file mode 100644 (file)
index 0000000..709a386
--- /dev/null
@@ -0,0 +1,3 @@
+switchesoff = obj.switchObject
+switcheson = obj.switchObject
+lock1 = obj.lockObject
diff --git a/Extractor/App2/inputMethodsFile2.groovy b/Extractor/App2/inputMethodsFile2.groovy
new file mode 100644 (file)
index 0000000..a5d4302
--- /dev/null
@@ -0,0 +1,5 @@
+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"
index e925f5ff6cc089b7ea5a76cb735116cab9285c76..2d4493cee90f6bd2226fb2a4084121766bdc2341 100644 (file)
@@ -1,10 +1,12 @@
+import os
 readyToReturn = 0
 ToReturn = ""
 
 def GetToken(f):
        global readyToReturn
        global ToReturn
-       Skip = ["(", "\"", ":", ",", "{", "}", ")", '\n', '\t', ' ', "/"]
+       Skip = ['\n', '\t', ' ']
+       Special = ["(", "\"", ":", ",", "{", "}", ")", "/", "*"]
        S = ""
        if (readyToReturn):
                readyToReturn = 0
@@ -12,242 +14,104 @@ def GetToken(f):
        ToReturn = ""
        c = f.read(1)
        while(True):
-               if (c in Skip):
+               if (c in Special):
                        if (S != ""):
-                               if (c == "{" or c == "}"):
-                                       readyToReturn = 1
-                                       ToReturn = c
-                                       return S
-                               else:
-                                       return S
-                                       
+                               readyToReturn = 1
+                               ToReturn = c
+                               return S
                        else:
-                               if (c == "{" or c == "}"):
-                                       return c
-                               else:
-                                       c = f.read(1)
-                                       continue
+                               return c
+               elif (c in Skip):
+                       if (S != ""):
+                               return S        
+                       else:
+                               c = f.read(1)
+                               continue
                S += c
                c = f.read(1)
                if not c:
                        return "EOF"
-               
-#For both apps 
-outGlobal = open("Extractor/outGlobal.groovy", "w+")
-lockIsSet = 0
-ContactIsSet = 0
-SwitchIsSet = 0
-
-
-def ExtractorFunc(F, outApp, outConstructorApp, Temp):
-       global outGlobal
-       global lockIsSet
-       global ContactIsSet
-       global SwitchIsSet
 
+def ExtractMethods(F, inputMethodsFile, appName):
+       Temp = GetToken(F)
+       inputMethod = ""
        while (Temp != "EOF"):
-               #Extract the global objects for input
+               #Extract the input methods
                if (Temp == "input"):
-                       Object = ""
-                       Type = ""
-                       Temp = GetToken(F) #name or "name"
-                       #input name: "name", type: "type",...
-                       if (Temp == "name"):
-                               Temp = GetToken(F) #"name"
-                               Object = Temp
-                               GetToken(F) #type
-                               Temp = GetToken(F) #"type"
-                               Type = Temp             
-                       #input "name", "type",...
-                       else:
-                               Object = Temp
-                               Temp = GetToken(F) #"type"
-                               Type = Temp
-                       Temp = GetToken(F)
-                       Title = ""
-                       Required = ""
-                       Multiple = ""
-                       while (Temp != "input" and Temp != "}"):
-                               if (Temp == "title"):
+                       inputMethod += Temp
+                       Temp = GetToken(F) #",(,input
+                       #input "","",linkedHashMap
+                       if (Temp == "\""):
+                               while (Temp!="input" and Temp!="}"):
+                                       inputMethod += Temp
                                        Temp = GetToken(F)
-                                       Title = Temp
-                               elif (Temp == "required"):
+                               inputMethod += ",\""+appName+"\""
+                       #input ()
+                       elif (Temp == "("):
+                               while (Temp!=")"):
+                                       inputMethod += Temp
                                        Temp = GetToken(F)
-                                       Required = Temp
-                               elif (Temp == "multiple"):
+                               inputMethod += ",\""+appName+"\")"
+                       #input linkedHashMap
+                       elif (Temp == "input"):
+                               while (Temp!="input" and Temp!="}"):
+                                       inputMethod += Temp
                                        Temp = GetToken(F)
-                                       Multiple = Temp
-                               Temp = GetToken(F)                      
-                       if (Type == "capability.lock"):
-                               if (Title != ""):
-                                       print(Object+", "+Title)
-                               if (Multiple != "" and Multiple == "true" and lockIsSet != 1):
-                                       lockIsSet = 1
-                                       g = raw_input("Enter the number of locks to control: (1, 2, or 3)\n") 
-                                       outGlobal.write("//Global Object for class lock!\n")
-                                       outGlobal.write("@Field def lockObject = new Locking(sendEvent, ")
-                                       outGlobal.write("%s)\n" % g)
-                               elif ((Multiple == "" or Multiple == "false") and lockIsSet != 1):
-                                       lockIsSet = 1
-                                       outGlobal.write("//Global Object for class lock!\n")
-                                       outGlobal.write("@Field def lockObject = new Locking(sendEvent, 1)\n")
-                               outApp.write("//Object for class lock!\n")
-                               outApp.write("def %s\n" % Object)
-                               outConstructorApp.write("%s = obj.lockObject\n" % Object)
-                       #elif (Type == "capability.alarm"):
-
-                       #elif (Type == "capability.battery"):
-
-                       #elif (Type == "capability.beacon"):
-
-                       #elif (Type == "capability.carbonMonoxideDetector"):
-
-                       #elif (Type == "capability.colorControl"):
-
-                       elif (Type == "capability.contactSensor"):
-                               if (Title != ""):
-                                       print(Object+", "+Title)
-                               if (Multiple != "" and Multiple == "true" and ContactIsSet != 1):
-                                       ContactIsSet = 1
-                                       g = raw_input("Enter the number of contact sensors to control: (1, 2, or 3)\n") 
-                                       outGlobal.write("//Global Object for class contactSensor!\n")
-                                       outGlobal.write("@Field def contactObject = new Contacting(sendEvent, ")
-                                       outGlobal.write("%s)\n" % g)
-                               elif ((Multiple == "" or Multiple == "false") and ContactIsSet != 1):
-                                       ContactIsSet = 1
-                                       outGlobal.write("//Global Object for class contactSensor!\n")
-                                       outGlobal.write("@Field def contactObject = new Contacting(sendEvent, 1)\n")
-                               outApp.write("//Object for class contactSensor!\n")
-                               outApp.write("def %s\n" % Object)
-                               outConstructorApp.write("%s = obj.contactObject\n" % Object)
-                       #elif (Type == "capability.doorControl"):
-
-                       #elif (Type == "capability.energyMeter"):
-
-                       #elif (Type == "capability.illuminanceMeasurement"):
-
-                       #elif (Type == "capability.accelerationSensor"):
-
-                       #elif (Type == "capability.motionSensor"):
-
-                       #elif (Type == "capability.musicPlayer"):
-
-                       #elif (Type == "capability.powerMeter"):
-
-                       #elif (Type == "capability.presenceSensor"):
-
-                       #elif (Type == "capability.relativeHumidityMeasurement"):
-
-                       #elif (Type == "capability.relaySwitch"):
-
-                       #elif (Type == "capability.sleepSensor"):
-
-                       #elif (Type == "capability.smokeDetector"):
-
-                       #elif (Type == "capability.stepSensor"):
-
-                       elif (Type == "capability.switch"):
-                               if (Title != ""):
-                                       print(Object+", "+Title)
-                               if (Multiple != "" and Multiple == "true" and SwitchIsSet != 1):
-                                       SwitchIsSet = 1
-                                       g = raw_input("Enter the number of switches to control: (1, 2, or 3)\n") 
-                                       outGlobal.write("//Global Object for class Switch!\n")
-                                       outGlobal.write("@Field def switchObject = new Switching(sendEvent, ")
-                                       outGlobal.write("%s)\n" % g)
-                               elif ((Multiple == "" or Multiple == "false") and SwitchIsSet != 1):
-                                       SwitchIsSet = 1
-                                       outGlobal.write("//Global Object for class Switch!\n")
-                                       outGlobal.write("@Field def switchObject = new Switching(sendEvent, 1)\n")
-                               outApp.write("//Object for class Switch!\n")
-                               outApp.write("def %s\n" % Object)
-                               outConstructorApp.write("%s = obj.switchObject\n" % Object)
-                       #elif (Type == "capability.switchLevel"):
-
-                       #elif (Type == "capability.temperatureMeasurement"):
-               
-                       #elif (Type == "capability.thermostat"):
-                       
-                       #elif (Type == "capability.valve"):
-
-                       #elif (Type == "capability.waterSensor"):
-
-                       #elif (Type == "capability.touchSensor"):
-
-                       #elif (Type == "capability.imageCapture"):
-
-                       #elif (Type == "device.mobilePresence"):
-
-                       #elif (Type == "device.aeonKeyFob"):
-
-                       elif (Type == "mode"):
-                               if (Title != ""):
-                                       print(Object+", "+Title)
-                               g = raw_input("Enter the mode: ") 
-                               outApp.write("//Global variable for mode!\n")
-                               outApp.write("def %s = " % Object)
-                               outApp.write("\"%s\"\n" % g)
-                       #elif (Type == "decimal"):
-
-                       #elif (Type == "text"):
-                       
-                       elif (Type == "number"):
-                               if (Title != ""):
-                                       print(Object+", "+Title)
-                               g = raw_input("Enter the number: ") 
-                               outApp.write("//Global variable for number!\n")
-                               outApp.write("def %s = " % Object)
-                               outApp.write("%s\n" % g)
-                       #elif (Type == "time"):
-
-                       #elif (Type == "enum"):
-
-                       #elif (Type == "bool"):
-
-                       elif (Type == "phone"):
-                               if (Title != ""):
-                                       print(Object+", "+Title)
-                               g = raw_input("Enter the number to send notification to:\n") 
-                               outApp.write("//Global variable for phone number!\n")
-                               outApp.write("def %s = " % Object)
-                               outApp.write("%s\n" % g)
-                       elif (Type == "contact"):
-                               if (Title != ""):
-                                       print(Object+", "+Title)
-                               g = raw_input("Enter the name of the recipients:\n") 
-                               outApp.write("//Global variable for recipients!\n")
-                               g = g.split()
-                               outApp.write("def %s = " % Object)
-                               outApp.write("%s\n" % g)
-               #Extract the global object for functions
+                               inputMethod += ",\""+appName+"\""
                elif (Temp == "def"):
                        Temp = GetToken(F)
                        NameofFunc = Temp
                        if (GetToken(F) != "="): #We have a function to create object for
-                               outApp.write("//Global Object for functions in subscribe method!\n")    
-                               outApp.write("def %s = this.&" % NameofFunc)
-                               outApp.write("%s\n" % NameofFunc)
-               if (Temp != "input"):
-                       Temp = GetToken(F)
-       
-       F.close()
-       outApp.close()
-       outConstructorApp.close()
-
-#For app1
-F = open("Extractor/App1.groovy", "r")
-outApp = open("Extractor/extractedObjectsApp1.groovy", "w+")
-outConstructorApp = open("Extractor/extractedObjectsConstructorApp1.groovy", "w+")
-Temp = GetToken(F)
-
-ExtractorFunc(F, outApp, outConstructorApp, Temp)
-
-#For app2
-F = open("Extractor/App2.groovy", "r")
-outApp = open("Extractor/extractedObjectsApp2.groovy", "w+")
-outConstructorApp = open("Extractor/extractedObjectsConstructorApp2.groovy", "w+")
-Temp = GetToken(F)
+                               if (appName == "App1"):
+                                       extractedFunctionsApp1.write("//Global Object for functions in subscribe method!\n")    
+                                       extractedFunctionsApp1.write("def %s = this.&" % NameofFunc)
+                                       extractedFunctionsApp1.write("%s\n" % NameofFunc)
+                               else:
+                                       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 = ""
+               
 
-ExtractorFunc(F, outApp, outConstructorApp, Temp)
 
-outGlobal.close()
+#Extract the methods from App1 and store in inputMethodsFile
+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()
+F1.close()
+
+#Extract the methods from App2 and store in inputMethodsFile
+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()
+F2.close()
+
+
+#Save the extracted methods and methods functions in a same file
+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:
+       extractorFile.write(line)
+extractorFile.write("\n\n")
+for line in inputMethodsFile1:
+       extractorFile.write(line)
+for line in inputMethodsFile2:
+       extractorFile.write(line)
+extractorFile.close()
+inputMethodsFile1.close()
+inputMethodsFile2.close()
+inputMethods.close()
+
+
+#Run the file to extract the objects
+os.system("groovy Extractor/extractorFile.groovy")
diff --git a/Extractor/extractedObjectsApp1.groovy b/Extractor/extractedObjectsApp1.groovy
deleted file mode 100644 (file)
index d205217..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-//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 = 1
-//Global variable for recipients!
-def recipients = ['AJ']
-//Global variable for phone number!
-def phoneNumber = 9495379373
-//Global Object for functions in subscribe method!
-def installed = this.&installed
-//Global Object for functions in subscribe method!
-def updated = this.&updated
-//Global Object for functions in subscribe method!
-def initialize = this.&initialize
-//Global Object for functions in subscribe method!
-def lockDoor = this.&lockDoor
-//Global Object for functions in subscribe method!
-def unlockDoor = this.&unlockDoor
-//Global Object for functions in subscribe method!
-def doorHandler = this.&doorHandler
diff --git a/Extractor/extractedObjectsApp2.groovy b/Extractor/extractedObjectsApp2.groovy
deleted file mode 100644 (file)
index 77277fe..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-//Object for class Switch!
-def switchesoff
-//Object for class Switch!
-def switcheson
-//Object for class lock!
-def lock1
-//Global variable for mode!
-def newMode = "away"
-//Global variable for number!
-def waitfor = 1
-//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 appTouch = this.&appTouch
diff --git a/Extractor/extractedObjectsConstructorApp1.groovy b/Extractor/extractedObjectsConstructorApp1.groovy
deleted file mode 100644 (file)
index 2e3aa8e..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-lock1 = obj.lockObject
-contact = obj.contactObject
diff --git a/Extractor/extractedObjectsConstructorApp2.groovy b/Extractor/extractedObjectsConstructorApp2.groovy
deleted file mode 100644 (file)
index 709a386..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-switchesoff = obj.switchObject
-switcheson = obj.switchObject
-lock1 = obj.lockObject
diff --git a/Extractor/extractorFile.groovy b/Extractor/extractorFile.groovy
new file mode 100644 (file)
index 0000000..612e6ac
--- /dev/null
@@ -0,0 +1,748 @@
+////////////////////////////////////////
+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
+       }       
+}
+
+
+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"
diff --git a/Extractor/inputMethods.groovy b/Extractor/inputMethods.groovy
new file mode 100644 (file)
index 0000000..43223d5
--- /dev/null
@@ -0,0 +1,735 @@
+////////////////////////////////////////
+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
+       }       
+}
index c1c09181fb46862c40dd0087828fd9257da9fa4f..35f7e8ff1f9364e3f85951a5beaafe6452e87d8e 100644 (file)
@@ -1,6 +1,6 @@
 //Global Object for class lock!
-@Field def lockObject = new Locking(sendEvent, 1)
+@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 contactObject = new Contacting(sendEvent,1)
+//Global Object for class switch!
 @Field def switchObject = new Switching(sendEvent, 1)
index f55a239234af3aab6b87362bfa887949bdc6f914..23c4e2e7923f78141739ef15d0cfc256a97138ac 100644 (file)
@@ -1,5 +1,6 @@
 //Create a class for lock device
 package Lock
+import Timer.SimulatedTimer
 
 public class Locking{
        int deviceNumbers       
@@ -7,13 +8,19 @@ public class Locking{
        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 Timer()
+               this.timers = new SimulatedTimer()
                this.deviceNumbers = deviceNumbers
                this.locks = []
                if (deviceNumbers == 1) {
-                       locks = [new Locks(sendEvent, 0, "lock0", "locked", "locked")]
+                       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) {
@@ -46,6 +53,9 @@ public class Locking{
        //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)
        }
 
index d5f97ae8e57e595e91feff1849a8f9978b19e45b..0f1244b8d1536ac43f3ce509f155d4b72bc07c03 100644 (file)
@@ -1,29 +1,30 @@
 //Create a class for lock device
 package Lock
+import Timer.SimulatedTimer
 
 public class Locks {
        private int id
        private String displayName
-       private String lockCurrentValue
+       private String lockState
        private String lockLatestValue
        def sendEvent   
        def timers
 
 
-       Locks(Closure sendEvent, int id, String displayName, String lockCurrentValue, String lockLatestValue) {
+       Locks(Closure sendEvent, int id, String displayName, String lockState, String lockLatestValue) {
                this.id = id
                this.sendEvent = sendEvent
                this.displayName = displayName
-               this.lockCurrentValue = lockCurrentValue
+               this.lockState = lockState
                this.lockLatestValue = lockLatestValue
-               this.timers = new Timer()
+               this.timers = new SimulatedTimer()
        }
 
        //By Apps
        def lock() {
                println("the door with id:$id is locked!")
-               this.lockLatestValue = this.lockCurrentValue
-               this.lockCurrentValue = "locked"
+               this.lockLatestValue = this.lockState
+               this.lockState = "locked"
                sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
                          displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
        }
@@ -31,8 +32,8 @@ public class Locks {
        def lock(LinkedHashMap metaData) {
                def task = timers.runAfter(metaData["delay"]) {
                        println("the door with id:$id is locked!")
-                       this.lockLatestValue = this.lockCurrentValue
-                       this.lockCurrentValue = "locked"
+                       this.lockLatestValue = this.lockState
+                       this.lockState = "locked"
                        sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
                }
@@ -40,8 +41,8 @@ public class Locks {
        
        def unlock() {
                println("the door with id:$id is unlocked!")
-               this.lockLatestValue = this.lockCurrentValue
-               this.lockCurrentValue = "unlocked"
+               this.lockLatestValue = this.lockState
+               this.lockState = "unlocked"
                sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
                          displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
        }
@@ -49,8 +50,8 @@ public class Locks {
        def unlock(LinkedHashMap metaData) {
                def task = timers.runAfter(metaData["delay"]) {
                        println("the door with id:$id is locked!")
-                       this.lockLatestValue = this.lockCurrentValue
-                       this.lockCurrentValue = "locked"
+                       this.lockLatestValue = this.lockState
+                       this.lockState = "locked"
                        sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
                }
@@ -59,13 +60,13 @@ public class Locks {
        //By Model Checker
        def setValue(String value) {
                println("the door with id:$id is $value!")
-               this.lockLatestValue = this.lockCurrentValue
-               this.lockCurrentValue = value
+               this.lockLatestValue = this.lockState
+               this.lockState = value
        }
        
        def currentValue(String deviceFeature) {
                if (deviceFeature == "lock") {
-                       return lockCurrentValue
+                       return lockState
                }
        }
 
index 5c8fc2d0b6285b75ffae09b89057d536c437ef17..4df76755bdcde3b5e594f06715617dafc8259430 100644 (file)
@@ -9,85 +9,20 @@ def eventHandler(LinkedHashMap eventDataMap) {
        def isStateChange = eventDataMap["isStateChange"]
        def unit = eventDataMap["unit"]
        def data = eventDataMap["data"]
-       def minSize
-       def smallest
 
-       //make search efficient
-       if (app1.eventList.size() == app2.eventList.size()) {
-               minSize = app1.eventList.size()
-               smallest = "equal"
-       } else if (app1.eventList.size() < app2.eventList.size()) {
-               minSize = app1.eventList.size()
-               smallest = "app1"
-       } else {
-               minSize = app2.eventList.size()
-               smallest = "app2"
-       }
-
-       for (int i = 0;i < minSize;i++) {
-               if (app1.eventList[i] == name) {
-                       evt.add(new Event())
-                       evt[-1].value = value
-                       evt[-1].name = name
-                       evt[-1].deviceId = deviceId
-                       evt[-1].descriptionText = descriptionText
-                       evt[-1].displayed = displayed
-                       evt[-1].linkText = linkText
-                       evt[-1].displayName = linkText
-                       evt[-1].isStateChange = isStateChange
-                       evt[-1].unit = unit
-                       evt[-1].data = data
-                       app1.functionList[i](evt[-1])
-               }
+       for (int i = 0;i < app2.eventList.size();i++) {
                if (app2.eventList[i] == name) {
-                       evt.add(new Event())
-                       evt[-1].value = value
-                       evt[-1].name = name
-                       evt[-1].deviceId = deviceId
-                       evt[-1].descriptionText = descriptionText
-                       evt[-1].displayed = displayed
-                       evt[-1].linkText = linkText
-                       evt[-1].displayName = linkText
-                       evt[-1].isStateChange = isStateChange
-                       evt[-1].unit = unit
-                       evt[-1].data = data
-                       app2.functionList[i](evt[-1])
+                       def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
+                       evt.add(event)
+                       app2.functionList[i](event)
                }
        }
 
-       if (smallest == "app1") {
-               for (int i = minSize;i < app2.eventList.size();i++) {
-                       if (app2.eventList[i] == name) {
-                               evt.add(new Event())
-                               evt[-1].value = value
-                               evt[-1].name = name
-                               evt[-1].deviceId = deviceId
-                               evt[-1].descriptionText = descriptionText
-                               evt[-1].displayed = displayed
-                               evt[-1].linkText = linkText
-                               evt[-1].displayName = linkText
-                               evt[-1].isStateChange = isStateChange
-                               evt[-1].unit = unit
-                               evt[-1].data = data
-                               app2.functionList[i](evt[-1])
-                       }
-               }
-       } else if (smallest == "app2") {
-               for (int i = minSize;i < app1.eventList.size();i++) {
-                       if (app1.eventList[i] == name) {
-                               evt.add(new Event())
-                               evt[-1].value = value
-                               evt[-1].name = name
-                               evt[-1].deviceId = deviceId
-                               evt[-1].descriptionText = descriptionText
-                               evt[-1].displayed = displayed
-                               evt[-1].linkText = linkText
-                               evt[-1].displayName = linkText
-                               evt[-1].isStateChange = isStateChange
-                               evt[-1].unit = unit
-                               evt[-1].data = data
-                               app1.functionList[i](evt[-1])
-                       }
+       for (int i = 0;i < app1.eventList.size();i++) {
+               if (app1.eventList[i] == name) {
+                       def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
+                       evt.add(event)
+                       app1.functionList[i](event)
                }
-       }       
+       }
 }
index 3816599fd3758d9e0a6a7fb612b3538a7867efd1..178e16da4433a9eb92a06a826596a4e395033458 100644 (file)
@@ -1,7 +1,12 @@
 /////////////////////////////////////////////////////////////////////
 ////runIn(time, func)
 def runIn(int seconds, Closure functionToCall) {
-       timersFuncList.add(functionToCall)
-       timersList.add(new Timer())
-       def task = timersList[-1].runAfter(1000*seconds, functionToCall)
+       if (timersFuncList.contains(functionToCall)) {
+               timersList[timersFuncList.indexOf(functionToCall)].cancel()
+               def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds, functionToCall)
+       } else {
+               timersFuncList.add(functionToCall)
+               timersList.add(new SimulatedTimer())
+               def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds, functionToCall)
+       }
 }
diff --git a/Methods/schedule.groovy b/Methods/schedule.groovy
new file mode 100644 (file)
index 0000000..be935b8
--- /dev/null
@@ -0,0 +1,50 @@
+/////////////////////////////////////////////////////////////////////
+////schedule(time, nameOfFunction as String)
+def schedule(String time, String nameOfFunction) {
+       def _inputTime = time.split(':')
+       Date date = new Date()  
+       def _currentTime = date.format("HH:mm:ss").split(':')
+
+       //Convert input time and current time to minutes
+       def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
+       def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
+       def delay
+
+       if (inputTime < currentTime) {
+               delay = 24*60*60-inputTime+currentTime
+       } else {
+               delay = inputTime-currentTime
+       }
+
+       timersFuncList.add(nameOfFunction)
+       timersList.add(new SimulatedTimer())
+       def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*1000) {
+               "$nameOfFunction"()
+       }
+}
+////schedule(time, nameOfFunction as Closure)
+def schedule(String time, Closure nameOfFunction) {
+       def _inputTime = time.split(':')
+       Date date = new Date()  
+       def _currentTime = date.format("HH:mm:ss").split(':')
+
+       //Convert input time and current time to minutes
+       def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
+       def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
+       def delay
+
+       if (inputTime < currentTime) {
+               delay = 24*60*60-inputTime+currentTime
+       } else {
+               delay = inputTime-currentTime
+       }
+
+       if (timersFuncList.contains(nameOfFunction)) {
+               timersList[timersFuncList.indexOf(nameOfFunction)].cancel()
+               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*seconds, nameOfFunction)
+       } else {
+               timersFuncList.add(nameOfFunction)
+               timersList.add(new SimulatedTimer())
+               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*seconds, nameOfFunction)
+       }
+}
index b5afd49cec538feb3ea27204f00c4007ed62015e..165d0a4320a977b8e0382d24b9aba7beeebd6dd4 100644 (file)
@@ -1,6 +1,6 @@
 /////////////////////////////////////////////////////////////////////
 ////sendNotificationToContacts(text, recipients)
-def sendNotificationToContacts(String text, List recipients) {
+def sendNotificationToContacts(String text, String recipients) {
        for (int i = 0;i < recipients.size();i++) {
                for (int j = 0;j < location.contacts.size();j++) {
                        if (recipients[i] == location.contacts[j]) {
diff --git a/Methods/sendPush.groovy b/Methods/sendPush.groovy
new file mode 100644 (file)
index 0000000..723ce8f
--- /dev/null
@@ -0,0 +1,5 @@
+/////////////////////////////////////////////////////////////////////
+////sendPush(text)
+def sendPush(String text) {
+       println(text)
+}
index 168962149f4a14c8840169d6af475f22f047aab0..322d80583d785a5631c6b7245495d05f67f56c2e 100644 (file)
@@ -3,7 +3,16 @@
 def unschedule(Closure functionToUnschedule) {
        for (int i = 0;i < timersFuncList.size();i++) {
                if (timersFuncList[i] == functionToUnschedule) {
-                       timersList[i].cancel()
+                       if (timersList != null)
+                               timersList[i].cancel()
                }
        }
 }
+
+
+def unschedule() {
+       for (int i = 0;i < timersFuncList.size();i++) {
+               if (timersList != null)
+                       timersList[i].cancel()
+       }
+}
index 0514c39842c402457c87facad62671ec51ada089..440899b6993e735bc404a0560c23b787c6a9a9f7 100644 (file)
--- a/Runner.py
+++ b/Runner.py
@@ -2,11 +2,14 @@ import os
 
 #Create directory for files to append in the main file
 
+#Extract information from preferences and subscribe method to create required objects
+os.system("python Extractor/ExtractorScript.py")
+
 #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
 GlobalVariablesEachApp = open("GlobalVariables/"+"GlobalVariablesEachApp.groovy", "r")
@@ -16,14 +19,16 @@ runIn = open("Methods/"+"runIn.groovy", "r")
 unschedule = open("Methods/"+"unschedule.groovy", "r")
 sendNotificationToContacts = open("Methods/"+"sendNotificationToContacts.groovy", "r")
 sendSms = open("Methods/"+"sendSms.groovy", "r")
+sendPush = open("Methods/"+"sendPush.groovy", "r")
 eventHandler = open("Methods/"+"eventHandler.groovy", "r")
-App1 = open("Extractor/"+"App1.groovy", "r")
-extractedObjectsApp1 = open("Extractor/"+"extractedObjectsApp1.groovy", "r")
-extractedObjectsConstructorApp1 = open("Extractor/"+"extractedObjectsConstructorApp1.groovy", "r")
+schedule = open("Methods/"+"schedule.groovy", "r")
+App1 = open("Extractor/"+"App1/App1.groovy", "r")
+extractedObjectsApp1 = open("Extractor/"+"App1/extractedObjectsApp1.groovy", "r")
+extractedObjectsConstructorApp1 = open("Extractor/"+"App1/extractedObjectsConstructorApp1.groovy", "r")
+extractedFunctionsApp1 = open("Extractor/"+"App1/extractedFunctionsApp1.groovy", "r")
+
 
 
-#Extract information from preferences and subscribe method to create required objects
-os.system("python Extractor/ExtractorScript.py")
 
 Out.write("//Infrastructure for SmartThings Application\n")
 Out.write("//Importing Libraries\n")
@@ -41,6 +46,7 @@ Out.write("import Location.LocationVar\n")
 Out.write("import Location.Phrase\n")
 Out.write("import appTouch.Touched\n")
 Out.write("import Event.Event\n")
+Out.write("import Timer.SimulatedTimer\n")
 Out.write("\n")
 Out.write("//Global eventHandler\n")
 for line in eventHandler:
@@ -64,6 +70,10 @@ Out.write("\t//Extracted objects for App1\n")
 for line in extractedObjectsApp1:
        Out.write("\t"+line)
 Out.write("\n")
+Out.write("\t//Extracted objects for functions for App1\n")
+for line in extractedFunctionsApp1:
+       Out.write("\t"+line)
+Out.write("\n")
 Out.write("\tApp1(Object obj) {\n")
 Out.write("\t\treference = obj\n")
 Out.write("\t\tlocation = obj.locationObject\n")
@@ -88,6 +98,10 @@ for line in sendNotificationToContacts:
        Out.write("\t"+line)
 for line in sendSms:
        Out.write("\t"+line)
+for line in sendPush:
+       Out.write("\t"+line)
+for line in schedule:
+       Out.write("\t"+line)
 Out.write("\n")
 Start = 0
 for line in App1:
@@ -109,9 +123,11 @@ unschedule = open("Methods/"+"unschedule.groovy", "r")
 sendNotificationToContacts = open("Methods/"+"sendNotificationToContacts.groovy", "r")
 sendSms = open("Methods/"+"sendSms.groovy", "r")
 eventHandler = open("Methods/"+"eventHandler.groovy", "r")
-App2 = open("Extractor/"+"App2.groovy", "r")
-extractedObjectsApp2 = open("Extractor/"+"extractedObjectsApp2.groovy", "r")
-extractedObjectsConstructorApp2 = open("Extractor/"+"extractedObjectsConstructorApp2.groovy", "r")
+schedule = open("Methods/"+"schedule.groovy", "r")
+App2 = open("Extractor/"+"App2/App2.groovy", "r")
+extractedObjectsApp2 = open("Extractor/"+"App2/extractedObjectsApp2.groovy", "r")
+extractedObjectsConstructorApp2 = open("Extractor/"+"App2/extractedObjectsConstructorApp2.groovy", "r")
+extractedFunctionsApp2 = open("Extractor/"+"App2/extractedFunctionsApp2.groovy", "r")
 
 Out.write("//Application #2\n")
 Out.write("class App2 {\n")
@@ -123,6 +139,10 @@ Out.write("\t//Extracted objects for App2\n")
 for line in extractedObjectsApp2:
        Out.write("\t"+line)
 Out.write("\n")
+Out.write("\t//Extracted objects for functions for App2\n")
+for line in extractedFunctionsApp2:
+       Out.write("\t"+line)
+Out.write("\n")
 Out.write("\tApp2(Object obj) {\n")
 Out.write("\t\treference = obj\n")
 Out.write("\t\tlocation = obj.locationObject\n")
@@ -147,6 +167,10 @@ for line in sendNotificationToContacts:
        Out.write("\t"+line)
 for line in sendSms:
        Out.write("\t"+line)
+for line in sendPush:
+       Out.write("\t"+line)
+for line in schedule:
+       Out.write("\t"+line)
 Out.write("\n")
 Start = 0
 for line in App2:
@@ -160,6 +184,9 @@ Out.write("@Field def app1 = new App1(this)\n")
 Out.write("@Field def app2 = new App2(this)\n")
 Out.write("app1.installed()\n")
 Out.write("app2.installed()\n")
+Out.write("\n")
+for line in eventSimulator:
+       Out.write("\t"+line)
 Out.close()
 
 
index f5e59e524698c82e32f4e401ec5a22edd6dbeb26..4071de52c0dacdcda365bb8f57dd0dcaea264db4 100644 (file)
@@ -1,30 +1,31 @@
 //Create a class for switch device
 package Switch
+import Timer.SimulatedTimer
 
 public class Switches {
        private int id = 0      
        private String displayName
-       private String switchCurrentValue
+       private String switchState
        private String switchLatestValue
        def sendEvent   
        def timers
        
 
-       Switches(Closure sendEvent, int id, String displayName, String switchCurrentValue, String switchLatestValue) {
+       Switches(Closure sendEvent, int id, String displayName, String switchState, String switchLatestValue) {
                this.sendEvent = sendEvent
-               this.timers = new Timer()
+               this.timers = new SimulatedTimer()
 
                this.id = id
                this.displayName = displayName
-               this.switchCurrentValue = switchCurrentValue
+               this.switchState = switchState
                this.switchLatestValue = switchLatestValue
        }
 
        //By Apps
        def on() {
                println("the switch with id:$id is on!")
-               this.switchLatestValue = this.switchCurrentValue
-               this.switchCurrentValue = "on"
+               this.switchLatestValue = this.switchState
+               this.switchState = "on"
                sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
                    displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
        }
@@ -32,8 +33,8 @@ public class Switches {
        def on(LinkedHashMap metaData) {
                def task = timers.runAfter(metaData["delay"]) {
                        println("the switch with id:$id is on!")
-                       this.switchLatestValue = this.switchCurrentValue
-                       this.switchCurrentValue = "on"
+                       this.switchLatestValue = this.switchState
+                       this.switchState = "on"
                        sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
                            displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
                }
@@ -41,8 +42,8 @@ public class Switches {
 
        def off() {
                println("the switch with id:$id is off!")
-               this.switchLatestValue = this.switchCurrentValue
-               this.switchCurrentValue = "off"
+               this.switchLatestValue = this.switchState
+               this.switchState = "off"
                sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
                    displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
        }
@@ -50,8 +51,8 @@ public class Switches {
        def off(LinkedHashMap metaData) {
                def task = timers.runAfter(metaData["delay"]) {
                        println("the switch with id:$id is off!")
-                       this.switchLatestValue = this.switchCurrentValue
-                       this.switchCurrentValue = "off"
+                       this.switchLatestValue = this.switchState
+                       this.switchState = "off"
                        sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
                            displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
                }
@@ -60,13 +61,13 @@ public class Switches {
        //By Model Checker
        def setValue(String value) {
                println("the switch with id:$id is $value!")
-               this.switchLatestValue = this.switchCurrentValue
-               this.switchCurrentValue = value
+               this.switchLatestValue = this.switchState
+               this.switchState = value
        }
        
        def currentValue(String deviceFeature) {
                if (deviceFeature == "switch") {
-                       return switchCurrentValue
+                       return switchState
                }
        }
 
index f65bd41d60c14d0e2884125ff82ef1f8f10c9ac3..34b58ef58e3601889c262065dde563ae8d060f74 100644 (file)
@@ -1,5 +1,6 @@
 //Create a class for switch device
 package Switch
+import Timer.SimulatedTimer
 
 public class Switching{
        int deviceNumbers       
@@ -7,13 +8,19 @@ public class Switching{
        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 Timer()
+               this.timers = new SimulatedTimer()
                this.deviceNumbers = deviceNumbers
                this.switches = []
                if (deviceNumbers == 1) {
-                       switches = [new Switches(sendEvent, 0, "switch0", "off", "off")]
+                       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) {
@@ -46,6 +53,9 @@ public class Switching{
        //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)
        }
 
diff --git a/Timer/SimulatedTimer.groovy b/Timer/SimulatedTimer.groovy
new file mode 100644 (file)
index 0000000..a133766
--- /dev/null
@@ -0,0 +1,28 @@
+//Create a class for timer\r
+package Timer\r
+\r
+public class SimulatedTimer {\r
+       private Thread thread;\r
+\r
+       SimulatedTimer() {\r
+               thread = null;\r
+       }\r
+\r
+       //By Apps\r
+       def runAfter(int delay, Closure closure) {\r
+               thread = new Thread() {\r
+       \r
+                       @Override\r
+                       public void run() {\r
+                               Thread.sleep(delay)\r
+                               closure()\r
+                       }\r
+               }.start()\r
+               return thread\r
+       }\r
+\r
+       def cancel() {\r
+               if (thread != null)\r
+                       thread.stop()\r
+       }\r
+}\r
diff --git a/bin/main/App1.class b/bin/main/App1.class
deleted file mode 100644 (file)
index 796d062..0000000
Binary files a/bin/main/App1.class and /dev/null differ
diff --git a/bin/main/App2.class b/bin/main/App2.class
deleted file mode 100644 (file)
index 22dbf9b..0000000
Binary files a/bin/main/App2.class and /dev/null differ
diff --git a/bin/main/ContactSensor/Contacting.class b/bin/main/ContactSensor/Contacting.class
deleted file mode 100644 (file)
index 5f5e0b1..0000000
Binary files a/bin/main/ContactSensor/Contacting.class and /dev/null differ
diff --git a/bin/main/ContactSensor/Contacts.class b/bin/main/ContactSensor/Contacts.class
deleted file mode 100644 (file)
index 51bed71..0000000
Binary files a/bin/main/ContactSensor/Contacts.class and /dev/null differ
diff --git a/bin/main/Event/Event.class b/bin/main/Event/Event.class
deleted file mode 100644 (file)
index 2f7f0e2..0000000
Binary files a/bin/main/Event/Event.class and /dev/null differ
diff --git a/bin/main/Location/LocationVar.class b/bin/main/Location/LocationVar.class
deleted file mode 100644 (file)
index 6b600fd..0000000
Binary files a/bin/main/Location/LocationVar.class and /dev/null differ
diff --git a/bin/main/Location/Phrase.class b/bin/main/Location/Phrase.class
deleted file mode 100644 (file)
index 9c29d56..0000000
Binary files a/bin/main/Location/Phrase.class and /dev/null differ
diff --git a/bin/main/Lock/Locking$_lock_closure1.class b/bin/main/Lock/Locking$_lock_closure1.class
deleted file mode 100644 (file)
index 516079e..0000000
Binary files a/bin/main/Lock/Locking$_lock_closure1.class and /dev/null differ
diff --git a/bin/main/Lock/Locking$_unlock_closure2.class b/bin/main/Lock/Locking$_unlock_closure2.class
deleted file mode 100644 (file)
index 90197ad..0000000
Binary files a/bin/main/Lock/Locking$_unlock_closure2.class and /dev/null differ
diff --git a/bin/main/Lock/Locking.class b/bin/main/Lock/Locking.class
deleted file mode 100644 (file)
index 9e966cf..0000000
Binary files a/bin/main/Lock/Locking.class and /dev/null differ
diff --git a/bin/main/Lock/Locks$_lock_closure1.class b/bin/main/Lock/Locks$_lock_closure1.class
deleted file mode 100644 (file)
index ca70ed1..0000000
Binary files a/bin/main/Lock/Locks$_lock_closure1.class and /dev/null differ
diff --git a/bin/main/Lock/Locks$_unlock_closure2.class b/bin/main/Lock/Locks$_unlock_closure2.class
deleted file mode 100644 (file)
index 6a77013..0000000
Binary files a/bin/main/Lock/Locks$_unlock_closure2.class and /dev/null differ
diff --git a/bin/main/Lock/Locks.class b/bin/main/Lock/Locks.class
deleted file mode 100644 (file)
index 93aa14a..0000000
Binary files a/bin/main/Lock/Locks.class and /dev/null differ
diff --git a/bin/main/Logger/Logger.class b/bin/main/Logger/Logger.class
deleted file mode 100644 (file)
index 492d200..0000000
Binary files a/bin/main/Logger/Logger.class and /dev/null differ
diff --git a/bin/main/Switch/Switches$_off_closure2.class b/bin/main/Switch/Switches$_off_closure2.class
deleted file mode 100644 (file)
index 973337d..0000000
Binary files a/bin/main/Switch/Switches$_off_closure2.class and /dev/null differ
diff --git a/bin/main/Switch/Switches$_on_closure1.class b/bin/main/Switch/Switches$_on_closure1.class
deleted file mode 100644 (file)
index cd4028c..0000000
Binary files a/bin/main/Switch/Switches$_on_closure1.class and /dev/null differ
diff --git a/bin/main/Switch/Switches.class b/bin/main/Switch/Switches.class
deleted file mode 100644 (file)
index d246380..0000000
Binary files a/bin/main/Switch/Switches.class and /dev/null differ
diff --git a/bin/main/Switch/Switching$_off_closure2.class b/bin/main/Switch/Switching$_off_closure2.class
deleted file mode 100644 (file)
index 7fdefd3..0000000
Binary files a/bin/main/Switch/Switching$_off_closure2.class and /dev/null differ
diff --git a/bin/main/Switch/Switching$_on_closure1.class b/bin/main/Switch/Switching$_on_closure1.class
deleted file mode 100644 (file)
index 29e4146..0000000
Binary files a/bin/main/Switch/Switching$_on_closure1.class and /dev/null differ
diff --git a/bin/main/Switch/Switching.class b/bin/main/Switch/Switching.class
deleted file mode 100644 (file)
index 60f69f8..0000000
Binary files a/bin/main/Switch/Switching.class and /dev/null differ
diff --git a/bin/main/appTouch/Touched.class b/bin/main/appTouch/Touched.class
deleted file mode 100644 (file)
index 563a7e4..0000000
Binary files a/bin/main/appTouch/Touched.class and /dev/null differ
diff --git a/bin/main/main$_closure1.class b/bin/main/main$_closure1.class
deleted file mode 100644 (file)
index b5c9a14..0000000
Binary files a/bin/main/main$_closure1.class and /dev/null differ
diff --git a/bin/main/main.class b/bin/main/main.class
deleted file mode 100644 (file)
index c1a6055..0000000
Binary files a/bin/main/main.class and /dev/null differ
diff --git a/eventSimulator/eventSimulator.groovy b/eventSimulator/eventSimulator.groovy
new file mode 100644 (file)
index 0000000..c414b3a
--- /dev/null
@@ -0,0 +1,68 @@
+// 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()
index b08146d504111bc87618f29f4504da16d3595b75..d0d579664406ff6254a92e6a19b2d419b996152a 100644 (file)
@@ -14,6 +14,7 @@ import Location.LocationVar
 import Location.Phrase
 import appTouch.Touched
 import Event.Event
+import Timer.SimulatedTimer
 
 //Global eventHandler
 /////////////////////////////////////////////////////////////////////
@@ -27,87 +28,22 @@ def eventHandler(LinkedHashMap eventDataMap) {
        def isStateChange = eventDataMap["isStateChange"]
        def unit = eventDataMap["unit"]
        def data = eventDataMap["data"]
-       def minSize
-       def smallest
 
-       //make search efficient
-       if (app1.eventList.size() == app2.eventList.size()) {
-               minSize = app1.eventList.size()
-               smallest = "equal"
-       } else if (app1.eventList.size() < app2.eventList.size()) {
-               minSize = app1.eventList.size()
-               smallest = "app1"
-       } else {
-               minSize = app2.eventList.size()
-               smallest = "app2"
-       }
-
-       for (int i = 0;i < minSize;i++) {
-               if (app1.eventList[i] == name) {
-                       evt.add(new Event())
-                       evt[-1].value = value
-                       evt[-1].name = name
-                       evt[-1].deviceId = deviceId
-                       evt[-1].descriptionText = descriptionText
-                       evt[-1].displayed = displayed
-                       evt[-1].linkText = linkText
-                       evt[-1].displayName = linkText
-                       evt[-1].isStateChange = isStateChange
-                       evt[-1].unit = unit
-                       evt[-1].data = data
-                       app1.functionList[i](evt[-1])
-               }
+       for (int i = 0;i < app2.eventList.size();i++) {
                if (app2.eventList[i] == name) {
-                       evt.add(new Event())
-                       evt[-1].value = value
-                       evt[-1].name = name
-                       evt[-1].deviceId = deviceId
-                       evt[-1].descriptionText = descriptionText
-                       evt[-1].displayed = displayed
-                       evt[-1].linkText = linkText
-                       evt[-1].displayName = linkText
-                       evt[-1].isStateChange = isStateChange
-                       evt[-1].unit = unit
-                       evt[-1].data = data
-                       app2.functionList[i](evt[-1])
+                       def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
+                       evt.add(event)
+                       app2.functionList[i](event)
                }
        }
 
-       if (smallest == "app1") {
-               for (int i = minSize;i < app2.eventList.size();i++) {
-                       if (app2.eventList[i] == name) {
-                               evt.add(new Event())
-                               evt[-1].value = value
-                               evt[-1].name = name
-                               evt[-1].deviceId = deviceId
-                               evt[-1].descriptionText = descriptionText
-                               evt[-1].displayed = displayed
-                               evt[-1].linkText = linkText
-                               evt[-1].displayName = linkText
-                               evt[-1].isStateChange = isStateChange
-                               evt[-1].unit = unit
-                               evt[-1].data = data
-                               app2.functionList[i](evt[-1])
-                       }
-               }
-       } else if (smallest == "app2") {
-               for (int i = minSize;i < app1.eventList.size();i++) {
-                       if (app1.eventList[i] == name) {
-                               evt.add(new Event())
-                               evt[-1].value = value
-                               evt[-1].name = name
-                               evt[-1].deviceId = deviceId
-                               evt[-1].descriptionText = descriptionText
-                               evt[-1].displayed = displayed
-                               evt[-1].linkText = linkText
-                               evt[-1].displayName = linkText
-                               evt[-1].isStateChange = isStateChange
-                               evt[-1].unit = unit
-                               evt[-1].data = data
-                               app1.functionList[i](evt[-1])
-                       }
+       for (int i = 0;i < app1.eventList.size();i++) {
+               if (app1.eventList[i] == name) {
+                       def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
+                       evt.add(event)
+                       app1.functionList[i](event)
                }
-       }       
+       }
 }
 
 //GlobalVariables for both Apps
@@ -124,10 +60,10 @@ def eventHandler(LinkedHashMap eventDataMap) {
 
 //Extracted global objects for both Apps
 //Global Object for class lock!
-@Field def lockObject = new Locking(sendEvent, 1)
+@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 contactObject = new Contacting(sendEvent,1)
+//Global Object for class switch!
 @Field def switchObject = new Switching(sendEvent, 1)
 
 //Application #1
@@ -144,11 +80,13 @@ class App1 {
        //Global variable for number!
        def minutesLater = 1
        //Global variable for number!
-       def secondsLater = 1
-       //Global variable for recipients!
-       def recipients = ['AJ']
-       //Global variable for phone number!
+       def secondsLater = 10
+       //Global variable for contact!
+       def recipients = "AJ"
+       //Global variable for phone!
        def phoneNumber = 9495379373
+
+       //Extracted objects for functions for App1
        //Global Object for functions in subscribe method!
        def installed = this.&installed
        //Global Object for functions in subscribe method!
@@ -215,22 +153,36 @@ class App1 {
        /////////////////////////////////////////////////////////////////////
        ////runIn(time, func)
        def runIn(int seconds, Closure functionToCall) {
-               timersFuncList.add(functionToCall)
-               timersList.add(new Timer())
-               def task = timersList[-1].runAfter(1000*seconds, functionToCall)
+               if (timersFuncList.contains(functionToCall)) {
+                       timersList[timersFuncList.indexOf(functionToCall)].cancel()
+                       def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds, functionToCall)
+               } else {
+                       timersFuncList.add(functionToCall)
+                       timersList.add(new SimulatedTimer())
+                       def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds, functionToCall)
+               }
        }
        /////////////////////////////////////////////////////////////////////
        ////unschedule(func)
        def unschedule(Closure functionToUnschedule) {
                for (int i = 0;i < timersFuncList.size();i++) {
                        if (timersFuncList[i] == functionToUnschedule) {
-                               timersList[i].cancel()
+                               if (timersList != null)
+                                       timersList[i].cancel()
                        }
                }
        }
+       
+       
+       def unschedule() {
+               for (int i = 0;i < timersFuncList.size();i++) {
+                       if (timersList != null)
+                               timersList[i].cancel()
+               }
+       }
        /////////////////////////////////////////////////////////////////////
        ////sendNotificationToContacts(text, recipients)
-       def sendNotificationToContacts(String text, List recipients) {
+       def sendNotificationToContacts(String text, String recipients) {
                for (int i = 0;i < recipients.size();i++) {
                        for (int j = 0;j < location.contacts.size();j++) {
                                if (recipients[i] == location.contacts[j]) {
@@ -244,6 +196,61 @@ class App1 {
        def sendSms(long phoneNumber, String text) {
                println("Sending \""+text+"\" to "+phoneNumber.toString())
        }
+       /////////////////////////////////////////////////////////////////////
+       ////sendPush(text)
+       def sendPush(String text) {
+               println(text)
+       }
+       /////////////////////////////////////////////////////////////////////
+       ////schedule(time, nameOfFunction as String)
+       def schedule(String time, String nameOfFunction) {
+               def _inputTime = time.split(':')
+               Date date = new Date()  
+               def _currentTime = date.format("HH:mm:ss").split(':')
+       
+               //Convert input time and current time to minutes
+               def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
+               def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
+               def delay
+       
+               if (inputTime < currentTime) {
+                       delay = 24*60*60-inputTime+currentTime
+               } else {
+                       delay = inputTime-currentTime
+               }
+       
+               timersFuncList.add(nameOfFunction)
+               timersList.add(new SimulatedTimer())
+               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*1000) {
+                       "$nameOfFunction"()
+               }
+       }
+       ////schedule(time, nameOfFunction as Closure)
+       def schedule(String time, Closure nameOfFunction) {
+               def _inputTime = time.split(':')
+               Date date = new Date()  
+               def _currentTime = date.format("HH:mm:ss").split(':')
+       
+               //Convert input time and current time to minutes
+               def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
+               def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
+               def delay
+       
+               if (inputTime < currentTime) {
+                       delay = 24*60*60-inputTime+currentTime
+               } else {
+                       delay = inputTime-currentTime
+               }
+       
+               if (timersFuncList.contains(nameOfFunction)) {
+                       timersList[timersFuncList.indexOf(nameOfFunction)].cancel()
+                       def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*seconds, nameOfFunction)
+               } else {
+                       timersFuncList.add(nameOfFunction)
+                       timersList.add(new SimulatedTimer())
+                       def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*seconds, nameOfFunction)
+               }
+       }
 
        def installed(){
            initialize()
@@ -340,16 +347,18 @@ class App2 {
        def app
 
        //Extracted objects for App2
-       //Object for class Switch!
+       //Object for class switch!
        def switchesoff
-       //Object for class Switch!
+       //Object for class switch!
        def switcheson
        //Object for class lock!
        def lock1
        //Global variable for mode!
        def newMode = "away"
        //Global variable for number!
-       def waitfor = 1
+       def waitfor = 4
+
+       //Extracted objects for functions for App2
        //Global Object for functions in subscribe method!
        def installed = this.&installed
        //Global Object for functions in subscribe method!
@@ -411,22 +420,36 @@ class App2 {
        /////////////////////////////////////////////////////////////////////
        ////runIn(time, func)
        def runIn(int seconds, Closure functionToCall) {
-               timersFuncList.add(functionToCall)
-               timersList.add(new Timer())
-               def task = timersList[-1].runAfter(1000*seconds, functionToCall)
+               if (timersFuncList.contains(functionToCall)) {
+                       timersList[timersFuncList.indexOf(functionToCall)].cancel()
+                       def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds, functionToCall)
+               } else {
+                       timersFuncList.add(functionToCall)
+                       timersList.add(new SimulatedTimer())
+                       def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds, functionToCall)
+               }
        }
        /////////////////////////////////////////////////////////////////////
        ////unschedule(func)
        def unschedule(Closure functionToUnschedule) {
                for (int i = 0;i < timersFuncList.size();i++) {
                        if (timersFuncList[i] == functionToUnschedule) {
-                               timersList[i].cancel()
+                               if (timersList != null)
+                                       timersList[i].cancel()
                        }
                }
        }
+       
+       
+       def unschedule() {
+               for (int i = 0;i < timersFuncList.size();i++) {
+                       if (timersList != null)
+                               timersList[i].cancel()
+               }
+       }
        /////////////////////////////////////////////////////////////////////
        ////sendNotificationToContacts(text, recipients)
-       def sendNotificationToContacts(String text, List recipients) {
+       def sendNotificationToContacts(String text, String recipients) {
                for (int i = 0;i < recipients.size();i++) {
                        for (int j = 0;j < location.contacts.size();j++) {
                                if (recipients[i] == location.contacts[j]) {
@@ -440,6 +463,56 @@ class App2 {
        def sendSms(long phoneNumber, String text) {
                println("Sending \""+text+"\" to "+phoneNumber.toString())
        }
+       /////////////////////////////////////////////////////////////////////
+       ////schedule(time, nameOfFunction as String)
+       def schedule(String time, String nameOfFunction) {
+               def _inputTime = time.split(':')
+               Date date = new Date()  
+               def _currentTime = date.format("HH:mm:ss").split(':')
+       
+               //Convert input time and current time to minutes
+               def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
+               def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
+               def delay
+       
+               if (inputTime < currentTime) {
+                       delay = 24*60*60-inputTime+currentTime
+               } else {
+                       delay = inputTime-currentTime
+               }
+       
+               timersFuncList.add(nameOfFunction)
+               timersList.add(new SimulatedTimer())
+               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*1000) {
+                       "$nameOfFunction"()
+               }
+       }
+       ////schedule(time, nameOfFunction as Closure)
+       def schedule(String time, Closure nameOfFunction) {
+               def _inputTime = time.split(':')
+               Date date = new Date()  
+               def _currentTime = date.format("HH:mm:ss").split(':')
+       
+               //Convert input time and current time to minutes
+               def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
+               def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
+               def delay
+       
+               if (inputTime < currentTime) {
+                       delay = 24*60*60-inputTime+currentTime
+               } else {
+                       delay = inputTime-currentTime
+               }
+       
+               if (timersFuncList.contains(nameOfFunction)) {
+                       timersList[timersFuncList.indexOf(nameOfFunction)].cancel()
+                       def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*seconds, nameOfFunction)
+               } else {
+                       timersFuncList.add(nameOfFunction)
+                       timersList.add(new SimulatedTimer())
+                       def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*seconds, nameOfFunction)
+               }
+       }
 
        def installed()
        {
@@ -477,6 +550,72 @@ class App2 {
 @Field def app2 = new App2(this)
 app1.installed()
 app2.installed()
-appObject.setValue([name: "Touched", value: "Touched", deviceId: 0, descriptionText: "",
-           displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
 
+       // 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()