Ankündigung

Einklappen
Keine Ankündigung bisher.

Plugin-Entwicklung

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

    Plugin-Entwicklung

    Hallo,

    Ich hab jetzt schon einige Zeit damit zugebracht nach Informationen zu suchen wie sich für das smartHome.py ein eigenständiges plugin realisieren lässt. Leider konnte ich dazu nichts finden. Daher meine Frage gibt es eine Anleitung,Beschreibung wie plugins umzusätzen sind (welche programmiersprache, anbindung an das config-file usw.)

    Wäre dankbar für jede Antwort.

    Thanks in advance Gerri

    #2
    Es gibt unter plugins ein Ordner "skeleton" wo mal der grobe Aufbau skizziert ist... außerdem wurde die Frage bereits mehrfach hier gestellt --> goto SuFu
    Mit freundlichen Grüßen
    Niko Will

    Logiken und Schnittstelle zu anderen Systemen: smarthome.py - Visualisierung: smartVISU
    - Gira TS3 - iPhone & iPad - Mobotix T24 - ekey - Denon 2313 - Russound C5 (RIO over TCP Plugin) -

    Kommentar


      #3
      Danke für die schnelle Antwort. werde mir das zu gemüte führen

      Kommentar


        #4
        Zitat von 2ndsky Beitrag anzeigen
        Es gibt unter plugins ein Ordner "skeleton" wo mal der grobe Aufbau skizziert ist... außerdem wurde die Frage bereits mehrfach hier gestellt --> goto SuFu
        Ich hole den Thread mal hervor. Die SuFu hat mir nicht weitergeholfen, es gibt zwar um die 100 Threads mit "Plugin" im Titel, aber ich scheine den entscheidenden Thread nicht gefunden zu haben. Falls es ein magisches Stichwort gibt, bitte ich um Nachhilfe.

        Ich versuche, ein Plugin zur Beschattung zu schreiben. Das führt beim Starten zu folgender Fehlermeldung:
        Code:
        Init SmartHome.py 1.0
        2014-04-28 00:47:30 INFO     Main         Start SmartHome.py 1.0
        2014-04-28 00:47:30 INFO     Main         Init Scheduler
        2014-04-28 00:47:30 INFO     Main         Init Plugins
        2014-04-28 00:47:35 ERROR    Main         Plugin sunprotect exception: 'module'
        object has no attribute 'sunprotect'
        Traceback (most recent call last):
          File "/usr/local/smarthome/lib/plugin.py", line 53, in __init__
            plugin_thread = Plugin(smarthome, plugin, classname, classpath, args)
          File "/usr/local/smarthome/lib/plugin.py", line 80, in __init__
            exec("self.plugin = {0}.{1}(smarthome{2})".format(classpath, classname, args))
          File "<string>", line 1, in <module>
        AttributeError: 'module' object has no attribute 'sunprotect'
        2014-04-28 00:47:35 INFO     Main         Init Items
        2014-04-28 00:47:38 INFO     Main         Start Plugins
        2014-04-28 00:47:38 INFO     Main         Start Logics
        2014-04-28 00:47:38 INFO     Connections  1-Wire: connected to 127.0.0.1:4304
        In der plugin.conf steht:
        Code:
        [sunprotect]
            class_name = sunprotect
            class_path = plugins.sunprotect
            interval = 2
        In plugins/sunprotect gibt es eine __init.py__, die fast 1:1 auf dem skeleton beruht:
        Code:
        #!/usr/bin/env python3
        # vim: set encoding=utf-8 tabstop=4 softtabstop=4 shiftwidth=4 expandtab
        #########################################################################
        # Copyright 2013 KNX-User-Forum e.V.            https://knx-user-forum.de/
        #########################################################################
        #  This file is part of SmartHome.py.    http://mknx.github.io/smarthome/
        #
        #  SmartHome.py is free software: you can redistribute it and/or modify
        #  it under the terms of the GNU General Public License as published by
        #  the Free Software Foundation, either version 3 of the License, or
        #  (at your option) any later version.
        #
        #  SmartHome.py is distributed in the hope that it will be useful,
        #  but WITHOUT ANY WARRANTY; without even the implied warranty of
        #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        #  GNU General Public License for more details.
        #
        #  You should have received a copy of the GNU General Public License
        #  along with SmartHome.py. If not, see <http://www.gnu.org/licenses/>.
        #########################################################################
        
        import logging
        
        logger = logging.getLogger('sunprotect')
        
        
        class Plugin():
        
            def __init__(self, smarthome):
                self._sh = smarthome
                logger.info("Denon: connecting to {0}:{1}".format(host, port))
                self.terminator = b'\r'
                self._host = host
                self._sh = smarthome
                self._items = {}
                self._sources = {}
                self._cmd_lock = threading.Lock()
                self._status_objects = ['MV?', 'SI?', 'MU?', 'PSBAS ?', 'PSTRE ?', 'PSTONE CTRL ON']
                self._status_objects_count = len(self._status_objects)
                self._status_objects_pointer = 0
                self._status_cycle_counter = 0
        
            def run(self):
                self.alive = True
                # if you want to create child threads, do not make them daemon = True!
                # They will not shutdown properly. (It's a python bug)
        
            def stop(self):
                self.alive = False
        
            def parse_item(self, item):
                if 'sunprotect' in item.conf:
                    logger.debug("parse item: {0}".format(item))
                    return self.update_item
                else:
                    return None
        
            def parse_logic(self, logic):
                pass
        
            def update_item(self, item, caller=None, source=None, dest=None):
                if caller != 'plugin':
                    logger.info("update item: {0}".format(item.id()))
        
        if __name__ == '__main__':
            logging.basicConfig(level=logging.DEBUG)
            myplugin = Plugin('smarthome-dummy')
            myplugin.run()
        Der Code ist teilweise aus dem Denon-Plugin geklaut, das fliegt natürlich wieder raus, wenn das Plugin läuft.

        Kann mir jemand einen Tipp geben, an welcher Stellschraube ich drehen muss? strace zeigt mir, dass die Datei gefunden wird, daran liegt es also wohl nicht.

        Gruß,

        Max

        Kommentar


          #5
          Hi Max,

          Code:
          class_name = sunprotect
          Vs.

          Code:
          class Plugin():
          Mit
          Code:
          class_name = Plugin
          sollte es klappen.
          Besser noch
          Code:
          class_name = Sunprotect
          und
          Code:
          class Sunprotect
          Bis bald

          Marcus

          Kommentar


            #6
            Ah, danke. Wird heute abend ausprobiert.

            Wenn gewünscht, füge ich das im README.md entsprechend ein, dann kann das vielleicht im nächsten Release mit ins Skeleton. Ich habe schlicht die Doku nicht gefunden.

            Max

            Kommentar


              #7
              Hi Max,

              gerne.

              Danke und bis bald

              Marcus

              Kommentar

              Lädt...
              X