Defined get_procedures() method on inspect plugin

This commit is contained in:
Fabio Manganiello 2020-06-17 22:31:04 +02:00
parent fb58c89911
commit a1c20a52da

View file

@ -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: