dbus
Platypush documentation
dbus
- class platypush.plugins.dbus.DbusPlugin(signals: Optional[Iterable[dict]] = None, service_name: Optional[str] = 'org.platypush.Bus', service_path: Optional[str] = '/', **kwargs)[source]
Bases:
RunnablePlugin
Plugin to interact with DBus.
This plugin can be used for the following tasks:
It can expose a D-Bus interface that other applications can use to push messages to Platypush (either action requests or events) serialized in JSON format. You can disable this listener by setting
service_name
tonull
in your configuration. If the D-Bus Platypush interface is enabled then you can push Platypush events and requests in JSON format from another application or script by specifying:The D-Bus service (default:
org.platypush.Bus
)The D-Bus interface (default:
org.platypush.Bus
)The D-Bus path (default:
/
)The D-Bus method (
Post
)The Platypush JSON payload (first argument of the request). Format:
{"type": "request", "action": "module.action", "args": {...}}
It can subscribe to multiple D-Bus signals, and it triggers a
DbusSignalEvent
when an event is received (signal filters should be specified in thesignals
configuration).It can be used to query and inspect D-Bus objects through the
query()
method.It can be used to execute methods exponsed by D-Bus objects through the
execute()
method.
Requires:
pydbus (
pip install pydbus
)defusedxml (
pip install defusedxml
)
Triggers:
platypush.message.event.dbus.DbusSignalEvent
when a signal is received.
- __init__(signals: Optional[Iterable[dict]] = None, service_name: Optional[str] = 'org.platypush.Bus', service_path: Optional[str] = '/', **kwargs)[source]
- Parameters:
signals –
Specify this if you want to subscribe to specific DBus signals. Structure:
[ { "bus": "string", "interface": "The DBus interface that should be monitored (default: all)", "path": "Path of the resource to be monitored (default: all)", "sender": "Signal sender filter (default: all senders)", "signal": "Signal name filter (default: all signals)" } ]
For example, to subscribe to all the messages on the session bus:
dbus: signals: - bus: session
service_name – Name of the D-Bus service where Platypush will listen for new messages (requests and events). Set to null if you want to disable message execution over D-Bus for Platypush (default:
org.platypush.Bus
).service_path – The path of the D-Bus message listener. Set to null if you want to disable message execution over D-Bus for Platypush (default:
/
).
- execute(service: str, interface: str, method_name: str, bus: str = 'session', path: str = '/', args: Optional[list] = None)[source]
Execute a method exposed on DBus.
- Parameters:
service – D-Bus service name.
interface – D-Bus nterface name.
method_name – Method name.
bus – Bus type. Supported:
system
andsession
(default:session
).path – Object path.
args – Arguments to be passed to the method, depending on the method signature.
- Returns:
Return value of the executed method.
- query(service: Optional[str] = None, bus=('system', 'session')) Dict[str, dict] [source]
Query DBus for a specific service or for the full list of services.
- Parameters:
service – Service name (default: None, query all services).
bus – Which bus(ses) should be queried (default: both
system
andsession
).
- Returns:
A
{service_name -> {properties}}
mapping. Example:"session": { "org.platypush.Bus": { "/": { "org.freedesktop.DBus.Properties": { "method": [ { "name": "Get", "args": [ { "type": "s", "name": "interface_name", "direction": "in" }, { "type": "s", "name": "property_name", "direction": "in" }, { "type": "v", "name": "value", "direction": "out" } ] }, { "name": "GetAll", "args": [ { "type": "s", "name": "interface_name", "direction": "in" }, { "type": "a{sv}", "name": "properties", "direction": "out" } ] }, { "name": "Set", "args": [ { "type": "s", "name": "interface_name", "direction": "in" }, { "type": "s", "name": "property_name", "direction": "in" }, { "type": "v", "name": "value", "direction": "in" } ] } ], "signal": [ { "name": "PropertiesChanged", "args": [ { "type": "s", "name": "interface_name" }, { "type": "a{sv}", "name": "changed_properties" }, { "type": "as", "name": "invalidated_properties" } ] } ] }, "org.freedesktop.DBus.Introspectable": { "method": [ { "name": "Introspect", "args": [ { "type": "s", "name": "xml_data", "direction": "out" } ] } ] }, "org.freedesktop.DBus.Peer": { "method": [ { "name": "Ping" }, { "name": "GetMachineId", "args": [ { "type": "s", "name": "machine_uuid", "direction": "out" } ] } ] }, "org.platypush.Bus": { "method": [ { "name": "Post", "args": [ { "type": "s", "name": "msg", "direction": "in" }, { "type": "s", "name": "response", "direction": "out" } ] } ] } } } }