Skip to content

Commit

Permalink
Add presense check for HH actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ethayer committed Apr 11, 2017
1 parent 6094e44 commit b65cacd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions smartapps/ethayer/lock-user.src/lock-user.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
}
}
4 changes: 2 additions & 2 deletions smartapps/ethayer/lock.src/lock.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit b65cacd

Please sign in to comment.