Add retain
This commit is contained in:
6
poo.py
6
poo.py
@@ -36,19 +36,19 @@ class PooRecorder:
|
|||||||
print("Connected")
|
print("Connected")
|
||||||
config = PooRecorder.compose_config()
|
config = PooRecorder.compose_config()
|
||||||
PooRecorder.mqtt.publish(PooRecorder.CONFIG_TOPIC, config)
|
PooRecorder.mqtt.publish(PooRecorder.CONFIG_TOPIC, config)
|
||||||
PooRecorder.publish_text("N/A")
|
PooRecorder.mqtt.publish(PooRecorder.AVAILABILITY_TOPIC, PooRecorder.ONLINE)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def publish_text(new_text: str) -> None:
|
def publish_text(new_text: str) -> None:
|
||||||
PooRecorder.mqtt.publish(PooRecorder.AVAILABILITY_TOPIC, PooRecorder.ONLINE)
|
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
|
@staticmethod
|
||||||
def publish_time(time: datetime) -> None:
|
def publish_time(time: datetime) -> None:
|
||||||
formatted_time = time.strftime("%a | %Y-%m-%d | %H:%M")
|
formatted_time = time.strftime("%a | %Y-%m-%d | %H:%M")
|
||||||
PooRecorder.mqtt.publish(PooRecorder.AVAILABILITY_TOPIC, PooRecorder.ONLINE)
|
PooRecorder.mqtt.publish(PooRecorder.AVAILABILITY_TOPIC, PooRecorder.ONLINE)
|
||||||
json_string = {"last_poo": formatted_time}
|
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
|
@staticmethod
|
||||||
def compose_config() -> dict:
|
def compose_config() -> dict:
|
||||||
|
|||||||
Reference in New Issue
Block a user