Skip to content

Commit

Permalink
Log invocation of functions
Browse files Browse the repository at this point in the history
  • Loading branch information
trickeydan committed Jul 11, 2021
1 parent b76e06b commit 15c5aee
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mqtt_automate/mqtt_automate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ def run(self) -> None:
def on_message(self, topic: str) -> Callable[[OnMessageHandler], OnMessageHandler]:
"""Register a topic to react to."""
def decorator(func: OnMessageHandler) -> OnMessageHandler:
# Register handler
self._handlers[Topic.parse(topic)] = func

async def wrapper(
engine: AutomationEngine,
match: Match[str],
payload: str,
) -> None:
LOGGER.info(f"INVOKE {topic} -> {func.__name__}")
await func(engine, match, payload)

# Register handler
self._handlers[Topic.parse(topic)] = wrapper
return wrapper
return decorator

0 comments on commit 15c5aee

Please sign in to comment.