Aller au contenu

Rechercher dans la communauté

Affichage des résultats pour les étiquettes 'variables globales'.



Plus d’options de recherche

  • Rechercher par étiquettes

    Saisir les étiquettes en les séparant par une virgule.
  • Rechercher par auteur

Type du contenu


Forums

  • Bienvenue
    • Nouveau ? Présentez-vous
    • Le bistrot
    • Mon installation domotique
    • Annonces et suggestions
  • La Home Center et ses périphériques
    • La Home Center pour les nuls
    • HC 2 & Lite
    • HC 3
    • Modules Fibaro
    • Modules Z-wave
    • Périphériques et matériels autres
    • Plugins
    • Quick App
    • Multimédia (audio, vidéo ...)
    • Chauffage et Energie
    • Actionneurs & Ouvrants (Portail, volets, piscines, ...)
    • Eclairage
    • Applications Smartphones et Tablettes
  • Autres solutions domotiques
    • Box / Logiciel
    • Modules Nice (433 & 866 MHz)
    • Modules Zigbee
    • GCE Electronics
    • Modules Bluetooth Low Energy
  • Objets connectés
    • Les Assistants Vocaux
    • Netatmo
    • Philips Hue
    • DIY (Do It Yoursel)
  • Sécurité
    • Alarmes
    • Caméras
    • Portiers
    • Serrures
  • Informatique / Réseau
    • Tutoriels
    • Matériels Réseaux
    • Matériels Informatique
    • NAS
    • Virtualisation
  • Les bonnes affaires
    • Sites internet
    • Petites annonces

Calendriers

Aucun résultat à afficher.


Rechercher les résultats dans…

Rechercher les résultats qui…


Date de création

  • Début

    Fin


Dernière mise à jour

  • Début

    Fin


Filtrer par nombre de…

Inscription

  • Début

    Fin


Groupe


Jabber


Skype


Ville :


Intéret :


Version

1 résultat trouvé

  1. Scène pour afficher l'utilisation des variables globales Références croisées (xref) Lorsque les développements prennent une certaine ampleur, et en absence d'atelier de développement logiciel, il est utile de de pouvoir rapidement identifier quel morceau de code utilise telle variable (globale dans le cas de la HC2). Ce sujet avait déjà été abordé il y a maintenant quelque temps : Je vous en propose une nouvelle version qui permet : D'obtenir pour chaque variable globale les scènes et VD qui en font usage ; Pour chaque scène et pour chaque VD d'avoir la liste des variables globales utilisées (c'est cela qui est nouveau). Voici un exemple des résultats affichés dans le fenêtre de debug : La scène est un peu longue lors de son exécution, je suis preneur d'idées d'algorithmes plus optimisés. Le code de la scène : --[[ This scene is used to list all the global variables and where they are used. It's a kind of xref. -- 07/02/2017: creation -- 24/10/2019: add scene and virtual devices --]] local startTime = os.time(); local globalVariables = api.get("/globalVariables"); -- Get all globals variables local scenes = api.get("/scenes?type=com.fibaro.luaScene&isLua=true"); -- all the scenes local devices = api.get("/devices?type=virtual_device"); -- and all the virtual devices since for others types there is no lua code function round(num, numDecimalPlaces) return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num)); end -- round function progressBar(progressPct, length) if length ~= nil or length == 0 then length = 20; end progressPct = math.abs(progressPct); progressPct = math.min(progressPct, length); return ' [' .. string.rep("*", progressPct) .. string.rep("_", length - progressPct) .. '] '; end -- progressBar fibaro:debug('<font color="Gold">Analyzing lua code for ' .. #globalVariables .. ' global variables, ' .. #scenes .. ' scenes, ' .. #devices .. ' virtual devices, this may take a while.</font>'); -- Where each global variable is used local txt = '<BR><font color="yellow">'.. string.rep('=', 80) .. '<BR>Globals variables ' .. os.date("%d/%m/%y %X") .. '</font><BR>'; local cnt = 0; for _, glob in pairs(globalVariables) do -- For each global variable txt = txt .. '<BR><font color="Orange">Global variable "' .. glob.name .. '":</font>'; cnt = cnt + 1; 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 == glob.name) then txt = txt .. '<BR><font color="lightgreen">&nbsp&nbsp&nbsp- trigger in scene "' .. scene.name .. '" (id:' .. scene.id .. ')</font>'; used = true; end end end -- Lua code inspection if (scene.lua ~= nil) and (string.find(scene.lua, glob.name) ~= nil) then txt = txt .. '<BR><font color="Chartreuse">&nbsp&nbsp&nbsp- used in scene "' .. scene.name .. '" (id:' .. scene.id .. ')</font>'; used = true; end end -- for _, s in pairs(scenes) for _,device in pairs(devices) do -- For each virtual device if (device.properties.mainLoop ~= nil) and (string.find(device.properties.mainLoop, glob.name) ~= nil) then -- look in mainloop txt = txt .. '<BR><font color="DeepSkyBlue">&nbsp&nbsp&nbsp- used in VD "' .. device.name .. '" mainloop</font>'; used = true; end local rows = device.properties.rows; -- look in buttons for _, row in pairs(rows) do if (row.type ~= nil) and (row.type == "button") and (row.elements ~= nil) then for _,element in pairs(row.elements) do if (element.lua ~= nil) and (element.lua == true) then if (element.msg ~= nil) and (string.find(element.msg, glob.name) ~= nil) then txt = txt .. '<BR><font color="LightSkyBlue">&nbsp&nbsp&nbsp- used in "' .. element.name .. '" btn (id: ' .. element.id .. ') of "' .. device.name .. '" VD (' .. device.id .. ')</font>'; used = true; end end end end end end -- for _,d in pairs(devices) if not used then txt = txt .. "<font color='Magenta'> unused</font>"; end local progress = round((cnt / #globalVariables) * 100) if (progress % 5) == 0 then fibaro:debug('<font color="gray">working,' .. progressBar(progress/5, 20) .. tostring(progress) .. '% done in ' .. (os.time()-startTime) .. ' secondes.</font>'); end end txt = txt .. '<BR><font color="gray">Total memory in use by Lua (version '.._VERSION..'): ' .. string.format("%.2f", collectgarbage("count")) .. ' KB</font>'; txt = txt .. '<BR><font color="gray">Time for global variables: ' .. (os.time()-startTime) .. ' secondes.</font><BR>'; -- Global variables used by scenes local sceneTime = os.time(); txt = txt .. '<BR><font color="yellow">'.. string.rep('=', 80) .. '<BR>Global variables used by scene ' .. os.date("%d/%m/%y %X") .. '</font><BR>'; for _, s in pairs(scenes) do -- For each scene txt = txt .. '<BR><font color="lightgreen">Scene "' .. s.name .. '" (id:'.. s.id .. '):</font>'; local used = false; 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 for _, glob in pairs(globalVariables) do -- For each global variable if (g == glob.name) then txt = txt .. '<BR><font color="Orange">&nbsp&nbsp&nbsp- global "' .. glob.name .. ' used as a trigger"</font>'; used = true; end end -- for _, glob end end -- Lua code inspection if (scene.lua ~= nil) then for _, glob in pairs(globalVariables) do -- For each global variable if (string.find(scene.lua, glob.name) ~= nil) then txt = txt .. '<BR><font color="Coral">&nbsp&nbsp&nbsp- global "' .. glob.name .. '" used</font>'; used = true; end end -- for _, glob end if not used then txt = txt .. "<font color='Magenta'> no global variable used</font>"; end end -- for _, s in pairs(scenes) txt = txt .. '<BR><font color="gray">Total memory in use by Lua (version '.._VERSION..'): ' .. string.format("%.2f", collectgarbage("count")) .. ' KB</font>'; txt = txt .. '<BR><font color="gray">Time for scenes: ' .. (os.time()-sceneTime) .. ' secondes.</font><BR>'; -- Global variables used by virtual devices local deviceTime = os.time(); txt = txt .. '<BR><font color="yellow">'.. string.rep('=', 80) .. '<BR>Global variables used by virtual devices ' .. os.date("%d/%m/%y %X") .. '</font><BR>'; for _,device in pairs(devices) do -- For each virtual device txt = txt .. '<BR><font color="DeepSkyBlue">Virtual device "' .. device.name .. '" (id:'.. device.id .. '):</font>'; local used = false; if (device.properties.mainLoop ~= nil) then -- look in mainloop for _, glob in pairs(globalVariables) do -- For each global variable if (string.find(device.properties.mainLoop, glob.name) ~= nil) then txt = txt .. '<BR><font color="Orange">&nbsp&nbsp&nbsp- global "' .. glob.name .. '" used in mainloop</font>'; used = true; end end end local rows = device.properties.rows; -- look in buttons for _, row in pairs(rows) do if (row.type ~= nil) and (row.type == "button") and (row.elements ~= nil) then for _,element in pairs(row.elements) do for _, glob in pairs(globalVariables) do -- For each global variable if (element.lua ~= nil) and (element.lua == true) then if (element.msg ~= nil) and (string.find(element.msg, glob.name) ~= nil) then txt = txt .. '<BR><font color="Coral">&nbsp&nbsp&nbsp- global "' .. glob.name .. '" used in btn "' .. element.name .. '" (id:' .. element.id .. ')</font>'; used = true; end end end end end end if not used then txt = txt .. "<font color='Magenta'> no global variable used</font>"; end end -- for _,device txt = txt .. '<BR><font color="gray">Total memory in use by Lua (version '.._VERSION..'): ' .. string.format("%.2f", collectgarbage("count")) .. ' KB</font>'; txt = txt .. '<BR><font color="gray">Time for virtual devices: ' .. (os.time()-deviceTime) .. ' secondes.</font>'; txt = txt .. '<BR><font color="gray">Total elapsed time: ' .. (os.time()-startTime) .. ' secondes.</font><BR>'; fibaro:debug(txt); Je vous propose l'icône que j'utilise et suis preneur d'une qui serait plus "artistique". A l'approche des frimas, je ne puis que conclure par un... Chaleureusement.
×