From a1c20a52da8c01a630b96858bbaf6c18ecac29ac Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 17 Jun 2020 22:31:04 +0200 Subject: [PATCH] Defined get_procedures() method on inspect plugin --- platypush/plugins/inspect.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/platypush/plugins/inspect.py b/platypush/plugins/inspect.py index 2805feb9..d41d622e 100644 --- a/platypush/plugins/inspect.py +++ b/platypush/plugins/inspect.py @@ -11,6 +11,7 @@ import platypush.message.event import platypush.message.response from platypush.backend import Backend +from platypush.config import Config from platypush.plugins import Plugin, action from platypush.message.event import Event from platypush.message.response import Response @@ -36,6 +37,16 @@ class Model: return docutils.core.publish_parts(doc, writer_name='html')['html_body'] +class ProcedureEncoder(json.JSONEncoder): + def default(self, o): + if callable(o): + return { + 'type': 'native_function', + } + + return super().default(o) + + class BackendModel(Model): def __init__(self, backend, prefix='', html_doc: bool = False): self.name = backend.__module__[len(prefix):] @@ -321,5 +332,12 @@ class InspectPlugin(Plugin): for package, events in self._responses.items() }) + @action + def get_procedures(self) -> dict: + """ + Get the list of procedures installed on the device. + """ + return json.loads(json.dumps(Config.get_procedures(), cls=ProcedureEncoder)) + # vim:sw=4:ts=4:et: