Skip to content

Commit

Permalink
ability to refresh codes
Browse files Browse the repository at this point in the history
  • Loading branch information
ethayer committed Mar 10, 2017
1 parent 754fd57 commit a24ca1f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
8 changes: 7 additions & 1 deletion smartapps/ethayer/lock-manager.src/lock-manager.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def mainPage() {
href(name: 'toKeypadPage', page: 'keypadPage', title: 'Keypad Routines (optional)', image: 'https://dl.dropboxusercontent.com/u/54190708/LockManager/keypad.png')
href(name: 'toNotificationPage', page: 'notificationPage', title: 'Notification Settings', description: notificationPageDescription(), state: notificationPageDescription() ? 'complete' : '', image: 'https://dl.dropboxusercontent.com/u/54190708/LockManager/bullhorn.png')
input(name: 'overwriteMode', title: 'Overwrite?', type: 'bool', required: true, defaultValue: true, description: 'Overwrite mode automatically deletes codes not in the users list')
href(name: 'toInfoRefreshPage', page: 'infoRefreshPage', title: 'Refresh Lock Data', description: 'Tap to refresh', image: 'https://dl.dropboxusercontent.com/u/54190708/LockManager/refresh.png')
}
}
}
Expand All @@ -53,9 +52,13 @@ 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.'
}
if (!refreshComplete) {
paragraph 'App is in refresh mode.'
}
def codeData = lockApp.codeData()
if (codeData) {
def setCode = ''
Expand All @@ -77,6 +80,9 @@ def lockInfoPage(params) {
} else {
image = 'https://dl.dropboxusercontent.com/u/54190708/LockManager/times-circle-o.png'
}
if (data.codeState == 'refresh') {
para = para +'\nPending refresh...'
}
paragraph para, image: image
}
}
Expand Down
33 changes: 31 additions & 2 deletions smartapps/ethayer/lock.src/lock.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ preferences {
page name: 'errorPage'
page name: 'notificationPage'
page name: 'helloHomePage'
page name: 'infoRefreshPage'
}

def installed() {
Expand Down Expand Up @@ -85,6 +86,11 @@ def mainPage() {
href(name: 'toHelloHomePage', page: 'helloHomePage', title: 'Hello Home Settings', image: 'https://dl.dropboxusercontent.com/u/54190708/LockManager/home.png')
if (actions) {
href(name: 'toHelloHomePage', page: 'helloHomePage', title: 'Hello Home Settings', image: 'https://dl.dropboxusercontent.com/u/54190708/LockManager/home.png')
if (state.initializeComplete && state.refreshComplete) {
href(name: 'toInfoRefreshPage', page: 'infoRefreshPage', title: 'Refresh Lock Data', description: 'Tap to refresh', image: 'https://dl.dropboxusercontent.com/u/54190708/LockManager/refresh.png')
} else {
paragraph 'Lock is loading data'
}
}
}
section('Setup', hideable: true, hidden: true) {
Expand All @@ -106,6 +112,14 @@ def errorPage() {
}
}
}
def infoRefreshPage() {
dynamicPage(name: 'infoRefreshPage', title: "Lock Info Refresh", nextPage: 'landingPage') {
refreshMode()
section("Ok!") {
paragraph 'Lock is now in refresh mode'
}
}
}

def notificationPage() {
dynamicPage(name: "notificationPage", title: "Notification Settings") {
Expand Down Expand Up @@ -156,6 +170,15 @@ def helloHomePage() {
}
}

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

def setupLockData() {
debugger('run lock data setup')
def lockUsers = parent.getUserApps()
Expand All @@ -168,6 +191,7 @@ def setupLockData() {
state.codes = [:]
state.initializeComplete = false
state.installComplete = true
state.refreshComplete = true
state.supportsKeypadData = true
state.pinLength = false
if (lock.hasAttribute('pinLength')) {
Expand Down Expand Up @@ -203,6 +227,7 @@ def makeRequest() {
lock.requestCode(requestSlot)
} else {
debugger('no request to make')
state.refreshComplete = true
state.initializeComplete = true
setCodes()
}
Expand All @@ -227,7 +252,7 @@ def updateCode(event) {
debugger("Recieved: s:${slot} c:${code}")

// check logic to see if all codes are in known state
if (!state.initializeComplete) {
if (!state.initializeComplete || !state.refreshComplete) {
runIn(5, makeRequest)
}
if (previousCode != code) {
Expand Down Expand Up @@ -342,7 +367,7 @@ def setCodes() {
// do nothing!
}
}
if (state.initializeComplete) {
if (state.initializeComplete && state.refreshComplete) {
runIn(5, loadCodes)
} else {
debugger('initialize not yet complete!')
Expand Down Expand Up @@ -492,6 +517,10 @@ def isCodeComplete() {
return state.initializeComplete
}

def isRefreshComplete() {
return state.refreshComplete
}

def codeData() {
return state.codes
}
Expand Down

0 comments on commit a24ca1f

Please sign in to comment.