--- /dev/null
+//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
+ }
+}
--- /dev/null
+//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]
+ }
+}
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
}
def latestValue(String deviceFeature) {
if (deviceFeature == "contact") {
- return contactLatestValue
+ return latestValue
}
}
}
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) {
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
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) {
import Timer.SimulatedTimer
public class DoorControl {
- private int id
+ private String id
private String label
private String displayName
private String doorState
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
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) {
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"]])
}
}
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) {
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 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"
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
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) {
package Event
public class Event {
- private int deviceId
+ private String deviceId
private String value
private String linkText
private String displayName
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
-////////////////
-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.
}
}
//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
-//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
-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]
-/////
+////////////////
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()
+ }
+ }
+ }
}
//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
+//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"
-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]
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")
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")
}
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")
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")
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")
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")
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")
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) {
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")
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) {
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")
}
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) {
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")
}
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) {
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")
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) {
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")
}
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) {
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")
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) {
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
}
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")
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")
-////////////////////@Field App
+////////////////////
+@Field App
App = "App2"
////////////////////////////////////////
//import libraries
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")
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")
}
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")
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")
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")
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")
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")
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) {
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")
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) {
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")
}
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) {
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")
}
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) {
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")
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) {
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")
}
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) {
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")
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) {
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
}
-/////
+////////////////
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()
+ }
+ }
+ }
}
@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)
-//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
def timersFuncList = []
//Create a global list for timer schedulers
def timersList = []
+//Create a global variable for settings
+def settings
class LocationVar {
private int contactBookEnabled
- private String modes
+ private def modes
private String mode
private List contacts
private List phoneNumbers
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
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)
+ }
}
-
import Timer.SimulatedTimer
public class Lock {
- private int id
+ private String id
private String label
private String displayName
private String lockState
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
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) {
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"]])
}
}
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) {
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"]])
}
}
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"
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()
}
}
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) {
--- /dev/null
+/////////////////////////////////////////////////////////////////////
+def now() {
+ return System.currentTimeMillis()
+}
--- /dev/null
+//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
+ }
+ }
+}
--- /dev/null
+//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]
+ }
+}
public class NfcTouch{
def sendEvent
private int isTouched
+ private String displayName = "NfcTouch0"
NfcTouch(Closure sendEvent, int isTouched) {
this.sendEvent = sendEvent
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
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"
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)
}
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) {
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")
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")
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:
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:
import Timer.SimulatedTimer
public class Switch {
- private int id
+ private String id
private String label
private String displayName
private String switchState
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
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) {
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"]])
}
}
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) {
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 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
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
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) {
import Timer.SimulatedTimer
public class Thermostat {
- private int id
+ private String id
private String label
private String displayName
private int temperature
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
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
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
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() {
}
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]
}
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
@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 {
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
def timersFuncList = []
//Create a global list for timer schedulers
def timersList = []
+ //Create a global variable for settings
+ def settings
//Methods
/////////////////////////////////////////////////////////////////////
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.
}
}
}
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
def timersFuncList = []
//Create a global list for timer schedulers
def timersList = []
+ //Create a global variable for settings
+ def settings
//Methods
/////////////////////////////////////////////////////////////////////
}
}
- 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()
+ }
+ }
+ }
}
}