dbus2mqtt 0.1.0__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.1.0/.dockerignore +14 -0
- dbus2mqtt-0.1.0/.env.example +4 -0
- dbus2mqtt-0.1.0/.github/workflows/main.yml +30 -0
- dbus2mqtt-0.1.0/.github/workflows/pre-commit.yml +29 -0
- dbus2mqtt-0.1.0/.github/workflows/publish.yml +127 -0
- dbus2mqtt-0.1.0/.gitignore +6 -0
- dbus2mqtt-0.1.0/.pre-commit-config.yaml +52 -0
- dbus2mqtt-0.1.0/.python-version +1 -0
- dbus2mqtt-0.1.0/.vscode/settings.json +4 -0
- dbus2mqtt-0.1.0/.yamllint.yml +4 -0
- dbus2mqtt-0.1.0/Dockerfile +39 -0
- dbus2mqtt-0.1.0/LICENSE +21 -0
- dbus2mqtt-0.1.0/PKG-INFO +220 -0
- dbus2mqtt-0.1.0/README.md +192 -0
- dbus2mqtt-0.1.0/config-test.yaml +141 -0
- dbus2mqtt-0.1.0/docs/debugging.md +24 -0
- dbus2mqtt-0.1.0/docs/examples/home_assistant_media_player.md +138 -0
- dbus2mqtt-0.1.0/docs/examples/home_assistant_media_player.yaml +70 -0
- dbus2mqtt-0.1.0/docs/examples/linux_desktop.md +23 -0
- dbus2mqtt-0.1.0/docs/examples/linux_desktop.yaml +35 -0
- dbus2mqtt-0.1.0/docs/examples.md +4 -0
- dbus2mqtt-0.1.0/pyproject.toml +110 -0
- dbus2mqtt-0.1.0/renovate.json +15 -0
- dbus2mqtt-0.1.0/src/dbus2mqtt/__init__.py +10 -0
- dbus2mqtt-0.1.0/src/dbus2mqtt/__main__.py +4 -0
- dbus2mqtt-0.1.0/src/dbus2mqtt/config.py +143 -0
- dbus2mqtt-0.1.0/src/dbus2mqtt/dbus/dbus_client.py +450 -0
- dbus2mqtt-0.1.0/src/dbus2mqtt/dbus/dbus_types.py +23 -0
- dbus2mqtt-0.1.0/src/dbus2mqtt/dbus/dbus_util.py +23 -0
- dbus2mqtt-0.1.0/src/dbus2mqtt/event_broker.py +70 -0
- dbus2mqtt-0.1.0/src/dbus2mqtt/flow/__init__.py +32 -0
- dbus2mqtt-0.1.0/src/dbus2mqtt/flow/actions/context_set.py +26 -0
- dbus2mqtt-0.1.0/src/dbus2mqtt/flow/actions/mqtt_publish.py +39 -0
- dbus2mqtt-0.1.0/src/dbus2mqtt/flow/flow_processor.py +197 -0
- dbus2mqtt-0.1.0/src/dbus2mqtt/main.py +135 -0
- dbus2mqtt-0.1.0/src/dbus2mqtt/mqtt/mqtt_client.py +101 -0
- dbus2mqtt-0.1.0/src/dbus2mqtt/template/dbus_template_functions.py +68 -0
- dbus2mqtt-0.1.0/src/dbus2mqtt/template/templating.py +129 -0
- dbus2mqtt-0.1.0/tests/__init__.py +53 -0
- dbus2mqtt-0.1.0/tests/config/test_examples.py +33 -0
- dbus2mqtt-0.1.0/tests/flow/actions/test_context_set.py +59 -0
- dbus2mqtt-0.1.0/tests/flow/actions/test_mqtt_publish.py +33 -0
- dbus2mqtt-0.1.0/tests/flow/test_flow_processor.py +127 -0
- dbus2mqtt-0.1.0/tests/flow/triggers/test_dbus_client_triggers.py +148 -0
- dbus2mqtt-0.1.0/tests/template/test_templating.py +55 -0
- dbus2mqtt-0.1.0/uv.lock +608 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: main
|
|
2
|
+
|
|
3
|
+
"on":
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Install uv
|
|
19
|
+
uses: astral-sh/setup-uv@v5
|
|
20
|
+
|
|
21
|
+
- name: "Set up Python"
|
|
22
|
+
uses: actions/setup-python@v5
|
|
23
|
+
with:
|
|
24
|
+
python-version-file: ".python-version"
|
|
25
|
+
|
|
26
|
+
- name: Uv sync
|
|
27
|
+
run: uv sync
|
|
28
|
+
|
|
29
|
+
- name: Run tests
|
|
30
|
+
run: uv run pytest
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: pre-commit
|
|
2
|
+
|
|
3
|
+
"on":
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
repository_dispatch:
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
pre-commit:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Install uv
|
|
19
|
+
uses: astral-sh/setup-uv@v5
|
|
20
|
+
|
|
21
|
+
- name: "Set up Python"
|
|
22
|
+
uses: actions/setup-python@v5
|
|
23
|
+
with:
|
|
24
|
+
python-version-file: ".python-version"
|
|
25
|
+
|
|
26
|
+
- name: Uv sync
|
|
27
|
+
run: uv sync
|
|
28
|
+
|
|
29
|
+
- uses: pre-commit/action@v3.0.1
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
|
|
2
|
+
|
|
3
|
+
"on":
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
tags:
|
|
8
|
+
- "v*"
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build:
|
|
13
|
+
name: Build distribution 📦
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
with:
|
|
19
|
+
persist-credentials: false
|
|
20
|
+
|
|
21
|
+
- name: Install uv
|
|
22
|
+
uses: astral-sh/setup-uv@v5
|
|
23
|
+
|
|
24
|
+
- name: "Set up Python"
|
|
25
|
+
uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version-file: ".python-version"
|
|
28
|
+
|
|
29
|
+
- name: Build
|
|
30
|
+
run: uv build
|
|
31
|
+
|
|
32
|
+
- name: Store the distribution packages
|
|
33
|
+
uses: actions/upload-artifact@v4
|
|
34
|
+
with:
|
|
35
|
+
name: python-package-distributions
|
|
36
|
+
path: dist/
|
|
37
|
+
|
|
38
|
+
publish-to-pypi:
|
|
39
|
+
name: >-
|
|
40
|
+
Publish Python 🐍 distribution 📦 to PyPI
|
|
41
|
+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
|
|
42
|
+
needs:
|
|
43
|
+
- build
|
|
44
|
+
runs-on: ubuntu-latest
|
|
45
|
+
environment:
|
|
46
|
+
name: pypi
|
|
47
|
+
url: https://pypi.org/p/dbus2mqtt # Replace <package-name> with your PyPI project name
|
|
48
|
+
permissions:
|
|
49
|
+
id-token: write # IMPORTANT: mandatory for trusted publishing
|
|
50
|
+
|
|
51
|
+
steps:
|
|
52
|
+
- name: Download all the dists
|
|
53
|
+
uses: actions/download-artifact@v4
|
|
54
|
+
with:
|
|
55
|
+
name: python-package-distributions
|
|
56
|
+
path: dist/
|
|
57
|
+
- name: Publish distribution 📦 to PyPI
|
|
58
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
59
|
+
|
|
60
|
+
github-release:
|
|
61
|
+
name: >-
|
|
62
|
+
Sign the Python 🐍 distribution 📦 with Sigstore
|
|
63
|
+
and upload them to GitHub Release
|
|
64
|
+
needs:
|
|
65
|
+
- publish-to-pypi
|
|
66
|
+
runs-on: ubuntu-latest
|
|
67
|
+
|
|
68
|
+
permissions:
|
|
69
|
+
contents: write # IMPORTANT: mandatory for making GitHub Releases
|
|
70
|
+
id-token: write # IMPORTANT: mandatory for sigstore
|
|
71
|
+
|
|
72
|
+
steps:
|
|
73
|
+
- name: Download all the dists
|
|
74
|
+
uses: actions/download-artifact@v4
|
|
75
|
+
with:
|
|
76
|
+
name: python-package-distributions
|
|
77
|
+
path: dist/
|
|
78
|
+
- name: Sign the dists with Sigstore
|
|
79
|
+
uses: sigstore/gh-action-sigstore-python@v3.0.0
|
|
80
|
+
with:
|
|
81
|
+
inputs: >-
|
|
82
|
+
./dist/*.tar.gz
|
|
83
|
+
./dist/*.whl
|
|
84
|
+
- name: Create GitHub Release
|
|
85
|
+
env:
|
|
86
|
+
GITHUB_TOKEN: ${{ github.token }}
|
|
87
|
+
run: >-
|
|
88
|
+
gh release create
|
|
89
|
+
"$GITHUB_REF_NAME"
|
|
90
|
+
--repo "$GITHUB_REPOSITORY"
|
|
91
|
+
--notes ""
|
|
92
|
+
- name: Upload artifact signatures to GitHub Release
|
|
93
|
+
env:
|
|
94
|
+
GITHUB_TOKEN: ${{ github.token }}
|
|
95
|
+
# Upload to GitHub Release using the `gh` CLI.
|
|
96
|
+
# `dist/` contains the built packages, and the
|
|
97
|
+
# sigstore-produced signatures and certificates.
|
|
98
|
+
run: >-
|
|
99
|
+
gh release upload
|
|
100
|
+
"$GITHUB_REF_NAME" dist/**
|
|
101
|
+
--repo "$GITHUB_REPOSITORY"
|
|
102
|
+
|
|
103
|
+
publish-to-testpypi:
|
|
104
|
+
name: Publish Python 🐍 distribution 📦 to TestPyPI
|
|
105
|
+
needs:
|
|
106
|
+
- build
|
|
107
|
+
runs-on: ubuntu-latest
|
|
108
|
+
|
|
109
|
+
environment:
|
|
110
|
+
name: testpypi
|
|
111
|
+
url: https://test.pypi.org/p/dbus2mqtt
|
|
112
|
+
|
|
113
|
+
permissions:
|
|
114
|
+
id-token: write # IMPORTANT: mandatory for trusted publishing
|
|
115
|
+
|
|
116
|
+
steps:
|
|
117
|
+
- name: Download all the dists
|
|
118
|
+
uses: actions/download-artifact@v4
|
|
119
|
+
with:
|
|
120
|
+
name: python-package-distributions
|
|
121
|
+
path: dist/
|
|
122
|
+
- name: Publish distribution 📦 to TestPyPI
|
|
123
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
124
|
+
with:
|
|
125
|
+
repository-url: https://test.pypi.org/legacy/
|
|
126
|
+
skip-existing: true
|
|
127
|
+
verbose: true
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
3
|
+
rev: v5.0.0
|
|
4
|
+
hooks:
|
|
5
|
+
- id: check-case-conflict
|
|
6
|
+
- id: check-executables-have-shebangs
|
|
7
|
+
- id: check-merge-conflict
|
|
8
|
+
- id: check-shebang-scripts-are-executable
|
|
9
|
+
- id: check-json
|
|
10
|
+
- id: check-yaml
|
|
11
|
+
files: .*\.(yaml|yml)$
|
|
12
|
+
- id: detect-private-key
|
|
13
|
+
- id: end-of-file-fixer
|
|
14
|
+
- id: fix-byte-order-marker
|
|
15
|
+
- id: mixed-line-ending
|
|
16
|
+
- id: trailing-whitespace
|
|
17
|
+
|
|
18
|
+
# - repo: https://github.com/shellcheck-py/shellcheck-py
|
|
19
|
+
# rev: v0.9.0.6
|
|
20
|
+
# hooks:
|
|
21
|
+
# - id: shellcheck
|
|
22
|
+
|
|
23
|
+
- repo: https://github.com/codespell-project/codespell
|
|
24
|
+
rev: v2.4.1
|
|
25
|
+
hooks:
|
|
26
|
+
- id: codespell
|
|
27
|
+
|
|
28
|
+
- repo: https://github.com/adrienverge/yamllint.git
|
|
29
|
+
rev: v1.37.0
|
|
30
|
+
hooks:
|
|
31
|
+
- id: yamllint
|
|
32
|
+
args:
|
|
33
|
+
- --strict
|
|
34
|
+
|
|
35
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
36
|
+
rev: v0.11.5
|
|
37
|
+
hooks:
|
|
38
|
+
- id: ruff
|
|
39
|
+
args:
|
|
40
|
+
- --fix
|
|
41
|
+
- --fixable
|
|
42
|
+
- I
|
|
43
|
+
|
|
44
|
+
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
45
|
+
rev: 0.6.14
|
|
46
|
+
hooks:
|
|
47
|
+
- id: uv-lock
|
|
48
|
+
|
|
49
|
+
- repo: https://github.com/RobertCraigie/pyright-python
|
|
50
|
+
rev: v1.1.399
|
|
51
|
+
hooks:
|
|
52
|
+
- id: pyright
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# An example using multi-stage image builds to create a final image without uv.
|
|
2
|
+
|
|
3
|
+
# First, build the application in the `/app` directory.
|
|
4
|
+
# See `Dockerfile` for details.
|
|
5
|
+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder
|
|
6
|
+
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
|
|
7
|
+
|
|
8
|
+
# Disable Python downloads, because we want to use the system interpreter
|
|
9
|
+
# across both images. If using a managed Python version, it needs to be
|
|
10
|
+
# copied from the build image into the final image; see `standalone.Dockerfile`
|
|
11
|
+
# for an example.
|
|
12
|
+
ENV UV_PYTHON_DOWNLOADS=0
|
|
13
|
+
|
|
14
|
+
WORKDIR /app
|
|
15
|
+
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
16
|
+
--mount=type=bind,source=uv.lock,target=uv.lock \
|
|
17
|
+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
|
|
18
|
+
uv sync --frozen --no-install-project --no-dev
|
|
19
|
+
|
|
20
|
+
ADD src/ pyproject.toml uv.lock .python-version README.md /app
|
|
21
|
+
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
22
|
+
uv sync --frozen --no-dev
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# Then, use a final image without uv
|
|
26
|
+
FROM python:3.12-slim-bookworm
|
|
27
|
+
# It is important to use the image that matches the builder, as the path to the
|
|
28
|
+
# Python executable must be the same, e.g., using `python:3.12-slim-bookworm`
|
|
29
|
+
# will fail.
|
|
30
|
+
|
|
31
|
+
# Copy the application from the builder
|
|
32
|
+
COPY --from=builder --chown=app:app /app /app
|
|
33
|
+
|
|
34
|
+
# Place executables in the environment at the front of the path
|
|
35
|
+
ENV PATH="/app/.venv/bin:$PATH"
|
|
36
|
+
|
|
37
|
+
# Run the FastAPI application by default
|
|
38
|
+
ENTRYPOINT ["python", "-m", "dbus2mqtt"]
|
|
39
|
+
CMD ["--help"]
|
dbus2mqtt-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jan-Willem Mulder
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
dbus2mqtt-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dbus2mqtt
|
|
3
|
+
Version: 0.1.0
|
|
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
|
+
Project-URL: Repository, https://github.com/jwnmulder/dbus2mqtt.git
|
|
6
|
+
Project-URL: Issues, https://github.com/jwnmulder/dbus2mqtt/issues
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: dbus,home-assistant,mpris,mqtt,python
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Requires-Dist: apscheduler>=3.11.0
|
|
17
|
+
Requires-Dist: colorlog>=6.9.0
|
|
18
|
+
Requires-Dist: dbus-next>=0.2.3
|
|
19
|
+
Requires-Dist: janus>=2.0.0
|
|
20
|
+
Requires-Dist: jinja2-ansible-filters>=1.3.2
|
|
21
|
+
Requires-Dist: jinja2>=3.1.6
|
|
22
|
+
Requires-Dist: jsonargparse>=4.38.0
|
|
23
|
+
Requires-Dist: paho-mqtt>=2.1.0
|
|
24
|
+
Requires-Dist: pydantic>=2.11.3
|
|
25
|
+
Requires-Dist: python-dotenv>=1.1.0
|
|
26
|
+
Requires-Dist: schedule>=1.2.2
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# dbus2mqtt
|
|
30
|
+
|
|
31
|
+
> **⚠️ Warning:** This project has no releases yet. Running from source works. Docker images and Python packages are planned but not yet available.
|
|
32
|
+
|
|
33
|
+
**dbus2mqtt** is a Python application that bridges **Linux D-Bus** with **MQTT**.
|
|
34
|
+
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
|
+
|
|
36
|
+
This makes it easy to integrate Linux desktop services or system signals into MQTT-based workflows - including **Home Assistant**.
|
|
37
|
+
|
|
38
|
+
## ✨ Features
|
|
39
|
+
|
|
40
|
+
* 🔗 Forward **D-Bus signals** to MQTT topics.
|
|
41
|
+
* 🧠 Enrich or transform **MQTT payloads** using Jinja2 templates and additional D-Bus calls.
|
|
42
|
+
* ⚡ Trigger message publishing via **signals, timers, property changes, or startup events**.
|
|
43
|
+
* 📡 Expose **D-Bus methods** for remote control via MQTT messages.
|
|
44
|
+
* 🏠 Includes example configurations for **MPRIS** and **Home Assistant Media Player** integration.
|
|
45
|
+
|
|
46
|
+
TODO list
|
|
47
|
+
|
|
48
|
+
* Create a release on PyPI
|
|
49
|
+
* Release a docker image
|
|
50
|
+
* Improve error handling when deleting message with 'retain' set. WARNING:dbus2mqtt.mqtt_client:on_message: Unexpected payload, expecting json, topic=dbus2mqtt/org.mpris.MediaPlayer2/command, payload=, error=Expecting value: line 1 column 1 (char 0)
|
|
51
|
+
* Property set only works the first time, need to restart after which the first set will work again
|
|
52
|
+
|
|
53
|
+
## Getting started with dbus2mqtt
|
|
54
|
+
|
|
55
|
+
Create a `config.yaml` file with the contents shown below. This configuration will expose all bus properties from the `org.mpris.MediaPlayer2.Player` interface to MQTT on the `dbus2mqtt/org.mpris.MediaPlayer2/state` topic. Have a look at [docs/examples](docs/examples.md) for more examples
|
|
56
|
+
|
|
57
|
+
```yaml
|
|
58
|
+
dbus:
|
|
59
|
+
subscriptions:
|
|
60
|
+
- bus_name: org.mpris.MediaPlayer2.*
|
|
61
|
+
path: /org/mpris/MediaPlayer2
|
|
62
|
+
interfaces:
|
|
63
|
+
- interface: org.freedesktop.DBus.Properties
|
|
64
|
+
methods:
|
|
65
|
+
- method: GetAll
|
|
66
|
+
|
|
67
|
+
flows:
|
|
68
|
+
- name: "Publish MPRIS state"
|
|
69
|
+
triggers:
|
|
70
|
+
- type: bus_name_added
|
|
71
|
+
- type: schedule
|
|
72
|
+
interval: {seconds: 5}
|
|
73
|
+
actions:
|
|
74
|
+
- type: context_set
|
|
75
|
+
context:
|
|
76
|
+
mpris_bus_name: '{{ dbus_list("org.mpris.MediaPlayer2.*") | first }}'
|
|
77
|
+
path: /org/mpris/MediaPlayer2
|
|
78
|
+
- type: mqtt_publish
|
|
79
|
+
topic: dbus2mqtt/org.mpris.MediaPlayer2/state
|
|
80
|
+
payload_type: json
|
|
81
|
+
payload_template: |
|
|
82
|
+
{{ dbus_call(mpris_bus_name, path, 'org.freedesktop.DBus.Properties', 'GetAll', ['org.mpris.MediaPlayer2.Player']) | to_yaml }}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
MQTT connection details can be configured in that same `config.yaml` file or via environment variables. For now create a `.env` file with the following contents.
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
MQTT__HOST=localhost
|
|
89
|
+
MQTT__PORT=1883
|
|
90
|
+
MQTT__USERNAME=
|
|
91
|
+
MQTT__PASSWORD=
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Running from source
|
|
95
|
+
|
|
96
|
+
To run dbus2mqtt from source (requires uv to be installed)
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
uv run main.py --config config.yaml
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Run using docker with auto start behavior
|
|
103
|
+
|
|
104
|
+
To build and run dbus2mqtt using Docker with the [home_assistant_media_player.yaml](docs/examples/home_assistant_media_player.yaml) example from this repository
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# setup configuration
|
|
108
|
+
mkdir -p $HOME/.config/dbus2mqtt
|
|
109
|
+
cp docs/examples/home_assistant_media_player.yaml $HOME/.config/dbus2mqtt/config.yaml
|
|
110
|
+
cp .env.example $HOME/.config/dbus2mqtt/.env
|
|
111
|
+
|
|
112
|
+
# build image
|
|
113
|
+
docker build -t jwnmulder/dbus2mqtt:latest .
|
|
114
|
+
|
|
115
|
+
# run image and automatically start on reboot
|
|
116
|
+
docker run --detach --name dbus2mqtt \
|
|
117
|
+
--volume "$HOME"/.config/dbus2mqtt:"$HOME"/.config/dbus2mqtt \
|
|
118
|
+
--volume /run/user:/run/user \
|
|
119
|
+
--env DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS" \
|
|
120
|
+
--env-file "$HOME"/.config/dbus2mqtt/.env \
|
|
121
|
+
--user $(id -u):$(id -g) \
|
|
122
|
+
--privileged \
|
|
123
|
+
--restart unless-stopped \
|
|
124
|
+
jwnmulder/dbus2mqtt \
|
|
125
|
+
--config "$HOME"/.config/dbus2mqtt/config.yaml
|
|
126
|
+
|
|
127
|
+
# view logs
|
|
128
|
+
sudo docker logs dbus2mqtt -f
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Examples
|
|
132
|
+
|
|
133
|
+
This repository contains some examples under [docs/examples](docs/examples.md). The most complete one being [MPRIS to Home Assistant Media Player integration](docs/examples/home_assistant_media_player.md)
|
|
134
|
+
|
|
135
|
+
## Configuration reference
|
|
136
|
+
|
|
137
|
+
dbus2mqtt leverages [jsonargparse](https://jsonargparse.readthedocs.io/en/stable/) which allows configuration via either yaml configuration, CLI or environment variables. Until this is fully documented have a look at the examples in this repository.
|
|
138
|
+
|
|
139
|
+
### MQTT and D-Bus connection details
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
# dbus_next configuration
|
|
143
|
+
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
|
|
144
|
+
|
|
145
|
+
# dbus2mqtt configuration
|
|
146
|
+
MQTT__HOST=localhost
|
|
147
|
+
MQTT__PORT=1883
|
|
148
|
+
MQTT__USERNAME=
|
|
149
|
+
MQTT__PASSWORD=
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
or
|
|
153
|
+
|
|
154
|
+
```yaml
|
|
155
|
+
mqtt:
|
|
156
|
+
host: localhost
|
|
157
|
+
port: 1883
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Exposing dbus methods
|
|
161
|
+
|
|
162
|
+
```yaml
|
|
163
|
+
dbus:
|
|
164
|
+
subscriptions:
|
|
165
|
+
- bus_name: org.mpris.MediaPlayer2.*
|
|
166
|
+
path: /org/mpris/MediaPlayer2
|
|
167
|
+
interfaces:
|
|
168
|
+
- interface: org.mpris.MediaPlayer2.Player
|
|
169
|
+
mqtt_call_method_topic: dbus2mqtt/org.mpris.MediaPlayer2/command
|
|
170
|
+
methods:
|
|
171
|
+
- method: Pause
|
|
172
|
+
- method: Play
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
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`
|
|
176
|
+
|
|
177
|
+
```json
|
|
178
|
+
{
|
|
179
|
+
"method" : "Play",
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
```json
|
|
184
|
+
{
|
|
185
|
+
"method" : "OpenUri",
|
|
186
|
+
"args": []
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Exposing dbus signals
|
|
191
|
+
|
|
192
|
+
Publishing signals to MQTT topics works by subscribing to the relevant signal and using flows for publishing
|
|
193
|
+
|
|
194
|
+
```yaml
|
|
195
|
+
dbus:
|
|
196
|
+
subscriptions:
|
|
197
|
+
- bus_name: org.mpris.MediaPlayer2.*
|
|
198
|
+
path: /org/mpris/MediaPlayer2
|
|
199
|
+
interfaces:
|
|
200
|
+
- interface: org.freedesktop.DBus.Properties
|
|
201
|
+
signals:
|
|
202
|
+
- signal: PropertiesChanged
|
|
203
|
+
|
|
204
|
+
flows:
|
|
205
|
+
- name: "Property Changed flow"
|
|
206
|
+
triggers:
|
|
207
|
+
- type: on_signal
|
|
208
|
+
actions:
|
|
209
|
+
- type: mqtt_publish
|
|
210
|
+
topic: dbus2mqtt/org.mpris.MediaPlayer2/signals/PropertiesChanged
|
|
211
|
+
payload_type: json
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Flows
|
|
215
|
+
|
|
216
|
+
TODO: Document flows, for now see the [MPRIS to Home Assistant Media Player integration](docs/examples/home_assistant_media_player.md) example
|
|
217
|
+
|
|
218
|
+
## Jinja templating
|
|
219
|
+
|
|
220
|
+
TODO: Document Jinja templating, for now see the [MPRIS to Home Assistant Media Player integration](docs/examples/home_assistant_media_player.md) example
|