From b5e91195e727c75b091455f2d9fa5f1ea56674ac Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Tue, 11 Jul 2023 23:15:23 +0200 Subject: [PATCH] publish state for hour format at startup --- include/mqtt.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/mqtt.h b/include/mqtt.h index 5d7d229..d99d3d7 100644 --- a/include/mqtt.h +++ b/include/mqtt.h @@ -105,6 +105,10 @@ namespace Mqtt { publish(brightnessMqtt->stateTopic, message); } + void publishHourFormat(bool format24) { + if (client.connected()) publish(hourFormatMqtt->stateTopic, format24 ? "ON" : "OFF"); + } + void publishConfig() { for (Ha::Component* cmp : sensors) { publishComponentConfig(*cmp); @@ -113,6 +117,7 @@ namespace Mqtt { publishComponentConfig(*cmp); } publishBrightness(); + publishHourFormat(Display::hourFormat24); ts.deleteTask(tPublishConfig); } @@ -153,9 +158,7 @@ namespace Mqtt { void setup() { Display::Brightness::onChanged(publishBrightness); - Display::onHourFormatChanged([](bool format24) { - if (client.connected()) publish(hourFormatMqtt->stateTopic, format24 ? "ON" : "OFF"); - }); + Display::onHourFormatChanged(publishHourFormat); client.onConnect([](bool sessionPresent) { tPublishConfig.enable(); tPublishBmp.enableIfNot();