publish state for hour format at startup

This commit is contained in:
Nicu Hodos 2023-07-11 23:15:23 +02:00
parent 3cc84ae4d2
commit b5e91195e7

View File

@ -105,6 +105,10 @@ namespace Mqtt {
publish(brightnessMqtt->stateTopic, message); publish(brightnessMqtt->stateTopic, message);
} }
void publishHourFormat(bool format24) {
if (client.connected()) publish(hourFormatMqtt->stateTopic, format24 ? "ON" : "OFF");
}
void publishConfig() { void publishConfig() {
for (Ha::Component* cmp : sensors) { for (Ha::Component* cmp : sensors) {
publishComponentConfig(*cmp); publishComponentConfig(*cmp);
@ -113,6 +117,7 @@ namespace Mqtt {
publishComponentConfig(*cmp); publishComponentConfig(*cmp);
} }
publishBrightness(); publishBrightness();
publishHourFormat(Display::hourFormat24);
ts.deleteTask(tPublishConfig); ts.deleteTask(tPublishConfig);
} }
@ -153,9 +158,7 @@ namespace Mqtt {
void setup() { void setup() {
Display::Brightness::onChanged(publishBrightness); Display::Brightness::onChanged(publishBrightness);
Display::onHourFormatChanged([](bool format24) { Display::onHourFormatChanged(publishHourFormat);
if (client.connected()) publish(hourFormatMqtt->stateTopic, format24 ? "ON" : "OFF");
});
client.onConnect([](bool sessionPresent) { client.onConnect([](bool sessionPresent) {
tPublishConfig.enable(); tPublishConfig.enable();
tPublishBmp.enableIfNot(); tPublishBmp.enableIfNot();