Author Topic: If something greater (>) than then luup and Xml  (Read 307 times)

Offline RichieB

  • Full Member
  • ***
  • Posts: 128
  • Karma: +2/-0
If something greater (>) than then luup and Xml
« on: September 16, 2018, 08:29:46 am »
so im writing a plugin and i need to use greater that & lesser than but it runs in the Implementation file the problem is i cant get it to work

using < or > in xml indicates a tag which give me Lua error

sp here is my code


Code: [Select]
<?xml version="1.0"?>
<implementation>
<functions>
function virtual_dimmable_light_startup (lul_device)
luup.log ("Virtual dimmable light running...")
end
</functions>
<startup>virtual_dimmable_light_startup</startup>
<actionList>
<action>
<serviceId>urn:upnp-org:serviceId:Dimming1</serviceId>
<name>SetLoadLevelTarget</name>
<job>
local CompSet
luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", lul_settings.newLoadlevelTarget, lul_device)
luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", lul_settings.newLoadlevelTarget, lul_device)

local CompSet = luup.variable_get ("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", 523)

         local CompSet = luup.variable_get ("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", 523)
if (tonumber (CompSet, 10) == 0) then
luup.call_action(weofwofejwfowf)
elseif ((tonumber (CompSet, 10) >= 1) and (tonumber (CompSet, 10) <= 33 )) then
luup.call_action(weofwofejwfowf)
elseif ((tonumber (CompSet, 10) >= 34) and (tonumber (CompSet, 10) <= 66 )) then
luup.call_action(weofwofejwfowf)
elseif ((tonumber (CompSet, 10) >= 67) and (tonumber (CompSet, 10) <= 100 )) then
luup.call_action(weofwofejwfowf)
end


if (tonumber (lul_settings.newLoadlevelTarget, 10) == 0) then
luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", "0", lul_device)
else
luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", "1", lul_device)
end
return 4, 5

</job>
</action>
</actionList>
</implementation>

I have tried replacing it with ("&gt;=" but still nothing 

"luup.call_action(weofwofejwfowf)" is really not what im calling but its just a place holder

the function works perfectly when not in the xml format

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 866
  • Karma: +64/-8
Re: If something greater (>) than then luup and Xml
« Reply #1 on: September 16, 2018, 08:11:28 pm »
Save yourself the hassle and split out the lua code into another file. It's then pretty easy to test the lua code in the AltUI or UI7 lua test box with minor adjustments. Plus an editor that has syntax highlighting will show up misc syntax errors. Notepad++ works well. It's all easier to read and maintain.

compSet  is declared three times in your code and this line is also duplicated:
local compSet = luup.variable_get ("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", DEVICE_523)
Magic numbers like 512 should be made a 'Constant' variable for clarity and easy software rework. You could rename DEVICE_523 to something meaningful.

The following may work. If it doesn't, it's close to correct. Need to replace L_MY_FILE_NAME.lua with your lua file name.
Not sure what you have planned for:   luup.call_action(weofwofejwfowf)

Lua file:
Code: [Select]
local THIS_LUL_DEVICE = nil
local DEVICE_523 = 523

local function setLoadLevelTarget(newLoadlevelTarget)

luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", newLoadlevelTarget, THIS_LUL_DEVICE)
luup.variable_set ("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", newLoadlevelTarget, THIS_LUL_DEVICE)

local compSet = luup.variable_get ("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget", DEVICE_523)
if (tonumber (compSet, 10) == 0) then
luup.call_action(weofwofejwfowf)
elseif ((tonumber (compSet, 10) >= 1) and (tonumber (compSet, 10) <= 33 )) then
luup.call_action(weofwofejwfowf)
elseif ((tonumber (compSet, 10) >= 34) and (tonumber (compSet, 10) <= 66 )) then
luup.call_action(weofwofejwfowf)
elseif ((tonumber (compSet, 10) >= 67) and (tonumber (compSet, 10) <= 100 )) then
luup.call_action(weofwofejwfowf)
end

if (tonumber (newLoadlevelTarget, 10) == 0) then
luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", "0", THIS_LUL_DEVICE)
else
luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", "1", THIS_LUL_DEVICE)
end

return 4, 5
end

-- function needs to be global and is called at start up
function virtual_dimmable_light_startup (lul_device)
    THIS_LUL_DEVICE = lul_device
    luup.log ("Virtual dimmable light running...")
end

Implementation file:
Code: [Select]
<?xml version="1.0"?>
<implementation>
<files>L_MY_FILE_NAME.lua</files>
<startup>virtual_dimmable_light_startup</startup>
<actionList>
<action>
<serviceId>urn:upnp-org:serviceId:Dimming1</serviceId>
<name>SetLoadLevelTarget</name>
            <job>
                <!-- We'll be explicit here, about what's being returned, just for the record -->
                local  jobStatus, timeout = setLoadLevelTarget(lul_settings.newLoadlevelTarget)
                return jobStatus, timeout
            </job>
</action>
</actionList>
</implementation>
« Last Edit: September 16, 2018, 11:00:45 pm by a-lurker »

Offline RichieB

  • Full Member
  • ***
  • Posts: 128
  • Karma: +2/-0
Re: If something greater (>) than then luup and Xml
« Reply #2 on: September 17, 2018, 08:53:02 am »
you are a great man