Fredmas Posté(e) le 15 novembre 2021 Auteur Signaler Posté(e) le 15 novembre 2021 Comme tu es dans un QA, qui ne tourne pas en boucle (voir discussion précédente) et donc qu'il n'y a pas de trigger, tu n'as pas le choix que de définir un intervalle régulier. Je viens de tester un truc très court et rapide qui fonctionne, mais qui ne s'arrête pas tout seul. Sinon il faut construire ton QA autrement (discussion précédente) avec un truc du style intervalRunner par exemple (voir au début de ce topic) que tu peux arrêter. Donne moi ton code de ta fonction consommation, et je te montre si tu veux. Sinon pour que tu comprennes l'idée ça peut ressembler à ça : function Essai() toto = toto + 1 print(toto) setTimeout(Essai, 2*1000) end Ca te crée une fonction qui boucle toute seule toutes les 2s (tu remplaces 2 parce que tu veux comme durée), mais qui ne s'arrête pas. Ce n'est pas que je ne sais pas faire pour l'arrêter, mais c'est pour te montrer pas à pas. Mais comme tu l'as compris, la fonction seule ne fera rien. Donc il faut que tu ajoutes à l'intérieur de ta fonction quickApp:onInit() la ligne de code suivante : toto = 0 Essai() Au démarrage de ton QA ça lancera la fonction essai(), qui ensuite bouclera à l'infini jusqu'à rencontrer un problème de crash. Pour l'arrêter il faut enlever Essai() de ta fonction quickApp:onInit() Encore une fois ce n'est pas clean, mais c'est juste pour te montrer le fonctionnement pour t'aider à faire ton code. Et dans ton cas, la fonction Essai() est en fait ta fonction bouton Raf1(), dans lequel tu ajoutes juste le setTimeout(blablabla).
Fredmas Posté(e) le 15 novembre 2021 Auteur Signaler Posté(e) le 15 novembre 2021 Evidemment, tu remplaces toto = toto + 1 print(toto) par ce que tu veux. Le rafraichissement, un contrôle de la conso pour simplement te donner un message OK, etc.
971jmd Posté(e) le 15 novembre 2021 Signaler Posté(e) le 15 novembre 2021 ok OK ça rafraîchit toutes les quatre secondes mais visiblement sauf le bouton de rafraîchissement mes conso n'a paraît pas function Essai() toto = toto + 1 print(toto) setTimeout(Essai, 4*1000) end function QuickApp:onInit() self:debug("onInit") idclim = 353 idclim2 = 93 timeoutClim1 = 0 timeoutClim2 = 0 duration = 0 toto = 0 Essai() end
Fredmas Posté(e) le 15 novembre 2021 Auteur Signaler Posté(e) le 15 novembre 2021 Donne ton code complet stp
971jmd Posté(e) le 15 novembre 2021 Signaler Posté(e) le 15 novembre 2021 Quel emmerdeur que je suis -- Generic device type have no default actions to handle -- To update controls you can use method self:updateView(<component ID>, <component property>, <desired value>). Eg: -- self:updateView("slider", "value", "55") -- self:updateView("button1", "text", "MUTE") -- self:updateView("label", "text", "TURNED ON") -- This is QuickApp inital method. It is called right after your QuickApp starts (after each save or on gateway startup). -- Here you can set some default values, setup http connection or get QuickApp variables. -- To learn more, please visit: -- * https://manuals.fibaro.com/home-center-3/ -- * https://manuals.fibaro.com/home-center-3-quick-apps/ function QuickApp:send(dataToSend, waitForResponse) self.sock:close() self:connect(function() local dataConverted = self:parseData(dataToSend) -- replace string starting with '0x' to hex value self.sock:write(dataConverted, { success = function() if waitForResponse then self:waitForResponseFunction() else self.sock:close() end end, error = function(err) self.sock:close() end }) end) end function QuickApp:parseData(str) while true do if string.find(str, '0x') then i,j = string.find(str, '0x') str = string.sub(str, 1, i - 1) .. self:fromhex(string.sub(str, i + 2, j +2)) .. string.sub(str, j + 3) else return str end end end function QuickApp:fromhex(str) return (str:gsub('..', function(cc) return string.char(tonumber(cc, 16)) end)) end function QuickApp:waitForResponseFunction() self.sock:read({ success = function(data) self:debug("response data:", data) self.sock:close() end, error = function() self:debug("response error") self.sock:close() end }) end function QuickApp:connect(successCallback) print("connecting:", self.ip, self.port) self.sock:connect(self.ip, self.port, { success = function() self:debug("connected") successCallback() end, error = function(err) self.sock:close() self:debug("connection error") end, }) end function QuickApp:onInit() self:debug("onInit") self.ip = self:getVariable("ip") self.port = tonumber(self:getVariable("port")) self.sock = net.TCPSocket() end -------------------------------------------------------- function Essai() toto = toto + 1 print(toto) setTimeout(Essai, 4*1000) end function QuickApp:onInit() self:debug("onInit") idclim = 353 idclim2 = 93 timeoutClim1 = 0 timeoutClim2 = 0 duration = 0 toto = 0 Essai() end function QuickApp:Raf1() self:updateView("power1", "text", "Climatiseur N°1 - "..fibaro.getValue(idclim, "power").." W") self:updateView("power2", "text", "Climatiseur N°2 - "..fibaro.getValue(idclim2, "power").." W") end --2H function QuickApp:buttonClim2() self:debug("BOUTON 2H") duration = 30*1000 test1(self) test2(self) end --4H function QuickApp:buttonClim4() self:debug("BOUTON 4H") duration = 60*1000 test1(self) test2(self) end function QuickApp:buttonReset() duration = 0 test1(self) end function QuickApp:ON24_S1_C1() fibaro.call(353, "turnOn") self:debug("onInit") end function QuickApp:OFF_S1_C1() fibaro.call(353, "turnOff") self:debug("onInit") end function QuickApp:ON24_S1_C2() fibaro.call(93, "turnOn") end function QuickApp:OFF_S1_C2() fibaro.call(93, "turnOff") end function test1(self) ---self:ON24_S1_C1() if timeoutClim1 > 0 then clearTimeout(timeoutClim1) timeoutClim1 = 0 end timeoutClim1 = setTimeout(function() self:OFF_S1_C1() end, duration) end function test2(self) ---self:ON24_S1_C2() if timeoutClim2 > 0 then clearTimeout(timeoutClim2) timeoutClim2 = 0 end timeoutClim2 = setTimeout(function() self:OFF_S1_C2() end, duration) end --[[ ---------------- CODE IR CLIM N°1 ----------------- function QuickApp:ON22_S1_C1() ---fibaro.call(89, "turnOn") self:send("sendir,1:3,1,36656,1,1,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,366,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,48,16,48,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,46920x0D0x0A",true) end function QuickApp:ON24_S1_C1() --- fibaro.call(89, "turnOn") self:send("sendir,1:3,1,36656,1,1,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,366,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,48,16,48,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,46920x0D0x0A",true) end function QuickApp:OFF_S1_C1() ---- fibaro.call(89, "turnOff") self:send("sendir,1:3,1,36656,1,1,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,366,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,48,16,48,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,46920x0D0x0A",true) end ---------------- CODE IR CLIM N°2 ----------------- function QuickApp:ON22_S1_C2() self:send("sendir,1:3,1,36656,1,1,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,366,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,48,16,48,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,46920x0D0x0A",true) end function QuickApp:ON24_S1_C2() --- fibaro.call(89, "turnOn") self:send("sendir,1:3,1,36656,1,1,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,366,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,48,16,48,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,46920x0D0x0A",true) end function QuickApp:OFF_S1_C2() self:send("sendir,1:3,1,36656,1,1,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,366,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,48,16,48,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,46920x0D0x0A",true) end --]]
Fredmas Posté(e) le 15 novembre 2021 Auteur Signaler Posté(e) le 15 novembre 2021 (modifié) Alors déjà je ne comprends pas pourquoi tu as 2 function QuickApp:onInit() Tu peux fusionner. Ensuite tu vires toute la fonction Essai() Dans ton onInit tu vires les 2 lignes toto=0 et Essai() Par contre tu ajoutes la ligne self:Raf1() Et à la fin de ta fonction Raf1() tu ajoutes la ligne : setTimeout(function() self:Raf1() end, 4*1000) Puis reviens me dire Modifié le 15 novembre 2021 par Fredmas
971jmd Posté(e) le 15 novembre 2021 Signaler Posté(e) le 15 novembre 2021 voila function QuickApp:Raf1() self:updateView("power1", "text", "Climatiseur N°1 - "..fibaro.getValue(idclim, "power").." W") self:updateView("power2", "text", "Climatiseur N°2 - "..fibaro.getValue(idclim2, "power").." W") setTimeout(function() self:Raf1() end, 4*1000) end mai toujours pas rafraîchissement du bouton
Fredmas Posté(e) le 15 novembre 2021 Auteur Signaler Posté(e) le 15 novembre 2021 (modifié) Tu as bien ajouté self:Raf1() dans ta function QuickApp:onInit() pour que le bouton Raf1 se lance au démarrage puis toutes les 4s et rafraichisse tes 2 label power1 et power2 ? Parce que j'ai testé chez moi et ça marche... Modifié le 15 novembre 2021 par Fredmas
971jmd Posté(e) le 15 novembre 2021 Signaler Posté(e) le 15 novembre 2021 c bon ça fonctionne Je crois que je vais aller mettre des coton d'eau fraîche sur mes yeux GRAND MERCI J'ai appris plein de choses à ça toi Bon là je crois que je vais moment à la plage me détendre
Fredmas Posté(e) le 15 novembre 2021 Auteur Signaler Posté(e) le 15 novembre 2021 De rien il y a 3 minutes, 971jmd a dit : Bon là je crois que je vais moment à la plage me détendre
971jmd Posté(e) le 15 novembre 2021 Signaler Posté(e) le 15 novembre 2021 Vu leur à laquelle tu me réponds j’imagine que tu es pas de la France
Fredmas Posté(e) le 15 novembre 2021 Auteur Signaler Posté(e) le 15 novembre 2021 Et si pourtant je suis en France. Mais j’aime ce forum qui m’aide, alors j’essaie d’aider aussi
971jmd Posté(e) le 15 novembre 2021 Signaler Posté(e) le 15 novembre 2021 (modifié) moi de la Guadeloupe Et ben merci beaucoup en tout cas Ça m’a bien aidé. J’ai beaucoup encore apprendre en tout cas dans le code. Modifié le 15 novembre 2021 par 971jmd
971jmd Posté(e) le 15 novembre 2021 Signaler Posté(e) le 15 novembre 2021 Un question concernant le code, quelle est l’utilité de placée Self entre parenthèse (self) function test1(self) Quel est l’utilité de me des choses entre parenthèses
Fredmas Posté(e) le 15 novembre 2021 Auteur Signaler Posté(e) le 15 novembre 2021 (modifié) Pour l’explication du self, voir ici plus tôt dans le topic Sinon d’ordre général, en dehors de cette précédente explication à propos du self, entre parenthèses c’est pour indiquer des paramètres reçus et utilisés comme arguments dans l’exécution de la fonction appelée. Modifié le 15 novembre 2021 par Fredmas
971jmd Posté(e) le 16 novembre 2021 Signaler Posté(e) le 16 novembre 2021 (modifié) salut, merci pour le lien, j'ai pas tout compris je vais le relire plusieurs fois Autre chose est-ce que tu sais comment récupérer lydi d'une icône ? J'ai ajouté ça au début de mon function QuickApp:onInit() self:updateProperty("deviceIcon", 75) Mais j'aurais souhaité récupérer ID d'une icône pour la remplacer Je suis dans un qa Appareil générique Modifié le 16 novembre 2021 par 971jmd
Fredmas Posté(e) le 16 novembre 2021 Auteur Signaler Posté(e) le 16 novembre 2021 (modifié) De mémoire, il faut d'abord que tu ajoutes ton icône ailleurs, par exemple en utilisant un autre QA qui te le permet (pas un generic device). Une fois que c'est fait, sur ce nouvel icône tu fais un clic droit pour ouvrir l'image dans un nouvel onglet (ou enregistrer l’image sous) par exemple. Et dans la barre d'adresse, dans le nom de l'image, à la fin de ce nom tu trouves l'ID de l'icône à utiliser dans ton code. Ensuite comme tu l'as compris : self:updateProperty("deviceIcon", id_icon) Modifié le 16 novembre 2021 par Fredmas
971jmd Posté(e) le 16 novembre 2021 Signaler Posté(e) le 16 novembre 2021 malheureusement l'astuce de récupérée ID avec clic droit pour ouvrir l'image dans un nouvel onglet... Fonctionnait très bien sûr HC2 mai pas sur HC3 Je chercher mais visiblement c'est pas évident
Fredmas Posté(e) le 16 novembre 2021 Auteur Signaler Posté(e) le 16 novembre 2021 Ta réponse est surprenante, et dans ce cas je préfère laisser répondre quelqu'un qui l'a déjà fait. Mais je suis sûr que ce que je t'ai proposé c'est ce que j'ai lu sur notre forum de membres qui l'ont fait sur HC3 pour leurs QA. Après perso pour l'instant je ne l'ai pas essayé, car je ne touche pas souvent mes QA et donc je les regarde pas tous les jours. L'icône Generic Device ne me dérangeant pas vraiment, pour l'instant, même si ce pourrait être plus joli avec des icônes personnalisés.
henri-allauch Posté(e) le 16 novembre 2021 Signaler Posté(e) le 16 novembre 2021 (modifié) Tu Insère un icône dans un device. Click droit sur l'icône : tu sélectionne enregistrer image sous Tu as dans le titre : User1005 par exemple Tu insère dans ton code -> self:updateProperty("deviceIcon", 1005) Modifié le 18 novembre 2021 par henri-allauch correction ICONE est masculin 1
Fredmas Posté(e) le 16 novembre 2021 Auteur Signaler Posté(e) le 16 novembre 2021 Ouf je ne m’étais pas trompé. Merci @henri-allauch
Fredmas Posté(e) le 17 novembre 2021 Auteur Signaler Posté(e) le 17 novembre 2021 Salut @Lazer, @Barelle, @jang, Continuant mon apprentissage je viens de relire pour la énième fois ce topic et d'autres. J'aimerais revenir sur le sujet de la localisation du onInit dans le QA pour lequel vous avez participé. Quand j'ai posé la question : https://www.domotique-fibaro.fr/topic/15182-questions-de-débutant-en-quick-apps-sur-hc3/?do=findComment&comment=240845 Le 25/07/2021 à 12:09, Fredmas a dit : p.s. : petit hors sujet, pourquoi dans la plupart des QA que nous trouvons, le onInit est très souvent rédigé à la fin du code ? J'ai plutôt tendance à l'écrire au début, est-ce une erreur ? Vous n'étiez pas tous du même avis : https://www.domotique-fibaro.fr/topic/15182-questions-de-débutant-en-quick-apps-sur-hc3/?do=findComment&comment=240846 https://www.domotique-fibaro.fr/topic/15182-questions-de-débutant-en-quick-apps-sur-hc3/?do=findComment&comment=240847 https://www.domotique-fibaro.fr/topic/15182-questions-de-débutant-en-quick-apps-sur-hc3/?do=findComment&comment=240848 https://www.domotique-fibaro.fr/topic/15182-questions-de-débutant-en-quick-apps-sur-hc3/?do=findComment&comment=240854 Je viens de faire un simple test, et ce code ci-dessous fonctionne et retourne bien "toto" : local test = "toto" function QuickApp:onInit() self:debug("onInit") print(test) end Mais ce code ci-dessous ne fonctionne pas et ne retourne pas "toto" mais "nil" comme si le code n'avait pas était entièrement lu avant d'exécuter onInit() : function QuickApp:onInit() self:debug("onInit") print(test) end local test = "toto" Donc la position du onInit semble bien avoir de l'importance finalement ? Ou je n'ai pas compris la discussion ? Je relance la discussion sans aucun besoin technique identifié. C'est uniquement pour discuter, comprendre, apprendre, blablabla
jang Posté(e) le 17 novembre 2021 Signaler Posté(e) le 17 novembre 2021 (modifié) il y a 22 minutes, Fredmas a dit : Hi @Lazer, @Barelle, @jang, Continuing my learning I just reread this topic and others for the umpteenth time. I would like to come back to the subject of the location of onInit in the QA for which you participated. When I asked the question : https://www.domotique-fibaro.fr/topic/15182-questions-de-débutant-en-quick-apps-sur-hc3/?do=findComment&comment=240845 You were not all of the same opinion : https://www.domotique-fibaro.fr/topic/15182-questions-de-débutant-en-quick-apps-sur-hc3/?do=findComment&comment=240846 https://www.domotique-fibaro.fr/topic/15182-questions-de-débutant-en-quick-apps-sur-hc3/?do=findComment&comment=240847 https://www.domotique-fibaro.fr/topic/15182-questions-de-débutant-en-quick-apps-sur-hc3/?do=findComment&comment=240848 https://www.domotique-fibaro.fr/topic/15182-questions-de-débutant-en-quick-apps-sur-hc3/?do=findComment&comment=240854 I just did a simple test, and this code below works and returns "foo" : But this code below does not work and does not return "foo" but "nil" as if the code had not been fully read before executing onInit () : QuickApp function : onInit () self : debug ( "onInit" ) print ( test ) end local test = "foo" So the position of onInit does seem to matter after all? Or did I not understand the discussion? I am relaunching the discussion without any technical need identified. It's only to discuss, understand, learn, blah blah is still valid. When Lua loads your file the statements are executed top-to-bottom. Your first example: sets local test to "foo" defines function function QuickApp:onInit(). When onInit() is defined (compiled) the variable 'test' is determined to be a local variable as it has been defined previously (step 1). When the file is loaded no one has called QuickApp:onInit() yet. However after the QA is loaded, fibaro calls your QuickApp:onInit() to "start" your QA. The QA prints "foo". Your second example. defines function function QuickApp:onInit(). When onInit() is defined (compiled) the variable 'test' is determined to be a global variable as it has not been seen previously. sets local test to "foo" fibaro calls your QuickApp:onInit() functions that tries to print the global variable 'test' that has the value nil. In my previous post I talked about "forward" declaring variables. This would solve it. local test function QuickApp : onInit () self : debug ( "onInit" ) print ( test ) end test = "foo" declares local variable test defines function function QuickApp:onInit(). When onInit() is defined (compiled) the variable 'test' is determined to be a local variable as it has been defined previously (step 1). local test is set to "foo" fibaro calls your QuickApp:onInit() functions that prints the global variable 'test' that has the value "foo" Modifié le 17 novembre 2021 par jang 1
Lazer Posté(e) le 17 novembre 2021 Signaler Posté(e) le 17 novembre 2021 il y a 28 minutes, Fredmas a dit : Donc la position du onInit semble bien avoir de l'importance finalement ? Ou je n'ai pas compris la discussion ? @jang a parfaitement répondu (qui en aurait douté ) Quant à ta phrase, je l'aurais plutôt écrite comme ceci : "La position de la déclaration de ta variable locale a de l'importance finalement." C'est en quelques sorte de la sémantique du langage.... notre langage d'humain 2 1
Fredmas Posté(e) le 17 novembre 2021 Auteur Signaler Posté(e) le 17 novembre 2021 il y a 2 minutes, jang a dit : When onInit() is defined (compiled) the variable 'test' is determined to be a global variable as it has not been seen previously. Clear, got it. I understand better the difference between loading and execution. So we need to keep in mind that onInit is also loaded in order of the full code, before to be executed And yes the position of onInit counts in the code. At least for declaration of variables used in
Messages recommandés