dbus2mqtt 0.4.0__tar.gz → 0.4.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dbus2mqtt might be problematic. Click here for more details.
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.github/release-drafter.yml +6 -7
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.pre-commit-config.yaml +3 -3
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/PKG-INFO +19 -7
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/README.md +18 -6
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/docker/Dockerfile.dev +1 -1
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/docker/Dockerfile.pypi +1 -1
- dbus2mqtt-0.4.2/docs/examples/bluez.md +37 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/docs/examples/bluez.yaml +25 -5
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/docs/examples/dbus2mqtt_internal_state.yaml +7 -1
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/docs/examples/home_assistant_media_player.md +1 -1
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/docs/examples/home_assistant_media_player.yaml +4 -5
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/docs/examples/linux_desktop.yaml +0 -4
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/docs/examples.md +1 -1
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/docs/flows.md +37 -11
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/pyproject.toml +4 -2
- dbus2mqtt-0.4.2/renovate.json +36 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/config/__init__.py +8 -1
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/dbus/dbus_client.py +44 -43
- dbus2mqtt-0.4.2/src/dbus2mqtt/flow/actions/log_action.py +36 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/flow/flow_processor.py +5 -1
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/mqtt/mqtt_client.py +30 -9
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/template/templating.py +11 -0
- dbus2mqtt-0.4.2/tests/conftest.py +16 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/tests/dbus/test_dbus_client.py +1 -1
- dbus2mqtt-0.4.2/tests/dbus/test_dbus_client_mqtt_command.py +206 -0
- dbus2mqtt-0.4.2/tests/flow/actions/test_log.py +28 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/uv.lock +4 -4
- dbus2mqtt-0.4.0/docs/examples/bluez.md +0 -19
- dbus2mqtt-0.4.0/renovate.json +0 -22
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.dockerignore +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.env.example +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.github/scripts/release-versions.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.github/workflows/ci.yml +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.github/workflows/docker-dev.yml +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.github/workflows/docker-stable.yml +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.github/workflows/pre-commit.yml +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.github/workflows/publish.yml +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.github/workflows/release-drafter.yml +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.gitignore +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.python-version +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.vscode/launch.json +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.vscode/settings.json +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/.yamllint.yml +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/LICENSE +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/docs/debugging.md +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/docs/examples/dbus2mqtt_internal_state.md +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/docs/examples/linux_desktop.md +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/__init__.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/__main__.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/config/jsonarparse.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/dbus/dbus_types.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/dbus/dbus_util.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/dbus/introspection_patches/mpris_playerctl.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/dbus/introspection_patches/mpris_vlc.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/event_broker.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/flow/__init__.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/flow/actions/context_set.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/flow/actions/mqtt_publish.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/main.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/src/dbus2mqtt/template/dbus_template_functions.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/tests/__init__.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/tests/config/fixtures/payload_template_jinja_expressions.yaml +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/tests/config/fixtures/payload_template_off.yaml +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/tests/config/fixtures/schedule_cron_trigger.yaml +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/tests/config/test_config.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/tests/config/test_examples.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/tests/flow/actions/test_context_set.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/tests/flow/actions/test_mqtt_publish.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/tests/flow/test_flow_processor.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/tests/flow/triggers/test_dbus_client_triggers.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/tests/template/test_templating.py +0 -0
- {dbus2mqtt-0.4.0 → dbus2mqtt-0.4.2}/tests/template/test_templating_config.py +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
name-template: 'v$RESOLVED_VERSION
|
|
1
|
+
name-template: 'v$RESOLVED_VERSION'
|
|
2
2
|
tag-template: 'v$RESOLVED_VERSION'
|
|
3
3
|
exclude-labels:
|
|
4
4
|
- dependencies
|
|
5
|
+
- skip-changelog
|
|
5
6
|
categories:
|
|
6
7
|
- title: 🚨 Breaking changes
|
|
7
8
|
labels:
|
|
@@ -13,13 +14,13 @@ categories:
|
|
|
13
14
|
- title: 🐛 Bug Fixes
|
|
14
15
|
labels:
|
|
15
16
|
- bugfix
|
|
16
|
-
- title: 🧰
|
|
17
|
+
- title: 🧰 Misc
|
|
17
18
|
labels:
|
|
18
19
|
- chore
|
|
19
20
|
- documentation
|
|
20
21
|
- title: ⬆️ Dependency updates
|
|
21
22
|
labels:
|
|
22
|
-
-
|
|
23
|
+
- dependencies
|
|
23
24
|
exclude-contributors:
|
|
24
25
|
- jwnmulder
|
|
25
26
|
autolabeler:
|
|
@@ -38,15 +39,13 @@ version-resolver:
|
|
|
38
39
|
minor:
|
|
39
40
|
labels:
|
|
40
41
|
- minor
|
|
41
|
-
- feature
|
|
42
|
-
- enhancement
|
|
43
42
|
- breaking-change # minor until we are on 1.x
|
|
44
43
|
patch:
|
|
45
44
|
labels:
|
|
46
45
|
- patch
|
|
46
|
+
- feature # patch until we are on 1.x
|
|
47
|
+
- enhancement # patch until we are on 1.x
|
|
47
48
|
default: patch
|
|
48
49
|
change-template: '* $TITLE (#$NUMBER)'
|
|
49
50
|
template: |
|
|
50
|
-
## Changes
|
|
51
|
-
|
|
52
51
|
$CHANGES
|
|
@@ -33,7 +33,7 @@ repos:
|
|
|
33
33
|
- --strict
|
|
34
34
|
|
|
35
35
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
36
|
-
rev: v0.
|
|
36
|
+
rev: v0.12.2
|
|
37
37
|
hooks:
|
|
38
38
|
- id: ruff
|
|
39
39
|
args:
|
|
@@ -42,11 +42,11 @@ repos:
|
|
|
42
42
|
- I
|
|
43
43
|
|
|
44
44
|
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
45
|
-
rev: 0.7.
|
|
45
|
+
rev: 0.7.19
|
|
46
46
|
hooks:
|
|
47
47
|
- id: uv-lock
|
|
48
48
|
|
|
49
49
|
- repo: https://github.com/RobertCraigie/pyright-python
|
|
50
|
-
rev: v1.1.
|
|
50
|
+
rev: v1.1.403
|
|
51
51
|
hooks:
|
|
52
52
|
- id: pyright
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dbus2mqtt
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
4
4
|
Summary: A Python tool to expose Linux D-Bus signals, methods and properties over MQTT - featuring templating, payload enrichment and Home Assistant-ready examples
|
|
5
5
|
Project-URL: Repository, https://github.com/jwnmulder/dbus2mqtt.git
|
|
6
6
|
Project-URL: Issues, https://github.com/jwnmulder/dbus2mqtt/issues
|
|
@@ -32,8 +32,8 @@ Description-Content-Type: text/markdown
|
|
|
32
32
|
|
|
33
33
|
# dbus2mqtt
|
|
34
34
|
|
|
35
|
-
**dbus2mqtt** is a Python application that bridges **
|
|
36
|
-
It lets you forward D-Bus signals and properties to MQTT topics, call D-Bus methods via MQTT messages, and shape payloads using flexible **Jinja2 templating**.
|
|
35
|
+
**dbus2mqtt** is a Python application that bridges **DBus** with **MQTT**.
|
|
36
|
+
It lets you forward Linux D-Bus signals and properties to MQTT topics, call D-Bus methods via MQTT messages, and shape payloads using flexible **Jinja2 templating**.
|
|
37
37
|
|
|
38
38
|
This makes it easy to integrate Linux desktop services or system signals into MQTT-based workflows - including **Home Assistant**.
|
|
39
39
|
|
|
@@ -154,6 +154,8 @@ or
|
|
|
154
154
|
mqtt:
|
|
155
155
|
host: localhost
|
|
156
156
|
port: 1883
|
|
157
|
+
subscription_topics:
|
|
158
|
+
- dbus2mqtt/#
|
|
157
159
|
```
|
|
158
160
|
|
|
159
161
|
### Exposing dbus methods
|
|
@@ -173,21 +175,31 @@ dbus:
|
|
|
173
175
|
|
|
174
176
|
This configuration will expose 2 methods. Triggering methods can be done by publishing json messages to the `dbus2mqtt/org.mpris.MediaPlayer2/command` MQTT topic. Arguments can be passed along in `args`.
|
|
175
177
|
|
|
176
|
-
|
|
178
|
+
Some examples that call methods on **all** bus_names matching the configured pattern
|
|
177
179
|
|
|
178
180
|
```json
|
|
179
181
|
{
|
|
180
|
-
"method"
|
|
182
|
+
"method": "Play",
|
|
181
183
|
}
|
|
182
184
|
```
|
|
183
185
|
|
|
184
186
|
```json
|
|
185
187
|
{
|
|
186
|
-
"method"
|
|
188
|
+
"method": "OpenUri",
|
|
187
189
|
"args": []
|
|
188
190
|
}
|
|
189
191
|
```
|
|
190
192
|
|
|
193
|
+
To specifically target objects the properties `bus_name` and/or `path` can be used. Both properties support wildcards
|
|
194
|
+
|
|
195
|
+
```json
|
|
196
|
+
{
|
|
197
|
+
"method": "Play",
|
|
198
|
+
"bus_name": "*.firefox",
|
|
199
|
+
"path": "/org/mpris/MediaPlayer2"
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
191
203
|
### Exposing dbus signals
|
|
192
204
|
|
|
193
205
|
Publishing signals to MQTT topics works by subscribing to the relevant signal and using flows for publishing
|
|
@@ -214,7 +226,7 @@ dbus:
|
|
|
214
226
|
|
|
215
227
|
## Flows
|
|
216
228
|
|
|
217
|
-
|
|
229
|
+
A reference of all supported flow triggers and actions can be found on [Flows](https://github.com/jwnmulder/dbus2mqtt/blob/main/docs/flows.md)
|
|
218
230
|
|
|
219
231
|
## Jinja templating
|
|
220
232
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# dbus2mqtt
|
|
2
2
|
|
|
3
|
-
**dbus2mqtt** is a Python application that bridges **
|
|
4
|
-
It lets you forward D-Bus signals and properties to MQTT topics, call D-Bus methods via MQTT messages, and shape payloads using flexible **Jinja2 templating**.
|
|
3
|
+
**dbus2mqtt** is a Python application that bridges **DBus** with **MQTT**.
|
|
4
|
+
It lets you forward Linux D-Bus signals and properties to MQTT topics, call D-Bus methods via MQTT messages, and shape payloads using flexible **Jinja2 templating**.
|
|
5
5
|
|
|
6
6
|
This makes it easy to integrate Linux desktop services or system signals into MQTT-based workflows - including **Home Assistant**.
|
|
7
7
|
|
|
@@ -122,6 +122,8 @@ or
|
|
|
122
122
|
mqtt:
|
|
123
123
|
host: localhost
|
|
124
124
|
port: 1883
|
|
125
|
+
subscription_topics:
|
|
126
|
+
- dbus2mqtt/#
|
|
125
127
|
```
|
|
126
128
|
|
|
127
129
|
### Exposing dbus methods
|
|
@@ -141,21 +143,31 @@ dbus:
|
|
|
141
143
|
|
|
142
144
|
This configuration will expose 2 methods. Triggering methods can be done by publishing json messages to the `dbus2mqtt/org.mpris.MediaPlayer2/command` MQTT topic. Arguments can be passed along in `args`.
|
|
143
145
|
|
|
144
|
-
|
|
146
|
+
Some examples that call methods on **all** bus_names matching the configured pattern
|
|
145
147
|
|
|
146
148
|
```json
|
|
147
149
|
{
|
|
148
|
-
"method"
|
|
150
|
+
"method": "Play",
|
|
149
151
|
}
|
|
150
152
|
```
|
|
151
153
|
|
|
152
154
|
```json
|
|
153
155
|
{
|
|
154
|
-
"method"
|
|
156
|
+
"method": "OpenUri",
|
|
155
157
|
"args": []
|
|
156
158
|
}
|
|
157
159
|
```
|
|
158
160
|
|
|
161
|
+
To specifically target objects the properties `bus_name` and/or `path` can be used. Both properties support wildcards
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{
|
|
165
|
+
"method": "Play",
|
|
166
|
+
"bus_name": "*.firefox",
|
|
167
|
+
"path": "/org/mpris/MediaPlayer2"
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
159
171
|
### Exposing dbus signals
|
|
160
172
|
|
|
161
173
|
Publishing signals to MQTT topics works by subscribing to the relevant signal and using flows for publishing
|
|
@@ -182,7 +194,7 @@ dbus:
|
|
|
182
194
|
|
|
183
195
|
## Flows
|
|
184
196
|
|
|
185
|
-
|
|
197
|
+
A reference of all supported flow triggers and actions can be found on [Flows](https://github.com/jwnmulder/dbus2mqtt/blob/main/docs/flows.md)
|
|
186
198
|
|
|
187
199
|
## Jinja templating
|
|
188
200
|
|
|
@@ -25,7 +25,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \
|
|
|
25
25
|
uv sync --frozen --no-dev
|
|
26
26
|
|
|
27
27
|
# Then, use a final image without uv
|
|
28
|
-
FROM python:3.13-slim-bookworm
|
|
28
|
+
FROM python:3.13-slim-bookworm@sha256:6544e0e002b40ae0f59bc3618b07c1e48064c4faed3a15ae2fbd2e8f663e8283
|
|
29
29
|
# It is important to use the image that matches the builder, as the path to the
|
|
30
30
|
# Python executable must be the same, e.g., using `python:3.12-slim-bookworm`
|
|
31
31
|
# will fail.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Bluez
|
|
2
|
+
|
|
3
|
+
This configuration file demonstrates how to use dbus2mqtt to bridge D-Bus events from BlueZ (the official Linux Bluetooth protocol stack) to MQTT topics. It subscribes to relevant D-Bus signals and properties for both the Bluetooth adapter (`hci0`) and all Bluetooth devices managed by BlueZ. The configuration defines flows that:
|
|
4
|
+
|
|
5
|
+
* Monitor property changes and object lifecycle events (added/removed) for the Bluetooth adapter and devices.
|
|
6
|
+
* Retrieve the current state of the adapter or device using the `GetAll` method from the `org.freedesktop.DBus.Properties` interface.
|
|
7
|
+
* Publish the retrieved state as JSON payloads to structured MQTT topics, enabling real-time monitoring and integration with home automation or IoT systems.
|
|
8
|
+
|
|
9
|
+
This setup allows MQTT clients to receive updates about Bluetooth adapter and device states, as well as notifications when devices are removed, making it easier to integrate Bluetooth events into broader automation workflows.
|
|
10
|
+
|
|
11
|
+
Configuration activities
|
|
12
|
+
|
|
13
|
+
* dbus2mqtt setup using the supplied [bluez.yaml](https://github.com/jwnmulder/dbus2mqtt/blob/main/docs/examples/bluez.yaml)
|
|
14
|
+
|
|
15
|
+
Execute the following command to run dbus2mqtt with the example configuration in this repository.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
uv run dbus2mqtt --config docs/examples/bluez.yaml
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Commands
|
|
22
|
+
|
|
23
|
+
The following table lists commands, their descriptions, and an example JSON payload for invoking them via MQTT.
|
|
24
|
+
|
|
25
|
+
Dbus methods can be invoked by sendig the JSON payload to MQTT topic `dbus2mqtt/bluez/hci0/command`. Method calls will be done for all matching dbus objects.
|
|
26
|
+
|
|
27
|
+
| Interface | Method<br />Property | Description | Example MQTT JSON Payload |
|
|
28
|
+
|----------------------|-----------------------|--------------------------------------|-------------------------------------------------|
|
|
29
|
+
| `org.bluez.Adapter1` | `StartDiscovery` | Starts bluetooth discovery | `{ "method": "StartDiscovery" }` |
|
|
30
|
+
| `org.bluez.Adapter1` | `StopDiscovery` | Stops bluetooth discovery | `{ "method": "StopDiscovery" }` |
|
|
31
|
+
| `org.bluez.Device1` | `Connect` | | `{ "method": "Connect", "path": "/org/bluez/hci0/dev_A1_A2_A3_A4_A5_A6" }` |
|
|
32
|
+
| `org.bluez.Device1` | `Disconnect` | | `{ "method": "Disconnect", "path": "/org/bluez/hci0/dev_A1_A2_A3_A4_A5_A6" }` |
|
|
33
|
+
| `org.bluez.Device1` | `Pair` | | `{ "method": "Pair", "path": "/org/bluez/hci0/dev_A1_A2_A3_A4_A5_A6" }` |
|
|
34
|
+
| `org.bluez.Device1` | `CancelPairing` | | `{ "method": "CancelPairing", "path": "/org/bluez/hci0/dev_A1_A2_A3_A4_A5_A6" }` |
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
https://manpages.ubuntu.com/manpages/noble/man5/org.bluez.
|
|
@@ -5,12 +5,18 @@ dbus:
|
|
|
5
5
|
- bus_name: org.bluez
|
|
6
6
|
path: /org/bluez/hci0
|
|
7
7
|
|
|
8
|
+
# https://manpages.ubuntu.com/manpages/oracular/man5/org.bluez.Adapter.5.html
|
|
9
|
+
|
|
8
10
|
interfaces:
|
|
9
11
|
- interface: org.freedesktop.DBus.Properties
|
|
10
12
|
signals:
|
|
11
13
|
- signal: PropertiesChanged
|
|
14
|
+
|
|
15
|
+
- interface: org.bluez.Adapter1
|
|
16
|
+
mqtt_command_topic: dbus2mqtt/bluez/hci0/command
|
|
12
17
|
methods:
|
|
13
|
-
- method:
|
|
18
|
+
- method: StartDiscovery
|
|
19
|
+
- method: StopDiscovery
|
|
14
20
|
|
|
15
21
|
flows:
|
|
16
22
|
- name: "publish adapter state"
|
|
@@ -27,18 +33,28 @@ dbus:
|
|
|
27
33
|
- type: mqtt_publish
|
|
28
34
|
topic: dbus2mqtt/bluez/hci0
|
|
29
35
|
payload_type: json
|
|
30
|
-
payload_template:
|
|
31
|
-
|
|
36
|
+
payload_template: |
|
|
37
|
+
{{
|
|
38
|
+
{ 'dbus_object_path': path }
|
|
39
|
+
| combine(adapter_properties)
|
|
40
|
+
}}
|
|
32
41
|
|
|
33
42
|
- bus_name: org.bluez
|
|
34
43
|
path: /org/bluez/hci0/dev_*
|
|
35
44
|
|
|
45
|
+
# https://manpages.ubuntu.com/manpages/noble/man5/org.bluez.Device.5.html
|
|
36
46
|
interfaces:
|
|
37
47
|
- interface: org.freedesktop.DBus.Properties
|
|
38
48
|
signals:
|
|
39
49
|
- signal: PropertiesChanged
|
|
50
|
+
|
|
51
|
+
- interface: org.bluez.Device1
|
|
52
|
+
mqtt_command_topic: dbus2mqtt/bluez/hci0/command
|
|
40
53
|
methods:
|
|
41
|
-
- method:
|
|
54
|
+
- method: Connect
|
|
55
|
+
- method: Disconnect
|
|
56
|
+
- method: Pair
|
|
57
|
+
- method: CancelPairing
|
|
42
58
|
|
|
43
59
|
flows:
|
|
44
60
|
- name: "publish device state"
|
|
@@ -55,7 +71,11 @@ dbus:
|
|
|
55
71
|
- type: mqtt_publish
|
|
56
72
|
topic: dbus2mqtt/bluez/{{ path | replace('/org/bluez/', '') }}
|
|
57
73
|
payload_type: json
|
|
58
|
-
payload_template:
|
|
74
|
+
payload_template: |
|
|
75
|
+
{{
|
|
76
|
+
{ 'dbus_object_path': path }
|
|
77
|
+
| combine(device_properties)
|
|
78
|
+
}}
|
|
59
79
|
- name: "device removed"
|
|
60
80
|
triggers:
|
|
61
81
|
- type: object_removed
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# mqtt:
|
|
2
2
|
# host:
|
|
3
3
|
# port:
|
|
4
|
+
# subscription_topics:
|
|
5
|
+
# - dbus2mqtt/#
|
|
4
6
|
|
|
5
7
|
dbus:
|
|
6
8
|
subscriptions:
|
|
@@ -37,4 +39,8 @@ flows:
|
|
|
37
39
|
payload_type: json
|
|
38
40
|
payload_template:
|
|
39
41
|
now: "{{ now().isoformat() }}"
|
|
40
|
-
|
|
42
|
+
dbus_list_res: "{{ dbus_list('*') }}"
|
|
43
|
+
- type: log
|
|
44
|
+
level: INFO
|
|
45
|
+
msg: >
|
|
46
|
+
Just published: dbus_list={{ dbus_list('*') }} to topic 'dbus2mqtt/state'
|
|
@@ -12,7 +12,7 @@ Pre-requisites:
|
|
|
12
12
|
Features:
|
|
13
13
|
|
|
14
14
|
* dbus subscription using `org.mpris.MediaPlayer2.*` wildcard to support multiple concurrent MRPIS players
|
|
15
|
-
* Every 5 seconds, the state
|
|
15
|
+
* Every 5 seconds, the state of the `first` known MPRIS player is published to MQTT topic `dbus2mqtt/org.mpris.MediaPlayer2/state`
|
|
16
16
|
* Every MPRIS property update immediately publishes the state to MQTT topic `dbus2mqtt/org.mpris.MediaPlayer2/state`
|
|
17
17
|
* Support for player commands (see below)
|
|
18
18
|
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
# mqtt:
|
|
2
|
-
# host:
|
|
3
|
-
# port:
|
|
4
|
-
|
|
5
1
|
dbus:
|
|
6
2
|
subscriptions:
|
|
7
3
|
|
|
@@ -68,10 +64,13 @@ dbus:
|
|
|
68
64
|
topic: dbus2mqtt/org.mpris.MediaPlayer2/state
|
|
69
65
|
payload_type: json
|
|
70
66
|
payload_template: |
|
|
67
|
+
{% set metadata = player_properties.get('Metadata') or {} %}
|
|
68
|
+
{% set metadata_xesam_url = metadata.get('xesam:url', '') | urldecode %}
|
|
71
69
|
{{
|
|
72
70
|
{ 'bus_name': mpris_bus_name }
|
|
73
71
|
| combine(player_properties)
|
|
74
|
-
| combine
|
|
72
|
+
| combine({ 'Position': seeked_position } if seeked_position else {})
|
|
73
|
+
| combine({ 'Metadata': { 'xesam:url': metadata_xesam_url } }, recursive=True)
|
|
75
74
|
}}
|
|
76
75
|
|
|
77
76
|
- name: "publish local art image"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Flows
|
|
2
2
|
|
|
3
|
-
**dbus2mqtt** allows you to add additional processing logic (flows) for when events occur. Configuration is
|
|
3
|
+
**dbus2mqtt** allows you to add additional processing logic (flows) for when events occur. Configuration is done in yaml and a complete example can be found in [home_assistant_media_player.yaml](https://github.com/jwnmulder/dbus2mqtt/blob/main/docs/examples/home_assistant_media_player.yaml) which is part of the [MPRIS to Home Assistant Media Player integration](https://github.com/jwnmulder/dbus2mqtt/blob/main/docs/examples/home_assistant_media_player.md) example
|
|
4
4
|
|
|
5
5
|
Flows can be defined on a global or dbus subscription level and can be triggered by any of the following events:
|
|
6
6
|
|
|
@@ -9,12 +9,26 @@ Flows can be defined on a global or dbus subscription level and can be triggered
|
|
|
9
9
|
* `object_added` when a new bus_name is registered on dbus
|
|
10
10
|
* `object_removed` when a bus_name is removed from dbus
|
|
11
11
|
|
|
12
|
-
Within each flow a set of actions can be configured. These are executed in order
|
|
12
|
+
Within each flow a set of actions can be configured. These are executed in the order as defined in yaml
|
|
13
13
|
|
|
14
|
+
* `log` for logging message
|
|
14
15
|
* `context_set` to set variables
|
|
15
16
|
* `mqtt_publish` to publish a mqtt message
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
An example
|
|
19
|
+
|
|
20
|
+
```yaml
|
|
21
|
+
flows:
|
|
22
|
+
- name: "Example flow"
|
|
23
|
+
triggers:
|
|
24
|
+
- type: schedule
|
|
25
|
+
interval: {seconds: 5}
|
|
26
|
+
actions:
|
|
27
|
+
- type: log
|
|
28
|
+
msg: hello from example flow
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Some action parameters allow the use of jinja2 templating. dbus2mqtt supports both builtin jinja2 filters and comes with additional filters from [jinja2-ansible-filters](https://pypi.org/project/jinja2-ansible-filters/). When supported, it is documented below.
|
|
18
32
|
|
|
19
33
|
## Flow triggers
|
|
20
34
|
|
|
@@ -22,7 +36,6 @@ Actions support string templating which is based on jinja2
|
|
|
22
36
|
|
|
23
37
|
```yaml
|
|
24
38
|
type: schedule
|
|
25
|
-
cron: {second: 5}
|
|
26
39
|
interval: {seconds: 5}
|
|
27
40
|
```
|
|
28
41
|
|
|
@@ -41,6 +54,12 @@ When triggered, the following context parameters are available
|
|
|
41
54
|
|
|
42
55
|
### dbus_signal
|
|
43
56
|
|
|
57
|
+
```yaml
|
|
58
|
+
type: dbus_signal
|
|
59
|
+
interface: org.freedesktop.DBus.Properties
|
|
60
|
+
signal: PropertiesChanged
|
|
61
|
+
```
|
|
62
|
+
|
|
44
63
|
DBus signals triggers must be configured with an anterface and path. Note that only subscribed signals can be configured as a trigger.
|
|
45
64
|
|
|
46
65
|
| key | description |
|
|
@@ -86,6 +105,19 @@ When triggered, the following context parameters are available
|
|
|
86
105
|
|
|
87
106
|
## Flow actions
|
|
88
107
|
|
|
108
|
+
### log
|
|
109
|
+
|
|
110
|
+
```yaml
|
|
111
|
+
type: log
|
|
112
|
+
msg: your log message
|
|
113
|
+
levvel: INFO
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
| key | type | description |
|
|
117
|
+
|------------------|------------------|--------------|
|
|
118
|
+
| msg | str | a templated string |
|
|
119
|
+
| level | str | One of ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], defaults to 'INFO' |
|
|
120
|
+
|
|
89
121
|
### context_set
|
|
90
122
|
|
|
91
123
|
```yaml
|
|
@@ -101,8 +133,6 @@ global_context: {}
|
|
|
101
133
|
| dbus_object_context | dict | Per dbus object context, shared between multiple flow executions. Value can be a dict of strings or dict of templated strings |
|
|
102
134
|
| global_context | dict | Global context, shared between multiple flow executions, over all subscriptions. Value can be a dict of strings or dict of templated strings |
|
|
103
135
|
|
|
104
|
-
|
|
105
|
-
|
|
106
136
|
### mqtt_publish
|
|
107
137
|
|
|
108
138
|
```yaml
|
|
@@ -113,11 +143,7 @@ payload_template: {PlaybackStatus: "Off"}
|
|
|
113
143
|
```
|
|
114
144
|
|
|
115
145
|
| key | type | description |
|
|
116
|
-
|
|
146
|
+
|------------------|------------------|--------------|
|
|
117
147
|
| topic | string | mqtt topic the messaage is published to |
|
|
118
148
|
| payload_type | string | any of [json, yaml, text], defaults to json, format the message is published in to mqtt |
|
|
119
149
|
| payload_template | string, dict | value can be a string, a dict of strings, a templated string or a nested dict of templated strings |
|
|
120
|
-
|
|
121
|
-
## Jinja2 based templating
|
|
122
|
-
|
|
123
|
-
Some configuration values allow the use of jinja 2 templating. dbus2mqtt supports both the builtin filters and comes with additional filters from [jinja2-ansible-filters](https://pypi.org/project/jinja2-ansible-filters/)
|
|
@@ -60,7 +60,7 @@ dev = [
|
|
|
60
60
|
"pyright>=1.1.396",
|
|
61
61
|
"pre-commit>=4.2.0",
|
|
62
62
|
"pip>=25.0.1",
|
|
63
|
-
"pytest-asyncio>=0.
|
|
63
|
+
"pytest-asyncio>=1.0.0"
|
|
64
64
|
]
|
|
65
65
|
|
|
66
66
|
[project.urls]
|
|
@@ -81,7 +81,9 @@ lint-pyright = "pyright"
|
|
|
81
81
|
addopts = "-s"
|
|
82
82
|
testpaths = ["tests"]
|
|
83
83
|
pythonpath = "."
|
|
84
|
-
asyncio_default_fixture_loop_scope = "
|
|
84
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
85
|
+
asyncio_default_test_loop_scope = "function"
|
|
86
|
+
log_cli = true
|
|
85
87
|
|
|
86
88
|
[tool.pyright]
|
|
87
89
|
venvPath = "."
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
3
|
+
"extends": ["local>jwnmulder/renovate-config"],
|
|
4
|
+
|
|
5
|
+
"labels": ["dependencies"],
|
|
6
|
+
|
|
7
|
+
"packageRules": [
|
|
8
|
+
{
|
|
9
|
+
"matchJsonata": ["isBreaking"],
|
|
10
|
+
"dependencyDashboardApproval": true
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"matchFileNames": [".pre-commit-config.yaml"],
|
|
14
|
+
"matchUpdateTypes": ["minor", "patch"],
|
|
15
|
+
"automerge": true,
|
|
16
|
+
"addLabels": ["automerge"]
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"description": "Disable Renovate for .python-version",
|
|
20
|
+
"matchFileNames": [".python-version"],
|
|
21
|
+
"enabled": false
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"matchDatasources": ["docker"],
|
|
25
|
+
"matchPackageNames": ["python"],
|
|
26
|
+
"pinDigests": true,
|
|
27
|
+
"separateMinorPatch": true
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"matchDatasources": ["docker"],
|
|
31
|
+
"matchPackageNames": "python",
|
|
32
|
+
"matchUpdateTypes": ["patch", "pin", "digest"],
|
|
33
|
+
"extends": ["schedule:weekly"]
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
@@ -107,8 +107,14 @@ class FlowActionMqttPublishConfig:
|
|
|
107
107
|
type: Literal["mqtt_publish"] = "mqtt_publish"
|
|
108
108
|
payload_type: Literal["json", "yaml", "text", "binary"] = "json"
|
|
109
109
|
|
|
110
|
+
@dataclass
|
|
111
|
+
class FlowActionLogConfig:
|
|
112
|
+
msg: str
|
|
113
|
+
type: Literal["log"] = "log"
|
|
114
|
+
level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO"
|
|
115
|
+
|
|
110
116
|
FlowActionConfig = Annotated[
|
|
111
|
-
FlowActionMqttPublishConfig | FlowActionContextSetConfig,
|
|
117
|
+
FlowActionMqttPublishConfig | FlowActionContextSetConfig | FlowActionLogConfig,
|
|
112
118
|
Field(discriminator="type")
|
|
113
119
|
]
|
|
114
120
|
|
|
@@ -157,6 +163,7 @@ class MqttConfig:
|
|
|
157
163
|
username: str
|
|
158
164
|
password: SecretStr
|
|
159
165
|
port: int = 1883
|
|
166
|
+
subscription_topics: list[str] = field(default_factory=lambda: ['dbus2mqtt/#'])
|
|
160
167
|
|
|
161
168
|
@dataclass
|
|
162
169
|
class Config:
|