Let's see. I am using telnet to connect to an AVR receiver. The receiver supports commands for volume up and volume down; but does not support setting the volume. So, instead, I run a loop and single step volume up/down until the values match.
In my code; on the response of the telnet call; I update an attribute.
// If response is volume related
if( resp.matches( 'VOL(.*)' ) ) {
// Remove VOL, check if even, divide by two
vol = resp.replaceAll("VOL", "").toInteger()
if( vol % 2 != 0 ) vol = vol - 1
sendEvent( name: "Volume", value: vol / 2 ) //********
}
Next (in the same response function), if a condition matches, I go to run a different function (recursively until the numbers match):
// If we are increasing or decreasing, call function
if( iterate == "increase" || iterate == "decrease" ) setVol( desired )
Lastly, in the setVol()
function, I grab that attribute again:
// Get current Volume
curVol = device.currentValue( "Volume" ).toInteger() //********
The issue is that sometimes the sendEvent()
function completes before the currentValue()
function is called; and sometimes it does not.
Is there a way to tie into the sendEvent()
function? Maybe a complete()
or then()
method?