The Vera Community forums have moved!

Advanced => Programming => General => Topic started by: kyle.dawson on December 22, 2018, 04:43:39 pm

Title: {SOLVED} How read the values from luup.call_action
Post by: kyle.dawson on December 22, 2018, 04:43:39 pm
I am looking to read the value, specifically the returnArguments from the luup.call_action.  It comes back as table or list and I can not figure out how to loop thru to get each value.    Below is sample code:

Code: [Select]
local ALTUI_DEVICE_NO = 850
local ALTUI_DEVICE_SID = "urn:upnp-org:serviceId:altui1"
local GROUP_ID_KITCHEN = "RINCON_B832343333301400:4353"


resultCode, resultString, job, returnArguments = luup.call_action(ALTSONOS_DEVICE_SID, "GetVolume", { groupID = GROUP_ID_KITCHEN} , ALTSONOS_DEVICE_NO)



Title: Re: How read the values from luup.call_action
Post by: akbooer on December 22, 2018, 05:44:26 pm
Return arguments are in a table with name/value pairs.

You can loop through these:

Code: [Select]
for name,value in pairs (returnArguments) do
  -- whatever you like
end

or simple access each value by name:

Code: [Select]
if returnArguments.whatever then ...

Be aware, though, that if ithe action is implemented as a job, the call may well return before the job is run.
Title: Re: How read the values from luup.call_action
Post by: amg0 on December 22, 2018, 05:44:46 pm
I am looking to read the value, specifically the returnArguments from the luup.call_action.  It comes back as table or list and I can not figure out how to loop thru to get each value.    Below is sample code:

Code: [Select]
local ALTUI_DEVICE_NO = 850
local ALTUI_DEVICE_SID = "urn:upnp-org:serviceId:altui1"
local GROUP_ID_KITCHEN = "RINCON_B8E93758FA4001400:725"
local GROUP_ID_FAMILY_ROOM = "RINCON_000E58C7D93A01400:4198103609"


resultCode, resultString, job, returnArguments = luup.call_action(ALTSONOS_DEVICE_SID, "GetVolume", { groupID = GROUP_ID_KITCHEN} , ALTSONOS_DEVICE_NO)

for key,val in pairs(returnArguments ) do
Title: Re: How read the values from luup.call_action
Post by: kyle.dawson on December 22, 2018, 10:47:20 pm
No matter what I try the value is nil. 


Code: [Select]
local ALTUI_DEVICE_NO = 850
local ALTUI_DEVICE_SID = "urn:upnp-org:serviceId:altui1"
local GROUP_ID_KITCHEN = "RINCON_A8E956A3758FA4"
resultCode, resultString, job, returnArguments = luup.call_action(ALTSONOS_DEVICE_SID, "GetVolume", { groupID = GROUP_ID_KITCHEN} , ALTSONOS_DEVICE_NO)
local name, value
for name,value in pairs(returnArguments) do
  luup.log("Debug Name: " .. name)
  luup.log("Debug Value: " .. value)
end

I get this result


[string "ALTUI - LuaRunHandler"]:6: bad argument #1 to 'pairs' (table expected, got nil)
Title: Re: How read the values from luup.call_action
Post by: akbooer on December 23, 2018, 02:34:27 am
Check the status return from the call... it must be failing.

Are you sure that you are using the correct serviceId and parameter names?
Title: Re: How read the values from luup.call_action
Post by: kyle.dawson on December 23, 2018, 10:30:55 am
Well that is a dumb user error. I was testing ALTUI and ALTSONS and mixed up the numbers.  Thanks so much, its working great now.