TypeError: Can't instantiate abstract class

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
eMeS
User
Beiträge: 1
Registriert: Montag 25. Februar 2019, 13:09

Hallo Leute,
da dies hier mein erster Post in diesem Forum ist bitte ich um Nachsicht, falls ich mit allen Gepflogenheiten noch nicht gänzlich vertraut bin.
Zu meinem Problem habe ich diverse Suchanfragen sowohl im Netz, als auch in diesem Forum hier gestellt, bin jedoch nicht so recht fündig geworden. Deshalb nun hier eine konkrete Anfrage:
Ich versuche auf Grund dieser Anleitung https://itler.net/raspberry-pi-mit-alex ... cription-8 einen Raspberry Pi mit Alexa (Amazon Echo) zu steuern. Ich habe die Anleitung komplett abgearbeitet und einschließlich der Testkonfiguration ohne CommandLinePlugin hat auch alles wie erwartet funktioniert. Meine Versuche scheitern nun jedoch bei der Konfiguration des CommandLinePlugin, welches die festgelegten Befehle auf der Kommandozeile starten soll.
Hier zunächst die steuernde 'config.json':

Code: Alles auswählen

{
"FAUXMO": {
    "ip_address": "auto"
    },
	"PLUGINS": {
	    "CommandLinePlugin": {
	    "path": "/home/pi/commandlineplugin.py",
	    "DEVICES": [
		{"name"   : "SonOffEins",
		 "port"   : 49915,
		 "on_cmd" : "python /home/pi/tlk-an.py",
		 "off_cmd": "python /home/pi/tlk-aus.py"
		},
		{"name"   : "SonOffZwei",
		 "port"   : 49916,
		 "on_cmd" : "python /home/pi/sn2-an.py",
		 "off_cmd": "python /home/pi/sn2-aus.py"
		},
		{"name"   : "SonOffDrei",
		 "port"   : 49917,
		 "on_cmd" : "python /home/pi/sn3-an.py",
		 "off_cmd": "python /home/pi/sn3-aus.py"
		}
	    ]
	}
    }
}
Die angesprochenen Kommandodateien sind alle im angegebenen Pfad vorhanden.
Es folgt nun die 'CommandLinePlugin.py' selbst:

Code: Alles auswählen

from functools import partialmethod  # type: ignore
import shlex
import subprocess
from fauxmo.plugins import FauxmoPlugin
class CommandLinePlugin(FauxmoPlugin):
    """Fauxmo Plugin for running commands on the local machine."""
    def __init__(self, name: str, port: int, on_cmd: str, off_cmd: str) -> None:
        """Initialize a CommandLinePlugin instance.
        Args:
            name: Name for this Fauxmo device
            port: Port on which to run a specific CommandLinePlugin instance
            on_cmd: Command to be called when turning device on
            off_cmd: Command to be called when turning device off
       """
        self.on_cmd = on_cmd
        self.off_cmd = off_cmd
        super().__init__(name=name, port=port)
    def run_cmd(self, cmd: str) -> bool:
        """Partialmethod to run command.
        Args:
            cmd: Will be one of `"on_cmd"` or `"off_cmd"`, which `getattr` will
                 use to get the instance attribute.
        """
        command_str = getattr(self, cmd)
        shlexed_cmd = shlex.split(command_str)
        process = subprocess.run(shlexed_cmd)
        return process.returncode == 0
        
    on = partialmethod(run_cmd, "on_cmd")
    off = partialmethod(run_cmd, "off_cmd")
Im Prinzip verstehe ich sehr wohl, was hier passieren soll, aber anscheinend nicht in der notwendigen Tiefe! Denn die Fehlermeldung, die beim Start des Scriptes produziert wird kann ich nicht einmal annäherd interprtieren, geschweige denn Behandeln.
Hier der zugehörige Programmstart:

Code: Alles auswählen

pi@RaspiALX:~ $ "$(pyenv root)"/versions/3.6.1/bin/python3.6 -m fauxmo.cli -c /home/pi/config.json -vvv
Und nun die komplette Fehlermeldung:
2019-02-24 17:19:15 fauxmo:37 INFO Fauxmo v0.4.8
2019-02-24 17:19:15 fauxmo:38 DEBUG 3.6.1 (default, Feb 2 2019, 22:26:42)
[GCC 6.3.0 20170516]
2019-02-24 17:19:15 fauxmo:25 DEBUG Attempting to get IP address automatically
2019-02-24 17:19:15 fauxmo:41 DEBUG Using IP address: 192.168.100.137
2019-02-24 17:19:15 fauxmo:100 DEBUG plugin_vars: {}
2019-02-24 17:19:15 fauxmo:103 DEBUG device config: {'name': 'SonOffEins', 'port': 49915, 'on_cmd': 'python /home/pi/tlk-an.py', 'off_cmd': 'python /home/pi/tlk-aus.py'}
2019-02-24 17:19:15 fauxmo:111 ERROR Error in plugin <class 'fauxmo.plugins.commandlineplugin.CommandLinePlugin'>
Traceback (most recent call last):
File "/opt/pyenv/versions/3.6.1/lib/python3.6/runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None, "__main__", mod_spec)
File "/opt/pyenv/versions/3.6.1/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/fauxmo/cli.py", line 34, in <module>
cli()
File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/fauxmo/cli.py", line 30, in cli
main(config_path_str=args.config, verbosity=verbosity)
File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/fauxmo/fauxmo.py", line 109, in main
plugin = PluginClass(**plugin_vars, **device)
TypeError: Can't instantiate abstract class CommandLinePlugin with abstract methods get_state
Kann mir jemand helfen, das Problem zu lösen und sowohl den Fehler, als auch die Lösung zu verstehen?
Ich wäre Euch sehr verbunden.

Gruß eMeS
Wo ich bin ist nichts, aber überall kann ich nicht sein.
Antworten