From a24ca1f5c84b2de98a891924a694edec5ed9a3e3 Mon Sep 17 00:00:00 2001 From: Erik Thayer Date: Fri, 10 Mar 2017 01:50:45 -0600 Subject: [PATCH] ability to refresh codes --- .../lock-manager.src/lock-manager.groovy | 8 ++++- smartapps/ethayer/lock.src/lock.groovy | 33 +++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/smartapps/ethayer/lock-manager.src/lock-manager.groovy b/smartapps/ethayer/lock-manager.src/lock-manager.groovy index ae1cb64..08c106f 100755 --- a/smartapps/ethayer/lock-manager.src/lock-manager.groovy +++ b/smartapps/ethayer/lock-manager.src/lock-manager.groovy @@ -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') } } } @@ -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 = '' @@ -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 } } diff --git a/smartapps/ethayer/lock.src/lock.groovy b/smartapps/ethayer/lock.src/lock.groovy index c00a8db..9f41f5d 100644 --- a/smartapps/ethayer/lock.src/lock.groovy +++ b/smartapps/ethayer/lock.src/lock.groovy @@ -20,6 +20,7 @@ preferences { page name: 'errorPage' page name: 'notificationPage' page name: 'helloHomePage' + page name: 'infoRefreshPage' } def installed() { @@ -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) { @@ -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") { @@ -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() @@ -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')) { @@ -203,6 +227,7 @@ def makeRequest() { lock.requestCode(requestSlot) } else { debugger('no request to make') + state.refreshComplete = true state.initializeComplete = true setCodes() } @@ -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) { @@ -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!') @@ -492,6 +517,10 @@ def isCodeComplete() { return state.initializeComplete } +def isRefreshComplete() { + return state.refreshComplete +} + def codeData() { return state.codes }