Verified Commit 5051a07e authored by Gigadoc 2's avatar Gigadoc 2

cmd name optional

parent fa4d769b
......@@ -77,19 +77,23 @@ class Eins:
"""
pass
def handle_cmd(self, cmd_name,
def handle_cmd(self, cmd_name=None,
args="none", descr=None, attribs={}):
"""Decorator to register an Eins command callback."""
def decorator(f):
self.register_command(f, cmd_name,
args="none", descr=None, attribs={})
self.register_command(f, cmd_name=cmd_name,
args=args, descr=descr, attribs=attribs)
return f
return decorator
def register_command(self, callback, cmd_name,
def register_command(self, callback, cmd_name=None,
args="none", descr=None, attribs={}):
command = Command(callback=callback, cmd_name=cmd_name,
args=args, descr=descr, attribs=attribs)
print("Registering command {}".format(callback.__name__))
command = Command(callback = callback,
cmd_name = cmd_name or callback.__name__,
args = args,
descr = descr,
attribs = attribs)
self._commands.append(command)
if self._connected:
self._online_register_command(command)
......
......@@ -4,16 +4,16 @@ from core import *
eins = Eins()
@eins.handle_cmd("test_sofort1")
@eins.handle_cmd()
def test_sofort1():
print("Test sofort1 called!")
@eins.handle_cmd("test_sofort2")
@eins.handle_cmd()
def test_sofort2():
print("Test sofort2 called!")
def on_connect():
@eins.handle_cmd("test_running")
@eins.handle_cmd
def test_running():
print("Test running called!")
......@@ -21,18 +21,26 @@ def on_connect():
def cmd_print(a):
print(a)
@eins.handle_cmd("multiarg")
@eins.handle_cmd()
def multiarg(a, b="asdf"):
print("Multiarg called!")
@eins.handle_cmd("topic_arg")
@eins.handle_cmd()
def topic_arg(mqtt_topic):
print(mqtt_topic)
@eins.handle_cmd("kwargs")
@eins.handle_cmd()
def kwargs(**kwargs):
print(kwargs)
@eins.handle_cmd()
def ètoile():
print("fancy")
@eins.handle_cmd()
def brøther():
print("LÂMP")
eins.on_connect = on_connect
eins.run()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment