From 8ccc0ab2a95afbccf9593bb28468371d8230c9c5 Mon Sep 17 00:00:00 2001 From: Erwin Boskma Date: Tue, 13 Aug 2024 14:34:24 +0200 Subject: [PATCH] Add hassbridge A bridge application that exposes Home Assistant media players to MPRIS --- flake.nix | 1 + pkgs/hassbridge/0001-fix-xesam-artist.patch | 23 ++++++++++++ pkgs/hassbridge/default.nix | 39 +++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 pkgs/hassbridge/0001-fix-xesam-artist.patch create mode 100644 pkgs/hassbridge/default.nix diff --git a/flake.nix b/flake.nix index b033be9..360ad9a 100644 --- a/flake.nix +++ b/flake.nix @@ -270,6 +270,7 @@ packages = { dnspyre = pkgs.callPackage ./pkgs/dnspyre { }; git-repo-go = pkgs.callPackage ./pkgs/git-repo-go { }; + hassbridge = pkgs.callPackage ./pkgs/hassbridge { }; tinyows = pkgs.callPackage ./pkgs/tinyows { }; }; diff --git a/pkgs/hassbridge/0001-fix-xesam-artist.patch b/pkgs/hassbridge/0001-fix-xesam-artist.patch new file mode 100644 index 0000000..f7ef077 --- /dev/null +++ b/pkgs/hassbridge/0001-fix-xesam-artist.patch @@ -0,0 +1,23 @@ +diff --git a/hassbridge/playerinterface.py b/hassbridge/playerinterface.py +index 34159c8..0c337c2 100644 +--- a/hassbridge/playerinterface.py ++++ b/hassbridge/playerinterface.py +@@ -279,7 +279,6 @@ class PlayerInterface(ServiceInterface): + metadata["mpris:length"] = Variant("x", duration) + + xesam_infos = { +- "media_artist": "xesam:artist", + "media_album_name": "xesam:album", + "media_title": "xesam:title", + } +@@ -288,6 +287,10 @@ class PlayerInterface(ServiceInterface): + if val is not None: + metadata[xesam_key] = Variant("s", val) + ++ artist = self.data.get("media_artist") ++ if artist is not None: ++ metadata["xesam:artist"] = Variant("as", [artist]) ++ + entity_picture = self.data.get("entity_picture") + if entity_picture is not None: + metadata["mpris:artUrl"] = Variant( diff --git a/pkgs/hassbridge/default.nix b/pkgs/hassbridge/default.nix new file mode 100644 index 0000000..5ef4cf5 --- /dev/null +++ b/pkgs/hassbridge/default.nix @@ -0,0 +1,39 @@ +{ + lib, + python3, + fetchFromGitHub, +}: + +python3.pkgs.buildPythonApplication rec { + pname = "hassbridge"; + version = "unstable-2024-08-10"; + pyproject = true; + + src = fetchFromGitHub { + owner = "rytilahti"; + repo = "homeassistant-mpris-bridge"; + rev = "b62f87033be971d265e1e112dc9a3a38dc65bbbd"; + hash = "sha256-M68H806wQtsgqWeRH4j07dk1E5PzT7e0oEtsE6cl+c0="; + }; + + patches = [ ./0001-fix-xesam-artist.patch ]; + + nativeBuildInputs = [ python3.pkgs.poetry-core ]; + + propagatedBuildInputs = with python3.pkgs; [ + anyio + asyncclick + dbus-next + websockets + ]; + + # pythonImportsCheck = [ "homeassistant_mpris_bridge" ]; + + meta = with lib; { + description = "Control your Home Assistant media players from your desktop using MPRIS"; + homepage = "https://github.com/rytilahti/homeassistant-mpris-bridge"; + license = licenses.gpl3Only; + maintainers = with maintainers; [ ]; + mainProgram = "hassbridge"; + }; +}