Add retain

This commit is contained in:
2024-07-17 16:47:28 +02:00
parent 7aef83360e
commit 638736a702

6
poo.py
View File

@@ -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: