//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) {
//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)
}
//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
}
}
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
}
}
+++ /dev/null
-//////////
-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!")
- }
- }
-}
--- /dev/null
+//////////
+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!")
+ }
+ }
+}
--- /dev/null
+//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
--- /dev/null
+//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
--- /dev/null
+lock1 = obj.lockObject
+contact = obj.contactObject
--- /dev/null
+input"lock1","capability.lock",required:true,"App1"
+input"contact","capability.contactSensor",required:true,"App1"
+input"minutesLater","number",title:"Delay(inminutes):",required:true,"App1"
+input"secondsLater","number",title:"Delay(inseconds):",required:true,"App1"
+input("recipients","contact",title:"Sendnotificationsto",required:false,"App1")
+input"phoneNumber","phone",title:"Warnwithtextmessage(optional)",description:"PhoneNumber",required:false,"App1"
+++ /dev/null
-/**
- * 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)
-}
--- /dev/null
+/////
+definition(
+ name: "Good Night House",
+ namespace: "charette.joseph@gmail.com",
+ author: "Joseph Charette",
+ description: "Some on, some off with delay for bedtime, Lock The Doors",
+ category: "Convenience",
+ iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
+ iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png"
+/**
+* Borrowed code from
+* Walk Gentle Into That Good Night
+*
+* Author: oneaccttorulethehouse@gmail.com
+* Date: 2014-02-01
+ */
+ )
+preferences {
+ section("When I touch the app turn these lights off…"){
+ input "switchesoff", "capability.switch", multiple: true, required:true
+ }
+ section("When I touch the app turn these lights on…"){
+ input "switcheson", "capability.switch", multiple: true, required:false
+ }
+ section("Lock theses locks...") {
+ input "lock1","capability.lock", multiple: true
+ }
+ section("And change to this mode...") {
+ input "newMode", "mode", title: "Mode?"
+ }
+ section("After so many seconds (optional)"){
+ input "waitfor", "number", title: "Off after (default 120)", required: true
+ }
+}
+
+
+def installed()
+{
+ log.debug "Installed with settings: ${settings}"
+ log.debug "Current mode = ${location.mode}"
+ subscribe(app, appTouch)
+}
+
+
+def updated()
+{
+ log.debug "Updated with settings: ${settings}"
+ log.debug "Current mode = ${location.mode}"
+ unsubscribe()
+ subscribe(app, appTouch)
+}
+
+def appTouch(evt) {
+ log.debug "changeMode, location.mode = $location.mode, newMode = $newMode, location.modes = $location.modes"
+ if (location.mode != newMode) {
+ setLocationMode(newMode)
+ log.debug "Changed the mode to '${newMode}'"
+ } else {
+ log.debug "New mode is the same as the old mode, leaving it be"
+ }
+ log.debug "appTouch: $evt"
+ lock1.lock()
+ switcheson.on()
+ def delay = (waitfor != null && waitfor != "") ? waitfor * 1000 : 120000
+ switchesoff.off(delay: delay)
+}
--- /dev/null
+//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
--- /dev/null
+//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
--- /dev/null
+switchesoff = obj.switchObject
+switcheson = obj.switchObject
+lock1 = obj.lockObject
--- /dev/null
+input"switchesoff","capability.switch",multiple:true,required:true,"App2"
+input"switcheson","capability.switch",multiple:true,required:false,"App2"
+input"lock1","capability.lock",multiple:true,"App2"
+input"newMode","mode",title:"Mode?","App2"
+input"waitfor","number",title:"Offafter(default120)",required:true,"App2"
+import os
readyToReturn = 0
ToReturn = ""
def GetToken(f):
global readyToReturn
global ToReturn
- Skip = ["(", "\"", ":", ",", "{", "}", ")", '\n', '\t', ' ', "/"]
+ Skip = ['\n', '\t', ' ']
+ Special = ["(", "\"", ":", ",", "{", "}", ")", "/", "*"]
S = ""
if (readyToReturn):
readyToReturn = 0
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")
+++ /dev/null
-//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
+++ /dev/null
-//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
+++ /dev/null
-lock1 = obj.lockObject
-contact = obj.contactObject
+++ /dev/null
-switchesoff = obj.switchObject
-switcheson = obj.switchObject
-lock1 = obj.lockObject
--- /dev/null
+////////////////////////////////////////
+import groovy.transform.Field
+@Field File outGlobal = new File("Extractor/outGlobal.groovy")
+@Field File extractedObjectsApp1 = new File("Extractor/App1/extractedObjectsApp1.groovy")
+@Field File extractedObjectsApp2 = new File("Extractor/App2/extractedObjectsApp2.groovy")
+@Field File extractedObjectsConstructorApp1 = new File("Extractor/App1/extractedObjectsConstructorApp1.groovy")
+@Field File extractedObjectsConstructorApp2 = new File("Extractor/App2/extractedObjectsConstructorApp2.groovy")
+
+//Empty the files
+outGlobal.write("")
+extractedObjectsApp1.write("")
+extractedObjectsApp2.write("")
+extractedObjectsConstructorApp1.write("")
+extractedObjectsConstructorApp2.write("")
+
+
+@Field lockIsSet = 0
+@Field contactIsSet = 0
+@Field switchIsSet = 0
+
+//input "",""
+def input(String name, String type, String App) {
+ switch(type) {
+ case "capability.lock":
+ if (lockIsSet != 1) {
+ lockIsSet = 1
+ outGlobal.append("//Global Object for class lock!\n")
+ outGlobal.append("@Field def lockObject = new Locking(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class lock!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.lockObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class lock!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.lockObject\n")
+ }
+ break
+ case "capability.alarm":
+ break
+ case "capability.battery":
+ break
+ case "capability.beacon":
+ break
+ case "capability.carbonMonoxideDetector":
+ break
+ case "capability.colorControl":
+ break
+ case "capability.contactSensor":
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ outGlobal.append("//Global Object for class contactSensor!\n")
+ outGlobal.append("@Field def contactObject = new Contacting(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class contactSensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.contactObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class contactSensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.contactObject\n")
+ }
+ break
+ case "capability.doorControl":
+ break
+ case "capability.energyMeter":
+ break
+ case "capability.illuminanceMeasurement":
+ break
+ case "capability.accelerationSensor":
+ break
+ case "capability.motionSensor":
+ break
+ case "capability.musicPlayer":
+ break
+ case "capability.powerMeter":
+ break
+ case "capability.presenceSensor":
+ break
+ case "capability.relativeHumidityMeasurement":
+ break
+ case "capability.relaySwitch":
+ break
+ case "capability.sleepSensor":
+ break
+ case "capability.smokeDetector":
+ break
+ case "capability.stepSensor":
+ break
+ case "capability.switch":
+ if (switchIsSet != 1) {
+ switchIsSet = 1
+ outGlobal.append("//Global Object for class switch!\n")
+ outGlobal.append("@Field def switchObject = new Switching(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class switch!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.switchObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class switch!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.switchObject\n")
+ }
+ break
+ case "capability.switchLevel":
+ break
+ case "capability.temperatureMeasurement":
+ break
+ case "capability.thermostat":
+ break
+ case "capability.valve":
+ break
+ case "capability.waterSensor":
+ break
+ case "capability.touchSensor":
+ break
+ case "capability.imageCapture":
+ break
+ case "device.mobilePresence":
+ break
+ case "device.aeonKeyFob":
+ break
+ case "mode":
+ def userInput = System.console().readLine 'Enter the mode:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for mode!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for mode!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "decimal":
+ break
+ case "text":
+ break
+ case "number":
+ def userInput = System.console().readLine 'Enter the number:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for number!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for number!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "time":
+ def userInput = System.console().readLine 'Enter the time:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for time!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for time!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "enum":
+ def userInput = System.console().readLine 'Enter the enum:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for enum!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for enum!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "bool":
+ break
+ case "phone":
+ def userInput = System.console().readLine 'Enter the phone:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for phone!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for phone!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "contact":
+ def userInput = System.console().readLine 'Enter the name of the contact:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for contact!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for contact!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ default:
+ break
+ }
+}
+
+//input "","",linkedHashMap
+def input(LinkedHashMap metaData, String name, String type, String App) {
+ switch(type) {
+ case "capability.lock":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (lockIsSet != 1) {
+ lockIsSet = 1
+ def count = System.console().readLine 'Enter the number of locks to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class lock!\n")
+ outGlobal.append("@Field def lockObject = new Locking(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (lockIsSet != 1) {
+ lockIsSet = 1
+ outGlobal.append("//Global Object for class lock!\n")
+ outGlobal.append("@Field def lockObject = new Locking(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class lock!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.lockObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class lock!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.lockObject\n")
+ }
+ break
+ case "capability.alarm":
+ break
+ case "capability.battery":
+ break
+ case "capability.beacon":
+ break
+ case "capability.carbonMonoxideDetector":
+ break
+ case "capability.colorControl":
+ break
+ case "capability.contactSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ def count = System.console().readLine 'Enter the number of contact sensors to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class contactSensor!\n")
+ outGlobal.append("@Field def contactObject = new Contacting(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ outGlobal.append("//Global Object for class contactSensor!\n")
+ outGlobal.append("@Field def contactObject = new Contacting(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class contactSensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.contactObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class contactSensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.contactObject\n")
+ }
+ break
+ case "capability.doorControl":
+ break
+ case "capability.energyMeter":
+ break
+ case "capability.illuminanceMeasurement":
+ break
+ case "capability.accelerationSensor":
+ break
+ case "capability.motionSensor":
+ break
+ case "capability.musicPlayer":
+ break
+ case "capability.powerMeter":
+ break
+ case "capability.presenceSensor":
+ break
+ case "capability.relativeHumidityMeasurement":
+ break
+ case "capability.relaySwitch":
+ break
+ case "capability.sleepSensor":
+ break
+ case "capability.smokeDetector":
+ break
+ case "capability.stepSensor":
+ break
+ case "capability.switch":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (switchIsSet != 1) {
+ switchIsSet = 1
+ def count = System.console().readLine 'Enter the number of switches to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class switch!\n")
+ outGlobal.append("@Field def switchObject = new Switching(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (switchIsSet != 1) {
+ switchIsSet = 1
+ outGlobal.append("//Global Object for class switch!\n")
+ outGlobal.append("@Field def switchObject = new Switching(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class switch!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.switchObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class switch!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.switchObject\n")
+ }
+ break
+ case "capability.switchLevel":
+ break
+ case "capability.temperatureMeasurement":
+ break
+ case "capability.thermostat":
+ break
+ case "capability.valve":
+ break
+ case "capability.waterSensor":
+ break
+ case "capability.touchSensor":
+ break
+ case "capability.imageCapture":
+ break
+ case "device.mobilePresence":
+ break
+ case "device.aeonKeyFob":
+ break
+ case "mode":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ def userInput = System.console().readLine 'Enter the mode:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for mode!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for mode!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "decimal":
+ break
+ case "text":
+ break
+ case "number":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the number:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for number!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for number!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "time":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the time:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for time!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for time!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "enum":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the enum:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for enum!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for enum!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "bool":
+ break
+ case "phone":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the phone:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for phone!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for phone!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "contact":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the name of the contact:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for contact!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for contact!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ default:
+ break
+ }
+}
+//input linkedHashMap
+def input(LinkedHashMap metaData, String App) {
+ switch(metaData['type']) {
+ case "capability.lock":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (lockIsSet != 1) {
+ lockIsSet = 1
+ def count = System.console().readLine 'Enter the number of locks to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class lock!\n")
+ outGlobal.append("@Field def lockObject = new Locking(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (lockIsSet != 1) {
+ lockIsSet = 1
+ outGlobal.append("//Global Object for class lock!\n")
+ outGlobal.append("@Field def lockObject = new Locking(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class lock!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['input']+" = obj.lockObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class lock!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['input']+" = obj.lockObject\n")
+ }
+ break
+ case "capability.alarm":
+ break
+ case "capability.battery":
+ break
+ case "capability.beacon":
+ break
+ case "capability.carbonMonoxideDetector":
+ break
+ case "capability.colorControl":
+ break
+ case "capability.contactSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ def count = System.console().readLine 'Enter the number of contact sensors to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class contactSensor!\n")
+ outGlobal.append("@Field def contactObject = new Contacting(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ outGlobal.append("//Global Object for class contactSensor!\n")
+ outGlobal.append("@Field def contactObject = new Contacting(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class contactSensor!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['input']+" = obj.contactObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class contactSensor!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['input']+" = obj.contactObject\n")
+ }
+ break
+ case "capability.doorControl":
+ break
+ case "capability.energyMeter":
+ break
+ case "capability.illuminanceMeasurement":
+ break
+ case "capability.accelerationSensor":
+ break
+ case "capability.motionSensor":
+ break
+ case "capability.musicPlayer":
+ break
+ case "capability.powerMeter":
+ break
+ case "capability.presenceSensor":
+ break
+ case "capability.relativeHumidityMeasurement":
+ break
+ case "capability.relaySwitch":
+ break
+ case "capability.sleepSensor":
+ break
+ case "capability.smokeDetector":
+ break
+ case "capability.stepSensor":
+ break
+ case "capability.switch":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (switchIsSet != 1) {
+ switchIsSet = 1
+ def count = System.console().readLine 'Enter the number of switches to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class switch!\n")
+ outGlobal.append("@Field def switchObject = new Switching(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (switchIsSet != 1) {
+ switchIsSet = 1
+ outGlobal.append("//Global Object for class switch!\n")
+ outGlobal.append("@Field def switchObject = new Switching(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class switch!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['input']+" = obj.switchObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class switch!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['input']+" = obj.switchObject\n")
+ }
+ break
+ case "capability.switchLevel":
+ break
+ case "capability.temperatureMeasurement":
+ break
+ case "capability.thermostat":
+ break
+ case "capability.valve":
+ break
+ case "capability.waterSensor":
+ break
+ case "capability.touchSensor":
+ break
+ case "capability.imageCapture":
+ break
+ case "device.mobilePresence":
+ break
+ case "device.aeonKeyFob":
+ break
+ case "mode":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the mode:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for mode!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for mode!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ }
+ break
+ case "decimal":
+ break
+ case "text":
+ break
+ case "number":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the number:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for number!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for number!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = "+userInput+"\n")
+ }
+ break
+ case "time":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the time:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for time!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for time!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ }
+ break
+ case "enum":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the enum:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for enum!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for enum!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ }
+ break
+ case "bool":
+ break
+ case "phone":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the phone:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for phone!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for phone!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = "+userInput+"\n")
+ }
+ break
+ case "contact":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the name of the contact:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for contact!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for contact!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ }
+ break
+ default:
+ break
+ }
+}
+
+
+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"
--- /dev/null
+////////////////////////////////////////
+import groovy.transform.Field
+@Field File outGlobal = new File("Extractor/outGlobal.groovy")
+@Field File extractedObjectsApp1 = new File("Extractor/App1/extractedObjectsApp1.groovy")
+@Field File extractedObjectsApp2 = new File("Extractor/App2/extractedObjectsApp2.groovy")
+@Field File extractedObjectsConstructorApp1 = new File("Extractor/App1/extractedObjectsConstructorApp1.groovy")
+@Field File extractedObjectsConstructorApp2 = new File("Extractor/App2/extractedObjectsConstructorApp2.groovy")
+
+//Empty the files
+outGlobal.write("")
+extractedObjectsApp1.write("")
+extractedObjectsApp2.write("")
+extractedObjectsConstructorApp1.write("")
+extractedObjectsConstructorApp2.write("")
+
+
+@Field lockIsSet = 0
+@Field contactIsSet = 0
+@Field switchIsSet = 0
+
+//input "",""
+def input(String name, String type, String App) {
+ switch(type) {
+ case "capability.lock":
+ if (lockIsSet != 1) {
+ lockIsSet = 1
+ outGlobal.append("//Global Object for class lock!\n")
+ outGlobal.append("@Field def lockObject = new Locking(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class lock!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.lockObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class lock!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.lockObject\n")
+ }
+ break
+ case "capability.alarm":
+ break
+ case "capability.battery":
+ break
+ case "capability.beacon":
+ break
+ case "capability.carbonMonoxideDetector":
+ break
+ case "capability.colorControl":
+ break
+ case "capability.contactSensor":
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ outGlobal.append("//Global Object for class contactSensor!\n")
+ outGlobal.append("@Field def contactObject = new Contacting(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class contactSensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.contactObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class contactSensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.contactObject\n")
+ }
+ break
+ case "capability.doorControl":
+ break
+ case "capability.energyMeter":
+ break
+ case "capability.illuminanceMeasurement":
+ break
+ case "capability.accelerationSensor":
+ break
+ case "capability.motionSensor":
+ break
+ case "capability.musicPlayer":
+ break
+ case "capability.powerMeter":
+ break
+ case "capability.presenceSensor":
+ break
+ case "capability.relativeHumidityMeasurement":
+ break
+ case "capability.relaySwitch":
+ break
+ case "capability.sleepSensor":
+ break
+ case "capability.smokeDetector":
+ break
+ case "capability.stepSensor":
+ break
+ case "capability.switch":
+ if (switchIsSet != 1) {
+ switchIsSet = 1
+ outGlobal.append("//Global Object for class switch!\n")
+ outGlobal.append("@Field def switchObject = new Switching(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class switch!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.switchObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class switch!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.switchObject\n")
+ }
+ break
+ case "capability.switchLevel":
+ break
+ case "capability.temperatureMeasurement":
+ break
+ case "capability.thermostat":
+ break
+ case "capability.valve":
+ break
+ case "capability.waterSensor":
+ break
+ case "capability.touchSensor":
+ break
+ case "capability.imageCapture":
+ break
+ case "device.mobilePresence":
+ break
+ case "device.aeonKeyFob":
+ break
+ case "mode":
+ def userInput = System.console().readLine 'Enter the mode:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for mode!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for mode!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "decimal":
+ break
+ case "text":
+ break
+ case "number":
+ def userInput = System.console().readLine 'Enter the number:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for number!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for number!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "time":
+ def userInput = System.console().readLine 'Enter the time:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for time!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for time!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "enum":
+ def userInput = System.console().readLine 'Enter the enum:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for enum!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for enum!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "bool":
+ break
+ case "phone":
+ def userInput = System.console().readLine 'Enter the phone:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for phone!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for phone!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "contact":
+ def userInput = System.console().readLine 'Enter the name of the contact:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for contact!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for contact!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ default:
+ break
+ }
+}
+
+//input "","",linkedHashMap
+def input(LinkedHashMap metaData, String name, String type, String App) {
+ switch(type) {
+ case "capability.lock":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (lockIsSet != 1) {
+ lockIsSet = 1
+ def count = System.console().readLine 'Enter the number of locks to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class lock!\n")
+ outGlobal.append("@Field def lockObject = new Locking(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (lockIsSet != 1) {
+ lockIsSet = 1
+ outGlobal.append("//Global Object for class lock!\n")
+ outGlobal.append("@Field def lockObject = new Locking(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class lock!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.lockObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class lock!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.lockObject\n")
+ }
+ break
+ case "capability.alarm":
+ break
+ case "capability.battery":
+ break
+ case "capability.beacon":
+ break
+ case "capability.carbonMonoxideDetector":
+ break
+ case "capability.colorControl":
+ break
+ case "capability.contactSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ def count = System.console().readLine 'Enter the number of contact sensors to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class contactSensor!\n")
+ outGlobal.append("@Field def contactObject = new Contacting(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ outGlobal.append("//Global Object for class contactSensor!\n")
+ outGlobal.append("@Field def contactObject = new Contacting(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class contactSensor!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.contactObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class contactSensor!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.contactObject\n")
+ }
+ break
+ case "capability.doorControl":
+ break
+ case "capability.energyMeter":
+ break
+ case "capability.illuminanceMeasurement":
+ break
+ case "capability.accelerationSensor":
+ break
+ case "capability.motionSensor":
+ break
+ case "capability.musicPlayer":
+ break
+ case "capability.powerMeter":
+ break
+ case "capability.presenceSensor":
+ break
+ case "capability.relativeHumidityMeasurement":
+ break
+ case "capability.relaySwitch":
+ break
+ case "capability.sleepSensor":
+ break
+ case "capability.smokeDetector":
+ break
+ case "capability.stepSensor":
+ break
+ case "capability.switch":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (switchIsSet != 1) {
+ switchIsSet = 1
+ def count = System.console().readLine 'Enter the number of switches to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class switch!\n")
+ outGlobal.append("@Field def switchObject = new Switching(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (switchIsSet != 1) {
+ switchIsSet = 1
+ outGlobal.append("//Global Object for class switch!\n")
+ outGlobal.append("@Field def switchObject = new Switching(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class switch!\n")
+ extractedObjectsApp1.append("def "+name+"\n")
+ extractedObjectsConstructorApp1.append(name+" = obj.switchObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class switch!\n")
+ extractedObjectsApp2.append("def "+name+"\n")
+ extractedObjectsConstructorApp2.append(name+" = obj.switchObject\n")
+ }
+ break
+ case "capability.switchLevel":
+ break
+ case "capability.temperatureMeasurement":
+ break
+ case "capability.thermostat":
+ break
+ case "capability.valve":
+ break
+ case "capability.waterSensor":
+ break
+ case "capability.touchSensor":
+ break
+ case "capability.imageCapture":
+ break
+ case "device.mobilePresence":
+ break
+ case "device.aeonKeyFob":
+ break
+ case "mode":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ def userInput = System.console().readLine 'Enter the mode:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for mode!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for mode!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "decimal":
+ break
+ case "text":
+ break
+ case "number":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the number:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for number!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for number!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "time":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the time:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for time!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for time!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "enum":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the enum:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for enum!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for enum!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ case "bool":
+ break
+ case "phone":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the phone:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for phone!\n")
+ extractedObjectsApp1.append("def "+name+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for phone!\n")
+ extractedObjectsApp2.append("def "+name+" = "+userInput+"\n")
+ }
+ break
+ case "contact":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the name of the contact:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for contact!\n")
+ extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for contact!\n")
+ extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n")
+ }
+ break
+ default:
+ break
+ }
+}
+//input linkedHashMap
+def input(LinkedHashMap metaData, String App) {
+ switch(metaData['type']) {
+ case "capability.lock":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (lockIsSet != 1) {
+ lockIsSet = 1
+ def count = System.console().readLine 'Enter the number of locks to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class lock!\n")
+ outGlobal.append("@Field def lockObject = new Locking(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (lockIsSet != 1) {
+ lockIsSet = 1
+ outGlobal.append("//Global Object for class lock!\n")
+ outGlobal.append("@Field def lockObject = new Locking(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class lock!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['input']+" = obj.lockObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class lock!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['input']+" = obj.lockObject\n")
+ }
+ break
+ case "capability.alarm":
+ break
+ case "capability.battery":
+ break
+ case "capability.beacon":
+ break
+ case "capability.carbonMonoxideDetector":
+ break
+ case "capability.colorControl":
+ break
+ case "capability.contactSensor":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ def count = System.console().readLine 'Enter the number of contact sensors to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class contactSensor!\n")
+ outGlobal.append("@Field def contactObject = new Contacting(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (contactIsSet != 1) {
+ contactIsSet = 1
+ outGlobal.append("//Global Object for class contactSensor!\n")
+ outGlobal.append("@Field def contactObject = new Contacting(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class contactSensor!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['input']+" = obj.contactObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class contactSensor!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['input']+" = obj.contactObject\n")
+ }
+ break
+ case "capability.doorControl":
+ break
+ case "capability.energyMeter":
+ break
+ case "capability.illuminanceMeasurement":
+ break
+ case "capability.accelerationSensor":
+ break
+ case "capability.motionSensor":
+ break
+ case "capability.musicPlayer":
+ break
+ case "capability.powerMeter":
+ break
+ case "capability.presenceSensor":
+ break
+ case "capability.relativeHumidityMeasurement":
+ break
+ case "capability.relaySwitch":
+ break
+ case "capability.sleepSensor":
+ break
+ case "capability.smokeDetector":
+ break
+ case "capability.stepSensor":
+ break
+ case "capability.switch":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('multiple')) {
+ if (metaData['multiple'] == true) {
+ if (switchIsSet != 1) {
+ switchIsSet = 1
+ def count = System.console().readLine 'Enter the number of switches to control?(1,2, or 3)'
+ outGlobal.append("//Global Object for class switch!\n")
+ outGlobal.append("@Field def switchObject = new Switching(sendEvent, ")
+ outGlobal.append(count+")\n")
+ }
+ }
+ }
+ if (switchIsSet != 1) {
+ switchIsSet = 1
+ outGlobal.append("//Global Object for class switch!\n")
+ outGlobal.append("@Field def switchObject = new Switching(sendEvent,1)\n")
+ }
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Object for class switch!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp1.append(metaData['input']+" = obj.switchObject\n")
+ } else {
+ extractedObjectsApp2.append("//Object for class switch!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+"\n")
+ extractedObjectsConstructorApp2.append(metaData['input']+" = obj.switchObject\n")
+ }
+ break
+ case "capability.switchLevel":
+ break
+ case "capability.temperatureMeasurement":
+ break
+ case "capability.thermostat":
+ break
+ case "capability.valve":
+ break
+ case "capability.waterSensor":
+ break
+ case "capability.touchSensor":
+ break
+ case "capability.imageCapture":
+ break
+ case "device.mobilePresence":
+ break
+ case "device.aeonKeyFob":
+ break
+ case "mode":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the mode:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for mode!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for mode!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ }
+ break
+ case "decimal":
+ break
+ case "text":
+ break
+ case "number":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the number:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for number!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for number!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = "+userInput+"\n")
+ }
+ break
+ case "time":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the time:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for time!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for time!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ }
+ break
+ case "enum":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the enum:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for enum!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for enum!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ }
+ break
+ case "bool":
+ break
+ case "phone":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the phone:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for phone!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = "+userInput+"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for phone!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = "+userInput+"\n")
+ }
+ break
+ case "contact":
+ if (metaData.containsKey('title')) {
+ println metaData['title']
+ }
+ if (metaData.containsKey('options')) {
+ println "Options: "+metaData['options']
+ }
+ if (metaData.containsKey('metadata')) {
+ println "metaData: "+metaData['metadata']
+ }
+ def userInput = System.console().readLine 'Enter the name of the contact:'
+ if (App == "App1") {
+ extractedObjectsApp1.append("//Global variable for contact!\n")
+ extractedObjectsApp1.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ } else {
+ extractedObjectsApp2.append("//Global variable for contact!\n")
+ extractedObjectsApp2.append("def "+metaData['input']+" = \""+userInput+"\"\n")
+ }
+ break
+ default:
+ break
+ }
+}
//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)
//Create a class for lock device
package Lock
+import Timer.SimulatedTimer
public class Locking{
int deviceNumbers
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) {
//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)
}
//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: []])
}
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: []])
}
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: []])
}
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: []])
}
//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
}
}
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)
}
- }
+ }
}
/////////////////////////////////////////////////////////////////////
////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)
+ }
}
--- /dev/null
+/////////////////////////////////////////////////////////////////////
+////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)
+ }
+}
/////////////////////////////////////////////////////////////////////
////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]) {
--- /dev/null
+/////////////////////////////////////////////////////////////////////
+////sendPush(text)
+def sendPush(String text) {
+ println(text)
+}
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()
+ }
+}
#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")
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")
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:
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")
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:
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")
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")
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:
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()
//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: []])
}
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: []])
}
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: []])
}
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: []])
}
//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
}
}
//Create a class for switch device
package Switch
+import Timer.SimulatedTimer
public class Switching{
int deviceNumbers
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) {
//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)
}
--- /dev/null
+//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
--- /dev/null
+// 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()
import Location.Phrase
import appTouch.Touched
import Event.Event
+import Timer.SimulatedTimer
//Global eventHandler
/////////////////////////////////////////////////////////////////////
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
//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
//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!
/////////////////////////////////////////////////////////////////////
////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]) {
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()
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!
/////////////////////////////////////////////////////////////////////
////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]) {
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()
{
@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()