From 58b864a2eb227bd8ad338b24e1bac9770471c519 Mon Sep 17 00:00:00 2001
From: "Edgar P. Burkhart" <git@edgarpierre.fr>
Date: Sun, 9 Mar 2025 23:26:40 +0100
Subject: [PATCH] Refactor power notification handling to use a dedicated
 method for improved readability and maintainability

---
 hasspy/mqtt.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/hasspy/mqtt.py b/hasspy/mqtt.py
index 31c52a0..2eac87d 100644
--- a/hasspy/mqtt.py
+++ b/hasspy/mqtt.py
@@ -153,12 +153,15 @@ class HassSystemClient(HassClient):
 
         match cmd:
             case "POWER_OFF":
-                self.publish(
-                    f"{self.node_id}/user/notify",
-                    "System will be shutting down in 1 minute.",
-                )
+                self.publish_notify("System will be shutting down in 1 minute.")
             case "POWER_ON":
-                self.publish(f"{self.node_id}/user/notify", "Shutdown cancelled.")
+                self.publish_notify("Shutdown cancelled.")
+
+    def publish_notify(
+        self, payload: str, *args: Any, **kwargs: Any
+    ) -> MQTTMessageInfo:
+        kwargs.setdefault("retain", False)
+        return self.publish(f"{self.node_id}/user/notify", payload, *args, **kwargs)
 
     @property
     def state_topic(self) -> str: