Skip to content

Commit

Permalink
the variable locks seems to be scoped
Browse files Browse the repository at this point in the history
  • Loading branch information
ethayer committed Sep 28, 2015
1 parent 2f22148 commit 17603a1
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions user-lock-manager.smartapp.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* User Lock Manager v4.0.5
* User Lock Manager v4.0.6
*
* Copyright 2015 Erik Thayer
*
Expand Down Expand Up @@ -38,10 +38,10 @@ def rootPage() {
dynamicPage(name: "rootPage", title: "", install: true, uninstall: true) {

section("Which Locks?") {
input "locks","capability.lockCodes", title: "Select Locks", required: true, multiple: true, submitOnChange: true
input "theLocks","capability.lockCodes", title: "Select Locks", required: true, multiple: true, submitOnChange: true
}

if (locks) {
if (theLocks) {
initalizeLockData()

section {
Expand Down Expand Up @@ -99,7 +99,7 @@ def userPage(params) {
def conflict = getConflicts(settings."userSlot${i}")
if (conflict.has_conflict) {
section("Conflicts:") {
locks.each { lock->
theLocks.each { lock->
if (conflict."lock${lock.id}" && conflict."lock${lock.id}".conflicts != []) {
paragraph "${lock.displayName} slot ${fancyString(conflict."lock${lock.id}".conflicts)}"
}
Expand All @@ -110,7 +110,7 @@ def userPage(params) {
section("Code #${i}") {
input(name: "userName${i}", type: "text", title: "Name for User", defaultValue: settings."userName${i}")
def title = "Code (4 to 8 digits)"
locks.each { lock->
theLocks.each { lock->
if (lock.hasAttribute('pinLength')) {
title = "Code (Must be ${lock.latestValue('pinLength')} digits)"
}
Expand Down Expand Up @@ -314,17 +314,17 @@ def getLock(params) {
}

state.lastLock = id
return locks.find{it.id == id}
return theLocks.find{it.id == id}
}

def infoPage(params) {
def infoPage() {
dynamicPage(name:"infoPage", title:"Lock Info") {
section() {
href(name: "toInfoRefreshPage", page: "infoRefreshPage", title: "Refresh Lock Data", description: 'Tap to refresh')
}
section("Locks") {
if (locks) {
locks.each { lock->
if (theLocks) {
theLocks.each { lock->
href(name: "toLockInfoPage${i}", page: "lockInfoPage", params: [id: lock.id], required: false, title: lock.displayName )
}
}
Expand Down Expand Up @@ -373,7 +373,7 @@ public humanReadableEndDate() {
}

def manualPoll() {
locks.poll()
theLocks.poll()
}

def getConflicts(i) {
Expand All @@ -383,7 +383,7 @@ def getConflicts(i) {
conflict.has_conflict = false


locks.each { lock->
theLocks.each { lock->
if (state."lock${lock.id}".codes) {
conflict."lock${lock.id}" = [:]
conflict."lock${lock.id}".conflicts = []
Expand Down Expand Up @@ -618,7 +618,7 @@ def schedulingHrefDescription() {
descriptionParts << "On ${fancyString(days)},"
}

descriptionParts << "${fancyDeviceString(locks)} will be accessible"
descriptionParts << "${fancyDeviceString(theLocks)} will be accessible"
if ((andOrTime != null) || (modeStart == null)) {
if (startTime) {
descriptionParts << "at ${humanReadableStartDate()}"
Expand Down Expand Up @@ -677,9 +677,9 @@ private initialize() {

subscribe(location, locationHandler)

subscribe(locks, "codeReport", codereturn)
subscribe(locks, "lock", codeUsed)
subscribe(locks, "reportAllCodes", pollCodeReport, [filterEvents:false])
subscribe(theLocks, "codeReport", codereturn)
subscribe(theLocks, "lock", codeUsed)
subscribe(theLocks, "reportAllCodes", pollCodeReport, [filterEvents:false])

revokeDisabledUsers()
reconcileCodes()
Expand Down Expand Up @@ -708,15 +708,15 @@ def enableUser(i) {
}

def initalizeLockData() {
locks.each { lock->
theLocks.each { lock->
if (state."lock${lock.id}" == null) {
state."lock${lock.id}" = [:]
}
}
}
def lockErrorLoopReset() {
state.error_loop_count = 0
locks.each { lock->
theLocks.each { lock->
if (state."lock${lock.id}" == null) {
state."lock${lock.id}" = [:]
}
Expand Down Expand Up @@ -1044,7 +1044,7 @@ def codeUsed(evt) {
}
}
if(settings."burnCode${usedIndex}") {
locks.deleteCode(codeData.usedCode)
theLocks.deleteCode(codeData.usedCode)
runIn(60*2, doPoll)
message += ". Now burning code."
}
Expand Down Expand Up @@ -1091,7 +1091,7 @@ def revokeDisabledUsers() {
}
def json = new groovy.json.JsonBuilder(array).toString()
if (json != '[]') {
locks.updateCodes(json)
theLocks.updateCodes(json)
runIn(60*2, doPoll)
}
}
Expand All @@ -1101,7 +1101,7 @@ def doPoll() {
if (!allCodesDone()) {
state.error_loop_count = state.error_loop_count + 1
}
locks.poll()
theLocks.poll()
}

def grantAccess() {
Expand All @@ -1117,7 +1117,7 @@ def grantAccess() {
}
def json = new groovy.json.JsonBuilder(array).toString()
if (json != '[]') {
locks.updateCodes(json)
theLocks.updateCodes(json)
runIn(60*2, doPoll)
}
}
Expand All @@ -1129,7 +1129,7 @@ def revokeAccess() {
}
def json = new groovy.json.JsonBuilder(array).toString()
if (json != '[]') {
locks.updateCodes(json)
theLocks.updateCodes(json)
runIn(60*2, doPoll)
}
}
Expand Down Expand Up @@ -1197,7 +1197,7 @@ def pollCodeReport(evt) {
}
}

def currentLock = locks.find{it.id == evt.deviceId}
def currentLock = theLocks.find{it.id == evt.deviceId}
populateDiscovery(codeData, currentLock)

def json = new groovy.json.JsonBuilder(array).toString()
Expand Down Expand Up @@ -1239,7 +1239,7 @@ def pollCodeReport(evt) {
def allCodesDone() {
def i = 0
def codeComplete = true
locks.each { lock->
theLocks.each { lock->
i++
if (state."lock${i}".error_loop == true) {
codeComplete = false
Expand Down

0 comments on commit 17603a1

Please sign in to comment.