Bonjour,
Pour savoir où les variables globales sont utilisées, je vous propose la scène ci-après qui permet de lister, dans la fenêtre de debug, les variables globales et les endroits où elles sont utilisées :
--[[
This scene is used to list all the global variables and where they are used.
Its a kind of xref.
--]]
local globalVariables = api.get("/globalVariables"); -- Get all globals variables,
local scenes = api.get("/scenes"); -- all the scenes
local devices = api.get("/devices"); -- and all the devices
local txt = '<BR><BR><font color="yellow">Globals Xref on : ' .. os.date("%d/%m/%y à %X") .. '</font><BR>';
for _, v in pairs(globalVariables) do -- For each global variable
txt = txt .. '<BR><font color="Orange">' .. v.name .. ' :</font>';
local used = false;
for _, s in pairs(scenes) do -- For each scene
local scene = api.get("/scenes/" .. s.id);
if scene.triggers.globals ~= nil then
for _, g in pairs(scene.triggers.globals) do -- We look each trigger
if (g ~= nil) and (g == v.name) then
txt = txt .. '<BR><font color="lightgreen"> - trigger in scene "' .. s.name.. '"</font>';
used = true;
end
end
end
-- On inspecte le code lua
if (scene.isLua ~= nil) and (scene.isLua == true) and (string.find(scene.lua, v.name) ~= nil) then
txt = txt .. '<BR><font color="Chartreuse"> - used in scene "' .. s.name .. '"</font>';
used = true;
end
end -- for _, s in pairs(scenes)
for _,device in pairs(devices) do -- On parcourt les devices
if device.type == "virtual_device" then -- For others types there is no lua code
if (device.properties.mainLoop ~= nil) and (string.find(device.properties.mainLoop, v.name) ~= nil) then
txt = txt .. '<BR><font color="DeepSkyBlue"> - used in VD "' .. device.name .. '" mainloop</font>';
used = true;
end
local rows = device.properties.rows;
for _, r in pairs(rows) do
if (r ~= nil) and (r.elements ~= nil) then
for _,e in pairs(r.elements) do
if (e.lua ~= nil) and (e.lua == true) then
if (e.msg ~= nil) and (string.find(e.msg, v.name) ~= nil) then
txt = txt .. "<BR><font color='LightSkyBlue'> - used in " .. '"' .. e.name .. '" (id: ' .. e.id .. ') of "' .. device.name .. '" VD</font>';
used = true;
end
end
end
end
end
end
end -- for _,d in pairs(devices)
if not used then
txt = txt .. "<font color='Magenta'> unused</font>";
end
end
fibaro:debug(txt);