Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. scriptedEnabled - Problem bei Abfrage

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    scriptedEnabled - Problem bei Abfrage

    This topic has been deleted. Only users with topic management privileges can see it.
    • liv-in-sky
      liv-in-sky @paul53 last edited by

      @paul53

      das ist doch seltsam - wenn du nun eines der scripte aus und einschaltest, wird dann auch bei dir das richtige angezeigt

      paul53 1 Reply Last reply Reply Quote 0
      • paul53
        paul53 @liv-in-sky last edited by

        @liv-in-sky sagte:

        wenn du nun eines der scripte aus und einschaltest, wird dann auch bei dir das richtige angezeigt

        Ja.

        liv-in-sky 2 Replies Last reply Reply Quote 0
        • liv-in-sky
          liv-in-sky @paul53 last edited by

          @paul53

          bug oder feature ?

          paul53 1 Reply Last reply Reply Quote 0
          • paul53
            paul53 @liv-in-sky last edited by

            @liv-in-sky sagte:

            bug oder feature ?

            ?? Entwickler fragen.

            1 Reply Last reply Reply Quote 0
            • liv-in-sky
              liv-in-sky @paul53 last edited by

              @paul53

              das ist schade, das konzept dieses scriptes sollte sein - eine kleine , 2 mal am tag upgedatete , liste in der vis zu haben, die mir nur scripte anzeigt, die laufen und einen falschen trigger haben

              danke für deine hilfe

              paul53 1 Reply Last reply Reply Quote 0
              • liv-in-sky
                liv-in-sky last edited by

                @apollon77

                hi ingo - du stehst in github als entwickler drin - weißt du, wieso das so ist - siehe bitte im ersten post ?

                zusammnegefaßt: selektor bekommt falsche states im script_enabled ordner beim prüfen, ob scripte enable/disabled sind

                AlCalzone 1 Reply Last reply Reply Quote 0
                • paul53
                  paul53 @liv-in-sky last edited by paul53

                  @liv-in-sky sagte:

                  das ist schade

                  Es funktioniert mit der asynchronen Version von getState(id, callback), ist also ein Puffer-Problem:

                  const idsEnabled = $('javascript.*.scriptEnabled.aktiv.*');
                  idsEnabled.each(function(id, i) {
                      if(existsState(id)) getState(id, function(err, state) {log(id + ': ' + state.val)});
                  });
                  
                  1 Reply Last reply Reply Quote 0
                  • AlCalzone
                    AlCalzone Developer @liv-in-sky last edited by

                    @liv-in-sky Welche Adapter-Version setzt du denn ein? Wir haben vor kurzem das Verhalten von Wildcards im Selektor gefixt - ggf. hat das damit zu tun.

                    liv-in-sky paul53 2 Replies Last reply Reply Quote 0
                    • liv-in-sky
                      liv-in-sky @AlCalzone last edited by

                      @AlCalzone

                      momentan 4.8.4

                      1 Reply Last reply Reply Quote 0
                      • paul53
                        paul53 @AlCalzone last edited by

                        @AlCalzone sagte:

                        Wir haben vor kurzem das Verhalten von Wildcards im Selektor gefixt - ggf. hat das damit zu tun.

                        Nein, damit hat es nichts zu tun, denn die IDs werden richtig selektiert. Die synchrone Version von getState(id) funktioniert bei diesen Datenpunkten nicht.

                        liv-in-sky 1 Reply Last reply Reply Quote 0
                        • liv-in-sky
                          liv-in-sky @paul53 last edited by liv-in-sky

                          @paul53

                          was ist hier falsch

                          function lookForEnabled(pfad) {
                            let myEnabled=false;
                            let myselctor="javascript.*.scriptEnabled."+pfad
                            $(myselctor).each(function(id, i) {   
                          
                              //if(existsState(id)) {if (getState(id).val) {myEnabled=true;}}
                              if(existsState(id)) {  getState(id, function(err, state){ if (state.val) { myEnabled=true; 
                                                                                                         return myEnabled;}})
                              }
                          });
                          }
                          

                          ich nehme an, der return wert darf da nicht drin sein - wenn ich den aber rausnehme funktioniert es nicht ?

                          paul53 1 Reply Last reply Reply Quote 0
                          • paul53
                            paul53 @liv-in-sky last edited by

                            @liv-in-sky sagte:

                            was ist hier falsch

                            Man kann keine Rückgabe aus einer Callback-Funktion an die aufrufende Funktion machen, denn die Callback-Funktion läuft asynchron.

                            liv-in-sky 1 Reply Last reply Reply Quote 0
                            • liv-in-sky
                              liv-in-sky @paul53 last edited by

                              @paul53
                              leidr weiß ich nicht, wie ich mit dieser function umgehen muss - letztlich gibt es doch ein promise - wenn das erfüllt/ausgeführt ist, soll der return gegeben werden

                              habe mit then() etwas versucht - klappt aber garnicht

                              AlCalzone 1 Reply Last reply Reply Quote 0
                              • AlCalzone
                                AlCalzone Developer @liv-in-sky last edited by AlCalzone

                                @liv-in-sky Probiers mal so:

                                async function lookForEnabled(pfad) {
                                  let myselctor = "javascript.*.scriptEnabled." + pfad;
                                  for (const id of $(myselctor)) {
                                    if (existsState(id) && (await getStateAsync(id)).val) return true;
                                  }
                                  return false;
                                }
                                

                                Dazu musst du aber auf 4.9.4 updaten, da die das Iterieren des Selector-Ergebnisses ermöglicht.
                                Und du musst das aus der aufrufenden Funktion ebenfalls mit await aufrufen, oder das Ergebnis mit .then(...) verarbeiten.

                                liv-in-sky AlCalzone 4 Replies Last reply Reply Quote 0
                                • liv-in-sky
                                  liv-in-sky @AlCalzone last edited by

                                  @AlCalzone

                                  jetzt sind alle true 😞

                                  Image 4.png

                                  1 Reply Last reply Reply Quote 0
                                  • liv-in-sky
                                    liv-in-sky @AlCalzone last edited by

                                    @AlCalzone

                                    sorry - das ist ein fehler im verarbeiten nach dem aufruf der function !!!!

                                    muss noch testen

                                    1 Reply Last reply Reply Quote 0
                                    • liv-in-sky
                                      liv-in-sky @AlCalzone last edited by

                                      @AlCalzone

                                      so wird die function jetzt aufgerufen:

                                      lookForEnabled(myGoal[b][1]) ? myEnabled="⚠️(aktiv)" : myEnabled="⚫" 
                                      
                                      
                                      async function lookForEnabled(pfad) {
                                        pfad=pfad.replace(".js","")   
                                        pfad=pfad.replace(/\//g,".")  
                                       // let scriptPfad=""
                                        //let myEnabled=false;
                                      
                                        
                                        let myselctor="javascript.*.scriptEnabled."+pfad
                                        for (const id of $(myselctor)) {
                                            log((await getStateAsync(id)).val+"  "+id)
                                          if (existsState(id) && (await getStateAsync(id)).val) {return true;}
                                        }
                                        return false;
                                      }
                                      

                                      das log in deiner function wird richtig angezeigt

                                      muss ich lookForEnabled anders aufrufen

                                      bei

                                        log(lookForEnabled(myGoal[b][1]).toString())
                                      

                                      kommt das:

                                      Image 6.png

                                      1 Reply Last reply Reply Quote 0
                                      • AlCalzone
                                        AlCalzone Developer @AlCalzone last edited by AlCalzone

                                        @liv-in-sky sagte in scriptedEnabled - Problem bei Abfrage:

                                        muss ich lookForEnabled anders aufrufen

                                        Ja, hab ich doch geschrieben:

                                        @AlCalzone sagte in scriptedEnabled - Problem bei Abfrage:

                                        Und du musst das aus der aufrufenden Funktion ebenfalls mit await aufrufen, oder das Ergebnis mit .then(...) verarbeiten.

                                        z.B.

                                        async function whatever() {
                                        const result = await lookForEnabled("meine-id");
                                        log(result);
                                        }
                                        

                                        Ggf. empfiehlt sich die Lektüre von https://gist.github.com/AlCalzone/d14b854b69ce5e8a03718336cc650a95#

                                        1 Reply Last reply Reply Quote 0
                                        • paul53
                                          paul53 @liv-in-sky last edited by paul53

                                          @liv-in-sky sagte:

                                          muss ich die abfrage irgendwie anders programmieren ?

                                          Weshalb verwendest Du nicht die synchrone Funktion isScriptActive(name) ?

                                          function lookForEnabled(pfad) {
                                            pfad=pfad.replace(".js","")   
                                            pfad=pfad.replace(/\//g,".")  
                                            return isScriptActive(pfad);
                                          }
                                          
                                          liv-in-sky 1 Reply Last reply Reply Quote 0
                                          • liv-in-sky
                                            liv-in-sky @paul53 last edited by

                                            @paul53

                                            bin vor lauter frust in den regen raus und habe die blätter vom garten entsorgt - dieses await ... bekomme ich einfach nicht hin

                                            habe den link von @AlCalzone 20mal gelesen und das ganze script mit funktionen gemacht und wollte am ende eine .then kette machen

                                            die function kannte ich nicht - werd die sofort mal testen

                                            paul53 AlCalzone 2 Replies Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            868
                                            Online

                                            31.8k
                                            Users

                                            80.0k
                                            Topics

                                            1.3m
                                            Posts

                                            javascript
                                            4
                                            51
                                            2444
                                            Loading More Posts
                                            • Oldest to Newest
                                            • Newest to Oldest
                                            • Most Votes
                                            Reply
                                            • Reply as topic
                                            Log in to reply
                                            Community
                                            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                            The ioBroker Community 2014-2023
                                            logo