Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [Gelöst] TypeScript Kompilierfehler setObject

    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

    [Gelöst] TypeScript Kompilierfehler setObject

    This topic has been deleted. Only users with topic management privileges can see it.
    • U
      uwe72 @haus-automatisierung last edited by uwe72

      @haus-automatisierung

      Gebe ich dir recht, insbesondere bei read/write. Dies könnte ich noch analog den anderen Einstellungen ändern.

      Bei custom hatte ich auch die Sorge, dass wenn da schon andere Custom-Einstellungen existieren für andere Adapter, z.B. Telegram, dass dies dann überschrieben wird und somit entfernt wird. Der Test hatte aber funktioniert.

      So oder so, wäre es nur ein hässlicher Workarround, der ja, ggf. auch Schaden anrichtet.

      Hast Du mir ein Verbesserungsvorschlag für meinen initialen Versuch? Danke dir.

      Vermutlich aber gar nicht so einfach, siehe #5
      https://forum.iobroker.net/topic/57264/typescript-kompilierfehler-setobject/5
      Für mich sieht dies nach einem Bug im TypeScript "Adapter" aus.

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

        @uwe72 Rein beim Drüberschauen würde ich vermuten, dass anhand der Objekt-ID nicht 100% klar ist, was das genau für ein Objekt ist. Wenn du TS auf die Sprünge hilfst, z.B.(

        let obj: iobJS.StateObject = getObject(objId);
        

        für einen State, oder

        let obj: iobJS.ChannelObject = getObject(objId);
        

        für einen Channel, etc., dann sollte die Zuweisung auch klappen (hoffentlich). Sonst muss ich nochmal schauen, ob das etwas weniger "auf die Fresse" geht 😄

        U 2 Replies Last reply Reply Quote 1
        • U
          uwe72 @AlCalzone last edited by

          @alcalzone said in TypeScript Kompilierfehler setObject:

          let obj: iobJS.StateObject = getObject(objId);

          Ich habe es nun so:

          const originalDatenpunkt = 'shelly.0.SHPLG2-1#49FE33#1.online';
          let obj: iobJS.StateObject = getObject(originalDatenpunkt);
          

          Bekomme diesen Fehler:

          javascript.1 (486) script.js.common.Berechnungen.Test_Statistics: TypeScript compilation failed: let obj: iobJS.StateObject = getObject(originalDatenpunkt); ^ ERROR: Type '{ common: { [x: string]: any; [x: number]: any; }; type: "state" | "channel" | "folder" | "device"; acl: { object: number; state: number; owner: string; ownerGroup: string; }; _id: string; native: { [x: string]: any; }; enums: { ...; }; from: string; user: string; ts: number; }' is not assignable to type 'StateObject'. Types of property 'type' are incompatible. Type '"state" | "channel" | "folder" | "device"' is not assignable to type '"state"'. Type '"channel"' is not assignable to type '"state"'.
          

          D.h. "obj" wird schon im Editor angemeckert:
          89e5ddda-12cc-4378-abd6-74f2f91520dc-image.png

          OliverIO 1 Reply Last reply Reply Quote 0
          • OliverIO
            OliverIO @uwe72 last edited by

            @uwe72
            Und was steht im iobroker was für ein Typ das Objekt ist?

            U 1 Reply Last reply Reply Quote 0
            • U
              uwe72 @OliverIO last edited by uwe72

              @oliverio

              Da steht das gleiche wie oben als Text gepostet:
              95d7a7d4-8749-4b44-a5ec-1fadf9b163d9-image.png

              javascript.1 (486) script.js.common.Berechnungen.Test_Statistics: TypeScript compilation failed: let obj: iobJS.StateObject = getObject(originalDatenpunkt); ^ ERROR: Type '{ common: { [x: string]: any; [x: number]: any; }; type: "state" | "channel" | "folder" | "device"; acl: { object: number; state: number; owner: string; ownerGroup: string; }; _id: string; native: { [x: string]: any; }; enums: { ...; }; from: string; user: string; ts: number; }' is not assignable to type 'StateObject'. Types of property 'type' are incompatible. Type '"state" | "channel" | "folder" | "device"' is not assignable to type '"state"'. Type '"channel"' is not assignable to type '"state"'.
              
              1 Reply Last reply Reply Quote 0
              • OliverIO
                OliverIO last edited by OliverIO

                @uwe72
                ich denke das in der Ansicht des Objektbaums bei Typ
                channel dran steht.
                Auf Typ channel kannst du kein typ state setzen., da channel kein attribut common.custom besitzt
                oder es ist umgekehrt, das kann ich nicht so richtig rauslesen

                @uwe72 sagte in TypeScript Kompilierfehler setObject:

                Type '"channel"' is not assignable to type '"state"'.

                warum willst du unbedingt in custom was reinschreiben? ganz davon abgesehen, das es schon gehen muss, aber wenn du eine objektstruktur in einem datenpunkt ablegen willst, dann würde ich einfach mit
                getState und setState arbeiten und das Objekt dort einfach mit JSON.stringify und JSON.parse schreiben und lesen.

                und was mir noch aufgefallen ist:
                statistics.0 ist kein eigener datenpunkt
                das erste richtige objekt in der hierarchie ist
                statistics.0.save und
                statistics.0.temp

                statistics.0 sieht zwar so aus, existiert für sich aber nicht als eigenständiges objekt
                dies ist erkennbar, das im objektbaum bei typ nix dran steht.

                U haus-automatisierung 2 Replies Last reply Reply Quote 0
                • U
                  uwe72 @OliverIO last edited by

                  @oliverio Ich möchte ja programmatisch für einen Datenpunkt den Statistic-Adapter aktivieren.

                  Habe ein Array mit allen Devices (ca. 200-250). So kann ich generisch wie gesagt für alle Devices den StatisticAdapter aktivieren.

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

                    @alcalzone Siehe zuvor. Hättest Du mir noch einen Tipp? Grüße aus Brasilien. Uwe

                    AlCalzone 1 Reply Last reply Reply Quote 0
                    • haus-automatisierung
                      haus-automatisierung Developer Most Active @OliverIO last edited by haus-automatisierung

                      @oliverio sagte in TypeScript Kompilierfehler setObject:

                      statistics.0 sieht zwar so aus, existiert für sich aber nicht als eigenständiges objekt
                      dies ist erkennbar, das im objektbaum bei typ nix dran steht.

                      Das ist normal und auch richtig so. Bei einigen Adaptern wird das als Objekt für den File-Meta-Storage angelegt (z.B. vis). Aber das ist ganz selten und hat mit dem Problem nichts zu tun.

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

                        @uwe72 Ok dann anders:

                        const originalDatenpunkt = 'shelly.0.SHPLG2-1#49FE33#1.online';
                        let obj = getObject(originalDatenpunkt) as iobJS.StateObject;
                        

                        Der Unterschied zur vorherigen Variante ist dass du TS jetzt sagst: "Ich bin mir sicher, das ist ein StateObject". Das andere hat bedeutet: "obj ist ein State, lese mir da das Objekt xyz rein" (was nicht garantiert ein StateObject ist)

                        U 2 Replies Last reply Reply Quote 0
                        • U
                          uwe72 @AlCalzone last edited by uwe72

                          @alcalzone Perfekt, danke dir! Bin wirklich sehr dankbar nun eine funktionierende programmatische Lösung zu haben (für das "Aktivieren" vom Statistikadapter, o.ä.) Hat nun funktioniert:

                          const objId = 'shelly.0.SHPLG2-1#49FE33#1.online';
                          let obj = getObject(objId) as iobJS.StateObject;
                          
                          if (!obj.common.custom) {
                            obj.common.custom = {};
                          }
                           
                          obj.common.custom['statistics.0'] = {
                            "enabled": true,
                            "count": false,
                            "sumCount": false,
                            "timeCount": true,
                            "fiveMin": false,
                            "impUnitPerImpulse": 1,
                            "impUnit": "",
                            "avg": false,
                            "minmax": false,
                            "sumDelta": false,
                            "sumIgnoreMinus": false,
                            "groupFactor": 1,
                            "logName": "online_script_trockner"
                          };
                           
                          setObject(objId, obj);
                          
                          1 Reply Last reply Reply Quote 1
                          • U
                            uwe72 @AlCalzone last edited by uwe72

                            Bitte diesen Kommentar löschen, habe ein neues Ticket aufgemacht:
                            https://forum.iobroker.net/topic/57367/typescript-zugriff-iobjs-stateobject-innerhalb-foreach

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post

                            Support us

                            ioBroker
                            Community Adapters
                            Donate

                            812
                            Online

                            31.8k
                            Users

                            80.0k
                            Topics

                            1.3m
                            Posts

                            6
                            19
                            794
                            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