From: amiraj Date: Sat, 20 Jul 2019 00:50:28 +0000 (-0700) Subject: Commit #9: extension to the infrastructure with more devices + minor changes in extra... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=2c464dd719752b34106af7eb1e7451e6e03072f6;p=smartthings-infrastructure.git Commit #9: extension to the infrastructure with more devices + minor changes in extractor part --- diff --git a/AeonKeyFob/AeonKeyFob.groovy b/AeonKeyFob/AeonKeyFob.groovy new file mode 100644 index 0000000..8ece0c6 --- /dev/null +++ b/AeonKeyFob/AeonKeyFob.groovy @@ -0,0 +1,35 @@ +//Create a class for aeon key fob +package AeonKeyFob +import Timer.SimulatedTimer + +public class AeonKeyFob { + private String id + private String label + private String displayName + private List events = [] + private List timeOfEvents = [] + + AeonKeyFob(String id, String label, String displayName) { + this.id = id + this.label = label + this.displayName = displayName + } + + def setValue(LinkedHashMap eventDataMap) { + def data = eventDataMap["data"] + def value = eventDataMap["value"] + println("the button with number $data is $value!") + this.events.add(eventDataMap) + this.timeOfEvents.add(System.currentTimeMillis()) + } + + def eventsSince(Date dateObj) { + def List happenedEvents = [] + def sinceThen = dateObj.time + for (int i = 0;i < timeOfEvents.size();i++) { + if (timeOfEvents[i]>=sinceThen) + happenedEvents.add(events[i]) + } + return happenedEvents + } +} diff --git a/AeonKeyFob/AeonKeyFobs.groovy b/AeonKeyFob/AeonKeyFobs.groovy new file mode 100644 index 0000000..673afa0 --- /dev/null +++ b/AeonKeyFob/AeonKeyFobs.groovy @@ -0,0 +1,57 @@ +//Create a class for aeon key fob +package AeonKeyFob +import Timer.SimulatedTimer + +public class AeonKeyFobs { + private int deviceNumbers + private List aeonKeyFobs + def sendEvent + + //For one device(We cannot have obj.id)-> We should have obj[0].id + private String id = "aeonKeyFobID0" + private String label = "aeonKeyFob0" + private String displayName = "aeonKeyFob0" + + + AeonKeyFobs(Closure sendEvent, int deviceNumbers) { + this.sendEvent = sendEvent + this.deviceNumbers = deviceNumbers + this.aeonKeyFobs = [] + + aeonKeyFobs.add(new AeonKeyFob(id, label, displayName)) + } + + //By Model Checker + def setValue(LinkedHashMap eventDataMap) { + aeonKeyFobs[0].setValue(eventDataMap) + sendEvent(eventDataMap) + } + + //Methods for closures + def count(Closure Input) { + aeonKeyFobs.count(Input) + } + def size() { + aeonKeyFobs.size() + } + def each(Closure Input) { + aeonKeyFobs.each(Input) + } + def find(Closure Input) { + aeonKeyFobs.find(Input) + } + def collect(Closure Input) { + aeonKeyFobs.collect(Input) + } + + + //methods + def eventsSince(Date dateObj) { + return aeonKeyFobs[0].eventsSince(dateObj) + } + + + def getAt(int ix) { + aeonKeyFobs[ix] + } +} diff --git a/ContactSensor/ContactSensor.groovy b/ContactSensor/ContactSensor.groovy index f11a325..05e961d 100644 --- a/ContactSensor/ContactSensor.groovy +++ b/ContactSensor/ContactSensor.groovy @@ -3,22 +3,22 @@ package ContactSensor import Timer.SimulatedTimer public class ContactSensor { - private int id + private String id private String label private String displayName private String contactState - private String contactLatestValue + private String latestValue - ContactSensor(int id, String label, String displayName, String contactState, String contactLatestValue) { + ContactSensor(String id, String label, String displayName, String contactState, String latestValue) { this.id = id this.label = label this.displayName = displayName this.contactState = contactState - this.contactLatestValue = contactLatestValue + this.latestValue = latestValue } def setValue(String value) { - this.contactLatestValue = contactState + this.latestValue = contactState println("the contact sensor with id:$id is triggered to $value!") this.contactState = value } @@ -31,7 +31,7 @@ public class ContactSensor { def latestValue(String deviceFeature) { if (deviceFeature == "contact") { - return contactLatestValue + return latestValue } } } diff --git a/ContactSensor/ContactSensors.groovy b/ContactSensor/ContactSensors.groovy index e53d7d1..10c4aa6 100644 --- a/ContactSensor/ContactSensors.groovy +++ b/ContactSensor/ContactSensors.groovy @@ -8,11 +8,11 @@ public class ContactSensors { def sendEvent //For one device(We cannot have obj.id)-> We should have obj[0].id - private int id = 10 - private String label = "contactSensor" - private String displayName = "contactSensor" + private String id = "contactSensorID0" + private String label = "contactSensor0" + private String displayName = "contactSensor0" private String contactState = "closed" - private String contactLatestValue = "closed" + private String latestValue = "closed" ContactSensors(Closure sendEvent, int deviceNumbers) { @@ -20,9 +20,7 @@ public class ContactSensors { this.deviceNumbers = deviceNumbers this.contacts = [] - for (int i = 0;i < deviceNumbers;i++) { - contacts.add(new ContactSensor(i+10, label+i.toString(), displayName+i.toString(), this.contactState, this.contactLatestValue)) - } + contacts.add(new ContactSensor(id, label, displayName, this.contactState, this.latestValue)) } //Methods for closures @@ -35,28 +33,27 @@ public class ContactSensors { def each(Closure Input) { contacts.each(Input) } + def find(Closure Input) { + contacts.find(Input) + } + def collect(Closure Input) { + contacts.collect(Input) + } //By Model Checker def setValue(LinkedHashMap eventDataMap) { - contacts[eventDataMap["deviceId"]].setValue(eventDataMap["value"]) - if (deviceNumbers == 1) - this.contactLatestValue = contacts[eventDataMap["deviceId"]].contactLatestValue - this.contactState = contacts[eventDataMap["deviceId"]].contactState + contacts[0].setValue(eventDataMap["value"]) + this.latestValue = contacts[0].latestValue + this.contactState = contacts[0].contactState sendEvent(eventDataMap) } def currentValue(String deviceFeature) { - if (deviceNumbers == 1) - contacts[0].currentValue(deviceFeature)//It is called if we have only one device - else - contacts*.currentValue(deviceFeature) + contacts[0].currentValue(deviceFeature)//It is called if we have only one device } def latestValue(String deviceFeature) { - if (deviceNumbers == 1) - contacts[0].latestValue(deviceFeature)//It is called if we have only one device - else - contacts*.latestValue(deviceFeature) + contacts[0].latestValue(deviceFeature)//It is called if we have only one device } def getAt(int ix) { diff --git a/DoorControl/DoorControl.groovy b/DoorControl/DoorControl.groovy index 6ad6f2b..4317849 100644 --- a/DoorControl/DoorControl.groovy +++ b/DoorControl/DoorControl.groovy @@ -3,7 +3,7 @@ package DoorControl import Timer.SimulatedTimer public class DoorControl { - private int id + private String id private String label private String displayName private String doorState @@ -12,7 +12,7 @@ public class DoorControl { def timers - DoorControl(Closure sendEvent, int id, String label, String displayName, String doorState, String doorLatestValue) { + DoorControl(Closure sendEvent, String id, String label, String displayName, String doorState, String doorLatestValue) { this.sendEvent = sendEvent this.timers = new SimulatedTimer() this.id = id @@ -27,7 +27,7 @@ public class DoorControl { this.doorLatestValue = this.doorState this.doorState = "open" sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) + displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "open"]]) } def open(LinkedHashMap metaData) { @@ -36,7 +36,7 @@ public class DoorControl { this.doorLatestValue = this.doorState this.doorState = "open" sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) + displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "open"]]) } } @@ -45,7 +45,7 @@ public class DoorControl { this.doorLatestValue = this.doorState this.doorState = "closed" sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) + displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "closed"]]) } def close(LinkedHashMap metaData) { @@ -54,7 +54,7 @@ public class DoorControl { this.doorLatestValue = this.doorState this.doorState = "closed" sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) + displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "closed"]]) } } diff --git a/DoorControl/DoorControls.groovy b/DoorControl/DoorControls.groovy index f2f520d..19cc18b 100644 --- a/DoorControl/DoorControls.groovy +++ b/DoorControl/DoorControls.groovy @@ -9,9 +9,9 @@ public class DoorControls { def sendEvent //If we have only one device - private int id = 40 - private String label = "DoorControl" - private String displayName = "DoorControl" + private String id = "DoorControlID0" + private String label = "DoorControl0" + private String displayName = "DoorControl0" private String doorState = "closed" private String doorLatestValue = "closed" @@ -20,9 +20,8 @@ public class DoorControls { this.timers = new SimulatedTimer() this.deviceNumbers = deviceNumbers this.doorControls = [] - for (int i = 0;i < deviceNumbers;i++) { - doorControls.add(new DoorControl(sendEvent, i+60, label+i.toString(), displayName+i.toString(), this.doorState, this.doorLatestValue)) - } + + doorControls.add(new DoorControl(sendEvent, id, label, displayName, this.doorState, this.doorLatestValue)) } //Methods for closures @@ -35,49 +34,48 @@ public class DoorControls { def each(Closure Input) { doorControls.each(Input) } + def find(Closure Input) { + doorControls.find(Input) + } + def collect(Closure Input) { + doorControls.collect(Input) + } //By Apps def open() { - doorControls*.on() + doorControls[0].on() } def open(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { - doorControls*.on() + doorControls[0].on() } } def close() { - doorControls*.off() + doorControls[0].off() } def close(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { - doorControls*.off() + doorControls[0].off() } } //By Model Checker def setValue(LinkedHashMap eventDataMap) { - doorControls[eventDataMap["deviceId"]].setValue(eventDataMap["value"]) - if (deviceNumbers == 1) - this.doorState = doorControls[eventDataMap["deviceId"]].doorState + doorControls[0].setValue(eventDataMap["value"]) + this.doorState = doorControls[0].doorState sendEvent(eventDataMap) } def currentValue(String deviceFeature) { - if (deviceNumbers == 1) - doorControls[0].currentValue(deviceFeature) - else - doorControls*.currentValue(deviceFeature) + doorControls[0].currentValue(deviceFeature) } def latestValue(String deviceFeature) { - if (deviceNumbers == 1) - doorControls[0].latestValue(deviceFeature) - else - doorControls*.latestValue(deviceFeature) + doorControls[0].latestValue(deviceFeature) } def getAt(int ix) { diff --git a/Event/Event.groovy b/Event/Event.groovy index 794dbca..b05425a 100644 --- a/Event/Event.groovy +++ b/Event/Event.groovy @@ -2,7 +2,7 @@ package Event public class Event { - private int deviceId + private String deviceId private String value private String linkText private String displayName @@ -11,9 +11,9 @@ public class Event { private String descriptionText private boolean isStateChange private String unit - private ArrayList data + private LinkedHashMap data - Event(String value, String name, int deviceId, String descriptionText, boolean displayed, String linkText, String displayName, boolean isStateChange, String unit, ArrayList data) { + Event(String value, String name, String deviceId, String descriptionText, boolean displayed, String linkText, String displayName, boolean isStateChange, String unit, LinkedHashMap data) { this.deviceId = deviceId this.linkText = linkText this.value = value diff --git a/Extractor/App1/App1.groovy b/Extractor/App1/App1.groovy index b94d720..0d4c97e 100644 --- a/Extractor/App1/App1.groovy +++ b/Extractor/App1/App1.groovy @@ -1,128 +1,102 @@ -//////////////// -definition( - name: "NFC Tag Toggle", - namespace: "smartthings", - author: "SmartThings", - description: "Allows toggling of a switch, lock, or garage door based on an NFC Tag touch event", - category: "SmartThings Internal", - iconUrl: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor.png", - iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor@2x.png", - iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor@2x.png") +/** + * Auto Lock Door + * + * Author: Chris Sader (@csader) + * Collaborators: @chrisb + * Date: 2013-08-21 + * URL: http://www.github.com/smartthings-users/smartapp.auto-lock-door + * + * Copyright (C) 2013 Chris Sader. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the "Software"), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ -preferences { - page(name: "pageOne", title: "Device selection", uninstall: true, nextPage: "pageTwo") { - section("Select an NFC tag") { - input "tag", "capability.touchSensor", title: "NFC Tag" - } - section("Select devices to control") { - input "switch1", "capability.switch", title: "Light or switch", required: false, multiple: true - input "lock", "capability.lock", title: "Lock", required: false, multiple: true - input "garageDoor", "capability.doorControl", title: "Garage door controller", required: false, multiple: true - } +preferences +{ + section("When a door unlocks...") { + input "lock1", "capability.lock" } - - page(name: "pageTwo", title: "Master devices", install: true, uninstall: true) -} - -def pageTwo() { - dynamicPage(name: "pageTwo") { - section("If set, the state of these devices will be toggled each time the tag is touched, " + - "e.g. a light that's on will be turned off and one that's off will be turned on, " + - "other devices of the same type will be set to the same state as their master device. " + - "If no master is designated then the majority of devices of the same type will be used " + - "to determine whether to turn on or off the devices.") { - - if (switch1 || masterSwitch) { - input "masterSwitch", "enum", title: "Master switch", options: switch1.collect{[(it.id): it.displayName]}, required: false - } - if (lock || masterLock) { - input "masterLock", "enum", title: "Master lock", options: lock.collect{[(it.id): it.displayName]}, required: false - } - if (garageDoor || masterDoor) { - input "masterDoor", "enum", title: "Master door", options: garageDoor.collect{[(it.id): it.displayName]}, required: false - } - } - section([mobileOnly:true]) { - label title: "Assign a name", required: false - mode title: "Set for specific mode(s)", required: false - } + section("Lock it how many minutes later?") { + input "minutesLater", "number", title: "When?" + } + section("Lock it only when this door is closed") { + input "openSensor", "capability.contactSensor", title: "Where?" } } -def installed() { - log.debug "Installed with settings: ${settings}" - - initialize() +def installed() +{ + log.debug "Auto Lock Door installed. (URL: http://www.github.com/smartthings-users/smartapp.auto-lock-door)" + initialize() } -def updated() { - log.debug "Updated with settings: ${settings}" - - unsubscribe() - initialize() +def updated() +{ + unsubscribe() + unschedule() + log.debug "Auto Lock Door updated." + initialize() } -def initialize() { - subscribe tag, "nfcTouch", touchHandler - subscribe app, touchHandler +def initialize() +{ + log.debug "Settings: ${settings}" + subscribe(lock1, "lock", doorHandler) + subscribe(openSensor, "contact.closed", doorClosed) + subscribe(openSensor, "contact.open", doorOpen) } -private currentStatus(devices, master, attribute) { - log.trace "currentStatus($devices, $master, $attribute)" - def result = null - if (master) { - result = devices.find{it.id == master}?.currentValue(attribute) - } - else { - def map = [:] - devices.each { - def value = it.currentValue(attribute) - map[value] = (map[value] ?: 0) + 1 - log.trace "$it.displayName: $value" +def lockDoor() +{ + log.debug "Locking Door if Closed" + if((openSensor.latestValue("contact") == "closed")){ + log.debug "Door Closed" + lock1.lock() + } else { + if ((openSensor.latestValue("contact") == "open")) { + def delay = minutesLater * 60 + log.debug "Door open will try again in $minutesLater minutes" + runIn( delay, lockDoor ) } - log.trace map - result = map.collect{it}.sort{it.value}[-1].key } - log.debug "$attribute = $result" - result } -def touchHandler(evt) { - log.trace "touchHandler($evt.descriptionText)" - if (switch1) { - def status = currentStatus(switch1, masterSwitch, "switch") - switch1.each { - if (status == "on") { - it.off() - } - else { - it.on() - } - } - } - - if (lock) { - def status = currentStatus(lock, masterLock, "lock") - lock.each { - if (status == "locked") { - lock.unlock() - } - else { - lock.lock() - } - } +def doorOpen(evt) { + log.debug "Door open reset previous lock task..." + unschedule( lockDoor ) + def delay = minutesLater * 60 + runIn( delay, lockDoor ) +} + +def doorClosed(evt) { + log.debug "Door Closed" +} + +def doorHandler(evt) +{ + log.debug "Door ${openSensor.latestValue}" + log.debug "Lock ${evt.name} is ${evt.value}." + + if (evt.value == "locked") { // If the human locks the door then... + log.debug "Cancelling previous lock task..." + unschedule( lockDoor ) // ...we don't need to lock it later. } - - if (garageDoor) { - def status = currentStatus(garageDoor, masterDoor, "status") - garageDoor.each { - if (status == "open") { - it.close() - } - else { - it.open() - } - } + else { // If the door is unlocked then... + def delay = minutesLater * 60 // runIn uses seconds + log.debug "Re-arming lock in ${minutesLater} minutes (${delay}s)." + runIn( delay, lockDoor ) // ...schedule to lock in x minutes. } } diff --git a/Extractor/App1/extractedFunctionsApp1.groovy b/Extractor/App1/extractedFunctionsApp1.groovy index 9efae44..a892f94 100644 --- a/Extractor/App1/extractedFunctionsApp1.groovy +++ b/Extractor/App1/extractedFunctionsApp1.groovy @@ -1,12 +1,14 @@ //Global Object for functions in subscribe method! -def pageTwo = this.&pageTwo -//Global Object for functions in subscribe method! def installed = this.&installed //Global Object for functions in subscribe method! def updated = this.&updated //Global Object for functions in subscribe method! def initialize = this.&initialize //Global Object for functions in subscribe method! -def currentStatus = this.¤tStatus +def lockDoor = this.&lockDoor +//Global Object for functions in subscribe method! +def doorOpen = this.&doorOpen +//Global Object for functions in subscribe method! +def doorClosed = this.&doorClosed //Global Object for functions in subscribe method! -def touchHandler = this.&touchHandler +def doorHandler = this.&doorHandler diff --git a/Extractor/App1/extractedObjectsApp1.groovy b/Extractor/App1/extractedObjectsApp1.groovy index 446015f..4ab787d 100644 --- a/Extractor/App1/extractedObjectsApp1.groovy +++ b/Extractor/App1/extractedObjectsApp1.groovy @@ -1,14 +1,6 @@ -//Object for class Touch Sensor! -def tag -//Object for class switch! -def switch1 //Object for class lock! -def lock -//Object for class door control! -def garageDoor -//Global variable for enum! -def masterSwitch = "40" -//Global variable for enum! -def masterLock = "20" -//Global variable for enum! -def masterDoor = "40" +def lock1 +//Global variable for number! +def minutesLater = 1 +//Object for class contactSensor! +def openSensor diff --git a/Extractor/App1/extractedObjectsConstructorApp1.groovy b/Extractor/App1/extractedObjectsConstructorApp1.groovy index 976189a..554fba3 100644 --- a/Extractor/App1/extractedObjectsConstructorApp1.groovy +++ b/Extractor/App1/extractedObjectsConstructorApp1.groovy @@ -1,4 +1,4 @@ -tag = obj.touchSensorObject -switch1 = obj.switchObject -lock = obj.lockObject -garageDoor = obj.doorControlObject +lock1 = obj.lockObject +openSensor = obj.contactObject +//Global variable for settings! +settings = [app:app, lock1:lock1, minutesLater:minutesLater, openSensor:openSensor] diff --git a/Extractor/App2/App2.groovy b/Extractor/App2/App2.groovy index 0af812f..ce2ea22 100644 --- a/Extractor/App2/App2.groovy +++ b/Extractor/App2/App2.groovy @@ -1,66 +1,128 @@ -///// +//////////////// 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 - */ - ) + name: "NFC Tag Toggle", + namespace: "smartthings", + author: "SmartThings", + description: "Allows toggling of a switch, lock, or garage door based on an NFC Tag touch event", + category: "SmartThings Internal", + iconUrl: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor.png", + iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor@2x.png", + iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor@2x.png") + + preferences { - section("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 + page(name: "pageOne", title: "Device selection", uninstall: true, nextPage: "pageTwo") { + section("Select an NFC tag") { + input "tag", "capability.touchSensor", title: "NFC Tag" + } + section("Select devices to control") { + input "switch1", "capability.switch", title: "Light or switch", required: false, multiple: true + input "lock", "capability.lock", title: "Lock", required: false, multiple: true + input "garageDoor", "capability.doorControl", title: "Garage door controller", required: false, multiple: true + } } - 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 - } + + page(name: "pageTwo", title: "Master devices", install: true, uninstall: true) } +def pageTwo() { + dynamicPage(name: "pageTwo") { + section("If set, the state of these devices will be toggled each time the tag is touched, " + + "e.g. a light that's on will be turned off and one that's off will be turned on, " + + "other devices of the same type will be set to the same state as their master device. " + + "If no master is designated then the majority of devices of the same type will be used " + + "to determine whether to turn on or off the devices.") { -def installed() -{ - log.debug "Installed with settings: ${settings}" - log.debug "Current mode = ${location.mode}" - subscribe(app, appTouch) + if (switch1 || masterSwitch) { + input "masterSwitch", "enum", title: "Master switch", options: switch1.collect{[(it.id): it.displayName]}, required: false + } + if (lock || masterLock) { + input "masterLock", "enum", title: "Master lock", options: lock.collect{[(it.id): it.displayName]}, required: false + } + if (garageDoor || masterDoor) { + input "masterDoor", "enum", title: "Master door", options: garageDoor.collect{[(it.id): it.displayName]}, required: false + } + } + section([mobileOnly:true]) { + label title: "Assign a name", required: false + mode title: "Set for specific mode(s)", required: false + } + } } +def installed() { + log.debug "Installed with settings: ${settings}" + + initialize() +} -def updated() -{ +def updated() { log.debug "Updated with settings: ${settings}" - log.debug "Current mode = ${location.mode}" + unsubscribe() - subscribe(app, appTouch) + initialize() +} + +def initialize() { + subscribe tag, "nfcTouch", touchHandler + subscribe app, touchHandler +} + +private currentStatus(devices, master, attribute) { + log.trace "currentStatus($devices, $master, $attribute)" + def result = null + if (master) { + result = devices.find{it.id == master}?.currentValue(attribute) + } + else { + def map = [:] + devices.each { + def value = it.currentValue(attribute) + map[value] = (map[value] ?: 0) + 1 + log.trace "$it.displayName: $value" + } + log.trace map + result = map.collect{it}.sort{it.value}[-1].key + } + log.debug "$attribute = $result" + result } -def 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) +def touchHandler(evt) { + log.trace "touchHandler($evt.descriptionText)" + if (switch1) { + def status = currentStatus(switch1, masterSwitch, "switch") + switch1.each { + if (status == "on") { + it.off() + } + else { + it.on() + } + } + } + + if (lock) { + def status = currentStatus(lock, masterLock, "lock") + lock.each { + if (status == "locked") { + lock.unlock() + } + else { + lock.lock() + } + } + } + + if (garageDoor) { + def status = currentStatus(garageDoor, masterDoor, "status") + garageDoor.each { + if (status == "open") { + it.close() + } + else { + it.open() + } + } + } } diff --git a/Extractor/App2/extractedFunctionsApp2.groovy b/Extractor/App2/extractedFunctionsApp2.groovy index 6d9060e..9efae44 100644 --- a/Extractor/App2/extractedFunctionsApp2.groovy +++ b/Extractor/App2/extractedFunctionsApp2.groovy @@ -1,6 +1,12 @@ //Global Object for functions in subscribe method! +def pageTwo = this.&pageTwo +//Global Object for functions in subscribe method! def installed = this.&installed //Global Object for functions in subscribe method! def updated = this.&updated //Global Object for functions in subscribe method! -def appTouch = this.&appTouch +def initialize = this.&initialize +//Global Object for functions in subscribe method! +def currentStatus = this.¤tStatus +//Global Object for functions in subscribe method! +def touchHandler = this.&touchHandler diff --git a/Extractor/App2/extractedObjectsApp2.groovy b/Extractor/App2/extractedObjectsApp2.groovy index 53e0420..ff33ee0 100644 --- a/Extractor/App2/extractedObjectsApp2.groovy +++ b/Extractor/App2/extractedObjectsApp2.groovy @@ -1,10 +1,14 @@ +//Object for class Touch Sensor! +def tag //Object for class switch! -def switchesoff -//Object for class switch! -def switcheson +def switch1 //Object for class lock! -def lock1 -//Global variable for mode! -def newMode = "home" -//Global variable for number! -def waitfor = 10 +def lock +//Object for class door control! +def garageDoor +//Global variable for enum! +def masterSwitch = "switchID0" +//Global variable for enum! +def masterLock = "lockID0" +//Global variable for enum! +def masterDoor = "DoorControlID0" diff --git a/Extractor/App2/extractedObjectsConstructorApp2.groovy b/Extractor/App2/extractedObjectsConstructorApp2.groovy index 709a386..6d5a754 100644 --- a/Extractor/App2/extractedObjectsConstructorApp2.groovy +++ b/Extractor/App2/extractedObjectsConstructorApp2.groovy @@ -1,3 +1,6 @@ -switchesoff = obj.switchObject -switcheson = obj.switchObject -lock1 = obj.lockObject +tag = obj.touchSensorObject +switch1 = obj.switchObject +lock = obj.lockObject +garageDoor = obj.doorControlObject +//Global variable for settings! +settings = [app:app, tag:tag, switch1:switch1, lock:lock, garageDoor:garageDoor, masterSwitch:masterSwitch, masterLock:masterLock, masterDoor:masterDoor] diff --git a/Extractor/Extractor.groovy b/Extractor/Extractor.groovy index 705cee8..2c2affe 100644 --- a/Extractor/Extractor.groovy +++ b/Extractor/Extractor.groovy @@ -22,877 +22,183 @@ import Location.LocationVar import Location.Phrase import appTouch.Touched import NfcTouch.NfcTouch +import AeonKeyFob.AeonKeyFob +import AeonKeyFob.AeonKeyFobs +import MusicPlayer.MusicPlayer +import MusicPlayer.MusicPlayers import Timer.SimulatedTimer +//GlobalVariables +@Field def location = new LocationVar() +//Settings variable defined to settings on purpose +@Field def settings = [app: "app"] +//Global variable for state[mode] +@Field def state = [home:[],away:[],night:[]] +//Create a global logger object for methods +@Field def log = new Logger() -@Field App //Default +//Global variables for files +@Field File extractedObjectsApp1 = new File("Extractor/App1/extractedObjectsApp1.groovy") +@Field File extractedObjectsApp2 = new File("Extractor/App2/extractedObjectsApp2.groovy") +@Field File extractedObjectsConstructorApp1 = new File("Extractor/App1/extractedObjectsConstructorApp1.groovy") +@Field File extractedObjectsConstructorApp2 = new File("Extractor/App2/extractedObjectsConstructorApp2.groovy") -//Global variables for files -@Field File extractedObjectsApp1 = new File("Extractor/App1/extractedObjectsApp1.groovy") -@Field File extractedObjectsApp2 = new File("Extractor/App2/extractedObjectsApp2.groovy") -@Field File extractedObjectsConstructorApp1 = new File("Extractor/App1/extractedObjectsConstructorApp1.groovy") -@Field File extractedObjectsConstructorApp2 = new File("Extractor/App2/extractedObjectsConstructorApp2.groovy") - - -//Empty the files -if (App == "App1") { - extractedObjectsApp1.write("") - extractedObjectsConstructorApp1.write("") -} else if (App == "App2") { - extractedObjectsApp2.write("") - extractedObjectsConstructorApp2.write("") -} - - - - - -//Global objects -//Global Object for class Touch Sensor! -@Field def touchSensorObject -//Global Object for class switch! -@Field def switchObject -//Global Object for class lock! -@Field def lockObject -//Global Object for class door control! -@Field def doorControlObject -//Global Object for class contact sensor! -@Field def contactObject -//Global Object for class presence sensor! -@Field def presenceSensorObject -//Global Object for class thermostat! -@Field def thermostatObject - - -//Global variables -//For mode -@Field modeVariables = 0 -@Field mode0 -@Field mode1 -@Field mode2 -@Field mode3 -@Field mode4 -@Field mode5 -//For number -@Field numberVariables = 0 -@Field number0 -@Field number1 -@Field number2 -@Field number3 -@Field number4 -@Field number5 -//For time -@Field timeVariables = 0 -@Field time0 -@Field time1 -@Field time2 -@Field time3 -@Field time4 -@Field time5 -//For enum -@Field enumVariables = 0 -@Field enum0 -@Field enum1 -@Field enum2 -@Field enum3 -@Field enum4 -@Field enum5 -//For phone -@Field phoneVariables = 0 -@Field phone0 -@Field phone1 -@Field phone2 -@Field phone3 -@Field phone4 -@Field phone5 -//For contact -@Field contactVariables = 0 -@Field contact0 -@Field contact1 -@Field contact2 -@Field contact3 -@Field contact4 -@Field contact5 - - - -/////Input Methods///// -//input "","" -def input(String name, String type) { - switch(type) { - case "capability.lock": - lockObject = name - this[lockObject] = new Locks({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class lock!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.lockObject\n") - } else { - extractedObjectsApp2.append("//Object for class lock!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.lockObject\n") - } - break - case "capability.alarm": - break - case "capability.battery": - break - case "capability.beacon": - break - case "capability.carbonMonoxideDetector": - break - case "capability.colorControl": - break - case "capability.contactSensor": - contactObject = name - this[contactObject] = new ContactSensors({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class contactSensor!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.contactObject\n") - } else { - extractedObjectsApp2.append("//Object for class contactSensor!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.contactObject\n") - } - break - case "capability.doorControl": - doorControlObject = name - this[doorControlObject] = new DoorControls({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class door control!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.doorControlObject\n") - } else { - extractedObjectsApp2.append("//Object for class door control!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.doorControlObject\n") - } - break - case "capability.energyMeter": - break - case "capability.illuminanceMeasurement": - break - case "capability.accelerationSensor": - break - case "capability.motionSensor": - break - case "capability.musicPlayer": - break - case "capability.powerMeter": - break - case "capability.presenceSensor": - presenceSensorObject = name - this[presenceSensorObject] = new PresenceSensors({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class presence sensor!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.presenceSensorObject\n") - } else { - extractedObjectsApp2.append("//Object for class presence sensor!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.presenceSensorObject\n") - } - break - case "capability.relativeHumidityMeasurement": - break - case "capability.relaySwitch": - break - case "capability.sleepSensor": - break - case "capability.smokeDetector": - break - case "capability.stepSensor": - break - case "capability.switch": - switchObject = name - this[switchObject] = new Switches({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class switch!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.switchObject\n") - } else { - extractedObjectsApp2.append("//Object for class switch!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.switchObject\n") - } - break - case "capability.switchLevel": - break - case "capability.temperatureMeasurement": - break - case "capability.thermostat": - thermostatObject = name - this[thermostatObject] = new Thermostats({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class thermostat!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.thermostatObject\n") - } else { - extractedObjectsApp2.append("//Object for class thermostat!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.thermostatObject\n") - } - break - case "capability.valve": - break - case "capability.waterSensor": - break - case "capability.touchSensor": - touchSensorObject = name - this[touchSensorObject] = new NfcTouch({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class Touch Sensor!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.touchSensorObject\n") - } else { - extractedObjectsApp2.append("//Object for class Touch Sensor!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.touchSensorObject\n") - } - break - case "capability.imageCapture": - break - case "device.mobilePresence": - break - case "device.aeonKeyFob": - break - case "mode": - def userInput = System.console().readLine 'Enter the mode:' - - if (modeVariables == 0) { - mode0 = name - this[mode0] = userInput - } else if (modeVariables == 1) { - mode1 = name - this[mode1] = userInput - } else if (modeVariables == 2) { - mode2 = name - this[mode2] = userInput - } else if (modeVariables == 3) { - mode3 = name - this[mode3] = userInput - } else if (modeVariables == 4) { - mode4 = name - this[mode4] = userInput - } else if (modeVariables == 5) { - mode5 = name - this[mode5] = userInput - } - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for mode!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for mode!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - case "decimal": - break - case "text": - break - case "number": - def userInput = System.console().readLine 'Enter the number:' - - if (numberVariables == 0) { - number0 = name - this[number0] = userInput - } else if (numberVariables == 1) { - number1 = name - this[number1] = userInput - } else if (numberVariables == 2) { - number2 = name - this[number2] = userInput - } else if (numberVariables == 3) { - number3 = name - this[number3] = userInput - } else if (numberVariables == 4) { - number4 = name - this[number4] = userInput - } else if (numberVariables == 5) { - number5 = name - this[number5] = userInput - } - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for number!\n") - extractedObjectsApp1.append("def "+name+" = "+userInput+"\n") - } else { - extractedObjectsApp2.append("//Global variable for number!\n") - extractedObjectsApp2.append("def "+name+" = "+userInput+"\n") - } - break - case "time": - def userInput = System.console().readLine 'Enter the time:' - - if (timeVariables == 0) { - time0 = name - this[time0] = userInput - } else if (timeVariables == 1) { - time1 = name - this[time1] = userInput - } else if (timeVariables == 2) { - time2 = name - this[time2] = userInput - } else if (timeVariables == 3) { - time3 = name - this[time3] = userInput - } else if (timeVariables == 4) { - time4 = name - this[time4] = userInput - } else if (timeVariables == 5) { - time5 = name - this[time5] = userInput - } - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for time!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for time!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - case "enum": - def userInput = System.console().readLine 'Enter the enum:' - - if (enumVariables == 0) { - enum0 = name - this[enum0] = userInput - } else if (enumVariables == 1) { - enum1 = name - this[enum1] = userInput - } else if (enumVariables == 2) { - enum2 = name - this[enum2] = userInput - } else if (enumVariables == 3) { - enum3 = name - this[enum3] = userInput - } else if (enumVariables == 4) { - enum4 = name - this[enum4] = userInput - } else if (enumVariables == 5) { - enum5 = name - this[enum5] = userInput - } - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for enum!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for enum!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - case "bool": - break - case "phone": - def userInput = System.console().readLine 'Enter the phone:' - - if (phoneVariables == 0) { - phone0 = name - this[phone0] = userInput - } else if (phoneVariables == 1) { - phone1 = name - this[phone1] = userInput - } else if (phoneVariables == 2) { - phone2 = name - this[phone2] = userInput - } else if (phoneVariables == 3) { - phone3 = name - this[phone3] = userInput - } else if (phoneVariables == 4) { - phone4 = name - this[phone4] = userInput - } else if (phoneVariables == 5) { - phone5 = name - this[phone5] = userInput - } - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for phone!\n") - extractedObjectsApp1.append("def "+name+" = "+userInput+"\n") - } else { - extractedObjectsApp2.append("//Global variable for phone!\n") - extractedObjectsApp2.append("def "+name+" = "+userInput+"\n") - } - break - case "contact": - def userInput = System.console().readLine 'Enter the name of the contact:' - - if (contactVariables == 0) { - contact0 = name - this[contact0] = userInput - } else if (contactVariables == 1) { - contact1 = name - this[contact1] = userInput - } else if (contactVariables == 2) { - contact2 = name - this[contact2] = userInput - } else if (contactVariables == 3) { - contact3 = name - this[contact3] = userInput - } else if (contactVariables == 4) { - contact4 = name - this[contact4] = userInput - } else if (contactVariables == 5) { - contact5 = name - this[contact5] = userInput - } - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for contact!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for contact!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - default: - break - } -} - -//input "","",linkedHashMap -def input(LinkedHashMap metaData, String name, String type) { - switch(type) { - case "capability.lock": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - lockObject = name - this[lockObject] = new Locks({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class lock!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.lockObject\n") - } else { - extractedObjectsApp2.append("//Object for class lock!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.lockObject\n") - } - break - case "capability.alarm": - break - case "capability.battery": - break - case "capability.beacon": - break - case "capability.carbonMonoxideDetector": - break - case "capability.colorControl": - break - case "capability.contactSensor": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - contactObject = name - this[contactObject] = new ContactSensors({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class contactSensor!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.contactObject\n") - } else { - extractedObjectsApp2.append("//Object for class contactSensor!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.contactObject\n") - } - break - case "capability.doorControl": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - doorControlObject = name - this[doorControlObject] = new DoorControls({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class door control!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.doorControlObject\n") - } else { - extractedObjectsApp2.append("//Object for class door control!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.doorControlObject\n") - } - break - case "capability.energyMeter": - break - case "capability.illuminanceMeasurement": - break - case "capability.accelerationSensor": - break - case "capability.motionSensor": - break - case "capability.musicPlayer": - break - case "capability.powerMeter": - break - case "capability.presenceSensor": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - presenceSensorObject = name - this[presenceSensorObject] = new PresenceSensors({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class presence sensor!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.presenceSensorObject\n") - } else { - extractedObjectsApp2.append("//Object for class presence sensor!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.presenceSensorObject\n") - } - break - case "capability.relativeHumidityMeasurement": - break - case "capability.relaySwitch": - break - case "capability.sleepSensor": - break - case "capability.smokeDetector": - break - case "capability.stepSensor": - break - case "capability.switch": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - switchObject = name - this[switchObject] = new Switches({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class switch!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.switchObject\n") - } else { - extractedObjectsApp2.append("//Object for class switch!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.switchObject\n") - } - break - case "capability.switchLevel": - break - case "capability.temperatureMeasurement": - break - case "capability.thermostat": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - thermostatObject = name - this[thermostatObject] = new Thermostats({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class thermostat!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.thermostatObject\n") - } else { - extractedObjectsApp2.append("//Object for class thermostat!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.thermostatObject\n") - } - break - case "capability.valve": - break - case "capability.waterSensor": - break - case "capability.touchSensor": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - touchSensorObject = name - this[touchSensorObject] = new NfcTouch({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class Touch Sensor!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.touchSensorObject\n") - } else { - extractedObjectsApp2.append("//Object for class Touch Sensor!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.touchSensorObject\n") - } - break - case "capability.imageCapture": - break - case "device.mobilePresence": - break - case "device.aeonKeyFob": - break - case "mode": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - def userInput = System.console().readLine 'Enter the mode:' - - if (modeVariables == 0) { - mode0 = name - this[mode0] = userInput - } else if (modeVariables == 1) { - mode1 = name - this[mode1] = userInput - } else if (modeVariables == 2) { - mode2 = name - this[mode2] = userInput - } else if (modeVariables == 3) { - mode3 = name - this[mode3] = userInput - } else if (modeVariables == 4) { - mode4 = name - this[mode4] = userInput - } else if (modeVariables == 5) { - mode5 = name - this[mode5] = userInput - } - - modeVariables=modeVariables+1 - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for mode!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for mode!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - case "decimal": - break - case "text": - break - case "number": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - def userInput = System.console().readLine 'Enter the number:' - - if (numberVariables == 0) { - number0 = name - this[number0] = userInput - } else if (numberVariables == 1) { - number1 = name - this[number1] = userInput - } else if (numberVariables == 2) { - number2 = name - this[number2] = userInput - } else if (numberVariables == 3) { - number3 = name - this[number3] = userInput - } else if (numberVariables == 4) { - number4 = name - this[number4] = userInput - } else if (numberVariables == 5) { - number5 = name - this[number5] = userInput - } - - numberVariables=numberVariables+1 - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for number!\n") - extractedObjectsApp1.append("def "+name+" = "+userInput+"\n") - } else { - extractedObjectsApp2.append("//Global variable for number!\n") - extractedObjectsApp2.append("def "+name+" = "+userInput+"\n") - } - break - case "time": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - def userInput = System.console().readLine 'Enter the time:' - - if (timeVariables == 0) { - time0 = name - this[time0] = userInput - } else if (timeVariables == 1) { - time1 = name - this[time1] = userInput - } else if (timeVariables == 2) { - time2 = name - this[time2] = userInput - } else if (timeVariables == 3) { - time3 = name - this[time3] = userInput - } else if (timeVariables == 4) { - time4 = name - this[time4] = userInput - } else if (timeVariables == 5) { - time5 = name - this[time5] = userInput - } - - timeVariables=timeVariables+1 - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for time!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for time!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - case "enum": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - def userInput = System.console().readLine 'Enter the enum:' - - if (enumVariables == 0) { - enum0 = name - this[enum0] = userInput - } else if (enumVariables == 1) { - enum1 = name - this[enum1] = userInput - } else if (enumVariables == 2) { - enum2 = name - this[enum2] = userInput - } else if (enumVariables == 3) { - enum3 = name - this[enum3] = userInput - } else if (enumVariables == 4) { - enum4 = name - this[enum4] = userInput - } else if (enumVariables == 5) { - enum5 = name - this[enum5] = userInput - } +//Empty the files +if (App == "App1") { + extractedObjectsApp1.write("") + extractedObjectsConstructorApp1.write("") +} else if (App == "App2") { + extractedObjectsApp2.write("") + extractedObjectsConstructorApp2.write("") +} - enumVariables=enumVariables+1 - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for enum!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for enum!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - case "bool": - break - case "phone": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - def userInput = System.console().readLine 'Enter the phone:' - if (phoneVariables == 0) { - phone0 = name - this[phone0] = userInput - } else if (phoneVariables == 1) { - phone1 = name - this[phone1] = userInput - } else if (phoneVariables == 2) { - phone2 = name - this[phone2] = userInput - } else if (phoneVariables == 3) { - phone3 = name - this[phone3] = userInput - } else if (phoneVariables == 4) { - phone4 = name - this[phone4] = userInput - } else if (phoneVariables == 5) { - phone5 = name - this[phone5] = userInput - } - phoneVariables=phoneVariables+1 - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for phone!\n") - extractedObjectsApp1.append("def "+name+" = "+userInput+"\n") - } else { - extractedObjectsApp2.append("//Global variable for phone!\n") - extractedObjectsApp2.append("def "+name+" = "+userInput+"\n") - } - break - case "contact": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - def userInput = System.console().readLine 'Enter the name of the contact:' - - if (contactVariables == 0) { - contact0 = name - this[contact0] = userInput - } else if (contactVariables == 1) { - contact1 = name - this[contact1] = userInput - } else if (contactVariables == 2) { - contact2 = name - this[contact2] = userInput - } else if (contactVariables == 3) { - contact3 = name - this[contact3] = userInput - } else if (contactVariables == 4) { - contact4 = name - this[contact4] = userInput - } else if (contactVariables == 5) { - contact5 = name - this[contact5] = userInput - } +//Global objects +//Global Object for class Touch Sensor! +@Field touchSensorObjects = 0 +@Field def touchSensorObject0 +@Field def touchSensorObject1 +@Field def touchSensorObject2 +//Global Object for class switch! +@Field switchObjects = 0 +@Field def switchObject0 +@Field def switchObject1 +@Field def switchObject2 +//Global Object for class lock! +@Field lockObjects = 0 +@Field def lockObject0 +@Field def lockObject1 +@Field def lockObject2 +//Global Object for class door control! +@Field doorControlObjects = 0 +@Field def doorControlObject0 +@Field def doorControlObject1 +@Field def doorControlObject2 +//Global Object for class contact sensor! +@Field contactObjects = 0 +@Field def contactObject0 +@Field def contactObject1 +@Field def contactObject2 +//Global Object for class presence sensor! +@Field presenceSensorObjects = 0 +@Field def presenceSensorObject0 +@Field def presenceSensorObject1 +@Field def presenceSensorObject2 +//Global Object for class thermostat! +@Field thermostatObjects = 0 +@Field def thermostatObject0 +@Field def thermostatObject1 +@Field def thermostatObject2 +//Global Object for class music player! +@Field musicPlayerObjects = 0 +@Field def musicPlayerObject0 +@Field def musicPlayerObject1 +@Field def musicPlayerObject2 +//Global Object for class music player! +@Field aeonKeyFobObjects = 0 +@Field def aeonKeyFobObject0 +@Field def aeonKeyFobObject1 +@Field def aeonKeyFobObject2 - contactVariables=contactVariables+1 - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for contact!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for contact!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - default: - break - } +//Global variables +//For mode +@Field modeVariables = 0 +@Field mode0 +@Field mode1 +@Field mode2 +@Field mode3 +@Field mode4 +@Field mode5 +//For number +@Field numberVariables = 0 +@Field number0 +@Field number1 +@Field number2 +@Field number3 +@Field number4 +@Field number5 +//For time +@Field timeVariables = 0 +@Field time0 +@Field time1 +@Field time2 +@Field time3 +@Field time4 +@Field time5 +//For enum +@Field enumVariables = 0 +@Field enum0 +@Field enum1 +@Field enum2 +@Field enum3 +@Field enum4 +@Field enum5 +//For phone +@Field phoneVariables = 0 +@Field phone0 +@Field phone1 +@Field phone2 +@Field phone3 +@Field phone4 +@Field phone5 +//For contact +@Field contactVariables = 0 +@Field contact0 +@Field contact1 +@Field contact2 +@Field contact3 +@Field contact4 +@Field contact5 + + + +/////Input Methods///// +//input "","" +def input(String name, String type) { + LinkedHashMap metaData = [] + metaData.put('name',name) + metaData.put('type',type) + input(metaData) +} + +//input "","",linkedHashMap +def input(LinkedHashMap metaData, String name, String type) { + metaData.put('name',name) + metaData.put('type',type) + input(metaData) } + //input linkedHashMap def input(LinkedHashMap metaData) { + if (metaData.containsKey('title')) { + println metaData['title'] + } + if (metaData.containsKey('options')) { + println "Options: "+metaData['options'] + } switch(metaData['type']) { case "capability.lock": - if (metaData.containsKey('title')) { - println metaData['title'] + if (lockObjects == 0) { + lockObject0 = metaData['name'] + this[lockObject0] = new Locks({}, 1) + } else if (lockObjects == 1) { + lockObject1 = metaData['name'] + this[lockObject1] = new Locks({}, 1) + } else if (lockObjects == 2) { + lockObject2 = metaData['name'] + this[lockObject2] = new Locks({}, 1) } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - lockObject = metaData['name'] - this[lockObject] = new Locks({}, 1) + + lockObjects=lockObjects+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Object for class lock!\n") extractedObjectsApp1.append("def "+metaData['name']+"\n") @@ -914,14 +220,21 @@ def input(LinkedHashMap metaData) { case "capability.colorControl": break case "capability.contactSensor": - if (metaData.containsKey('title')) { - println metaData['title'] + if (contactObjects == 0) { + contactObject0 = metaData['name'] + this[contactObject0] = new ContactSensors({}, 1) + } else if (contactObjects == 1) { + contactObject1 = metaData['name'] + this[contactObject1] = new ContactSensors({}, 1) + } else if (contactObjects == 2) { + contactObject2 = metaData['name'] + this[contactObject2] = new ContactSensors({}, 1) } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - contactObject = metaData['name'] - this[contactObject] = new ContactSensors({}, 1) + + contactObjects=contactObjects+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Object for class contactSensor!\n") extractedObjectsApp1.append("def "+metaData['name']+"\n") @@ -933,8 +246,21 @@ def input(LinkedHashMap metaData) { } break case "capability.doorControl": - doorControlObject = metaData['name'] - this[doorControlObject] = new DoorControls({}, 1) + if (doorControlObjects == 0) { + doorControlObject0 = metaData['name'] + this[doorControlObject0] = new DoorControls({}, 1) + } else if (doorControlObjects == 1) { + doorControlObject1 = metaData['name'] + this[doorControlObject1] = new DoorControls({}, 1) + } else if (doorControlObjects == 2) { + doorControlObject2 = metaData['name'] + this[doorControlObject2] = new DoorControls({}, 1) + } + + doorControlObjects=doorControlObjects+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Object for class door control!\n") extractedObjectsApp1.append("def "+metaData['name']+"\n") @@ -954,18 +280,49 @@ def input(LinkedHashMap metaData) { case "capability.motionSensor": break case "capability.musicPlayer": + if (musicPlayerObjects == 0) { + musicPlayerObject0 = metaData['name'] + this[musicPlayerObject0] = new MusicPlayers({}, 1) + } else if (musicPlayerObjects == 1) { + musicPlayerObject1 = metaData['name'] + this[musicPlayerObject1] = new MusicPlayers({}, 1) + } else if (musicPlayerObjects == 2) { + musicPlayerObject2 = metaData['name'] + this[musicPlayerObject2] = new MusicPlayers({}, 1) + } + + musicPlayerObjects=musicPlayerObjects+1 + + settings.put(metaData['name'], metaData['name']) + + if (App == "App1") { + extractedObjectsApp1.append("//Object for class music player!\n") + extractedObjectsApp1.append("def "+metaData['name']+"\n") + extractedObjectsConstructorApp1.append(metaData['name']+" = obj.musicPlayerObject\n") + } else { + extractedObjectsApp2.append("//Object for class music player!\n") + extractedObjectsApp2.append("def "+metaData['name']+"\n") + extractedObjectsConstructorApp2.append(metaData['name']+" = obj.musicPlayerObject\n") + } break case "capability.powerMeter": break case "capability.presenceSensor": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] + if (presenceSensorObjects == 0) { + presenceSensorObject0 = metaData['name'] + this[presenceSensorObject0] = new PresenceSensors({}, 1) + } else if (presenceSensorObjects == 1) { + presenceSensorObject1 = metaData['name'] + this[presenceSensorObject1] = new PresenceSensors({}, 1) + } else if (presenceSensorObjects == 2) { + presenceSensorObject2 = metaData['name'] + this[presenceSensorObject2] = new PresenceSensors({}, 1) } - presenceSensorObject = metaData['name'] - this[presenceSensorObject] = new PresenceSensors({}, 1) + + presenceSensorObjects=presenceSensorObjects+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Object for class presence sensor!\n") extractedObjectsApp1.append("def "+metaData['name']+"\n") @@ -987,14 +344,21 @@ def input(LinkedHashMap metaData) { case "capability.stepSensor": break case "capability.switch": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - switchObject = metaData['name'] - this[switchObject] = new Switches({}, 1) + if (switchObjects == 0) { + switchObject0 = metaData['name'] + this[switchObject0] = new Switches({}, 1) + } else if (switchObjects == 1) { + switchObject1 = metaData['name'] + this[switchObject1] = new Switches({}, 1) + } else if (switchObjects == 2) { + switchObject2 = metaData['name'] + this[switchObject2] = new Switches({}, 1) + } + + switchObjects=switchObjects+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Object for class switch!\n") extractedObjectsApp1.append("def "+metaData['name']+"\n") @@ -1010,14 +374,21 @@ def input(LinkedHashMap metaData) { case "capability.temperatureMeasurement": break case "capability.thermostat": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] + if (thermostatObjects == 0) { + thermostatObject0 = metaData['name'] + this[thermostatObject0] = new Thermostats({}, 1) + } else if (thermostatObjects == 1) { + thermostatObject1 = metaData['name'] + this[thermostatObject1] = new Thermostats({}, 1) + } else if (thermostatObjects == 2) { + thermostatObject2 = metaData['name'] + this[thermostatObject2] = new Thermostats({}, 1) } - thermostatObject = metaData['name'] - this[thermostatObject] = new Thermostats({}, 1) + + thermostatObjects=thermostatObjects+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Object for class thermostat!\n") extractedObjectsApp1.append("def "+metaData['name']+"\n") @@ -1033,14 +404,21 @@ def input(LinkedHashMap metaData) { case "capability.waterSensor": break case "capability.touchSensor": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] + if (touchSensorObjects == 0) { + touchSensorObject0 = metaData['name'] + this[touchSensorObject0] = new NfcTouch({}, 1) + } else if (touchSensorObjects == 1) { + touchSensorObject1 = metaData['name'] + this[touchSensorObject1] = new NfcTouch({}, 1) + } else if (touchSensorObjects == 2) { + touchSensorObject2 = metaData['name'] + this[touchSensorObject2] = new NfcTouch({}, 1) } - touchSensorObject = metaData['name'] - this[touchSensorObject] = new NfcTouch({}, 1) + + touchSensorObjects=touchSensorObjects+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Object for class Touch Sensor!\n") extractedObjectsApp1.append("def "+metaData['name']+"\n") @@ -1056,14 +434,32 @@ def input(LinkedHashMap metaData) { case "device.mobilePresence": break case "device.aeonKeyFob": - break - case "mode": - if (metaData.containsKey('title')) { - println metaData['title'] + if (aeonKeyFobObjects == 0) { + aeonKeyFobObject0 = metaData['name'] + this[aeonKeyFobObject0] = new AeonKeyFobs({}, 1) + } else if (aeonKeyFobObjects == 1) { + aeonKeyFobObject1 = metaData['name'] + this[aeonKeyFobObject1] = new AeonKeyFobs({}, 1) + } else if (aeonKeyFobObjects == 2) { + aeonKeyFobObject2 = metaData['name'] + this[aeonKeyFobObject2] = new AeonKeyFobs({}, 1) } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] + + aeonKeyFobObjects=aeonKeyFobObjects+1 + + settings.put(metaData['name'], metaData['name']) + + if (App == "App1") { + extractedObjectsApp1.append("//Object for class aeon key fob!\n") + extractedObjectsApp1.append("def "+metaData['name']+"\n") + extractedObjectsConstructorApp1.append(metaData['name']+" = obj.aeonKeyFobObject\n") + } else { + extractedObjectsApp2.append("//Object for class aeon key fob!\n") + extractedObjectsApp2.append("def "+metaData['name']+"\n") + extractedObjectsConstructorApp2.append(metaData['name']+" = obj.aeonKeyFobObject\n") } + break + case "mode": def userInput = System.console().readLine 'Enter the mode:' if (modeVariables == 0) { @@ -1086,6 +482,10 @@ def input(LinkedHashMap metaData) { this[mode5] = userInput } + modeVariables=modeVariables+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Global variable for mode!\n") extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n") @@ -1099,12 +499,6 @@ def input(LinkedHashMap metaData) { case "text": break case "number": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } def userInput = System.console().readLine 'Enter the number:' if (numberVariables == 0) { @@ -1127,6 +521,10 @@ def input(LinkedHashMap metaData) { this[number5] = userInput } + numberVariables=numberVariables+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Global variable for number!\n") extractedObjectsApp1.append("def "+metaData['name']+" = "+userInput+"\n") @@ -1136,12 +534,6 @@ def input(LinkedHashMap metaData) { } break case "time": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } def userInput = System.console().readLine 'Enter the time:' if (timeVariables == 0) { @@ -1164,6 +556,10 @@ def input(LinkedHashMap metaData) { this[time5] = userInput } + timeVariables=timeVariables+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Global variable for time!\n") extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n") @@ -1173,12 +569,6 @@ def input(LinkedHashMap metaData) { } break case "enum": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } def userInput = System.console().readLine 'Enter the enum:' if (enumVariables == 0) { @@ -1201,6 +591,10 @@ def input(LinkedHashMap metaData) { this[enum5] = userInput } + enumVariables=enumVariables+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Global variable for enum!\n") extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n") @@ -1212,12 +606,6 @@ def input(LinkedHashMap metaData) { case "bool": break case "phone": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } def userInput = System.console().readLine 'Enter the phone:' if (phoneVariables == 0) { @@ -1240,6 +628,10 @@ def input(LinkedHashMap metaData) { this[phone5] = userInput } + phoneVariables=phoneVariables+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Global variable for phone!\n") extractedObjectsApp1.append("def "+metaData['name']+" = "+userInput+"\n") @@ -1249,12 +641,6 @@ def input(LinkedHashMap metaData) { } break case "contact": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } def userInput = System.console().readLine 'Enter the metaData['name'] of the contact:' if (contactVariables == 0) { @@ -1277,6 +663,10 @@ def input(LinkedHashMap metaData) { this[contact5] = userInput } + contactVariables=contactVariables+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Global variable for contact!\n") extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n") @@ -1321,6 +711,13 @@ def definition(LinkedHashMap metaData) { def preferences(Closure inputData) { find(inputData) //Run the closure to extract pages/sections/inputMethods + if (App == "App1") { + extractedObjectsConstructorApp1.append("//Global variable for settings!\n") + extractedObjectsConstructorApp1.append("settings = $settings\n") + } else { + extractedObjectsConstructorApp2.append("//Global variable for settings!\n") + extractedObjectsConstructorApp2.append("settings = $settings\n") + } } def page(LinkedHashMap metaData, Closure inputData) { @@ -1351,6 +748,10 @@ def section(String title, Closure inputData) { find(inputData) //Run the closure to extract inputMethods } +def section(Closure inputData) { + find(inputData) //Run the closure to extract inputMethods +} + def section(LinkedHashMap metaData, Closure inputData) { find(inputData) //Run the closure to extract inputMethods } diff --git a/Extractor/ExtractorScript.py b/Extractor/ExtractorScript.py index a699816..1588235 100644 --- a/Extractor/ExtractorScript.py +++ b/Extractor/ExtractorScript.py @@ -69,7 +69,7 @@ extractorFile = open("Extractor/extractorFile.groovy", "w+") Extractor = open("Extractor/Extractor.groovy", "r") F1 = open("Extractor/App1/App1.groovy", "r") -extractorFile.write("////////////////////") +extractorFile.write("////////////////////\n") extractorFile.write("@Field App\n") extractorFile.write("App = \"App1\"") extractorFile.write("\n") @@ -90,7 +90,7 @@ extractorFile = open("Extractor/extractorFile.groovy", "w+") Extractor = open("Extractor/Extractor.groovy", "r") F2 = open("Extractor/App2/App2.groovy", "r") -extractorFile.write("////////////////////") +extractorFile.write("////////////////////\n") extractorFile.write("@Field App\n") extractorFile.write("App = \"App2\"") extractorFile.write("\n") diff --git a/Extractor/extractorFile.groovy b/Extractor/extractorFile.groovy index 38d948a..e59706c 100644 --- a/Extractor/extractorFile.groovy +++ b/Extractor/extractorFile.groovy @@ -1,4 +1,5 @@ -////////////////////@Field App +//////////////////// +@Field App App = "App2" //////////////////////////////////////// //import libraries @@ -24,877 +25,183 @@ import Location.LocationVar import Location.Phrase import appTouch.Touched import NfcTouch.NfcTouch +import AeonKeyFob.AeonKeyFob +import AeonKeyFob.AeonKeyFobs +import MusicPlayer.MusicPlayer +import MusicPlayer.MusicPlayers import Timer.SimulatedTimer +//GlobalVariables +@Field def location = new LocationVar() +//Settings variable defined to settings on purpose +@Field def settings = [app: "app"] +//Global variable for state[mode] +@Field def state = [home:[],away:[],night:[]] +//Create a global logger object for methods +@Field def log = new Logger() -@Field App //Default +//Global variables for files +@Field File extractedObjectsApp1 = new File("Extractor/App1/extractedObjectsApp1.groovy") +@Field File extractedObjectsApp2 = new File("Extractor/App2/extractedObjectsApp2.groovy") +@Field File extractedObjectsConstructorApp1 = new File("Extractor/App1/extractedObjectsConstructorApp1.groovy") +@Field File extractedObjectsConstructorApp2 = new File("Extractor/App2/extractedObjectsConstructorApp2.groovy") -//Global variables for files -@Field File extractedObjectsApp1 = new File("Extractor/App1/extractedObjectsApp1.groovy") -@Field File extractedObjectsApp2 = new File("Extractor/App2/extractedObjectsApp2.groovy") -@Field File extractedObjectsConstructorApp1 = new File("Extractor/App1/extractedObjectsConstructorApp1.groovy") -@Field File extractedObjectsConstructorApp2 = new File("Extractor/App2/extractedObjectsConstructorApp2.groovy") - - -//Empty the files -if (App == "App1") { - extractedObjectsApp1.write("") - extractedObjectsConstructorApp1.write("") -} else if (App == "App2") { - extractedObjectsApp2.write("") - extractedObjectsConstructorApp2.write("") -} - - - - - -//Global objects -//Global Object for class Touch Sensor! -@Field def touchSensorObject -//Global Object for class switch! -@Field def switchObject -//Global Object for class lock! -@Field def lockObject -//Global Object for class door control! -@Field def doorControlObject -//Global Object for class contact sensor! -@Field def contactObject -//Global Object for class presence sensor! -@Field def presenceSensorObject -//Global Object for class thermostat! -@Field def thermostatObject - - -//Global variables -//For mode -@Field modeVariables = 0 -@Field mode0 -@Field mode1 -@Field mode2 -@Field mode3 -@Field mode4 -@Field mode5 -//For number -@Field numberVariables = 0 -@Field number0 -@Field number1 -@Field number2 -@Field number3 -@Field number4 -@Field number5 -//For time -@Field timeVariables = 0 -@Field time0 -@Field time1 -@Field time2 -@Field time3 -@Field time4 -@Field time5 -//For enum -@Field enumVariables = 0 -@Field enum0 -@Field enum1 -@Field enum2 -@Field enum3 -@Field enum4 -@Field enum5 -//For phone -@Field phoneVariables = 0 -@Field phone0 -@Field phone1 -@Field phone2 -@Field phone3 -@Field phone4 -@Field phone5 -//For contact -@Field contactVariables = 0 -@Field contact0 -@Field contact1 -@Field contact2 -@Field contact3 -@Field contact4 -@Field contact5 - - - -/////Input Methods///// -//input "","" -def input(String name, String type) { - switch(type) { - case "capability.lock": - lockObject = name - this[lockObject] = new Locks({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class lock!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.lockObject\n") - } else { - extractedObjectsApp2.append("//Object for class lock!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.lockObject\n") - } - break - case "capability.alarm": - break - case "capability.battery": - break - case "capability.beacon": - break - case "capability.carbonMonoxideDetector": - break - case "capability.colorControl": - break - case "capability.contactSensor": - contactObject = name - this[contactObject] = new ContactSensors({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class contactSensor!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.contactObject\n") - } else { - extractedObjectsApp2.append("//Object for class contactSensor!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.contactObject\n") - } - break - case "capability.doorControl": - doorControlObject = name - this[doorControlObject] = new DoorControls({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class door control!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.doorControlObject\n") - } else { - extractedObjectsApp2.append("//Object for class door control!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.doorControlObject\n") - } - break - case "capability.energyMeter": - break - case "capability.illuminanceMeasurement": - break - case "capability.accelerationSensor": - break - case "capability.motionSensor": - break - case "capability.musicPlayer": - break - case "capability.powerMeter": - break - case "capability.presenceSensor": - presenceSensorObject = name - this[presenceSensorObject] = new PresenceSensors({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class presence sensor!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.presenceSensorObject\n") - } else { - extractedObjectsApp2.append("//Object for class presence sensor!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.presenceSensorObject\n") - } - break - case "capability.relativeHumidityMeasurement": - break - case "capability.relaySwitch": - break - case "capability.sleepSensor": - break - case "capability.smokeDetector": - break - case "capability.stepSensor": - break - case "capability.switch": - switchObject = name - this[switchObject] = new Switches({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class switch!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.switchObject\n") - } else { - extractedObjectsApp2.append("//Object for class switch!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.switchObject\n") - } - break - case "capability.switchLevel": - break - case "capability.temperatureMeasurement": - break - case "capability.thermostat": - thermostatObject = name - this[thermostatObject] = new Thermostats({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class thermostat!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.thermostatObject\n") - } else { - extractedObjectsApp2.append("//Object for class thermostat!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.thermostatObject\n") - } - break - case "capability.valve": - break - case "capability.waterSensor": - break - case "capability.touchSensor": - touchSensorObject = name - this[touchSensorObject] = new NfcTouch({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class Touch Sensor!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.touchSensorObject\n") - } else { - extractedObjectsApp2.append("//Object for class Touch Sensor!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.touchSensorObject\n") - } - break - case "capability.imageCapture": - break - case "device.mobilePresence": - break - case "device.aeonKeyFob": - break - case "mode": - def userInput = System.console().readLine 'Enter the mode:' - - if (modeVariables == 0) { - mode0 = name - this[mode0] = userInput - } else if (modeVariables == 1) { - mode1 = name - this[mode1] = userInput - } else if (modeVariables == 2) { - mode2 = name - this[mode2] = userInput - } else if (modeVariables == 3) { - mode3 = name - this[mode3] = userInput - } else if (modeVariables == 4) { - mode4 = name - this[mode4] = userInput - } else if (modeVariables == 5) { - mode5 = name - this[mode5] = userInput - } - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for mode!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for mode!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - case "decimal": - break - case "text": - break - case "number": - def userInput = System.console().readLine 'Enter the number:' - - if (numberVariables == 0) { - number0 = name - this[number0] = userInput - } else if (numberVariables == 1) { - number1 = name - this[number1] = userInput - } else if (numberVariables == 2) { - number2 = name - this[number2] = userInput - } else if (numberVariables == 3) { - number3 = name - this[number3] = userInput - } else if (numberVariables == 4) { - number4 = name - this[number4] = userInput - } else if (numberVariables == 5) { - number5 = name - this[number5] = userInput - } - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for number!\n") - extractedObjectsApp1.append("def "+name+" = "+userInput+"\n") - } else { - extractedObjectsApp2.append("//Global variable for number!\n") - extractedObjectsApp2.append("def "+name+" = "+userInput+"\n") - } - break - case "time": - def userInput = System.console().readLine 'Enter the time:' - - if (timeVariables == 0) { - time0 = name - this[time0] = userInput - } else if (timeVariables == 1) { - time1 = name - this[time1] = userInput - } else if (timeVariables == 2) { - time2 = name - this[time2] = userInput - } else if (timeVariables == 3) { - time3 = name - this[time3] = userInput - } else if (timeVariables == 4) { - time4 = name - this[time4] = userInput - } else if (timeVariables == 5) { - time5 = name - this[time5] = userInput - } - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for time!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for time!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - case "enum": - def userInput = System.console().readLine 'Enter the enum:' - - if (enumVariables == 0) { - enum0 = name - this[enum0] = userInput - } else if (enumVariables == 1) { - enum1 = name - this[enum1] = userInput - } else if (enumVariables == 2) { - enum2 = name - this[enum2] = userInput - } else if (enumVariables == 3) { - enum3 = name - this[enum3] = userInput - } else if (enumVariables == 4) { - enum4 = name - this[enum4] = userInput - } else if (enumVariables == 5) { - enum5 = name - this[enum5] = userInput - } - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for enum!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for enum!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - case "bool": - break - case "phone": - def userInput = System.console().readLine 'Enter the phone:' - - if (phoneVariables == 0) { - phone0 = name - this[phone0] = userInput - } else if (phoneVariables == 1) { - phone1 = name - this[phone1] = userInput - } else if (phoneVariables == 2) { - phone2 = name - this[phone2] = userInput - } else if (phoneVariables == 3) { - phone3 = name - this[phone3] = userInput - } else if (phoneVariables == 4) { - phone4 = name - this[phone4] = userInput - } else if (phoneVariables == 5) { - phone5 = name - this[phone5] = userInput - } - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for phone!\n") - extractedObjectsApp1.append("def "+name+" = "+userInput+"\n") - } else { - extractedObjectsApp2.append("//Global variable for phone!\n") - extractedObjectsApp2.append("def "+name+" = "+userInput+"\n") - } - break - case "contact": - def userInput = System.console().readLine 'Enter the name of the contact:' - - if (contactVariables == 0) { - contact0 = name - this[contact0] = userInput - } else if (contactVariables == 1) { - contact1 = name - this[contact1] = userInput - } else if (contactVariables == 2) { - contact2 = name - this[contact2] = userInput - } else if (contactVariables == 3) { - contact3 = name - this[contact3] = userInput - } else if (contactVariables == 4) { - contact4 = name - this[contact4] = userInput - } else if (contactVariables == 5) { - contact5 = name - this[contact5] = userInput - } - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for contact!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for contact!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - default: - break - } -} - -//input "","",linkedHashMap -def input(LinkedHashMap metaData, String name, String type) { - switch(type) { - case "capability.lock": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - lockObject = name - this[lockObject] = new Locks({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class lock!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.lockObject\n") - } else { - extractedObjectsApp2.append("//Object for class lock!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.lockObject\n") - } - break - case "capability.alarm": - break - case "capability.battery": - break - case "capability.beacon": - break - case "capability.carbonMonoxideDetector": - break - case "capability.colorControl": - break - case "capability.contactSensor": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - contactObject = name - this[contactObject] = new ContactSensors({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class contactSensor!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.contactObject\n") - } else { - extractedObjectsApp2.append("//Object for class contactSensor!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.contactObject\n") - } - break - case "capability.doorControl": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - doorControlObject = name - this[doorControlObject] = new DoorControls({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class door control!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.doorControlObject\n") - } else { - extractedObjectsApp2.append("//Object for class door control!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.doorControlObject\n") - } - break - case "capability.energyMeter": - break - case "capability.illuminanceMeasurement": - break - case "capability.accelerationSensor": - break - case "capability.motionSensor": - break - case "capability.musicPlayer": - break - case "capability.powerMeter": - break - case "capability.presenceSensor": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - presenceSensorObject = name - this[presenceSensorObject] = new PresenceSensors({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class presence sensor!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.presenceSensorObject\n") - } else { - extractedObjectsApp2.append("//Object for class presence sensor!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.presenceSensorObject\n") - } - break - case "capability.relativeHumidityMeasurement": - break - case "capability.relaySwitch": - break - case "capability.sleepSensor": - break - case "capability.smokeDetector": - break - case "capability.stepSensor": - break - case "capability.switch": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - switchObject = name - this[switchObject] = new Switches({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class switch!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.switchObject\n") - } else { - extractedObjectsApp2.append("//Object for class switch!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.switchObject\n") - } - break - case "capability.switchLevel": - break - case "capability.temperatureMeasurement": - break - case "capability.thermostat": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - thermostatObject = name - this[thermostatObject] = new Thermostats({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class thermostat!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.thermostatObject\n") - } else { - extractedObjectsApp2.append("//Object for class thermostat!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.thermostatObject\n") - } - break - case "capability.valve": - break - case "capability.waterSensor": - break - case "capability.touchSensor": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - touchSensorObject = name - this[touchSensorObject] = new NfcTouch({}, 1) - if (App == "App1") { - extractedObjectsApp1.append("//Object for class Touch Sensor!\n") - extractedObjectsApp1.append("def "+name+"\n") - extractedObjectsConstructorApp1.append(name+" = obj.touchSensorObject\n") - } else { - extractedObjectsApp2.append("//Object for class Touch Sensor!\n") - extractedObjectsApp2.append("def "+name+"\n") - extractedObjectsConstructorApp2.append(name+" = obj.touchSensorObject\n") - } - break - case "capability.imageCapture": - break - case "device.mobilePresence": - break - case "device.aeonKeyFob": - break - case "mode": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - def userInput = System.console().readLine 'Enter the mode:' - - if (modeVariables == 0) { - mode0 = name - this[mode0] = userInput - } else if (modeVariables == 1) { - mode1 = name - this[mode1] = userInput - } else if (modeVariables == 2) { - mode2 = name - this[mode2] = userInput - } else if (modeVariables == 3) { - mode3 = name - this[mode3] = userInput - } else if (modeVariables == 4) { - mode4 = name - this[mode4] = userInput - } else if (modeVariables == 5) { - mode5 = name - this[mode5] = userInput - } - - modeVariables=modeVariables+1 - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for mode!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for mode!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - case "decimal": - break - case "text": - break - case "number": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - def userInput = System.console().readLine 'Enter the number:' - - if (numberVariables == 0) { - number0 = name - this[number0] = userInput - } else if (numberVariables == 1) { - number1 = name - this[number1] = userInput - } else if (numberVariables == 2) { - number2 = name - this[number2] = userInput - } else if (numberVariables == 3) { - number3 = name - this[number3] = userInput - } else if (numberVariables == 4) { - number4 = name - this[number4] = userInput - } else if (numberVariables == 5) { - number5 = name - this[number5] = userInput - } - - numberVariables=numberVariables+1 - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for number!\n") - extractedObjectsApp1.append("def "+name+" = "+userInput+"\n") - } else { - extractedObjectsApp2.append("//Global variable for number!\n") - extractedObjectsApp2.append("def "+name+" = "+userInput+"\n") - } - break - case "time": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - def userInput = System.console().readLine 'Enter the time:' - - if (timeVariables == 0) { - time0 = name - this[time0] = userInput - } else if (timeVariables == 1) { - time1 = name - this[time1] = userInput - } else if (timeVariables == 2) { - time2 = name - this[time2] = userInput - } else if (timeVariables == 3) { - time3 = name - this[time3] = userInput - } else if (timeVariables == 4) { - time4 = name - this[time4] = userInput - } else if (timeVariables == 5) { - time5 = name - this[time5] = userInput - } - - timeVariables=timeVariables+1 - - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for time!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for time!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - case "enum": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - def userInput = System.console().readLine 'Enter the enum:' - - if (enumVariables == 0) { - enum0 = name - this[enum0] = userInput - } else if (enumVariables == 1) { - enum1 = name - this[enum1] = userInput - } else if (enumVariables == 2) { - enum2 = name - this[enum2] = userInput - } else if (enumVariables == 3) { - enum3 = name - this[enum3] = userInput - } else if (enumVariables == 4) { - enum4 = name - this[enum4] = userInput - } else if (enumVariables == 5) { - enum5 = name - this[enum5] = userInput - } - - enumVariables=enumVariables+1 - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for enum!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for enum!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - case "bool": - break - case "phone": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - def userInput = System.console().readLine 'Enter the phone:' +//Empty the files +if (App == "App1") { + extractedObjectsApp1.write("") + extractedObjectsConstructorApp1.write("") +} else if (App == "App2") { + extractedObjectsApp2.write("") + extractedObjectsConstructorApp2.write("") +} - if (phoneVariables == 0) { - phone0 = name - this[phone0] = userInput - } else if (phoneVariables == 1) { - phone1 = name - this[phone1] = userInput - } else if (phoneVariables == 2) { - phone2 = name - this[phone2] = userInput - } else if (phoneVariables == 3) { - phone3 = name - this[phone3] = userInput - } else if (phoneVariables == 4) { - phone4 = name - this[phone4] = userInput - } else if (phoneVariables == 5) { - phone5 = name - this[phone5] = userInput - } - phoneVariables=phoneVariables+1 - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for phone!\n") - extractedObjectsApp1.append("def "+name+" = "+userInput+"\n") - } else { - extractedObjectsApp2.append("//Global variable for phone!\n") - extractedObjectsApp2.append("def "+name+" = "+userInput+"\n") - } - break - case "contact": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - def userInput = System.console().readLine 'Enter the name of the contact:' - - if (contactVariables == 0) { - contact0 = name - this[contact0] = userInput - } else if (contactVariables == 1) { - contact1 = name - this[contact1] = userInput - } else if (contactVariables == 2) { - contact2 = name - this[contact2] = userInput - } else if (contactVariables == 3) { - contact3 = name - this[contact3] = userInput - } else if (contactVariables == 4) { - contact4 = name - this[contact4] = userInput - } else if (contactVariables == 5) { - contact5 = name - this[contact5] = userInput - } - contactVariables=contactVariables+1 - if (App == "App1") { - extractedObjectsApp1.append("//Global variable for contact!\n") - extractedObjectsApp1.append("def "+name+" = \""+userInput+"\"\n") - } else { - extractedObjectsApp2.append("//Global variable for contact!\n") - extractedObjectsApp2.append("def "+name+" = \""+userInput+"\"\n") - } - break - default: - break - } +//Global objects +//Global Object for class Touch Sensor! +@Field touchSensorObjects = 0 +@Field def touchSensorObject0 +@Field def touchSensorObject1 +@Field def touchSensorObject2 +//Global Object for class switch! +@Field switchObjects = 0 +@Field def switchObject0 +@Field def switchObject1 +@Field def switchObject2 +//Global Object for class lock! +@Field lockObjects = 0 +@Field def lockObject0 +@Field def lockObject1 +@Field def lockObject2 +//Global Object for class door control! +@Field doorControlObjects = 0 +@Field def doorControlObject0 +@Field def doorControlObject1 +@Field def doorControlObject2 +//Global Object for class contact sensor! +@Field contactObjects = 0 +@Field def contactObject0 +@Field def contactObject1 +@Field def contactObject2 +//Global Object for class presence sensor! +@Field presenceSensorObjects = 0 +@Field def presenceSensorObject0 +@Field def presenceSensorObject1 +@Field def presenceSensorObject2 +//Global Object for class thermostat! +@Field thermostatObjects = 0 +@Field def thermostatObject0 +@Field def thermostatObject1 +@Field def thermostatObject2 +//Global Object for class music player! +@Field musicPlayerObjects = 0 +@Field def musicPlayerObject0 +@Field def musicPlayerObject1 +@Field def musicPlayerObject2 +//Global Object for class music player! +@Field aeonKeyFobObjects = 0 +@Field def aeonKeyFobObject0 +@Field def aeonKeyFobObject1 +@Field def aeonKeyFobObject2 + + +//Global variables +//For mode +@Field modeVariables = 0 +@Field mode0 +@Field mode1 +@Field mode2 +@Field mode3 +@Field mode4 +@Field mode5 +//For number +@Field numberVariables = 0 +@Field number0 +@Field number1 +@Field number2 +@Field number3 +@Field number4 +@Field number5 +//For time +@Field timeVariables = 0 +@Field time0 +@Field time1 +@Field time2 +@Field time3 +@Field time4 +@Field time5 +//For enum +@Field enumVariables = 0 +@Field enum0 +@Field enum1 +@Field enum2 +@Field enum3 +@Field enum4 +@Field enum5 +//For phone +@Field phoneVariables = 0 +@Field phone0 +@Field phone1 +@Field phone2 +@Field phone3 +@Field phone4 +@Field phone5 +//For contact +@Field contactVariables = 0 +@Field contact0 +@Field contact1 +@Field contact2 +@Field contact3 +@Field contact4 +@Field contact5 + + + +/////Input Methods///// +//input "","" +def input(String name, String type) { + LinkedHashMap metaData = [] + metaData.put('name',name) + metaData.put('type',type) + input(metaData) +} + +//input "","",linkedHashMap +def input(LinkedHashMap metaData, String name, String type) { + metaData.put('name',name) + metaData.put('type',type) + input(metaData) } + //input linkedHashMap def input(LinkedHashMap metaData) { + if (metaData.containsKey('title')) { + println metaData['title'] + } + if (metaData.containsKey('options')) { + println "Options: "+metaData['options'] + } switch(metaData['type']) { case "capability.lock": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] + if (lockObjects == 0) { + lockObject0 = metaData['name'] + this[lockObject0] = new Locks({}, 1) + } else if (lockObjects == 1) { + lockObject1 = metaData['name'] + this[lockObject1] = new Locks({}, 1) + } else if (lockObjects == 2) { + lockObject2 = metaData['name'] + this[lockObject2] = new Locks({}, 1) } - lockObject = metaData['name'] - this[lockObject] = new Locks({}, 1) + + lockObjects=lockObjects+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Object for class lock!\n") extractedObjectsApp1.append("def "+metaData['name']+"\n") @@ -916,14 +223,21 @@ def input(LinkedHashMap metaData) { case "capability.colorControl": break case "capability.contactSensor": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] + if (contactObjects == 0) { + contactObject0 = metaData['name'] + this[contactObject0] = new ContactSensors({}, 1) + } else if (contactObjects == 1) { + contactObject1 = metaData['name'] + this[contactObject1] = new ContactSensors({}, 1) + } else if (contactObjects == 2) { + contactObject2 = metaData['name'] + this[contactObject2] = new ContactSensors({}, 1) } - contactObject = metaData['name'] - this[contactObject] = new ContactSensors({}, 1) + + contactObjects=contactObjects+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Object for class contactSensor!\n") extractedObjectsApp1.append("def "+metaData['name']+"\n") @@ -935,8 +249,21 @@ def input(LinkedHashMap metaData) { } break case "capability.doorControl": - doorControlObject = metaData['name'] - this[doorControlObject] = new DoorControls({}, 1) + if (doorControlObjects == 0) { + doorControlObject0 = metaData['name'] + this[doorControlObject0] = new DoorControls({}, 1) + } else if (doorControlObjects == 1) { + doorControlObject1 = metaData['name'] + this[doorControlObject1] = new DoorControls({}, 1) + } else if (doorControlObjects == 2) { + doorControlObject2 = metaData['name'] + this[doorControlObject2] = new DoorControls({}, 1) + } + + doorControlObjects=doorControlObjects+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Object for class door control!\n") extractedObjectsApp1.append("def "+metaData['name']+"\n") @@ -956,18 +283,49 @@ def input(LinkedHashMap metaData) { case "capability.motionSensor": break case "capability.musicPlayer": + if (musicPlayerObjects == 0) { + musicPlayerObject0 = metaData['name'] + this[musicPlayerObject0] = new MusicPlayers({}, 1) + } else if (musicPlayerObjects == 1) { + musicPlayerObject1 = metaData['name'] + this[musicPlayerObject1] = new MusicPlayers({}, 1) + } else if (musicPlayerObjects == 2) { + musicPlayerObject2 = metaData['name'] + this[musicPlayerObject2] = new MusicPlayers({}, 1) + } + + musicPlayerObjects=musicPlayerObjects+1 + + settings.put(metaData['name'], metaData['name']) + + if (App == "App1") { + extractedObjectsApp1.append("//Object for class music player!\n") + extractedObjectsApp1.append("def "+metaData['name']+"\n") + extractedObjectsConstructorApp1.append(metaData['name']+" = obj.musicPlayerObject\n") + } else { + extractedObjectsApp2.append("//Object for class music player!\n") + extractedObjectsApp2.append("def "+metaData['name']+"\n") + extractedObjectsConstructorApp2.append(metaData['name']+" = obj.musicPlayerObject\n") + } break case "capability.powerMeter": break case "capability.presenceSensor": - if (metaData.containsKey('title')) { - println metaData['title'] + if (presenceSensorObjects == 0) { + presenceSensorObject0 = metaData['name'] + this[presenceSensorObject0] = new PresenceSensors({}, 1) + } else if (presenceSensorObjects == 1) { + presenceSensorObject1 = metaData['name'] + this[presenceSensorObject1] = new PresenceSensors({}, 1) + } else if (presenceSensorObjects == 2) { + presenceSensorObject2 = metaData['name'] + this[presenceSensorObject2] = new PresenceSensors({}, 1) } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - presenceSensorObject = metaData['name'] - this[presenceSensorObject] = new PresenceSensors({}, 1) + + presenceSensorObjects=presenceSensorObjects+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Object for class presence sensor!\n") extractedObjectsApp1.append("def "+metaData['name']+"\n") @@ -989,14 +347,21 @@ def input(LinkedHashMap metaData) { case "capability.stepSensor": break case "capability.switch": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - switchObject = metaData['name'] - this[switchObject] = new Switches({}, 1) + if (switchObjects == 0) { + switchObject0 = metaData['name'] + this[switchObject0] = new Switches({}, 1) + } else if (switchObjects == 1) { + switchObject1 = metaData['name'] + this[switchObject1] = new Switches({}, 1) + } else if (switchObjects == 2) { + switchObject2 = metaData['name'] + this[switchObject2] = new Switches({}, 1) + } + + switchObjects=switchObjects+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Object for class switch!\n") extractedObjectsApp1.append("def "+metaData['name']+"\n") @@ -1012,14 +377,21 @@ def input(LinkedHashMap metaData) { case "capability.temperatureMeasurement": break case "capability.thermostat": - if (metaData.containsKey('title')) { - println metaData['title'] + if (thermostatObjects == 0) { + thermostatObject0 = metaData['name'] + this[thermostatObject0] = new Thermostats({}, 1) + } else if (thermostatObjects == 1) { + thermostatObject1 = metaData['name'] + this[thermostatObject1] = new Thermostats({}, 1) + } else if (thermostatObjects == 2) { + thermostatObject2 = metaData['name'] + this[thermostatObject2] = new Thermostats({}, 1) } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - thermostatObject = metaData['name'] - this[thermostatObject] = new Thermostats({}, 1) + + thermostatObjects=thermostatObjects+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Object for class thermostat!\n") extractedObjectsApp1.append("def "+metaData['name']+"\n") @@ -1035,14 +407,21 @@ def input(LinkedHashMap metaData) { case "capability.waterSensor": break case "capability.touchSensor": - if (metaData.containsKey('title')) { - println metaData['title'] + if (touchSensorObjects == 0) { + touchSensorObject0 = metaData['name'] + this[touchSensorObject0] = new NfcTouch({}, 1) + } else if (touchSensorObjects == 1) { + touchSensorObject1 = metaData['name'] + this[touchSensorObject1] = new NfcTouch({}, 1) + } else if (touchSensorObjects == 2) { + touchSensorObject2 = metaData['name'] + this[touchSensorObject2] = new NfcTouch({}, 1) } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } - touchSensorObject = metaData['name'] - this[touchSensorObject] = new NfcTouch({}, 1) + + touchSensorObjects=touchSensorObjects+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Object for class Touch Sensor!\n") extractedObjectsApp1.append("def "+metaData['name']+"\n") @@ -1058,14 +437,32 @@ def input(LinkedHashMap metaData) { case "device.mobilePresence": break case "device.aeonKeyFob": - break - case "mode": - if (metaData.containsKey('title')) { - println metaData['title'] + if (aeonKeyFobObjects == 0) { + aeonKeyFobObject0 = metaData['name'] + this[aeonKeyFobObject0] = new AeonKeyFobs({}, 1) + } else if (aeonKeyFobObjects == 1) { + aeonKeyFobObject1 = metaData['name'] + this[aeonKeyFobObject1] = new AeonKeyFobs({}, 1) + } else if (aeonKeyFobObjects == 2) { + aeonKeyFobObject2 = metaData['name'] + this[aeonKeyFobObject2] = new AeonKeyFobs({}, 1) } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] + + aeonKeyFobObjects=aeonKeyFobObjects+1 + + settings.put(metaData['name'], metaData['name']) + + if (App == "App1") { + extractedObjectsApp1.append("//Object for class aeon key fob!\n") + extractedObjectsApp1.append("def "+metaData['name']+"\n") + extractedObjectsConstructorApp1.append(metaData['name']+" = obj.aeonKeyFobObject\n") + } else { + extractedObjectsApp2.append("//Object for class aeon key fob!\n") + extractedObjectsApp2.append("def "+metaData['name']+"\n") + extractedObjectsConstructorApp2.append(metaData['name']+" = obj.aeonKeyFobObject\n") } + break + case "mode": def userInput = System.console().readLine 'Enter the mode:' if (modeVariables == 0) { @@ -1088,6 +485,10 @@ def input(LinkedHashMap metaData) { this[mode5] = userInput } + modeVariables=modeVariables+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Global variable for mode!\n") extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n") @@ -1101,12 +502,6 @@ def input(LinkedHashMap metaData) { case "text": break case "number": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } def userInput = System.console().readLine 'Enter the number:' if (numberVariables == 0) { @@ -1129,6 +524,10 @@ def input(LinkedHashMap metaData) { this[number5] = userInput } + numberVariables=numberVariables+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Global variable for number!\n") extractedObjectsApp1.append("def "+metaData['name']+" = "+userInput+"\n") @@ -1138,12 +537,6 @@ def input(LinkedHashMap metaData) { } break case "time": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } def userInput = System.console().readLine 'Enter the time:' if (timeVariables == 0) { @@ -1166,6 +559,10 @@ def input(LinkedHashMap metaData) { this[time5] = userInput } + timeVariables=timeVariables+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Global variable for time!\n") extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n") @@ -1175,12 +572,6 @@ def input(LinkedHashMap metaData) { } break case "enum": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } def userInput = System.console().readLine 'Enter the enum:' if (enumVariables == 0) { @@ -1203,6 +594,10 @@ def input(LinkedHashMap metaData) { this[enum5] = userInput } + enumVariables=enumVariables+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Global variable for enum!\n") extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n") @@ -1214,12 +609,6 @@ def input(LinkedHashMap metaData) { case "bool": break case "phone": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } def userInput = System.console().readLine 'Enter the phone:' if (phoneVariables == 0) { @@ -1242,6 +631,10 @@ def input(LinkedHashMap metaData) { this[phone5] = userInput } + phoneVariables=phoneVariables+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Global variable for phone!\n") extractedObjectsApp1.append("def "+metaData['name']+" = "+userInput+"\n") @@ -1251,12 +644,6 @@ def input(LinkedHashMap metaData) { } break case "contact": - if (metaData.containsKey('title')) { - println metaData['title'] - } - if (metaData.containsKey('options')) { - println "Options: "+metaData['options'] - } def userInput = System.console().readLine 'Enter the metaData['name'] of the contact:' if (contactVariables == 0) { @@ -1279,6 +666,10 @@ def input(LinkedHashMap metaData) { this[contact5] = userInput } + contactVariables=contactVariables+1 + + settings.put(metaData['name'], metaData['name']) + if (App == "App1") { extractedObjectsApp1.append("//Global variable for contact!\n") extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n") @@ -1323,6 +714,13 @@ def definition(LinkedHashMap metaData) { def preferences(Closure inputData) { find(inputData) //Run the closure to extract pages/sections/inputMethods + if (App == "App1") { + extractedObjectsConstructorApp1.append("//Global variable for settings!\n") + extractedObjectsConstructorApp1.append("settings = $settings\n") + } else { + extractedObjectsConstructorApp2.append("//Global variable for settings!\n") + extractedObjectsConstructorApp2.append("settings = $settings\n") + } } def page(LinkedHashMap metaData, Closure inputData) { @@ -1353,6 +751,10 @@ def section(String title, Closure inputData) { find(inputData) //Run the closure to extract inputMethods } +def section(Closure inputData) { + find(inputData) //Run the closure to extract inputMethods +} + def section(LinkedHashMap metaData, Closure inputData) { find(inputData) //Run the closure to extract inputMethods } @@ -1360,69 +762,131 @@ def section(LinkedHashMap metaData, Closure inputData) { -///// +//////////////// 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 - */ - ) + name: "NFC Tag Toggle", + namespace: "smartthings", + author: "SmartThings", + description: "Allows toggling of a switch, lock, or garage door based on an NFC Tag touch event", + category: "SmartThings Internal", + iconUrl: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor.png", + iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor@2x.png", + iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Developers/nfc-tag-executor@2x.png") + + preferences { - section("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 + page(name: "pageOne", title: "Device selection", uninstall: true, nextPage: "pageTwo") { + section("Select an NFC tag") { + input "tag", "capability.touchSensor", title: "NFC Tag" + } + section("Select devices to control") { + input "switch1", "capability.switch", title: "Light or switch", required: false, multiple: true + input "lock", "capability.lock", title: "Lock", required: false, multiple: true + input "garageDoor", "capability.doorControl", title: "Garage door controller", required: false, multiple: true + } } - 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 - } + + page(name: "pageTwo", title: "Master devices", install: true, uninstall: true) } +def pageTwo() { + dynamicPage(name: "pageTwo") { + section("If set, the state of these devices will be toggled each time the tag is touched, " + + "e.g. a light that's on will be turned off and one that's off will be turned on, " + + "other devices of the same type will be set to the same state as their master device. " + + "If no master is designated then the majority of devices of the same type will be used " + + "to determine whether to turn on or off the devices.") { + + if (switch1 || masterSwitch) { + input "masterSwitch", "enum", title: "Master switch", options: switch1.collect{[(it.id): it.displayName]}, required: false + } + if (lock || masterLock) { + input "masterLock", "enum", title: "Master lock", options: lock.collect{[(it.id): it.displayName]}, required: false + } + if (garageDoor || masterDoor) { + input "masterDoor", "enum", title: "Master door", options: garageDoor.collect{[(it.id): it.displayName]}, required: false + } + } + section([mobileOnly:true]) { + label title: "Assign a name", required: false + mode title: "Set for specific mode(s)", required: false + } + } +} -def installed() -{ +def installed() { log.debug "Installed with settings: ${settings}" - log.debug "Current mode = ${location.mode}" - subscribe(app, appTouch) -} + initialize() +} -def updated() -{ +def updated() { log.debug "Updated with settings: ${settings}" - log.debug "Current mode = ${location.mode}" + unsubscribe() - subscribe(app, appTouch) + initialize() +} + +def initialize() { + subscribe tag, "nfcTouch", touchHandler + subscribe app, touchHandler +} + +private currentStatus(devices, master, attribute) { + log.trace "currentStatus($devices, $master, $attribute)" + def result = null + if (master) { + result = devices.find{it.id == master}?.currentValue(attribute) + } + else { + def map = [:] + devices.each { + def value = it.currentValue(attribute) + map[value] = (map[value] ?: 0) + 1 + log.trace "$it.displayName: $value" + } + log.trace map + result = map.collect{it}.sort{it.value}[-1].key + } + log.debug "$attribute = $result" + result } -def 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) +def touchHandler(evt) { + log.trace "touchHandler($evt.descriptionText)" + if (switch1) { + def status = currentStatus(switch1, masterSwitch, "switch") + switch1.each { + if (status == "on") { + it.off() + } + else { + it.on() + } + } + } + + if (lock) { + def status = currentStatus(lock, masterLock, "lock") + lock.each { + if (status == "locked") { + lock.unlock() + } + else { + lock.lock() + } + } + } + + if (garageDoor) { + def status = currentStatus(garageDoor, masterDoor, "status") + garageDoor.each { + if (status == "open") { + it.close() + } + else { + it.open() + } + } + } } diff --git a/GlobalVariables/GlobalVariablesBothApps.groovy b/GlobalVariables/GlobalVariablesBothApps.groovy index 3c65af1..8810742 100644 --- a/GlobalVariables/GlobalVariablesBothApps.groovy +++ b/GlobalVariables/GlobalVariablesBothApps.groovy @@ -22,3 +22,7 @@ @Field def presenceSensorObject = new PresenceSensors(sendEvent, 1) //Global Object for class thermostat! @Field def thermostatObject = new Thermostats(sendEvent, 1) +//Global Object for class aeon key fob! +@Field def aeonKeyFobObject = new AeonKeyFobs(sendEvent, 1) +//Global Object for class music player! +@Field def musicPlayerObject = new MusicPlayers(sendEvent, 1) diff --git a/GlobalVariables/GlobalVariablesEachApp.groovy b/GlobalVariables/GlobalVariablesEachApp.groovy index 2b6544c..ce8308c 100644 --- a/GlobalVariables/GlobalVariablesEachApp.groovy +++ b/GlobalVariables/GlobalVariablesEachApp.groovy @@ -1,5 +1,3 @@ -//Settings variable defined to settings on purpose -def settings = "Settings" //Global variable for state[mode] def state = [home:[],away:[],night:[]] //Create a global logger object for methods @@ -14,3 +12,5 @@ def eventList = [] def timersFuncList = [] //Create a global list for timer schedulers def timersList = [] +//Create a global variable for settings +def settings diff --git a/Location/LocationVar.groovy b/Location/LocationVar.groovy index cfaa308..43c88cd 100644 --- a/Location/LocationVar.groovy +++ b/Location/LocationVar.groovy @@ -3,7 +3,7 @@ package Location class LocationVar { private int contactBookEnabled - private String modes + private def modes private String mode private List contacts private List phoneNumbers @@ -11,7 +11,7 @@ class LocationVar { private Phrase helloHome LocationVar() { - this.modes = "'home', 'away', 'night'" + this.modes = [[name: "home"],[name: "away"],[name: "night"]] this.mode = "home" this.helloHome = new Phrase() this.contactBookEnabled = 1 diff --git a/Location/Phrase.groovy b/Location/Phrase.groovy index c70b934..e646096 100644 --- a/Location/Phrase.groovy +++ b/Location/Phrase.groovy @@ -2,14 +2,17 @@ package Location class Phrase { - private LinkedHashMap phrases + private phrases Phrase() { - this.phrases = [id:0, label:"Good Morning!"] + this.phrases = [[id:0, label:"Good Night!"],[id:1, label:"Good Morning!"], + [id:2, label:"Goodbye!"],[id:3, label:"I'm Back!"]] } def getPhrases() { return this.phrases } + def execute(String phrase) { + println(phrase) + } } - diff --git a/Lock/Lock.groovy b/Lock/Lock.groovy index cc4b466..ada1d82 100644 --- a/Lock/Lock.groovy +++ b/Lock/Lock.groovy @@ -3,7 +3,7 @@ package Lock import Timer.SimulatedTimer public class Lock { - private int id + private String id private String label private String displayName private String lockState @@ -13,7 +13,7 @@ public class Lock { def timers - Lock(Closure sendEvent, int id, String label, String displayName, String lockState, String lockLatestValue) { + Lock(Closure sendEvent, String id, String label, String displayName, String lockState, String lockLatestValue) { this.id = id this.label = label this.sendEvent = sendEvent @@ -31,7 +31,7 @@ public class Lock { this.lockState = "locked" this.currentLock = "locked" sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) + displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "locked"]]) } def lock(LinkedHashMap metaData) { @@ -41,7 +41,7 @@ public class Lock { this.lockState = "locked" this.currentLock = "locked" sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) + displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "locked"]]) } } @@ -51,7 +51,7 @@ public class Lock { this.lockState = "unlocked" this.currentLock = "unlocked" sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) + displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "unlocked"]]) } def unlock(LinkedHashMap metaData) { @@ -61,7 +61,7 @@ public class Lock { this.lockState = "locked" this.currentLock = "locked" sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) + displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "unlocked"]]) } } diff --git a/Lock/Locks.groovy b/Lock/Locks.groovy index 6133572..6214b84 100644 --- a/Lock/Locks.groovy +++ b/Lock/Locks.groovy @@ -9,9 +9,9 @@ public class Locks{ def timers //When we have only one device - private int id = 20 - private String label = "lock" - private String displayName = "lock" + private String id = "lockID0" + private String label = "lock0" + private String displayName = "lock0" private String lockState = "locked" private String currentLock = "locked" private String lockLatestValue = "locked" @@ -21,30 +21,29 @@ public class Locks{ this.timers = new SimulatedTimer() this.deviceNumbers = deviceNumbers this.locks = [] - for (int i = 0;i < deviceNumbers;i++) { - locks.add(new Lock(sendEvent, i+20, label+i.toString(), displayName+i.toString(), this.lockState, this.lockLatestValue)) - } + + locks.add(new Lock(sendEvent,id, label, displayName, this.lockState, this.lockLatestValue)) } //By Apps def lock() { - locks*.lock() + locks[0].lock() } def lock(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { - locks*.lock() + locks[0].lock() } } def unlock() { - locks*.unlock() + locks[0].unlock() } def unlock(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { - locks*.unlock() + locks[0].unlock() } } @@ -58,29 +57,28 @@ public class Locks{ def each(Closure Input) { locks.each(Input) } + def find(Closure Input) { + locks.find(Input) + } + def collect(Closure Input) { + locks.collect(Input) + } //By Model Checker def setValue(LinkedHashMap eventDataMap) { - locks[eventDataMap["deviceId"]].setValue(eventDataMap["value"]) - if (deviceNumbers == 1) - this.lockState = locks[eventDataMap["deviceId"]].lockState - this.currentLock = locks[eventDataMap["deviceId"]].lockState - this.lockLatestValue = locks[eventDataMap["deviceId"]].lockLatestValue + locks[0].setValue(eventDataMap["value"]) + this.lockState = locks[0].lockState + this.currentLock = locks[0].lockState + this.lockLatestValue = locks[0].lockLatestValue sendEvent(eventDataMap) } def currentValue(String deviceFeature) { - if (deviceNumbers == 1) - locks[0].currentValue(deviceFeature) - else - locks*.currentValue(deviceFeature) + locks[0].currentValue(deviceFeature) } def latestValue(String deviceFeature) { - if (deviceNumbers == 1) - locks[0].latestValue(deviceFeature) - else - locks*.latestValue(deviceFeature) + locks[0].latestValue(deviceFeature) } def getAt(int ix) { diff --git a/Methods/now.groovy b/Methods/now.groovy new file mode 100644 index 0000000..017c034 --- /dev/null +++ b/Methods/now.groovy @@ -0,0 +1,4 @@ +///////////////////////////////////////////////////////////////////// +def now() { + return System.currentTimeMillis() +} diff --git a/MusicPlayer/MusicPlayer.groovy b/MusicPlayer/MusicPlayer.groovy new file mode 100644 index 0000000..6de93c1 --- /dev/null +++ b/MusicPlayer/MusicPlayer.groovy @@ -0,0 +1,93 @@ +//Create a class for music player +package MusicPlayer +import Timer.SimulatedTimer + + +public class MusicPlayer { + private String id + private String label + private String displayName + private int level + private String mute + private String status + private int trackNumber + private List trackData + + MusicPlayer(String id, String label, String displayName, int level, String mute, String status, int trackNumber, List trackData) { + this.id = id + this.label = label + this.displayName = displayName + this.level = level + this.mute = mute + this.status = status + this.trackNumber = trackNumber + this.trackData = trackData + } + + //methods + def mute() { + println("the music player with id:$id is muted!") + this.mute = "muted" + } + def nextTrack() { + if (trackNumber != trackData.size()-1) + trackNumber = trackNumber+1 + else + trackNumber = 0 + def trackPlaying = trackData[trackNumber] + println("the $trackPlaying is selected!") + this.status = "playing" + } + def pause() { + println("the music player with id:$id is paused!") + this.status = "paused" + } + def play() { + println("the music player with id:$id is starting to play!") + this.status = "playing" + } + def playTrack(String trackToPlay) { + trackNumber = list.indexOf(trackToPlay) + def trackPlaying = trackData[trackNumber] + println("the $trackPlaying is selected to play!") + this.status = "playing" + } + def previousTrack() { + if (trackNumber != 0) + trackNumber = trackNumber-1 + else + trackNumber = trackData.size()-1 + def trackPlaying = trackData[trackNumber] + println("the $trackPlaying is selected!") + this.status = "playing" + } + /*def restoreTrack(String trackToRestore) { + musicPlayers*.restoreTrack(trackToRestore) + }*/ + def resumeTrack(String trackToResume) { + trackNumber = list.indexOf(trackToResume) + def trackPlaying = trackData[trackNumber] + println("the $trackPlaying is resumed!") + this.status = "playing" + } + def setLevel(int level) { + this.level = level + println("the level of sound is changed to $level!") + } + def setTrack(String trackToSet) { + trackNumber = list.indexOf(trackToSet) + def trackPlaying = trackData[trackNumber] + println("the $trackPlaying is set!") + this.status = "playing" + } + def stop() { + println("the music player with id:$id is stopped!") + this.status = "stopped" + } + + def currentValue(String deviceFeature) { + if (deviceFeature == "musicPlayer") { + return status + } + } +} diff --git a/MusicPlayer/MusicPlayers.groovy b/MusicPlayer/MusicPlayers.groovy new file mode 100644 index 0000000..9968595 --- /dev/null +++ b/MusicPlayer/MusicPlayers.groovy @@ -0,0 +1,90 @@ +//Create a class for music player +package MusicPlayer +import Timer.SimulatedTimer + + +public class MusicPlayers { + private int deviceNumbers + private List musicPlayers + def sendEvent + + //For one device(We cannot have obj.id)-> We should have obj[0].id + private String id = "musicPlayerID0" + private String label = "musicPlayer0" + private String displayName = "musicPlayer0" + private int level = 20 + private String mute = "unmuted" + private String status = "pause" + private int trackNumber = 0 + private List trackData = ["track1", "track2", "track3", "track4"] + + + + MusicPlayers(Closure sendEvent, int deviceNumbers) { + this.sendEvent = sendEvent + this.deviceNumbers = deviceNumbers + this.musicPlayers = [] + + musicPlayers.add(new MusicPlayer(id, label, displayName, this.level, this.mute, this.status, this.trackNumber, this.trackData)) + } + + //Methods for closures + def count(Closure Input) { + musicPlayers.count(Input) + } + def size() { + musicPlayers.size() + } + def each(Closure Input) { + musicPlayers.each(Input) + } + def find(Closure Input) { + musicPlayers.find(Input) + } + def collect(Closure Input) { + musicPlayers.collect(Input) + } + + //methods + def mute() { + musicPlayers[0].mute() + } + def nextTrack() { + musicPlayers[0].nextTrack() + } + def pause() { + musicPlayers[0].pause() + } + def play() { + musicPlayers[0].play() + } + def playTrack(String trackToPlay) { + musicPlayers[0].playTrack(trackToPlay) + } + def previousTrack() { + musicPlayers[0].previousTrack() + } + def restoreTrack(String trackToRestore) { + musicPlayers[0].restoreTrack(trackToRestore) + } + def resumeTrack(String trackToResume) { + musicPlayers[0].resumeTrack(trackToResume) + } + def setLevel(int level) { + musicPlayers[0].setLevel(level) + } + def setTrack(String trackToSet) { + musicPlayers[0].setTrack(trackToSet) + } + def stop() { + musicPlayers[0].stop() + } + + def currentValue(String deviceFeature) { + musicPlayers[0].currentValue(deviceFeature) + } + + def getAt(int ix) { + musicPlayers[ix] + } +} diff --git a/NfcTouch/NfcTouch.groovy b/NfcTouch/NfcTouch.groovy index 617704d..3635d51 100644 --- a/NfcTouch/NfcTouch.groovy +++ b/NfcTouch/NfcTouch.groovy @@ -4,6 +4,7 @@ package NfcTouch public class NfcTouch{ def sendEvent private int isTouched + private String displayName = "NfcTouch0" NfcTouch(Closure sendEvent, int isTouched) { this.sendEvent = sendEvent diff --git a/PresenceSensor/PresenceSensor.groovy b/PresenceSensor/PresenceSensor.groovy index b7e62ca..7d0e629 100644 --- a/PresenceSensor/PresenceSensor.groovy +++ b/PresenceSensor/PresenceSensor.groovy @@ -3,14 +3,14 @@ package PresenceSensor import Timer.SimulatedTimer public class PresenceSensor { - private int id + private String id private String label private String displayName private String presenceState private String currentPresence private String presenceLatestValue - PresenceSensor(int id, String label, String displayName, String presenceState, String presenceLatestValue) { + PresenceSensor(String id, String label, String displayName, String presenceState, String presenceLatestValue) { this.id = id this.label = label this.displayName = displayName diff --git a/PresenceSensor/PresenceSensors.groovy b/PresenceSensor/PresenceSensors.groovy index 44328d6..cc5c820 100644 --- a/PresenceSensor/PresenceSensors.groovy +++ b/PresenceSensor/PresenceSensors.groovy @@ -8,9 +8,9 @@ public class PresenceSensors { def sendEvent //For one device(We cannot have obj.id)-> We should have obj[0].id - private int id = 0 - private String label = "presenceSensor" - private String displayName = "presenceSensor" + private String id = "presenceSensorID0" + private String label = "presenceSensor0" + private String displayName = "presenceSensor0" private String presenceState = "not present" private String currentPresence = "not present" private String presenceLatestValue = "not present" @@ -21,18 +21,16 @@ public class PresenceSensors { this.deviceNumbers = deviceNumbers this.presenceSensors = [] - for (int i = 0;i < deviceNumbers;i++) { - presenceSensors.add(new PresenceSensor(i+30, label+i.toString(), displayName+i.toString(), this.presenceState, this.presenceLatestValue)) - } + presenceSensors.add(new PresenceSensor(id, label, displayName, this.presenceState, this.presenceLatestValue)) } //By Model Checker def setValue(LinkedHashMap eventDataMap) { - presenceSensors[eventDataMap["deviceId"]].setValue(eventDataMap["value"]) + presenceSensors[0].setValue(eventDataMap["value"]) if (deviceNumbers == 1) - this.presenceLatestValue = presenceSensors[eventDataMap["deviceId"]].presenceLatestValue - this.presenceState = presenceSensors[eventDataMap["deviceId"]].presenceState - this.currentPresence = presenceSensors[eventDataMap["deviceId"]].presenceState + this.presenceLatestValue = presenceSensors[0].presenceLatestValue + this.presenceState = presenceSensors[0].presenceState + this.currentPresence = presenceSensors[0].presenceState sendEvent(eventDataMap) } @@ -46,20 +44,20 @@ public class PresenceSensors { def each(Closure Input) { presenceSensors.each(Input) } + def find(Closure Input) { + presenceSensors.find(Input) + } + def collect(Closure Input) { + presenceSensors.collect(Input) + } def currentValue(String deviceFeature) { - if (deviceNumbers == 1) - presenceSensors[0].currentValue(deviceFeature)//It is called if we have only one device - else - presenceSensors*.currentValue(deviceFeature) + presenceSensors[0].currentValue(deviceFeature)//It is called if we have only one device } def latestValue(String deviceFeature) { - if (deviceNumbers == 1) - presenceSensors[0].latestValue(deviceFeature)//It is called if we have only one device - else - presenceSensors*.latestValue(deviceFeature) + presenceSensors[0].latestValue(deviceFeature)//It is called if we have only one device } def getAt(int ix) { diff --git a/Runner.py b/Runner.py index e2826a5..33b3b56 100644 --- a/Runner.py +++ b/Runner.py @@ -21,6 +21,7 @@ sendSms = open("Methods/"+"sendSms.groovy", "r") sendPush = open("Methods/"+"sendPush.groovy", "r") eventHandler = open("Methods/"+"eventHandler.groovy", "r") schedule = open("Methods/"+"schedule.groovy", "r") +now = open("Methods/"+"now.groovy", "r") App1 = open("Extractor/"+"App1/App1.groovy", "r") extractedObjectsApp1 = open("Extractor/"+"App1/extractedObjectsApp1.groovy", "r") extractedObjectsConstructorApp1 = open("Extractor/"+"App1/extractedObjectsConstructorApp1.groovy", "r") @@ -51,6 +52,10 @@ Out.write("import Location.LocationVar\n") Out.write("import Location.Phrase\n") Out.write("import appTouch.Touched\n") Out.write("import NfcTouch.NfcTouch\n") +Out.write("import AeonKeyFob.AeonKeyFob\n") +Out.write("import AeonKeyFob.AeonKeyFobs\n") +Out.write("import MusicPlayer.MusicPlayer\n") +Out.write("import MusicPlayer.MusicPlayers\n") Out.write("import Event.Event\n") Out.write("import Timer.SimulatedTimer\n") Out.write("\n") @@ -104,6 +109,8 @@ for line in sendPush: Out.write("\t"+line) for line in schedule: Out.write("\t"+line) +for line in now: + Out.write("\t"+line) Out.write("\n") Start = 0 for line in App1: @@ -173,6 +180,8 @@ for line in sendPush: Out.write("\t"+line) for line in schedule: Out.write("\t"+line) +for line in now: + Out.write("\t"+line) Out.write("\n") Start = 0 for line in App2: diff --git a/Switch/Switch.groovy b/Switch/Switch.groovy index 1e6cf9d..b9c0a81 100644 --- a/Switch/Switch.groovy +++ b/Switch/Switch.groovy @@ -3,7 +3,7 @@ package Switch import Timer.SimulatedTimer public class Switch { - private int id + private String id private String label private String displayName private String switchState @@ -14,7 +14,7 @@ public class Switch { def timers - Switch(Closure sendEvent, int id, String label, String displayName, String switchState, String currentSwitch, int currentLevel, String switchLatestValue) { + Switch(Closure sendEvent, String id, String label, String displayName, String switchState, String currentSwitch, int currentLevel, String switchLatestValue) { this.sendEvent = sendEvent this.timers = new SimulatedTimer() this.currentSwitch = currentSwitch @@ -38,7 +38,7 @@ public class Switch { this.switchState = "on" this.currentSwitch = "on" sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) + displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "on"]]) } def on(LinkedHashMap metaData) { @@ -48,7 +48,7 @@ public class Switch { this.switchState = "on" this.currentSwitch = "on" sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) + displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "on"]]) } } @@ -58,7 +58,7 @@ public class Switch { this.switchState = "off" this.currentSwitch = "off" sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) + displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "off"]]) } def off(LinkedHashMap metaData) { @@ -68,7 +68,7 @@ public class Switch { this.switchState = "off" this.currentSwitch = "off" sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) + displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "off"]]) } } diff --git a/Switch/Switches.groovy b/Switch/Switches.groovy index fad05f8..cf8c068 100644 --- a/Switch/Switches.groovy +++ b/Switch/Switches.groovy @@ -9,9 +9,9 @@ public class Switches { def sendEvent //If we have only one device - private int id = 40 - private String label = "switch" - private String displayName = "switch" + private String id = "switchID0" + private String label = "switch0" + private String displayName = "switch0" private String switchState = "off" private String currentSwitch = "off" private int currentLevel = 50 @@ -22,9 +22,8 @@ public class Switches { this.timers = new SimulatedTimer() this.deviceNumbers = deviceNumbers this.switches = [] - for (int i = 0;i < deviceNumbers;i++) { - switches.add(new Switch(sendEvent, i+40, label+i.toString(), displayName+i.toString(), this.switchState, this.currentSwitch, this.currentLevel, this.switchLatestValue)) - } + + switches.add(new Switch(sendEvent, id, label, displayName, this.switchState, this.currentSwitch, this.currentLevel, this.switchLatestValue)) } //Methods for closures @@ -37,54 +36,53 @@ public class Switches { def each(Closure Input) { switches.each(Input) } + def find(Closure Input) { + switches.find(Input) + } + def collect(Closure Input) { + switches.collect(Input) + } //By Apps def setLevel(int level) { - switches*.setLevel(level) + switches[0].setLevel(level) } def on() { - switches*.on() + switches[0].on() } def on(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { - switches*.on() + switches[0].on() } } def off() { - switches*.off() + switches[0].off() } def off(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { - switches*.off() + switches[0].off() } } //By Model Checker def setValue(LinkedHashMap eventDataMap) { - switches[eventDataMap["deviceId"]].setValue(eventDataMap["value"]) - if (deviceNumbers == 1) - this.switchState = switches[eventDataMap["deviceId"]].switchState - this.switchLatestValue = switches[eventDataMap["deviceId"]].switchLatestValue + switches[0].setValue(eventDataMap["value"]) + this.switchState = switches[0].switchState + this.switchLatestValue = switches[0].switchLatestValue sendEvent(eventDataMap) } def currentValue(String deviceFeature) { - if (deviceNumbers == 1) - switches[0].currentValue(deviceFeature) - else - switches*.currentValue(deviceFeature) + switches[0].currentValue(deviceFeature) } def latestValue(String deviceFeature) { - if (deviceNumbers == 1) - switches[0].latestValue(deviceFeature) - else - switches*.latestValue(deviceFeature) + switches[0].latestValue(deviceFeature) } def getAt(int ix) { diff --git a/Thermostat/Thermostat.groovy b/Thermostat/Thermostat.groovy index 2badeb6..8bd5e9f 100644 --- a/Thermostat/Thermostat.groovy +++ b/Thermostat/Thermostat.groovy @@ -3,7 +3,7 @@ package Thermostat import Timer.SimulatedTimer public class Thermostat { - private int id + private String id private String label private String displayName private int temperature @@ -24,7 +24,7 @@ public class Thermostat { def timers - Thermostat(Closure sendEvent, int id, String label, String displayName, int temperature, int currentCoolingSetpoint, int currentHeatingSetpoint, int coolingSetpoint, + Thermostat(Closure sendEvent, String id, String label, String displayName, int temperature, int currentCoolingSetpoint, int currentHeatingSetpoint, int coolingSetpoint, int thermostatSetpoint, int heatingSetpoint, List coolingSetpointRange, List thermostatSetpointRange, List heatingSetpointRange, List supportedThermostatFanModes, List supportedThermostatModes, String thermostatOperatingState, String thermostatFanMode, String thermostatMode) { this.id = id diff --git a/Thermostat/Thermostats.groovy b/Thermostat/Thermostats.groovy index 49cfe5e..78386ab 100644 --- a/Thermostat/Thermostats.groovy +++ b/Thermostat/Thermostats.groovy @@ -9,9 +9,9 @@ public class Thermostats{ def timers //When we have only one device - private int id = 50 - private String label = "thermostat" - private String displayName = "thermostat" + private String id = "thermostatID0" + private String label = "thermostat0" + private String displayName = "thermostat0" private int temperature = 66 private int currentCoolingSetpoint = 70 private int currentHeatingSetpoint = 50 @@ -32,12 +32,11 @@ public class Thermostats{ this.timers = new SimulatedTimer() this.deviceNumbers = deviceNumbers this.thermostats = [] - for (int i = 0;i < deviceNumbers;i++) { - thermostats.add(new Thermostat(sendEvent, i+50, label+i.toString(), displayName+i.toString(), this.temperature, this.currentCoolingSetpoint, - this.currentHeatingSetpoint, this.coolingSetpoint, this.thermostatSetpoint, this.heatingSetpoint, this.coolingSetpointRange, - this.thermostatSetpointRange, this.heatingSetpointRange, this.supportedThermostatFanModes, this.supportedThermostatModes, - this.thermostatOperatingState, this.thermostatFanMode, this.thermostatMode)) - } + + thermostats.add(new Thermostat(sendEvent, id, label, displayName, this.temperature, this.currentCoolingSetpoint, + this.currentHeatingSetpoint, this.coolingSetpoint, this.thermostatSetpoint, this.heatingSetpoint, this.coolingSetpointRange, + this.thermostatSetpointRange, this.heatingSetpointRange, this.supportedThermostatFanModes, this.supportedThermostatModes, + this.thermostatOperatingState, this.thermostatFanMode, this.thermostatMode)) } //Methods for closures @@ -50,14 +49,20 @@ public class Thermostats{ def each(Closure Input) { thermostats.each(Input) } + def find(Closure Input) { + thermostats.find(Input) + } + def collect(Closure Input) { + thermostats.collect(Input) + } //By Apps def setCoolingSetpoint(int coolingSetpoint) { - thermostats*.setCoolingSetpoint(coolingSetpoint) + thermostats[0].setCoolingSetpoint(coolingSetpoint) } def setHeatingSetpoint(int heatingSetpoint) { - thermostats*.setHeatingSetpoint(heatingSetpoint) + thermostats[0].setHeatingSetpoint(heatingSetpoint) } def setSchedule() { @@ -65,24 +70,14 @@ public class Thermostats{ } def setThermostatFanMode(String thermostatFanMode) { - thermostats*.setThermostatFanMode(thermostatFanMode) + thermostats[0].setThermostatFanMode(thermostatFanMode) } def setThermostatMode(String thermostatMode) { - thermostats*.setThermostatMode(thermostatMode) + thermostats[0].setThermostatMode(thermostatMode) } - //By Model Checker(There is no event based on thermostat?) - /*def setValue(LinkedHashMap eventDataMap) { - thermostats[eventDataMap["deviceId"]].setValue(eventDataMap["value"]) - if (deviceNumbers == 1) - this.lockState = locks[eventDataMap["deviceId"]].lockState - this.currentLock = locks[eventDataMap["deviceId"]].lockState - this.lockLatestValue = locks[eventDataMap["deviceId"]].lockLatestValue - sendEvent(eventDataMap) - }*/ - def getAt(int ix) { locks[ix] } diff --git a/main.groovy b/main.groovy index e282ed8..6ba6942 100644 --- a/main.groovy +++ b/main.groovy @@ -20,6 +20,10 @@ import Location.LocationVar import Location.Phrase import appTouch.Touched import NfcTouch.NfcTouch +import AeonKeyFob.AeonKeyFob +import AeonKeyFob.AeonKeyFobs +import MusicPlayer.MusicPlayer +import MusicPlayer.MusicPlayers import Event.Event import Timer.SimulatedTimer @@ -78,6 +82,10 @@ def eventHandler(LinkedHashMap eventDataMap) { @Field def presenceSensorObject = new PresenceSensors(sendEvent, 1) //Global Object for class thermostat! @Field def thermostatObject = new Thermostats(sendEvent, 1) +//Global Object for class aeon key fob! +@Field def aeonKeyFobObject = new AeonKeyFobs(sendEvent, 1) +//Global Object for class music player! +@Field def musicPlayerObject = new MusicPlayers(sendEvent, 1) //Application #1 class App1 { @@ -86,47 +94,39 @@ class App1 { def app //Extracted objects for App1 - //Object for class Touch Sensor! - def tag - //Object for class switch! - def switch1 //Object for class lock! - def lock - //Object for class door control! - def garageDoor - //Global variable for enum! - def masterSwitch = "40" - //Global variable for enum! - def masterLock = "20" - //Global variable for enum! - def masterDoor = "40" + def lock1 + //Global variable for number! + def minutesLater = 1 + //Object for class contactSensor! + def openSensor //Extracted objects for functions for App1 //Global Object for functions in subscribe method! - def pageTwo = this.&pageTwo - //Global Object for functions in subscribe method! def installed = this.&installed //Global Object for functions in subscribe method! def updated = this.&updated //Global Object for functions in subscribe method! def initialize = this.&initialize //Global Object for functions in subscribe method! - def currentStatus = this.¤tStatus + def lockDoor = this.&lockDoor //Global Object for functions in subscribe method! - def touchHandler = this.&touchHandler + def doorOpen = this.&doorOpen + //Global Object for functions in subscribe method! + def doorClosed = this.&doorClosed + //Global Object for functions in subscribe method! + def doorHandler = this.&doorHandler App1(Object obj) { reference = obj location = obj.locationObject app = obj.appObject - tag = obj.touchSensorObject - switch1 = obj.switchObject - lock = obj.lockObject - garageDoor = obj.doorControlObject + lock1 = obj.lockObject + openSensor = obj.contactObject + //Global variable for settings! + settings = [app:app, lock1:lock1, minutesLater:minutesLater, openSensor:openSensor] } //Global variables for each app - //Settings variable defined to settings on purpose - def settings = "Settings" //Global variable for state[mode] def state = [home:[],away:[],night:[]] //Create a global logger object for methods @@ -141,6 +141,8 @@ class App1 { def timersFuncList = [] //Create a global list for timer schedulers def timersList = [] + //Create a global variable for settings + def settings //Methods ///////////////////////////////////////////////////////////////////// @@ -274,106 +276,72 @@ class App1 { def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*seconds, nameOfFunction) } } + ///////////////////////////////////////////////////////////////////// + def now() { + return System.currentTimeMillis() + } - def pageTwo() { - dynamicPage(name: "pageTwo") { - section("If set, the state of these devices will be toggled each time the tag is touched, " + - "e.g. a light that's on will be turned off and one that's off will be turned on, " + - "other devices of the same type will be set to the same state as their master device. " + - "If no master is designated then the majority of devices of the same type will be used " + - "to determine whether to turn on or off the devices.") { - - if (switch1 || masterSwitch) { - input "masterSwitch", "enum", title: "Master switch", options: switch1.collect{[(it.id): it.displayName]}, required: false - } - if (lock || masterLock) { - input "masterLock", "enum", title: "Master lock", options: lock.collect{[(it.id): it.displayName]}, required: false - } - if (garageDoor || masterDoor) { - input "masterDoor", "enum", title: "Master door", options: garageDoor.collect{[(it.id): it.displayName]}, required: false - } - } - section([mobileOnly:true]) { - label title: "Assign a name", required: false - mode title: "Set for specific mode(s)", required: false - } - } + def installed() + { + log.debug "Auto Lock Door installed. (URL: http://www.github.com/smartthings-users/smartapp.auto-lock-door)" + initialize() } - def installed() { - log.debug "Installed with settings: ${settings}" - - initialize() + def updated() + { + unsubscribe() + unschedule() + log.debug "Auto Lock Door updated." + initialize() } - def updated() { - log.debug "Updated with settings: ${settings}" + def initialize() + { + log.debug "Settings: ${settings}" + subscribe(lock1, "lock", doorHandler) + subscribe(openSensor, "contact.closed", doorClosed) + subscribe(openSensor, "contact.open", doorOpen) + } - unsubscribe() - initialize() + def lockDoor() + { + log.debug "Locking Door if Closed" + if((openSensor.latestValue("contact") == "closed")){ + log.debug "Door Closed" + lock1.lock() + } else { + if ((openSensor.latestValue("contact") == "open")) { + def delay = minutesLater * 60 + log.debug "Door open will try again in $minutesLater minutes" + runIn( delay, lockDoor ) + } + } } - def initialize() { - subscribe tag, "nfcTouch", touchHandler - subscribe app, touchHandler + def doorOpen(evt) { + log.debug "Door open reset previous lock task..." + unschedule( lockDoor ) + def delay = minutesLater * 60 + runIn( delay, lockDoor ) } - private currentStatus(devices, master, attribute) { - log.trace "currentStatus($devices, $master, $attribute)" - def result = null - if (master) { - result = devices.find{it.id == master}?.currentValue(attribute) - } - else { - def map = [:] - devices.each { - def value = it.currentValue(attribute) - map[value] = (map[value] ?: 0) + 1 - log.trace "$it.displayName: $value" - } - log.trace map - result = map.collect{it}.sort{it.value}[-1].key - } - log.debug "$attribute = $result" - result + def doorClosed(evt) { + log.debug "Door Closed" } - def touchHandler(evt) { - log.trace "touchHandler($evt.descriptionText)" - if (switch1) { - def status = currentStatus(switch1, masterSwitch, "switch") - switch1.each { - if (status == "on") { - it.off() - } - else { - it.on() - } - } - } - - if (lock) { - def status = currentStatus(lock, masterLock, "lock") - lock.each { - if (status == "locked") { - lock.unlock() - } - else { - lock.lock() - } - } + def doorHandler(evt) + { + log.debug "Door ${openSensor.latestValue}" + log.debug "Lock ${evt.name} is ${evt.value}." + + if (evt.value == "locked") { // If the human locks the door then... + log.debug "Cancelling previous lock task..." + unschedule( lockDoor ) // ...we don't need to lock it later. } - - if (garageDoor) { - def status = currentStatus(garageDoor, masterDoor, "status") - garageDoor.each { - if (status == "open") { - it.close() - } - else { - it.open() - } - } + else { // If the door is unlocked then... + def delay = minutesLater * 60 // runIn uses seconds + log.debug "Re-arming lock in ${minutesLater} minutes (${delay}s)." + runIn( delay, lockDoor ) // ...schedule to lock in x minutes. } } } @@ -386,36 +354,47 @@ class App2 { def app //Extracted objects for App2 + //Object for class Touch Sensor! + def tag //Object for class switch! - def switchesoff - //Object for class switch! - def switcheson + def switch1 //Object for class lock! - def lock1 - //Global variable for mode! - def newMode = "home" - //Global variable for number! - def waitfor = 10 + def lock + //Object for class door control! + def garageDoor + //Global variable for enum! + def masterSwitch = "switchID0" + //Global variable for enum! + def masterLock = "lockID0" + //Global variable for enum! + def masterDoor = "DoorControlID0" //Extracted objects for functions for App2 //Global Object for functions in subscribe method! + def pageTwo = this.&pageTwo + //Global Object for functions in subscribe method! def installed = this.&installed //Global Object for functions in subscribe method! def updated = this.&updated //Global Object for functions in subscribe method! - def appTouch = this.&appTouch + def initialize = this.&initialize + //Global Object for functions in subscribe method! + def currentStatus = this.¤tStatus + //Global Object for functions in subscribe method! + def touchHandler = this.&touchHandler App2(Object obj) { reference = obj location = obj.locationObject app = obj.appObject - switchesoff = obj.switchObject - switcheson = obj.switchObject - lock1 = obj.lockObject + tag = obj.touchSensorObject + switch1 = obj.switchObject + lock = obj.lockObject + garageDoor = obj.doorControlObject + //Global variable for settings! + settings = [app:app, tag:tag, switch1:switch1, lock:lock, garageDoor:garageDoor, masterSwitch:masterSwitch, masterLock:masterLock, masterDoor:masterDoor] } //Global variables for each app - //Settings variable defined to settings on purpose - def settings = "Settings" //Global variable for state[mode] def state = [home:[],away:[],night:[]] //Create a global logger object for methods @@ -430,6 +409,8 @@ class App2 { def timersFuncList = [] //Create a global list for timer schedulers def timersList = [] + //Create a global variable for settings + def settings //Methods ///////////////////////////////////////////////////////////////////// @@ -559,35 +540,106 @@ class App2 { } } - def installed() - { - log.debug "Installed with settings: ${settings}" - log.debug "Current mode = ${location.mode}" - subscribe(app, appTouch) + def pageTwo() { + dynamicPage(name: "pageTwo") { + section("If set, the state of these devices will be toggled each time the tag is touched, " + + "e.g. a light that's on will be turned off and one that's off will be turned on, " + + "other devices of the same type will be set to the same state as their master device. " + + "If no master is designated then the majority of devices of the same type will be used " + + "to determine whether to turn on or off the devices.") { + + if (switch1 || masterSwitch) { + input "masterSwitch", "enum", title: "Master switch", options: switch1.collect{[(it.id): it.displayName]}, required: false + } + if (lock || masterLock) { + input "masterLock", "enum", title: "Master lock", options: lock.collect{[(it.id): it.displayName]}, required: false + } + if (garageDoor || masterDoor) { + input "masterDoor", "enum", title: "Master door", options: garageDoor.collect{[(it.id): it.displayName]}, required: false + } + } + section([mobileOnly:true]) { + label title: "Assign a name", required: false + mode title: "Set for specific mode(s)", required: false + } + } } + def installed() { + log.debug "Installed with settings: ${settings}" - def updated() - { + initialize() + } + + 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) + initialize() + } + + def initialize() { + subscribe tag, "nfcTouch", touchHandler + subscribe app, touchHandler + } + + private currentStatus(devices, master, attribute) { + log.trace "currentStatus($devices, $master, $attribute)" + def result = null + if (master) { + result = devices.find{it.id == master}?.currentValue(attribute) + } + else { + def map = [:] + devices.each { + def value = it.currentValue(attribute) + map[value] = (map[value] ?: 0) + 1 + log.trace "$it.displayName: $value" + } + log.trace map + result = map.collect{it}.sort{it.value}[-1].key + } + log.debug "$attribute = $result" + result + } + + def touchHandler(evt) { + log.trace "touchHandler($evt.descriptionText)" + if (switch1) { + def status = currentStatus(switch1, masterSwitch, "switch") + switch1.each { + if (status == "on") { + it.off() + } + else { + it.on() + } + } + } + + if (lock) { + def status = currentStatus(lock, masterLock, "lock") + lock.each { + if (status == "locked") { + lock.unlock() + } + else { + lock.lock() + } + } + } + + if (garageDoor) { + def status = currentStatus(garageDoor, masterDoor, "status") + garageDoor.each { + if (status == "open") { + it.close() + } + else { + it.open() + } + } + } } }