Changeset 220


Ignore:
Timestamp:
2014-11-13 00:25:18 (10 years ago)
Author:
amg0
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/ipx800/L_IPX800.lua

    r219 r220  
    209209 
    210210function updateDevice(lul_device, xmldata) 
     211    lul_device = tonumber(lul_device) 
    211212    log(string.format("updateDevice(%d)",lul_device)) 
    212213 
     
    225226        luup.variable_set(service, "Present", "1", lul_device) 
    226227        luup.variable_set(service, "IconCode", "100", lul_device) 
    227     end 
     228        return lomtab 
     229    end 
     230    return nil 
     231end 
     232 
     233function updateChildrenDevice(lul_device, lomtab) 
     234    lul_device = tonumber(lul_device) 
     235    log(string.format("updateChildrenDevice(%d)",lul_device)) 
     236     
     237    -- for all children device, iterate 
     238    local param = {} 
     239    for k,v in pairs(luup.devices) do 
     240        if( getParent(k)==lul_device) then 
     241            -- find the altid 
     242            local name = v.id 
     243            debug(string.format("device altid=%s",name)) 
     244            -- find the xml node with the same name 
     245            -- read the value  
     246            local led = xpath.selectNodes(lomtab,"/response/"..name.."/text()") 
     247            debug(string.format("xml %s value=%s",name, led[1])) 
     248            -- set the power value 
     249            setPowerTarget(k,led[1]) 
     250        end 
     251    end 
     252 
    228253end 
    229254 
     
    306331         
    307332    local xmldata = getGlobalStatus(lul_device,ipxIpAddress,user,password) 
    308     updateDevice(lul_device, xmldata) 
    309      
     333    local lomtab = updateDevice(lul_device, xmldata) 
     334    if (lomtab~=nil) then 
     335        updateChildrenDevice(lul_device, lomtab) 
     336    end 
    310337    -- repeat every x seconds 
    311338    if (updateFrequencySec>0) and (norepeat~=true) then  
     
    320347function createChildDevices(lul_device) 
    321348    lul_device = tonumber(lul_device) 
    322  
     349    log("createChildDevices, called on behalf of device:"..lul_device) 
     350    local outputRelays = getSetVariable(service,"OutputRelays", lul_device, "") or "" 
     351     
    323352    -- for now , just test with one device 
    324353    local child_devices = luup.chdev.start(lul_device); 
    325     luup.chdev.append( 
    326         lul_device, child_devices,  
    327         "led0", "IPX Out 0",  
    328         "urn:schemas-upnp-org:device:BinaryLight:1","D_BinaryLight1.xml",  
    329         "", "",  
    330         true        -- embedded 
    331         ) 
     354     
     355    for k,v in pairs(outputRelays:split(",")) do 
     356        local i = tonumber(v) 
     357        if (i>=1) and (i<=32) then 
     358            debug(string.format("Creating device for output relay:%d",i)) 
     359            luup.chdev.append( 
     360                lul_device, child_devices,  
     361                "led"..(i-1), "IPX800 Out "..i,  
     362                "urn:schemas-upnp-org:device:BinaryLight:1","D_BinaryLight1.xml",  
     363                "", "",  
     364                true        -- embedded 
     365                ) 
     366        end 
     367    end 
     368     
    332369    luup.chdev.sync(lul_device, child_devices) 
    333370end 
     
    346383    local password= getSetVariable(service,"Password", lul_device, "") 
    347384    local updateFrequencySec= getSetVariable(service,"UpdateFrequency", lul_device, 60) 
     385    local outputRelays= getSetVariable(service,"OutputRelays", lul_device, "") 
    348386 
    349387    if (debugmode=="1") then 
     
    370408    end 
    371409     
     410    createChildDevices(lul_device) 
     411     
    372412    -- start refreshes , with repeat 
    373413    refreshDevice(lul_device,false) 
    374414     
    375     createChildDevices(lul_device) 
    376415end 
    377416         
Note: See TracChangeset for help on using the changeset viewer.