Re: Incrementing a variable and parsing string
Posted: Sun Mar 22, 2020 11:23 am
Jay,
Thanks very much for your help with this parser. It's taken me some time... but now that I'm on COVID-19 lockdown I'm giving the Python another go. I've set the variables in and tried running it.
Currently returning this error:
Error seems to be on this line:
first_value, second_value, vaux_zone_number, vaux_bass_setting, vaux_treble_setting = vaux_response_string.split(",")
Would appreciate your thoughts.
Thanks very much for your help with this parser. It's taken me some time... but now that I'm on COVID-19 lockdown I'm giving the Python another go. I've set the variables in and tried running it.
- Code: Select all
# Get the entire response string
vaux_response_string = indigo.variables[1925362107].value #VauxResponse variable
# I'm assuming that the list will always split into 5 items. This avoids setting
# each variable individually. If not, it can be done much like you do it in
# AppleScript by splitting into a list then just grabbing each item.
first_value, second_value, vaux_zone_number, vaux_bass_setting, vaux_treble_setting = vaux_response_string.split(",")
if "!s" in first_value.lower():
# Get the boolean value of the logging variable and log if it's true
if indigo.variables[767117833].getValue(bool): #vauxLogging_Enabled
indigo.server.log(vaux_response_string)
if second_value == "40":
# Log the zone and it's settings
indigo.server.log("{} {} {}".format(vaux_zone_number, vaux_bass_setting, vaux_treble_setting))
# This is a more Pythonic way of doing your zone number map
zone_map = {
"0": "Off",
"1": "Kitchen",
"2": "FamRm",
"3": "Study",
"4": "LivDnRm",
"5": "GameRm",
"6": "Patio",
"7": "Pool",
"8": "MBR",
}
# Save off the current zone name for use later in case it doesn't change for some reason
vaux_zone_variable = indigo.variables[519871620] #VauxZoneName
temp_zone_name = vaux_zone_variable.value
# If the zone number from the list is in the map's keys, save off the new name and set the Indigo variable
if vaux_zone_number in zone_map.keys():
temp_zone_name = zone_map[vaux_zone_number]
indigo.variable.updateValue(vaux_zone_variable, value=temp_zone_name)
# Create the string that's going to be set in the variable and logged
new_string_value = "{} Bass {} Treble {}".format(temp_zone_name, vaux_bass_setting, vaux_treble_setting)
# Set the Indigo variable
indigo.variable.updateValue(1963098885, value=new_string_value)
# Log the string
indigo.server.log(new_string_value)
Currently returning this error:
Mar 22, 2020 at 1:12:56 PM
Simple Serial Plugin Response from serial device (text): !S,1,5,1,2,27,27,6,8
, of length 22 characters
Script Error Vaux Parser Python.py: too many values to unpack
Script Error Exception Traceback (most recent call shown last):
Vaux Parser Python.py, line 6, at top level
ValueError: too many values to unpack
Error seems to be on this line:
first_value, second_value, vaux_zone_number, vaux_bass_setting, vaux_treble_setting = vaux_response_string.split(",")
Would appreciate your thoughts.