From b65cacd574a3961ed748152280d52c01dfa17278 Mon Sep 17 00:00:00 2001 From: Erik Thayer Date: Tue, 11 Apr 2017 13:36:48 -0500 Subject: [PATCH] Add presense check for HH actions --- .../ethayer/lock-user.src/lock-user.groovy | 21 +++++++++++++++++++ smartapps/ethayer/lock.src/lock.groovy | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/smartapps/ethayer/lock-user.src/lock-user.groovy b/smartapps/ethayer/lock-user.src/lock-user.groovy index 11b5562..56c3412 100755 --- a/smartapps/ethayer/lock-user.src/lock-user.groovy +++ b/smartapps/ethayer/lock-user.src/lock-user.groovy @@ -177,6 +177,9 @@ def mainPage() { actions.sort() input name: 'userUnlockPhrase', type: 'enum', title: 'Hello Home Phrase on unlock', multiple: true, required: false, options: actions, refreshAfterSelection: true, image: 'https://dl.dropboxusercontent.com/u/54190708/LockManager/home.png' input name: 'userLockPhrase', type: 'enum', title: 'Hello Home Phrase on lock', description: 'Available on select locks only', multiple: true, required: false, options: actions, refreshAfterSelection: true, image: 'https://dl.dropboxusercontent.com/u/54190708/LockManager/home.png' + + input "userNoRunPresence", "capability.presenceSensor", title: "DO NOT run Actions if any of these are present:", multiple: true, required: false + input "userDoRunPresence", "capability.presenceSensor", title: "ONLY run Actions if any of these are present:", multiple: true, required: false } input(name: 'burnAfterInt', title: 'How many uses before burn?', type: 'number', required: false, description: 'Blank or zero is infinite', image: 'https://dl.dropboxusercontent.com/u/54190708/LockManager/fire.png') href(name: 'toSchedulingPage', page: 'schedulingPage', title: 'Schedule (optional)', description: schedulingHrefDescription(), state: schedulingHrefDescription() ? 'complete' : '', image: 'https://dl.dropboxusercontent.com/u/54190708/LockManager/calendar.png') @@ -943,3 +946,21 @@ def debugger(message) { log.debug(message) } } + +def executeHelloPresenceCheck(routines) { + if (userNoRunPresence && userDoRunPresence == null) { + if (!anyoneHome(userNoRunPresence)) { + location.helloHome.execute(routines) + } + } else if (userDoRunPresence && userNoRunPresence == null) { + if (anyoneHome(userDoRunPresence)) { + location.helloHome.execute(routines) + } + } else if (userDoRunPresence && userNoRunPresence) { + if (anyoneHome(userDoRunPresence) && !anyoneHome(userNoRunPresence)) { + location.helloHome.execute(routines) + } + } else { + location.helloHome.execute(routines) + } +} diff --git a/smartapps/ethayer/lock.src/lock.groovy b/smartapps/ethayer/lock.src/lock.groovy index 6feb30f..95b5fb4 100644 --- a/smartapps/ethayer/lock.src/lock.groovy +++ b/smartapps/ethayer/lock.src/lock.groovy @@ -385,7 +385,7 @@ def codeUsed(evt) { message += '. Now burning code.' } if (userApp.userUnlockPhrase) { - location.helloHome.execute(userApp.userUnlockPhrase) + userApp.executeHelloPresenceCheck(userApp.userUnlockPhrase) } } else if (manualUse) { // unlocked manually @@ -407,7 +407,7 @@ def codeUsed(evt) { if (userApp) { message = "${lock.label} was locked by ${userApp.userName}" if (userApp.userLockPhrase) { - location.helloHome.execute(userApp.userLockPhrase) + userApp.executeHelloPresenceCheck(userApp.userLockPhrase) } } if (data && data.usedCode == 0) {