Skip to content

Commit

Permalink
fix user reset options
Browse files Browse the repository at this point in the history
  • Loading branch information
ethayer committed Jun 11, 2017
1 parent 5589d70 commit 93bd6de
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 45 deletions.
8 changes: 3 additions & 5 deletions smartapps/ethayer/lock-manager.src/lock-manager.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,10 @@ def lockInfoPage(params) {
if (lockApp) {
section("${lockApp.label}") {
def complete = lockApp.isCodeComplete()
def refreshComplete = lockApp.isRefreshComplete()
if (!complete) {
paragraph 'App is learning codes. They will appear here when received.\n Lock may require special DTH to work properly'
lockApp.lock.poll()
}
if (!refreshComplete) {
paragraph 'App is in refresh mode.'
}
def codeData = lockApp.codeData()
if (codeData) {
def setCode = ''
Expand Down Expand Up @@ -107,9 +103,11 @@ def lockInfoPage(params) {

section('Lock Settings') {
def pinLength = lockApp.pinLength()
def lockCodeSlots = lockApp.lockCodeSlots()
if (pinLength) {
paragraph "Required Length: ${pinLength}"
}
paragraph "Slot Count: ${lockCodeSlots}"
}
} else {
section() {
Expand Down Expand Up @@ -296,7 +294,7 @@ def getLockAppByIndex(params) {
def availableSlots(selectedSlot) {
def options = []
(1..30).each { slot->
def children = getChildApps()
def children = getLockApps()
def available = true
children.each { child ->
def userSlot = child.userSlot
Expand Down
39 changes: 27 additions & 12 deletions smartapps/ethayer/lock-user.src/lock-user.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ def incrementLockUsage(lockId) {
state."lock${lockId}".usage = state."lock${lockId}".usage + 1
}

def resetLockUsage(lockId) {
state."lock${lockId}".usage = 0
lockReset(lockId)
}

def lockReset(lockId) {
state."lock${lockId}".enabled = true
state."lock${lockId}".disabledReason = ''
Expand Down Expand Up @@ -235,16 +230,20 @@ def lockInfoPageImage(lock) {

def lockPage(params) {
dynamicPage(name:"lockPage", title:"Lock Settings") {
debugger('current params: ' + params)
def lock = getLock(params)
def lockApp = getLockApp(lock.id)
log.debug lockApp
def slotData = lockApp.slotData(userSlot)

def usage = state."lock${lock.id}".usage

debugger('found lock id?: ' + lock?.id)

if (!state."lock${lock.id}".enabled) {
section {
paragraph "WARNING:\n\nThis user has been disabled.\nReason: ${state."lock${lock.id}".disabledReason}", image: 'https://dl.dropboxusercontent.com/u/54190708/LockManager/ban.png'
href(name: 'reEnableUserLockPage', title: 'Reset User', page: 'reEnableUserLockPage', params: [id: lock.id], description: 'Tap to reset')
href(name: 'toReEnableUserLockPage', page: 'reEnableUserLockPage', title: 'Reset User', description: 'Retry setting this user.', params: [id: lock.id], image: 'https://dl.dropboxusercontent.com/u/54190708/LockManager/refresh.png' )
}
}
section("${deviceLabel(lock)} settings for ${app.label}") {
Expand Down Expand Up @@ -291,6 +290,7 @@ def reEnableUserLockPage(params) {
// do reset
def lock = getLock(params)
lockReset(lock.id)

dynamicPage(name:'reEnableUserLockPage', title:'User re-enabled') {
section {
paragraph 'Lock has been reset.'
Expand All @@ -304,7 +304,10 @@ def reEnableUserLockPage(params) {
def lockResetPage(params) {
// do reset
def lock = getLock(params)
resetLockUsage(lock.id)

state."lock${lock.id}".usage = 0
lockReset(lock.id)

dynamicPage(name:'lockResetPage', title:'Lock reset') {
section {
paragraph 'Lock has been reset.'
Expand Down Expand Up @@ -785,17 +788,24 @@ def getLockApp(lockId) {
def getLock(params) {
def id = ''
// Assign params to id. Sometimes parameters are double nested.
debugger('params: ' + params)
debugger('last: ' + state.lastLock)
if (params?.id) {
id = params.id
} else if (params?.params){
id = params.params.id
} else if (state.lastLock) {
id = state.lastLock
}
state.lastLock = id
def lockApp = getLockApp(state.lastLock)
def lockApp = getLockApp(id)
if (!lockApp) {
lockApp = getLockApp(state.lastLock)
}

return lockApp?.lock
if (lockApp) {
state.lastLock = lockApp.lock.id
return lockApp.lock
} else {
return false
}
}

def userNotificationSettings() {
Expand Down Expand Up @@ -892,6 +902,11 @@ def disableLock(lockID) {
state."lock${lockID}".disabledReason = 'Controller failed to set user code.'
}

def enableLock(lockID) {
state."lock${lockID}".enabled = true
state."lock${lockID}".disabledReason = null
}

def getLockUserInfo(lock) {
def para = "\n${app.label}"
if (settings."lockDisabled${lock.id}") {
Expand Down
36 changes: 8 additions & 28 deletions smartapps/ethayer/lock.src/lock.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ def mainPage() {
label title: 'Label', defaultValue: "Lock: ${lock.label}", required: false, description: 'recommended to start with Lock:'
input(name: 'lock', title: 'Which Lock?', type: 'capability.lock', multiple: false, required: true)
input(name: 'contactSensor', title: 'Which contact sensor?', type: "capability.contactSensor", multiple: false, required: false)
if (state.refreshComplete) {
href(name: 'toInfoRefreshPage', page: 'infoRefreshPage', title: 'Refresh Lock Data', description: 'Tap to request code refresh. Not avalible on all locks.', image: 'https://dl.dropboxusercontent.com/u/54190708/LockManager/refresh.png')
} else {
paragraph 'Lock is loading data'
}
input(name: 'slotCount', title: 'How many slots?', type: 'number', multiple: false, required: false, description: 'Overwrite number of slots supported.')
paragraph 'Lock Manager © 2017 v1.4'
}
}
Expand All @@ -120,15 +116,6 @@ def errorPage() {
}
}

def infoRefreshPage() {
dynamicPage(name: 'infoRefreshPage', title: 'Lock Info Refresh', nextPage: 'landingPage') {
refreshMode()
section('Refresh Initiated') {
paragraph 'Lock is now in refresh mode.'
}
}
}

def notificationPage() {
dynamicPage(name: 'notificationPage', title: 'Notification Settings') {
section {
Expand Down Expand Up @@ -201,17 +188,6 @@ def helloHomePage() {
}
}

def refreshMode() {
def codeSlots = lockCodeSlots()
initSlots()
(1..codeSlots).each { slot ->
state.codes["slot${slot}"].codeState = 'refresh'
}
state.requestCount = 0
state.refreshComplete = false
makeRequest()
}

def queSetupLockData() {
runIn(10, setupLockData)
}
Expand Down Expand Up @@ -709,9 +685,13 @@ def isRefreshComplete() {
}

def lockCodeSlots() {
// default to 30
def codeSlots = 30
if (state?.codeSlots?.isNumber()) {
codeSlots = state.codeSlots
if (slotCount) {
// return the user defined value
codeSlots = slotCount
} else if (state?.codeSlots) {
codeSlots = state.codeSlots.toInteger()
debugger("Lock has ${codeSlots} code slots.")
}
return codeSlots
Expand All @@ -727,7 +707,7 @@ def slotData(slot) {

def enableUser(slot) {
state.codes["slot${slot}"].attempts = 0
makeRequest()
runIn(10, makeRequest)
}

def pinLength() {
Expand Down

0 comments on commit 93bd6de

Please sign in to comment.