Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ethayer committed Sep 17, 2015
1 parent df4b8d7 commit 27494d9
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions user-lock-manager.smartapp.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* User Lock Manager v3.9
* User Lock Manager v4.0
*
* Copyright 2015 Erik Thayer
*
Expand Down Expand Up @@ -42,6 +42,8 @@ def rootPage() {
}

if (locks) {
initalizeLockData()

section {
input name: "maxUsers", title: "Number of users", type: "number", multiple: false, refreshAfterSelection: true, submitOnChange: true
href(name: "toSetupPage", title: "User Settings", page: "setupPage", description: setupPageDescription(), state: setupPageDescription() ? "complete" : "")
Expand All @@ -66,6 +68,9 @@ def setupPage() {
//there's no values, so reset
resetCodeUsage(user)
}
if (settings."userCode${user}" && settings."userSlot${user}") {
getConflicts(settings."userSlot${user}")
}
href(name: "toUserPage${user}", page: "userPage", params: [number: user], required: false, description: userHrefDescription(user), title: userHrefTitle(user), state: userPageState(user) )
}
}
Expand All @@ -90,8 +95,8 @@ def userPage(params) {
href(name: "toreEnableUserPage", title: "Reset User", page: "reEnableUserPage", params: [number: i], description: "Tap to reset")
}
}
if (settings."userCode${i}") {
def conflict = getConflicts(i)
if (settings."userCode${i}" && settings."userSlot${i}") {
def conflict = getConflicts(settings."userSlot${i}")
if (conflict.has_conflict) {
section("Conflicts:") {
locks.each { lock->
Expand Down Expand Up @@ -337,6 +342,7 @@ def infoRefreshPage() {

def lockInfoPage(params) {
dynamicPage(name:"lockInfoPage", title:"Lock Info") {

def lock = getLock(params)
section() {
if (lock) {
Expand Down Expand Up @@ -399,34 +405,30 @@ def getConflicts(i) {
def isUnique(newInt, oldInt) {
def newArray = []
def oldArray = []


// just to get the size
oldInt.toList().collect { oldArray << normalizeNumber(it.toInteger()) }
def oldSize = oldArray.size()
oldArray = []
def result = true

def i = 0
// Get a normalized sequence, at the same length
newInt.toList().collect {
i++
if (i <= oldSize) {
if (i <= oldInt.length()) {
newArray << normalizeNumber(it.toInteger())
}
}

i = 0
oldInt.toList().collect {
i++
if (i <= newArray.size()) {
if (i <= newInt.length()) {
oldArray << normalizeNumber(it.toInteger())
}
}

def result = true
i = 0
newArray.each { num->
i++
if (newArray.join() == oldArray.join()) {
// The normalized numbers are the same!
result = false
}
}
Expand All @@ -435,6 +437,8 @@ def isUnique(newInt, oldInt) {

def normalizeNumber(number) {
def result = null
// RULE: Since some locks share buttons, make sure unique.
// Even locks with 10-keys follow this rule! (annoyingly)
switch (number) {
case [1,2]:
result = 1
Expand Down

0 comments on commit 27494d9

Please sign in to comment.