Refactor power notification handling to use a dedicated method for improved readability and maintainability
This commit is contained in:
parent
d48cc1b785
commit
58b864a2eb
1 changed files with 8 additions and 5 deletions
|
@ -153,12 +153,15 @@ class HassSystemClient(HassClient):
|
||||||
|
|
||||||
match cmd:
|
match cmd:
|
||||||
case "POWER_OFF":
|
case "POWER_OFF":
|
||||||
self.publish(
|
self.publish_notify("System will be shutting down in 1 minute.")
|
||||||
f"{self.node_id}/user/notify",
|
|
||||||
"System will be shutting down in 1 minute.",
|
|
||||||
)
|
|
||||||
case "POWER_ON":
|
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
|
@property
|
||||||
def state_topic(self) -> str:
|
def state_topic(self) -> str:
|
||||||
|
|
Loading…
Add table
Reference in a new issue