Incrementing a variable and parsing string
Posted: Tue Sep 25, 2018 6:33 pm
Was hoping I could get a little help with incrementing a variable +1. i use this for my home audio matrix to change the source. It advances through 4 sources, and then at 4 goes to 0 again, corresponding to "off."
This simple Applescript works:
My Python attempt seems to be OK up to the +1 part, but it increments "0" to "01", instead of just going to "1"
On another note, I have a parser I wrote for that switch, and it uses some of the variable actions in this thread... Any easy suggestions as to how to convert this to Python? The issues are the if statement for the variable "vauxResponse", the text item delimiters, picking out the pieces of the serial response from the unit, then stringing the response together. This is the bass/treble set sequence. I moved this post from another thread as it seems this is more appropriate.
This is that response sequence:
Thanks very much; just not sure where to get specifics for a situation like this.
This simple Applescript works:
- Code: Select all
if value of variable "audio_7_source" = "4" then
set value of variable "audio_7_source" to "0"
else
set value of variable "audio_7_source" to (value of variable "audio_7_source") + 1
end if
My Python attempt seems to be OK up to the +1 part, but it increments "0" to "01", instead of just going to "1"
- Code: Select all
audio_7_sourceVar = indigo.variables[718347542]
if audio_7_sourceVar.value == "4":
indigo.variable.updateValue(718347542, "0")
else:
indigo.variable.updateValue (718347542, ((audio_7_sourceVar.value) + ("1")))
On another note, I have a parser I wrote for that switch, and it uses some of the variable actions in this thread... Any easy suggestions as to how to convert this to Python? The issues are the if statement for the variable "vauxResponse", the text item delimiters, picking out the pieces of the serial response from the unit, then stringing the response together. This is the bass/treble set sequence. I moved this post from another thread as it seems this is more appropriate.
- Code: Select all
using terms from application "IndigoServer"
tell application "IndigoServer"
if value of variable "vauxResponse" contains "!s" then
set vauxResponseString to value of variable "vauxResponse"
if value of variable "vauxLogging_Enabled" is equal to "true" then
log vauxResponseString
end if
set {myTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {","}}
set myList to text items of vauxResponseString
set AppleScript's text item delimiters to myTID -- It's considered good practice to return the TID's to their original state
--log list of myList
--if myList contains less than 5 items then stop
end if
try
if item 2 of myList is "40" then --this is for setting bass and treble.
set vauxZoneNumber to item 3 of myList
set vauxBassSetting to item 4 of myList
set vauxTrebleSetting to item 5 of myList
log ((vauxZoneNumber as string) & " " & (vauxBassSetting as string) & " " & (vauxTrebleSetting as string))
if vauxZoneNumber is "0" then set value of variable "vauxZoneName" to "Off"
if vauxZoneNumber is "1" then set value of variable "vauxZoneName" to "Kitchen"
if vauxZoneNumber is "2" then set value of variable "vauxZoneName" to "FamRm"
if vauxZoneNumber is "3" then set value of variable "vauxZoneName" to "Study"
if vauxZoneNumber is "4" then set value of variable "vauxZoneName" to "LivDnRm"
if vauxZoneNumber is "5" then set value of variable "vauxZoneName" to "GameRm"
if vauxZoneNumber is "6" then set value of variable "vauxZoneName" to "Patio"
if vauxZoneNumber is "7" then set value of variable "vauxZoneName" to "Pool"
if vauxZoneNumber is "8" then set value of variable "vauxZoneName" to "MBR"
set value of variable "vauxResponseBassTreble" to ((value of variable "vauxZoneName" as string) & " Bass " & (vauxBassSetting as string) & " Treble " & (vauxTrebleSetting as string))
log value of variable "vauxResponseBassTreble" as string
end if
end try
This is that response sequence:
- Code: Select all
Simple Serial Plugin Debug Queue has 1 command(s) waiting.
Simple Serial Plugin Debug Processing command: *CW,44,1
Simple Serial Plugin Debug Sending command:*CW,44,1
Simple Serial Plugin Response from serial device (text): !S,40,1,6,8
, of length 13 characters
Simple Serial Plugin Debug *CW,44,1
command completed
Script !S,40,1,6,8
Script 1 6 8
Script Kitchen Bass 6 Treble 8
Script Kitchen(K) Off 0
Script Kitc Off 0
Thanks very much; just not sure where to get specifics for a situation like this.