From 638736a7022ec43ac24c26381706fdc0e9a5ece8 Mon Sep 17 00:00:00 2001 From: Tianyu Liu Date: Wed, 17 Jul 2024 16:47:28 +0200 Subject: [PATCH] Add retain --- poo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/poo.py b/poo.py index 00536a8..1af5dac 100644 --- a/poo.py +++ b/poo.py @@ -36,19 +36,19 @@ class PooRecorder: print("Connected") config = PooRecorder.compose_config() PooRecorder.mqtt.publish(PooRecorder.CONFIG_TOPIC, config) - PooRecorder.publish_text("N/A") + PooRecorder.mqtt.publish(PooRecorder.AVAILABILITY_TOPIC, PooRecorder.ONLINE) @staticmethod def publish_text(new_text: str) -> None: PooRecorder.mqtt.publish(PooRecorder.AVAILABILITY_TOPIC, PooRecorder.ONLINE) - PooRecorder.mqtt.publish(PooRecorder.STATE_TOPIC, new_text) + PooRecorder.mqtt.publish(PooRecorder.STATE_TOPIC, new_text, retain=True) @staticmethod def publish_time(time: datetime) -> None: formatted_time = time.strftime("%a | %Y-%m-%d | %H:%M") PooRecorder.mqtt.publish(PooRecorder.AVAILABILITY_TOPIC, PooRecorder.ONLINE) json_string = {"last_poo": formatted_time} - PooRecorder.mqtt.publish(PooRecorder.JSON_TOPIC, json_string) + PooRecorder.mqtt.publish(PooRecorder.JSON_TOPIC, json_string, retain=True) @staticmethod def compose_config() -> dict: