From 2137378f079679172eab35b08686334f9366ee86 Mon Sep 17 00:00:00 2001
From: "Edgar P. Burkhart" <git@edgarpierre.fr>
Date: Sun, 9 Mar 2025 12:29:14 +0100
Subject: [PATCH] Add play/pause command support to HassUserClient with button
 component

---
 hasspy/mqtt.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/hasspy/mqtt.py b/hasspy/mqtt.py
index dd23d48..c78fc7a 100644
--- a/hasspy/mqtt.py
+++ b/hasspy/mqtt.py
@@ -175,3 +175,22 @@ class HassSystemClient(HassClient):
 class HassUserClient(HassClient):
     def __init__(self, node_id: str, config: Mapping[str, Any]) -> None:
         super().__init__(f"{node_id}_{getpass.getuser()}", config)
+
+    def do_command(self, payload: str) -> None:
+        super().do_command(payload)
+
+        match payload:
+            case "PLAY_PAUSE":
+                log.info("Toggling play/pauseā€¦")
+                run(["playerctl", "play-pause"])
+
+    @property
+    def components(self) -> dict[str, dict[str, str]]:
+        return {
+            "play-pause": {
+                "unique_id": f"{self.node_id}_play_pause",
+                "p": "button",
+                "name": "Play/Pause",
+                "payload_press": "PLAY_PAUSE",
+            },
+        }