Ankündigung

Einklappen
Keine Ankündigung bisher.

item.type() funktioniert nicht

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    item.type() funktioniert nicht

    Hallo,

    in der wunderground Logik (https://knx-user-forum.de/smarthome-...-new-post.html) muss ich prüfen, welchen typ das Item hat.

    Code:
    for item in sh.find_children(weatheritems, 'xmlstring'):
     try:
      s=item.conf['xmlstring']
      if len(s)>0:
    [...]
         if not item.type()=='str':
    Das funktioniert bei mir. Bei anderen Nutzern aber nicht. Woran kann das liegen?

    Gruß,
    Hendrik

    #2
    Moin Hendrik,

    schnelle Raterunde: evtl. Python-Version. Hast Du einen Raspi oder was selbst gebautes/VM?

    Schau mal diesen Post hier, vielleicht ist das mit isinstance portabler...

    Gruß,
    Bernd

    Kommentar


      #3
      Hallo,

      vllt. ist wirklich die Py-Version schuld.

      Welche kommt denn zum Einsatz (python3 -V)

      Bis bald

      Marcus

      Kommentar


        #4
        Also bei mir funzt es mit folgenden Versionen:
        SmartHome.py 1.1.904.dev
        Python 3.2.3

        Kommentar


          #5
          Hallo,

          ich nutze:
          Code:
          python3.4 -V
          Python 3.4.0
          ./bin/smarthome.py -V
          1.1.0.man
          Und da funktioniert es auch. Jetzt wäre es nützlich, wenn jemand, bei dem es nicht funktioniert mal seine Version postet.

          Gruß,
          Hendrik

          Kommentar


            #6
            funktioniert nicht

            Hallo Leute,

            bei mir funktioniert es nicht mit

            Raspberry Pi Modell B
            SmartHome.py v1.0 von https://github.com/mknx/smarthome/releases

            Python 3.2.3
            SmartHome.py 1.0

            smarthome.log:
            Code:
            2014-12-28 23:43:10,804 DEBUG    97_Wundergrd [Wunderground] Behandle jetzt Item wunderground.Windrichtung mit xmlstring wind_degrees -- 97_Wunderground.py:<module>:42
            2014-12-28 23:43:10,830 DEBUG    97_Wundergrd [Wunderground] Wert 45 in xml gefunden -- 97_Wunderground.py:<module>:48
            2014-12-28 23:43:10,874 ERROR    97_Wundergrd Logic: 97_Wundergrd, File: /usr/smarthome/logics/97_Wunderground.py, Line: 49, Method: <module>, Exception: 'Item' object has no attribute 'type' -- scheduler.py:_task:334
            Traceback (most recent call last):
              File "/usr/smarthome/lib/scheduler.py", line 327, in _task
                exec(obj.bytecode)
              File "/usr/smarthome/logics/97_Wunderground.py", line 49, in <module>
                if not item.type()=='str':
            AttributeError: 'Item' object has no attribute 'type'
            Das Item hat aber einen 'type':
            Code:
            [wunderground]
                [[Windrichtung]]
                    type = num
                    xmlstring = wind_degrees
                    nw_udp_send = 192.168.178.104:33333=wunderground.Windrichtung: itemvalue
            MfG
            Maik

            Kommentar


              #7
              Hi,

              komisch, macht es einen Unterschied wenn Du Leerzeichen rein machst?

              Also:
              Code:
              if not item.type() == 'str':
              Bis bald

              Marcus

              Kommentar


                #8
                &quot;isinstance(item(), str)&quot; statt &quot;item.type()=='str':&quot;

                Hallo Marcus,

                erst einmal noch alles Gute für 2015! - Euch allen natürlich!

                Zitat von mknx Beitrag anzeigen
                Hi,

                komisch, macht es einen Unterschied wenn Du Leerzeichen rein machst?

                Also:
                Code:
                if not item.type() == 'str':
                Ohne und mit Leerzeichen macht keinen Unterschied.

                Ich habe mich deshalb auf verschiedenen Seiten im Netz über type und isinstance belesen und die Logik daraufhin erfolgreich angepasst:

                Der Typ wird jetzt folgendermaßen geprüft:
                Code:
                     if not isinstance(item(), str):
                smarthome.log bringt keinen Fehler:
                Code:
                2015-01-01 21:19:53,939 DEBUG    Main         192.168.178.7:58801 sent '{"cmd":"logic","name":"97_Wundergrd","val":"1"}' -- __init__.py:json_parse:270
                2015-01-01 21:19:53,942 INFO     Main         Client 192.168.178.7:58801 triggerd logic 97_Wundergrd with '1' -- __init__.py:json_parse:302
                2015-01-01 21:19:53,945 DEBUG    Main         Triggering 97_Wundergrd - by: Visu source: 192.168.178.7:58801 dest: None value: 1 -- scheduler.py:trigger:162
                2015-01-01 21:19:54,576 DEBUG    97_Wundergrd [Wunderground] xml heruntergeladen b'<?xml version="1.0" encoding="utf-8" ?>\n\t<current_observation>\n\t\t<credit>Weather Underground Personal Weather Station</credit>\n\t\t<credit_URL>http://wunderground.com/weatherstation/</credit_URL>\n\t\t<image>\n\t\t<url>http://icons.wunderground.com/graphics/bh-wui_logo.gif</url>\n\t\t<title>Weather Underground</title>\n\t\t<link>http://wunderground.com/weatherstation/</link>\n\t\t</image>\n\t\t<location>\n\t\t<full>Hauptbahnhof, Leipzig, SACHSEN</full>\n\t\t<neighborhood>Hauptbahnhof</neighborhood>\n\t\t<city>Leipzig</city>\n\t\t<state>SACHSEN</state>\n\t\t<zip></zip>\n\t\t<latitude>51.342873</latitude>\n\t\t<longitude>12.383821</longitude>\n\t\t<elevation>650 ft</elevation>\n\t\t</location>\n\t\t<station_id>ISACHSEN106</station_id>\n\t\t<station_type>WH 2080</station_type>\n\t\t<observation_time>Last Updated on January 1, 9:19 PM CET</observation_time>\n\t\t<observation_time_rfc822>Thu, 01 Jan 2015 20:19:54 GMT</observation_time_rfc822>\n\t\t<weather></weather>\n\t\t<temperature_string>37.0 F (2.8 C)</temperature_string>\n\t\t<temp_f>37.0</temp_f>\n\t\t<temp_c>2.8</temp_c>\n\t\t<relative_humidity>86</relative_humidity>\n\t\t<wind_string>From the NW at 2.2 MPH Gusting to 4.5 MPH</wind_string>\n\t\t<wind_dir>NW</wind_dir>\n\t\t<wind_degrees>315</wind_degrees>\n\t\t<wind_mph>2.2</wind_mph>\n\t\t<wind_gust_mph>4.5</wind_gust_mph>\n\t\t<pressure_string>30.50" (1032.7 mb)</pressure_string>\n\t\t<pressure_mb>1032.7</pressure_mb>\n\t\t<pressure_in>30.50</pressure_in>\n\t\t<dewpoint_string>33.2 F (0.7 C)</dewpoint_string>\n\t\t<dewpoint_f>33.2</dewpoint_f>\n\t\t<dewpoint_c>0.7</dewpoint_c>\n\t\t\n\t\t<heat_index_string></heat_index_string>\n\t\t<heat_index_f></heat_index_f>\n\t\t<heat_index_c></heat_index_c>\n\t\t\n\t\t\n\t\t<windchill_string></windchill_string>\n\t\t<windchill_f></windchill_f>\n\t\t<windchill_c></windchill_c>\n\t\t\n\t\t<solar_radiation></solar_radiation>\n\t\t<UV></UV>\n\t\t<precip_1hr_string>0.00 in (0.0 mm)</precip_1hr_string>\n\t\t<precip_1hr_in>0.00</precip_1hr_in>\n\t\t<precip_1hr_metric>0.0</precip_1hr_metric>\n\t\t<precip_today_string>0.30 in (0.8 cm)</precip_today_string>\n\t\t<precip_today_in>0.30</precip_today_in>\n\t\t<precip_today_metric>0.8 cm</precip_today_metric>\n\t\t<history_url>http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=ISACHSEN106</history_url>\n\t\t<ob_url>http://www.wunderground.com/cgi-bin/findweather/getForecast?query=51.342873,12.383821</ob_url>\n\t</current_observation>\n\n' -- 97_Wunderground.py:<module>:36
                2015-01-01 21:19:54,590 DEBUG    97_Wundergrd [Wunderground] Behandle jetzt Item wunderground.Windrichtung mit xmlstring wind_degrees -- 97_Wunderground.py:<module>:42
                2015-01-01 21:19:54,595 DEBUG    97_Wundergrd [Wunderground] Wert 315 in xml gefunden -- 97_Wunderground.py:<module>:48
                2015-01-01 21:19:54,598 DEBUG    97_Wundergrd [Wunderground] wunderground.Windrichtung hat Typ str: True -- 97_Wunderground.py:<module>:49
                2015-01-01 21:19:54,613 INFO     97_Wundergrd Item wunderground.Windrichtung = 315 via Logic None None -- item.py:__update:363
                2015-01-01 21:19:54,633 DEBUG    97_Wundergrd UDP: Sending data to 192.168.178.104:33333:  -- __init__.py:udp:150
                2015-01-01 21:19:54,636 DEBUG    97_Wundergrd [Wunderground] Wert 315 ins item geschrieben -- 97_Wunderground.py:<module>:54
                2015-01-01 21:19:54,639 DEBUG    97_Wundergrd [Wunderground] Behandle jetzt Item wunderground.Luftdruck mit xmlstring pressure_mb -- 97_Wunderground.py:<module>:42
                2015-01-01 21:19:54,654 DEBUG    97_Wundergrd [Wunderground] Wert 1032.7 in xml gefunden -- 97_Wunderground.py:<module>:48
                2015-01-01 21:19:54,657 DEBUG    97_Wundergrd [Wunderground] wunderground.Luftdruck hat Typ str: False -- 97_Wunderground.py:<module>:49
                2015-01-01 21:19:54,671 DEBUG    97_Wundergrd [Wunderground] Wert 1032.7 ins item geschrieben -- 97_Wunderground.py:<module>:54
                2015-01-01 21:19:54,674 DEBUG    97_Wundergrd [Wunderground] Behandle jetzt Item wunderground.Taupunkt mit xmlstring dewpoint_c -- 97_Wunderground.py:<module>:42
                2015-01-01 21:19:54,689 DEBUG    97_Wundergrd [Wunderground] Wert 0.7 in xml gefunden -- 97_Wunderground.py:<module>:48
                2015-01-01 21:19:54,692 DEBUG    97_Wundergrd [Wunderground] wunderground.Taupunkt hat Typ str: False -- 97_Wunderground.py:<module>:49
                2015-01-01 21:19:54,696 DEBUG    97_Wundergrd [Wunderground] Wert 0.7 ins item geschrieben -- 97_Wunderground.py:<module>:54
                2015-01-01 21:19:54,709 DEBUG    97_Wundergrd [Wunderground] Behandle jetzt Item wunderground.Wind_mph mit xmlstring wind_mph -- 97_Wunderground.py:<module>:42
                2015-01-01 21:19:54,715 DEBUG    97_Wundergrd [Wunderground] Wert 2.2 in xml gefunden -- 97_Wunderground.py:<module>:48
                2015-01-01 21:19:54,718 DEBUG    97_Wundergrd [Wunderground] wunderground.Wind_mph hat Typ str: False -- 97_Wunderground.py:<module>:49
                2015-01-01 21:19:54,740 DEBUG    97_Wundergrd [Wunderground] Wert 2.2 ins item geschrieben -- 97_Wunderground.py:<module>:54
                2015-01-01 21:19:54,743 DEBUG    97_Wundergrd [Wunderground] Behandle jetzt Item wunderground.Windboen_mph mit xmlstring wind_gust_mph -- 97_Wunderground.py:<module>:42
                2015-01-01 21:19:54,748 DEBUG    97_Wundergrd [Wunderground] Wert 4.5 in xml gefunden -- 97_Wunderground.py:<module>:48
                2015-01-01 21:19:54,761 DEBUG    97_Wundergrd [Wunderground] wunderground.Windboen_mph hat Typ str: False -- 97_Wunderground.py:<module>:49
                2015-01-01 21:19:54,765 DEBUG    97_Wundergrd [Wunderground] Wert 4.5 ins item geschrieben -- 97_Wunderground.py:<module>:54
                2015-01-01 21:19:54,768 DEBUG    97_Wundergrd [Wunderground] Behandle jetzt Item wunderground.Temperatur mit xmlstring temp_c -- 97_Wunderground.py:<module>:42
                2015-01-01 21:19:54,783 DEBUG    97_Wundergrd [Wunderground] Wert 2.8 in xml gefunden -- 97_Wunderground.py:<module>:48
                2015-01-01 21:19:54,786 DEBUG    97_Wundergrd [Wunderground] wunderground.Temperatur hat Typ str: False -- 97_Wunderground.py:<module>:49
                2015-01-01 21:19:54,800 DEBUG    97_Wundergrd [Wunderground] Wert 2.8 ins item geschrieben -- 97_Wunderground.py:<module>:54
                2015-01-01 21:19:54,803 DEBUG    97_Wundergrd [Wunderground] Behandle jetzt Item wunderground.Niederschlag_Heute mit xmlstring precip_today_metric -- 97_Wunderground.py:<module>:42
                2015-01-01 21:19:54,808 DEBUG    97_Wundergrd [Wunderground] Wert 0.8 cm in xml gefunden -- 97_Wunderground.py:<module>:48
                2015-01-01 21:19:54,821 DEBUG    97_Wundergrd [Wunderground] wunderground.Niederschlag_Heute hat Typ str: False -- 97_Wunderground.py:<module>:49
                2015-01-01 21:19:54,825 DEBUG    97_Wundergrd [Wunderground] Wert 0.8 ins item geschrieben -- 97_Wunderground.py:<module>:54
                2015-01-01 21:19:54,828 DEBUG    97_Wundergrd [Wunderground] Behandle jetzt Item wunderground.Niederschlag_letzte_stunde mit xmlstring precip_1hr_metric -- 97_Wunderground.py:<module>:42
                2015-01-01 21:19:54,843 DEBUG    97_Wundergrd [Wunderground] Wert 0.0 in xml gefunden -- 97_Wunderground.py:<module>:48
                2015-01-01 21:19:54,846 DEBUG    97_Wundergrd [Wunderground] wunderground.Niederschlag_letzte_stunde hat Typ str: False -- 97_Wunderground.py:<module>:49
                2015-01-01 21:19:54,851 DEBUG    97_Wundergrd [Wunderground] Wert 0.0 ins item geschrieben -- 97_Wunderground.py:<module>:54
                2015-01-01 21:19:54,857 DEBUG    97_Wundergrd [Wunderground] Behandle jetzt Item wunderground.relative_luftfeuchte_perc mit xmlstring relative_humidity -- 97_Wunderground.py:<module>:42
                2015-01-01 21:19:54,868 DEBUG    97_Wundergrd [Wunderground] Wert 86 in xml gefunden -- 97_Wunderground.py:<module>:48
                2015-01-01 21:19:54,881 DEBUG    97_Wundergrd [Wunderground] wunderground.relative_luftfeuchte_perc hat Typ str: False -- 97_Wunderground.py:<module>:49
                2015-01-01 21:19:54,885 DEBUG    97_Wundergrd [Wunderground] Wert 86.0 ins item geschrieben -- 97_Wunderground.py:<module>:54
                Vielen Dank an Bernd für den Hinweis!

                Im Anhang die angepasste Logik. Ich denke, damit können wir das Thema als erledigt markieren.

                Grüße aus Leipzig
                Maik
                Angehängte Dateien

                Kommentar


                  #9
                  Danke!

                  Warum funktioniert item.type() denn 'manchmal' nicht?

                  Gruß,
                  Hendrik

                  Kommentar


                    #10


                    Weil es nur in develop ist!

                    Bis bald

                    Marcu

                    Kommentar


                      #11
                      Arrgh

                      Kommentar

                      Lädt...
                      X