From 4c11bc74dad5814ff9ba94fa21894ff0f90dc291 Mon Sep 17 00:00:00 2001 From: amiraj Date: Fri, 28 Jun 2019 16:51:55 -0700 Subject: [PATCH] Commit #2 --- Extractor/App.groovy | 182 ++++++++++---------------- Extractor/ExtractedObjects.groovy | 24 ++-- Methods/subscribe.groovy | 1 + main.groovy | 207 +++++++++++------------------- 4 files changed, 156 insertions(+), 258 deletions(-) diff --git a/Extractor/App.groovy b/Extractor/App.groovy index 0c52140..176a336 100644 --- a/Extractor/App.groovy +++ b/Extractor/App.groovy @@ -1,124 +1,80 @@ -/////////////////////////////////////////// +/** + * Good Night House + * + * Copyright 2014 Joseph Charette + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License + * for the specific language governing permissions and limitations under the License. + * + */ definition( - name: "Enhanced Auto Lock Door", - namespace: "Lock Auto Super Enhanced", - author: "Arnaud", - description: "Automatically locks a specific door after X minutes when closed and unlocks it when open after X seconds.", - category: "Safety & Security", - iconUrl: "http://www.gharexpert.com/mid/4142010105208.jpg", - iconX2Url: "http://www.gharexpert.com/mid/4142010105208.jpg" -) - -preferences{ - section("Select the door lock:") { - input "lock1", "capability.lock", required: true, multiple: true - } - section("Select the door contact sensor:") { - input "contact", "capability.contactSensor", required: true - } - section("Automatically lock the door when closed...") { - input "minutesLater", "number", title: "Delay (in minutes):", required: true - } - section("Automatically unlock the door when open...") { - input "secondsLater", "number", title: "Delay (in seconds):", required: true + name: "Good Night House", + namespace: "charette.joseph@gmail.com", + author: "Joseph Charette", + description: "Some on, some off with delay for bedtime, Lock The Doors", + category: "Convenience", + iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png", + iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png" +/** +* Borrowed code from +* Walk Gentle Into That Good Night +* +* Author: oneaccttorulethehouse@gmail.com +* Date: 2014-02-01 + */ + ) +preferences { + section("When I touch the app turn these lights off…"){ + input "switchesoff", "capability.switch", multiple: true, required:true + } + section("When I touch the app turn these lights on…"){ + input "switcheson", "capability.switch", multiple: true, required:false + } + section("Lock theses locks...") { + input "lock1","capability.lock", multiple: true } - section( "Notifications" ) { - input("recipients", "contact", title: "Send notifications to", required: false) { - input "phoneNumber", "phone", title: "Warn with text message (optional)", description: "Phone Number", required: false - } - } -} - -def installed(){ - initialize() + section("And change to this mode...") { + input "newMode", "mode", title: "Mode?" + } + section("After so many seconds (optional)"){ + input "waitfor", "number", title: "Off after (default 120)", required: true + } } -def updated(){ - unsubscribe() - unschedule() - initialize() -} -def initialize(){ - log.debug "Settings: ${settings}" - subscribe(lock1, "lock", doorHandler, [filterEvents: false]) - subscribe(lock1, "unlock", doorHandler, [filterEvents: false]) - subscribe(contact, "contact.open", doorHandler) - subscribe(contact, "contact.closed", doorHandler) +def installed() +{ + log.debug "Installed with settings: ${settings}" + log.debug "Current mode = ${location.mode}" + subscribe(app, appTouch) } -def lockDoor(){ - log.debug "Locking the door." - lock1.lock() - if(location.contactBookEnabled) { - if ( recipients ) { - log.debug ( "Sending Push Notification..." ) - sendNotificationToContacts( "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!", recipients) - } - } - if (phoneNumber) { - log.debug("Sending text message...") - sendSms( phoneNumber, "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!") - } -} -def unlockDoor(){ - log.debug "Unlocking the door." - lock1.unlock() - if(location.contactBookEnabled) { - if ( recipients ) { - log.debug ( "Sending Push Notification..." ) - sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!", recipients) - } - } - if ( phoneNumber ) { - log.debug("Sending text message...") - sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!") - } +def updated() +{ + log.debug "Updated with settings: ${settings}" + log.debug "Current mode = ${location.mode}" + unsubscribe() + subscribe(app, appTouch) } -def doorHandler(evt){ - log.debug evt.value - log.debug contact.latestValue("contact") - if ((contact.latestValue("contact") == "open") && (evt.value == "locked")) { // If the door is open and a person locks the door then... - //def delay = (secondsLater) // runIn uses seconds - log.debug "1" - runIn( secondsLater, unlockDoor ) // ...schedule (in minutes) to unlock... We don't want the door to be closed while the lock is engaged. - } - else if ((contact.latestValue("contact") == "open") && (evt.value == "unlocked")) { // If the door is open and a person unlocks it then... - log.debug "2" - unschedule( unlockDoor ) // ...we don't need to unlock it later. - } - else if ((contact.latestValue("contact") == "closed") && (evt.value == "locked")) { // If the door is closed and a person manually locks it then... - log.debug "3" - unschedule( lockDoor ) // ...we don't need to lock it later. - } - else if ((contact.latestValue("contact") == "closed") && (evt.value == "unlocked")) { // If the door is closed and a person unlocks it then... - log.debug "4" - //def delay = (minutesLater * 60) // runIn uses seconds - runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock. - } - else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "open")) { // If a person opens an unlocked door... - log.debug "5" - unschedule( lockDoor ) // ...we don't need to lock it later. - } - else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "closed")) { // If a person closes an unlocked door... - //def delay = (minutesLater * 60) // runIn uses seconds - log.debug "6" - runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock. - } - else { //Opening or Closing door when locked (in case you have a handle lock) - log.debug "Unlocking the door." - lock1.unlock() - if(location.contactBookEnabled) { - if ( recipients ) { - log.debug ( "Sending Push Notification..." ) - sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!", recipients) - } - } - if ( phoneNumber ) { - log.debug("Sending text message...") - sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!") - } - } +def appTouch(evt) { + log.debug "changeMode, location.mode = $location.mode, newMode = $newMode, location.modes = $location.modes" + if (location.mode != newMode) { + setLocationMode(newMode) + log.debug "Changed the mode to '${newMode}'" + } else { + log.debug "New mode is the same as the old mode, leaving it be" + } + log.debug "appTouch: $evt" + lock1.lock() + switcheson.on() + def delay = (waitfor != null && waitfor != "") ? waitfor * 1000 : 120000 + switchesoff.off(delay: delay) } diff --git a/Extractor/ExtractedObjects.groovy b/Extractor/ExtractedObjects.groovy index 7e7e4db..7fb41f5 100644 --- a/Extractor/ExtractedObjects.groovy +++ b/Extractor/ExtractedObjects.groovy @@ -1,24 +1,16 @@ +//Global Object for class switch! +@Field def switchesoff = new switching(1) +//Global Object for class switch! +@Field def switcheson = new switching(1) //Global Object for class lock! @Field def lock1 = new locking(1) -//Global Object for class contactSensor! -@Field def contact = new contacting(1) +//Global variable for mode! +@Field def newMode = "away" //Global variable for number! -@Field def minutesLater = 1 -//Global variable for number! -@Field def secondsLater = 10 -//Global variable for recipients! -@Field def recipients = ['AJ'] -//Global variable for phone number! -@Field def phoneNumber = 9495379373 +@Field def waitfor = 5 //Global Object for functions in subscribe method! @Field def installed = this.&installed //Global Object for functions in subscribe method! @Field def updated = this.&updated //Global Object for functions in subscribe method! -@Field def initialize = this.&initialize -//Global Object for functions in subscribe method! -@Field def lockDoor = this.&lockDoor -//Global Object for functions in subscribe method! -@Field def unlockDoor = this.&unlockDoor -//Global Object for functions in subscribe method! -@Field def doorHandler = this.&doorHandler +@Field def appTouch = this.&appTouch diff --git a/Methods/subscribe.groovy b/Methods/subscribe.groovy index 74200cb..c7104fc 100644 --- a/Methods/subscribe.groovy +++ b/Methods/subscribe.groovy @@ -1,6 +1,7 @@ ///////////////////////////////////////////////////////////////////// ////subscribe(app, func) def subscribe(Object Obj, Closure Input) { + ObjectList.add(Obj) EventList.add("Touched") FunctionList.add(Input) } diff --git a/main.groovy b/main.groovy index 11d617c..e406b84 100644 --- a/main.groovy +++ b/main.groovy @@ -40,30 +40,22 @@ import appTouch.Touch //ExtractedObjects +//Global Object for class switch! +@Field def switchesoff = new switching(1) +//Global Object for class switch! +@Field def switcheson = new switching(1) //Global Object for class lock! @Field def lock1 = new locking(1) -//Global Object for class contactSensor! -@Field def contact = new contacting(1) +//Global variable for mode! +@Field def newMode = "away" //Global variable for number! -@Field def minutesLater = 1 -//Global variable for number! -@Field def secondsLater = 10 -//Global variable for recipients! -@Field def recipients = ['AJ'] -//Global variable for phone number! -@Field def phoneNumber = 9495379373 +@Field def waitfor = 5 //Global Object for functions in subscribe method! @Field def installed = this.&installed //Global Object for functions in subscribe method! @Field def updated = this.&updated //Global Object for functions in subscribe method! -@Field def initialize = this.&initialize -//Global Object for functions in subscribe method! -@Field def lockDoor = this.&lockDoor -//Global Object for functions in subscribe method! -@Field def unlockDoor = this.&unlockDoor -//Global Object for functions in subscribe method! -@Field def doorHandler = this.&doorHandler +@Field def appTouch = this.&appTouch //Methods ///////////////////////////////////////////////////////////////////// @@ -83,6 +75,7 @@ def setLocationMode(String mode) { ///////////////////////////////////////////////////////////////////// ////subscribe(app, func) def subscribe(Object Obj, Closure Input) { + ObjectList.add(Obj) EventList.add("Touched") FunctionList.add(Input) } @@ -272,129 +265,85 @@ def sendSms(long Phone, String S) { println("Sending \""+S+"\" to "+Phone.toString()) } -/////////////////////////////////////////// +/** + * Good Night House + * + * Copyright 2014 Joseph Charette + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License + * for the specific language governing permissions and limitations under the License. + * + */ definition( - name: "Enhanced Auto Lock Door", - namespace: "Lock Auto Super Enhanced", - author: "Arnaud", - description: "Automatically locks a specific door after X minutes when closed and unlocks it when open after X seconds.", - category: "Safety & Security", - iconUrl: "http://www.gharexpert.com/mid/4142010105208.jpg", - iconX2Url: "http://www.gharexpert.com/mid/4142010105208.jpg" -) - -preferences{ - section("Select the door lock:") { - input "lock1", "capability.lock", required: true, multiple: true - } - section("Select the door contact sensor:") { - input "contact", "capability.contactSensor", required: true - } - section("Automatically lock the door when closed...") { - input "minutesLater", "number", title: "Delay (in minutes):", required: true - } - section("Automatically unlock the door when open...") { - input "secondsLater", "number", title: "Delay (in seconds):", required: true - } - section( "Notifications" ) { - input("recipients", "contact", title: "Send notifications to", required: false) { - input "phoneNumber", "phone", title: "Warn with text message (optional)", description: "Phone Number", required: false - } + name: "Good Night House", + namespace: "charette.joseph@gmail.com", + author: "Joseph Charette", + description: "Some on, some off with delay for bedtime, Lock The Doors", + category: "Convenience", + iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png", + iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png" +/** +* Borrowed code from +* Walk Gentle Into That Good Night +* +* Author: oneaccttorulethehouse@gmail.com +* Date: 2014-02-01 + */ + ) +preferences { + section("When I touch the app turn these lights off…"){ + input "switchesoff", "capability.switch", multiple: true, required:true + } + section("When I touch the app turn these lights on…"){ + input "switcheson", "capability.switch", multiple: true, required:false + } + section("Lock theses locks...") { + input "lock1","capability.lock", multiple: true } + section("And change to this mode...") { + input "newMode", "mode", title: "Mode?" + } + section("After so many seconds (optional)"){ + input "waitfor", "number", title: "Off after (default 120)", required: true + } } -def installed(){ - initialize() -} -def updated(){ - unsubscribe() - unschedule() - initialize() +def installed() +{ + log.debug "Installed with settings: ${settings}" + log.debug "Current mode = ${location.mode}" + subscribe(app, appTouch) } -def initialize(){ - log.debug "Settings: ${settings}" - subscribe(lock1, "lock", doorHandler, [filterEvents: false]) - subscribe(lock1, "unlock", doorHandler, [filterEvents: false]) - subscribe(contact, "contact.open", doorHandler) - subscribe(contact, "contact.closed", doorHandler) -} -def lockDoor(){ - log.debug "Locking the door." - lock1.lock() - if(location.contactBookEnabled) { - if ( recipients ) { - log.debug ( "Sending Push Notification..." ) - sendNotificationToContacts( "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!", recipients) - } - } - if (phoneNumber) { - log.debug("Sending text message...") - sendSms( phoneNumber, "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!") - } -} - -def unlockDoor(){ - log.debug "Unlocking the door." - lock1.unlock() - if(location.contactBookEnabled) { - if ( recipients ) { - log.debug ( "Sending Push Notification..." ) - sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!", recipients) - } - } - if ( phoneNumber ) { - log.debug("Sending text message...") - sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!") - } +def updated() +{ + log.debug "Updated with settings: ${settings}" + log.debug "Current mode = ${location.mode}" + unsubscribe() + subscribe(app, appTouch) } -def doorHandler(evt){ - log.debug evt.value - log.debug contact.latestValue("contact") - if ((contact.latestValue("contact") == "open") && (evt.value == "locked")) { // If the door is open and a person locks the door then... - //def delay = (secondsLater) // runIn uses seconds - log.debug "1" - runIn( secondsLater, unlockDoor ) // ...schedule (in minutes) to unlock... We don't want the door to be closed while the lock is engaged. - } - else if ((contact.latestValue("contact") == "open") && (evt.value == "unlocked")) { // If the door is open and a person unlocks it then... - log.debug "2" - unschedule( unlockDoor ) // ...we don't need to unlock it later. - } - else if ((contact.latestValue("contact") == "closed") && (evt.value == "locked")) { // If the door is closed and a person manually locks it then... - log.debug "3" - unschedule( lockDoor ) // ...we don't need to lock it later. - } - else if ((contact.latestValue("contact") == "closed") && (evt.value == "unlocked")) { // If the door is closed and a person unlocks it then... - log.debug "4" - //def delay = (minutesLater * 60) // runIn uses seconds - runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock. - } - else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "open")) { // If a person opens an unlocked door... - log.debug "5" - unschedule( lockDoor ) // ...we don't need to lock it later. - } - else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "closed")) { // If a person closes an unlocked door... - //def delay = (minutesLater * 60) // runIn uses seconds - log.debug "6" - runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock. - } - else { //Opening or Closing door when locked (in case you have a handle lock) - log.debug "Unlocking the door." - lock1.unlock() - if(location.contactBookEnabled) { - if ( recipients ) { - log.debug ( "Sending Push Notification..." ) - sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!", recipients) - } - } - if ( phoneNumber ) { - log.debug("Sending text message...") - sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!") - } - } +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) } installed() -- 2.34.1