From 255347ab7747e79dfae44848f5cc20bd77a6dad5 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Thu, 20 Jan 2022 17:38:18 +0100 Subject: [PATCH] Minor clenup. --- usermods/multi_relay/usermod_multi_relay.h | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/usermods/multi_relay/usermod_multi_relay.h b/usermods/multi_relay/usermod_multi_relay.h index 9073051b0..e089ed4eb 100644 --- a/usermods/multi_relay/usermod_multi_relay.h +++ b/usermods/multi_relay/usermod_multi_relay.h @@ -254,6 +254,7 @@ class MultiRelay : public Usermod { mqtt->subscribe(subuf, 0); publishHomeAssistantAutodiscovery(); for (uint8_t i=0; i= 0 && _relay[i].external) { StaticJsonDocument<1024> json; - sprintf(buf, "%s Switch %d", serverDescription, i); //max length: 33 + 8 + 3 = 44 + sprintf_P(buf, PSTR("%s Switch %d"), serverDescription, i); //max length: 33 + 8 + 3 = 44 json[F("name")] = buf; - sprintf(buf, "%s/relay/%d", mqttDeviceTopic, i); //max length: 33 + 7 + 3 = 43 + sprintf_P(buf, PSTR("%s/relay/%d"), mqttDeviceTopic, i); //max length: 33 + 7 + 3 = 43 json["~"] = buf; - strcat(buf, "/command"); + strcat_P(buf, PSTR("/command")); mqtt->subscribe(buf, 0); - json[F("stat_t")] = "~"; - json[F("cmd_t")] = "~/command"; - json[F("pl_off")] = F("off"); - json[F("pl_on")] = F("on"); + json[F("stat_t")] = "~"; + json[F("cmd_t")] = F("~/command"); + json[F("pl_off")] = F("off"); + json[F("pl_on")] = F("on"); json[F("uniq_id")] = uid; strcpy(buf, mqttDeviceTopic); //max length: 33 + 7 = 40 - strcat(buf, "/status"); - json[F("avty_t")] = buf; - json[F("pl_avail")] = F("online"); + strcat_P(buf, PSTR("/status")); + json[F("avty_t")] = buf; + json[F("pl_avail")] = F("online"); json[F("pl_not_avail")] = F("offline"); //TODO: dev payload_size = serializeJson(json, json_str); } else { //Unpublish disabled or internal relays - json_str[0] = 0; + json_str[0] = 0; payload_size = 0; } - sprintf(buf, "homeassistant/switch/%s/config", uid); + sprintf_P(buf, PSTR("homeassistant/switch/%s/config"), uid); mqtt->publish(buf, 0, true, json_str, payload_size); } }