I wrote an app that will program a door lock code using setCode()
, then wait 5 seconds and check the value of lockCodes
to verify that the setCode()
function worked, and if not, try up to 4x more. I can see in the events for the door lock that the that value of lockCodes
gets updated within a few seconds after setCode()
, but each time my app queries lockCodes
, even up to 20 seconds after the first execution of setCode()
, the value of lockCodes
is still the same as it was before I ran my app's function.
def findExistingAirbnbCodePosition(lock) {
int airbnbCodePosition = 0
Boolean codeAvailable = false
if(debugMode) log.debug "Getting the door lock codes"
def codes = lock.currentState("lockCodes").value
if(debugMode) log.debug "The door lock codes from ${lock} are ${codes}"
def codeJson
codeJson = new JsonSlurper().parseText(codes)
for(codePosition in codeJson) {
if(debugMode) log.debug "The code position is ${codePosition.value} in ${codePosition.key}"
for(codeData in codePosition.value) {
if(codeData.key == "name") {
if(debugMode) log.debug "The code name is ${codeData.value}"
if(codeData.value == "RentalAutomator") {
if(debugMode) log.debug "KEY FOUND at position ${codePosition.key}"
airbnbCodePosition = codePosition.key.toInteger()
codeAvailable = true
break
}
}
}
if(codeAvailable) break
}
if(codeAvailable) {
if(debugMode) log.debug "The availaable code position being returned is ${airbnbCodePosition}"
return airbnbCodePosition
}
return null
}
You can see in the screenshot below that the setCode()
was run at 2023-11-19 10:53:19.821 PM, and then when I checked the value of lockCodes
at 2023-11-19 10:53:29.850 PM, that code #3 "RentalAutomator" was not in the list. Then, if you reference the screenshot below that, you'll see a snip from the door lock device's event where this shows that the values for lockCodes
was updated at 10:53:22.351 PM, which is also seen in the first screenshot.