rename snprintf_P to snprintf

This commit is contained in:
proddy
2021-09-19 21:27:39 +02:00
parent b214d7a662
commit ee34dd72f7
8 changed files with 63 additions and 63 deletions

View File

@@ -299,13 +299,13 @@ uint64_t DallasSensor::Sensor::id() const {
std::string DallasSensor::Sensor::id_string() const { std::string DallasSensor::Sensor::id_string() const {
std::string str(20, '\0'); std::string str(20, '\0');
snprintf_P(&str[0], snprintf(&str[0],
str.capacity() + 1, str.capacity() + 1,
"%02X-%04X-%04X-%04X", "%02X-%04X-%04X-%04X",
(unsigned int)(id_ >> 48) & 0xFF, (unsigned int)(id_ >> 48) & 0xFF,
(unsigned int)(id_ >> 32) & 0xFFFF, (unsigned int)(id_ >> 32) & 0xFFFF,
(unsigned int)(id_ >> 16) & 0xFFFF, (unsigned int)(id_ >> 16) & 0xFFFF,
(unsigned int)(id_)&0xFFFF); (unsigned int)(id_)&0xFFFF);
return str; return str;
} }
@@ -347,7 +347,7 @@ void DallasSensor::delete_ha_config(uint8_t index, const char * name) {
std::string topicname = name; std::string topicname = name;
std::replace(topicname.begin(), topicname.end(), '-', '_'); std::replace(topicname.begin(), topicname.end(), '-', '_');
snprintf_P(topic, sizeof(topic), "homeassistant/sensor/%s/dallassensor_%s/config", Mqtt::base().c_str(), topicname.c_str()); snprintf(topic, sizeof(topic), "homeassistant/sensor/%s/dallassensor_%s/config", Mqtt::base().c_str(), topicname.c_str());
Mqtt::publish(topic); Mqtt::publish(topic);
registered_ha_[index] = false; // forces a recreate of the HA config topic registered_ha_[index] = false; // forces a recreate of the HA config topic
} }
@@ -461,7 +461,7 @@ bool DallasSensor::command_info(const char * value, const int8_t id, JsonObject
uint8_t i = 1; // sensor count uint8_t i = 1; // sensor count
for (const auto & sensor : sensors_) { for (const auto & sensor : sensors_) {
char sensorID[10]; // sensor{1-n} char sensorID[10]; // sensor{1-n}
snprintf_P(sensorID, 10, "sensor%d", i++); snprintf(sensorID, 10, "sensor%d", i++);
if (id == -1) { // show number and id if (id == -1) { // show number and id
JsonObject dataSensor = json.createNestedObject(sensorID); JsonObject dataSensor = json.createNestedObject(sensorID);
dataSensor["id"] = sensor.to_string(); dataSensor["id"] = sensor.to_string();
@@ -493,7 +493,7 @@ void DallasSensor::publish_values(const bool force) {
for (const auto & sensor : sensors_) { for (const auto & sensor : sensors_) {
char sensorID[10]; // sensor{1-n} char sensorID[10]; // sensor{1-n}
snprintf_P(sensorID, 10, "sensor%d", sensor_no); snprintf(sensorID, 10, "sensor%d", sensor_no);
if (dallas_format_ == Dallas_Format::NUMBER) { if (dallas_format_ == Dallas_Format::NUMBER) {
// e.g. dallassensor_data = {"sensor1":{"id":"28-EA41-9497-0E03","temp":23.3},"sensor2":{"id":"28-233D-9497-0C03","temp":24.0}} // e.g. dallassensor_data = {"sensor1":{"id":"28-EA41-9497-0E03","temp":23.3},"sensor2":{"id":"28-233D-9497-0C03","temp":24.0}}
JsonObject dataSensor = doc.createNestedObject(sensorID); JsonObject dataSensor = doc.createNestedObject(sensorID);
@@ -513,28 +513,28 @@ void DallasSensor::publish_values(const bool force) {
config["dev_cla"] = FJSON("temperature"); config["dev_cla"] = FJSON("temperature");
char stat_t[50]; char stat_t[50];
snprintf_P(stat_t, sizeof(stat_t), "%s/dallassensor_data", Mqtt::base().c_str()); snprintf(stat_t, sizeof(stat_t), "%s/dallassensor_data", Mqtt::base().c_str());
config["stat_t"] = stat_t; config["stat_t"] = stat_t;
config["unit_of_meas"] = FJSON("°C"); config["unit_of_meas"] = FJSON("°C");
char str[50]; char str[50];
if (dallas_format_ != Dallas_Format::NUMBER) { if (dallas_format_ != Dallas_Format::NUMBER) {
snprintf_P(str, sizeof(str), "{{value_json['%s']}}", sensor.to_string().c_str()); snprintf(str, sizeof(str), "{{value_json['%s']}}", sensor.to_string().c_str());
} else { } else {
snprintf_P(str, sizeof(str), "{{value_json.sensor%d.temp}}", sensor_no); snprintf(str, sizeof(str), "{{value_json.sensor%d.temp}}", sensor_no);
} }
config["val_tpl"] = str; config["val_tpl"] = str;
// name as sensor number not the long unique ID // name as sensor number not the long unique ID
if (dallas_format_ != Dallas_Format::NUMBER) { if (dallas_format_ != Dallas_Format::NUMBER) {
snprintf_P(str, sizeof(str), "Dallas Sensor %s", sensor.to_string().c_str()); snprintf(str, sizeof(str), "Dallas Sensor %s", sensor.to_string().c_str());
} else { } else {
snprintf_P(str, sizeof(str), "Dallas Sensor %d", sensor_no); snprintf(str, sizeof(str), "Dallas Sensor %d", sensor_no);
} }
config["name"] = str; config["name"] = str;
snprintf_P(str, sizeof(str), "dallasensor_%s", sensor.to_string().c_str()); snprintf(str, sizeof(str), "dallasensor_%s", sensor.to_string().c_str());
config["uniq_id"] = str; config["uniq_id"] = str;
JsonObject dev = config.createNestedObject("dev"); JsonObject dev = config.createNestedObject("dev");
@@ -543,12 +543,12 @@ void DallasSensor::publish_values(const bool force) {
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
if (dallas_format_ == Dallas_Format::NUMBER) { if (dallas_format_ == Dallas_Format::NUMBER) {
snprintf_P(topic, sizeof(topic), "sensor/%s/dallassensor_%d/config", Mqtt::base().c_str(), sensor_no); snprintf(topic, sizeof(topic), "sensor/%s/dallassensor_%d/config", Mqtt::base().c_str(), sensor_no);
} else { } else {
// use '_' as HA doesn't like '-' in the topic name // use '_' as HA doesn't like '-' in the topic name
std::string topicname = sensor.to_string(); std::string topicname = sensor.to_string();
std::replace(topicname.begin(), topicname.end(), '-', '_'); std::replace(topicname.begin(), topicname.end(), '-', '_');
snprintf_P(topic, sizeof(topic), "sensor/%s/dallassensor_%s/config", Mqtt::base().c_str(), topicname.c_str()); snprintf(topic, sizeof(topic), "sensor/%s/dallassensor_%s/config", Mqtt::base().c_str(), topicname.c_str());
} }
Mqtt::publish_ha(topic, config.as<JsonObject>()); Mqtt::publish_ha(topic, config.as<JsonObject>());

View File

@@ -287,7 +287,7 @@ bool Boiler::publish_ha_config() {
doc["ic"] = F_(icondevice); doc["ic"] = F_(icondevice);
char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE]; char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str()); snprintf(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
doc["stat_t"] = stat_t; doc["stat_t"] = stat_t;
char name_s[40]; char name_s[40];
@@ -304,7 +304,7 @@ bool Boiler::publish_ha_config() {
ids.add("ems-esp-boiler"); ids.add("ems-esp-boiler");
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), "sensor/%s/boiler/config", Mqtt::base().c_str()); snprintf(topic, sizeof(topic), "sensor/%s/boiler/config", Mqtt::base().c_str());
Mqtt::publish_ha(topic, Mqtt::publish_ha(topic,
doc.as<JsonObject>()); // publish the config payload with retain flag doc.as<JsonObject>()); // publish the config payload with retain flag
@@ -791,7 +791,7 @@ void Boiler::process_UBAMaintenanceStatus(std::shared_ptr<const Telegram> telegr
// ignore if 0, which means all is ok // ignore if 0, which means all is ok
if (Helpers::hasValue(message_code) && message_code > 0) { if (Helpers::hasValue(message_code) && message_code > 0) {
snprintf_P(maintenanceMessage_, sizeof(maintenanceMessage_), "H%02d", message_code); snprintf(maintenanceMessage_, sizeof(maintenanceMessage_), "H%02d", message_code);
} }
} }
@@ -818,7 +818,7 @@ void Boiler::process_UBAErrorMessage(std::shared_ptr<const Telegram> telegram) {
uint32_t date = (year - 2000) * 535680UL + month * 44640UL + day * 1440UL + hour * 60 + min; uint32_t date = (year - 2000) * 535680UL + month * 44640UL + day * 1440UL + hour * 60 + min;
// store only the newest code from telegrams 10 and 11 // store only the newest code from telegrams 10 and 11
if (date > lastCodeDate_) { if (date > lastCodeDate_) {
snprintf_P(lastCode_, sizeof(lastCode_), "%s(%d) %02d.%02d.%d %02d:%02d", code, codeNo, day, month, year, hour, min); snprintf(lastCode_, sizeof(lastCode_), "%s(%d) %02d.%02d.%d %02d:%02d", code, codeNo, day, month, year, hour, min);
lastCodeDate_ = date; lastCodeDate_ = date;
} }
} }
@@ -844,7 +844,7 @@ void Boiler::process_UBAMaintenanceData(std::shared_ptr<const Telegram> telegram
uint8_t month = telegram->message_data[3]; uint8_t month = telegram->message_data[3];
uint8_t year = telegram->message_data[4]; uint8_t year = telegram->message_data[4];
if (day > 0 && month > 0) { if (day > 0 && month > 0) {
snprintf_P(maintenanceDate_, sizeof(maintenanceDate_), "%02d.%02d.%04d", day, month, year + 2000); snprintf(maintenanceDate_, sizeof(maintenanceDate_), "%02d.%02d.%04d", day, month, year + 2000);
} }
} }

View File

@@ -47,7 +47,7 @@ bool Heatpump::publish_ha_config() {
doc["ic"] = F_(icondevice); doc["ic"] = F_(icondevice);
char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE]; char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str()); snprintf(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
doc["stat_t"] = stat_t; doc["stat_t"] = stat_t;
char name_s[40]; char name_s[40];
@@ -64,7 +64,7 @@ bool Heatpump::publish_ha_config() {
ids.add("ems-esp-heatpump"); ids.add("ems-esp-heatpump");
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), "sensor/%s/heatpump/config", Mqtt::base().c_str()); snprintf(topic, sizeof(topic), "sensor/%s/heatpump/config", Mqtt::base().c_str());
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
return true; return true;

View File

@@ -110,23 +110,23 @@ bool Mixer::publish_ha_config() {
char uniq_id[20]; char uniq_id[20];
if (type_ == Type::MP) { if (type_ == Type::MP) {
snprintf_P(uniq_id, sizeof(uniq_id), "MixerMP"); snprintf(uniq_id, sizeof(uniq_id), "MixerMP");
} else { } else {
snprintf_P(uniq_id, sizeof(uniq_id), "Mixer%02X", device_id() - 0x20 + 1); snprintf(uniq_id, sizeof(uniq_id), "Mixer%02X", device_id() - 0x20 + 1);
} }
doc["uniq_id"] = uniq_id; doc["uniq_id"] = uniq_id;
doc["ic"] = F_(icondevice); doc["ic"] = F_(icondevice);
char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE]; char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str()); snprintf(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
doc["stat_t"] = stat_t; doc["stat_t"] = stat_t;
char name[20]; char name[20];
if (type_ == Type::MP) { if (type_ == Type::MP) {
snprintf_P(name, sizeof(name), "Mixer MP"); snprintf(name, sizeof(name), "Mixer MP");
} else { } else {
snprintf_P(name, sizeof(name), "Mixer %02X", device_id() - 0x20 + 1); snprintf(name, sizeof(name), "Mixer %02X", device_id() - 0x20 + 1);
} }
doc["name"] = name; doc["name"] = name;
@@ -151,11 +151,11 @@ bool Mixer::publish_ha_config() {
// determine the topic, if its HC and WWC. This is determined by the incoming telegram types. // determine the topic, if its HC and WWC. This is determined by the incoming telegram types.
std::string topic(Mqtt::MQTT_TOPIC_MAX_SIZE, '\0'); std::string topic(Mqtt::MQTT_TOPIC_MAX_SIZE, '\0');
if (type_ == Type::HC) { if (type_ == Type::HC) {
snprintf_P(&topic[0], topic.capacity() + 1, "sensor/%s/mixer_hc%d/config", Mqtt::base().c_str(), hc_); snprintf(&topic[0], topic.capacity() + 1, "sensor/%s/mixer_hc%d/config", Mqtt::base().c_str(), hc_);
} else if (type_ == Type::WWC) { } else if (type_ == Type::WWC) {
snprintf_P(&topic[0], topic.capacity() + 1, "sensor/%s/mixer_wwc%d/config", Mqtt::base().c_str(), hc_); // WWC snprintf(&topic[0], topic.capacity() + 1, "sensor/%s/mixer_wwc%d/config", Mqtt::base().c_str(), hc_); // WWC
} else if (type_ == Type::MP) { } else if (type_ == Type::MP) {
snprintf_P(&topic[0], topic.capacity() + 1, "sensor/%s/mixer_mp/config", Mqtt::base().c_str()); snprintf(&topic[0], topic.capacity() + 1, "sensor/%s/mixer_mp/config", Mqtt::base().c_str());
} }
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag

View File

@@ -194,7 +194,7 @@ bool Solar::publish_ha_config() {
doc["ic"] = F_(icondevice); doc["ic"] = F_(icondevice);
char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE]; char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str()); snprintf(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
doc["stat_t"] = stat_t; doc["stat_t"] = stat_t;
char name_s[40]; char name_s[40];
@@ -211,7 +211,7 @@ bool Solar::publish_ha_config() {
ids.add("ems-esp-solar"); ids.add("ems-esp-solar");
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), "sensor/%s/solar/config", Mqtt::base().c_str()); snprintf(topic, sizeof(topic), "sensor/%s/solar/config", Mqtt::base().c_str());
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
return true; return true;

View File

@@ -53,11 +53,11 @@ bool Switch::publish_ha_config() {
doc["ic"] = F_(icondevice); doc["ic"] = F_(icondevice);
char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE]; char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str()); snprintf(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
doc["stat_t"] = stat_t; doc["stat_t"] = stat_t;
char name_s[40]; char name_s[40];
snprintf_P(name_s, sizeof(name_s), FSTR_(productid_fmt), device_type_name().c_str()); snprintf(name_s, sizeof(name_s), FSTR_(productid_fmt), device_type_name().c_str());
doc["name"] = name_s; doc["name"] = name_s;
doc["val_tpl"] = FJSON("{{value_json.id}}"); doc["val_tpl"] = FJSON("{{value_json.id}}");
@@ -70,7 +70,7 @@ bool Switch::publish_ha_config() {
ids.add("ems-esp-switch"); ids.add("ems-esp-switch");
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), "sensor/%s/switch/config", Mqtt::base().c_str()); snprintf(topic, sizeof(topic), "sensor/%s/switch/config", Mqtt::base().c_str());
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
return true; return true;

View File

@@ -202,7 +202,7 @@ bool Thermostat::publish_ha_config() {
doc["ic"] = F_(icondevice); doc["ic"] = F_(icondevice);
char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE]; char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str()); snprintf(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
doc["stat_t"] = stat_t; doc["stat_t"] = stat_t;
char name_s[40]; char name_s[40];
@@ -219,7 +219,7 @@ bool Thermostat::publish_ha_config() {
ids.add("ems-esp-thermostat"); ids.add("ems-esp-thermostat");
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), "sensor/%s/thermostat/config", Mqtt::base().c_str()); snprintf(topic, sizeof(topic), "sensor/%s/thermostat/config", Mqtt::base().c_str());
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
return true; return true;
@@ -390,13 +390,13 @@ void Thermostat::publish_ha_config_hc(uint8_t hc_num) {
StaticJsonDocument<EMSESP_JSON_SIZE_HA_CONFIG> doc; StaticJsonDocument<EMSESP_JSON_SIZE_HA_CONFIG> doc;
char str1[20]; char str1[20];
snprintf_P(str1, sizeof(str1), "Thermostat hc%d", hc_num); snprintf(str1, sizeof(str1), "Thermostat hc%d", hc_num);
char str2[20]; char str2[20];
snprintf_P(str2, sizeof(str2), "thermostat_hc%d", hc_num); snprintf(str2, sizeof(str2), "thermostat_hc%d", hc_num);
char str3[25]; char str3[25];
snprintf_P(str3, sizeof(str3), "~/%s", str2); snprintf(str3, sizeof(str3), "~/%s", str2);
doc["mode_cmd_t"] = str3; doc["mode_cmd_t"] = str3;
doc["temp_cmd_t"] = str3; doc["temp_cmd_t"] = str3;
doc["name"] = str1; doc["name"] = str1;
@@ -407,23 +407,23 @@ void Thermostat::publish_ha_config_hc(uint8_t hc_num) {
char topic_t[Mqtt::MQTT_TOPIC_MAX_SIZE]; char topic_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
if (Mqtt::nested_format() == 1) { if (Mqtt::nested_format() == 1) {
snprintf_P(topic_t, sizeof(topic_t), "~/%s", Mqtt::tag_to_topic(EMSdevice::DeviceType::THERMOSTAT, DeviceValueTAG::TAG_NONE).c_str()); snprintf(topic_t, sizeof(topic_t), "~/%s", Mqtt::tag_to_topic(EMSdevice::DeviceType::THERMOSTAT, DeviceValueTAG::TAG_NONE).c_str());
char mode_str_tpl[40]; char mode_str_tpl[40];
snprintf_P(mode_str_tpl, sizeof(mode_str_tpl), "{{value_json.hc%d.hamode}}", hc_num); snprintf(mode_str_tpl, sizeof(mode_str_tpl), "{{value_json.hc%d.hamode}}", hc_num);
doc["mode_stat_tpl"] = mode_str_tpl; doc["mode_stat_tpl"] = mode_str_tpl;
char seltemp_str[30]; char seltemp_str[30];
snprintf_P(seltemp_str, sizeof(seltemp_str), "{{value_json.hc%d.seltemp}}", hc_num); snprintf(seltemp_str, sizeof(seltemp_str), "{{value_json.hc%d.seltemp}}", hc_num);
doc["temp_stat_tpl"] = seltemp_str; doc["temp_stat_tpl"] = seltemp_str;
char currtemp_str[30]; char currtemp_str[30];
snprintf_P(currtemp_str, sizeof(currtemp_str), "{{value_json.hc%d.hatemp}}", hc_num); snprintf(currtemp_str, sizeof(currtemp_str), "{{value_json.hc%d.hatemp}}", hc_num);
doc["curr_temp_tpl"] = currtemp_str; doc["curr_temp_tpl"] = currtemp_str;
} else { } else {
snprintf_P(topic_t, sizeof(topic_t), "~/%s", Mqtt::tag_to_topic(EMSdevice::DeviceType::THERMOSTAT, DeviceValueTAG::TAG_HC1 + hc_num - 1).c_str()); snprintf(topic_t, sizeof(topic_t), "~/%s", Mqtt::tag_to_topic(EMSdevice::DeviceType::THERMOSTAT, DeviceValueTAG::TAG_HC1 + hc_num - 1).c_str());
doc["mode_stat_tpl"] = FJSON("{{value_json.hamode}}"); doc["mode_stat_tpl"] = FJSON("{{value_json.hamode}}");
doc["temp_stat_tpl"] = FJSON("{{value_json.seltemp}}"); doc["temp_stat_tpl"] = FJSON("{{value_json.seltemp}}");
@@ -452,12 +452,12 @@ void Thermostat::publish_ha_config_hc(uint8_t hc_num) {
ids.add("ems-esp-thermostat"); ids.add("ems-esp-thermostat");
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), "climate/%s/thermostat_hc%d/config", Mqtt::base().c_str(), hc_num); snprintf(topic, sizeof(topic), "climate/%s/thermostat_hc%d/config", Mqtt::base().c_str(), hc_num);
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
// enable the a special "thermostat_hc<n>" topic to take both mode strings and floats for each of the heating circuits // enable the a special "thermostat_hc<n>" topic to take both mode strings and floats for each of the heating circuits
std::string topic2(Mqtt::MQTT_TOPIC_MAX_SIZE, '\0'); std::string topic2(Mqtt::MQTT_TOPIC_MAX_SIZE, '\0');
snprintf_P(&topic2[0], topic2.capacity() + 1, "thermostat_hc%d", hc_num); snprintf(&topic2[0], topic2.capacity() + 1, "thermostat_hc%d", hc_num);
register_mqtt_topic(topic2, [=](const char * m) { return thermostat_ha_cmd(m, hc_num); }); register_mqtt_topic(topic2, [=](const char * m) { return thermostat_ha_cmd(m, hc_num); });
} }
@@ -1120,15 +1120,15 @@ void Thermostat::process_RCTime(std::shared_ptr<const Telegram> telegram) {
char buf4[6]; char buf4[6];
char buf5[6]; char buf5[6];
char buf6[6]; char buf6[6];
snprintf_P(dateTime_, snprintf(dateTime_,
sizeof(dateTime_), sizeof(dateTime_),
"%s:%s:%s %s/%s/%s", "%s:%s:%s %s/%s/%s",
Helpers::smallitoa(buf1, telegram->message_data[2]), // hour Helpers::smallitoa(buf1, telegram->message_data[2]), // hour
Helpers::smallitoa(buf2, telegram->message_data[4]), // minute Helpers::smallitoa(buf2, telegram->message_data[4]), // minute
Helpers::smallitoa(buf3, telegram->message_data[5]), // second Helpers::smallitoa(buf3, telegram->message_data[5]), // second
Helpers::smallitoa(buf4, telegram->message_data[3]), // day Helpers::smallitoa(buf4, telegram->message_data[3]), // day
Helpers::smallitoa(buf5, telegram->message_data[1]), // month Helpers::smallitoa(buf5, telegram->message_data[1]), // month
Helpers::itoa(buf6, (telegram->message_data[0] & 0x7F) + 2000) // year Helpers::itoa(buf6, (telegram->message_data[0] & 0x7F) + 2000) // year
); );
has_update((strcmp(timeold, dateTime_) != 0)); has_update((strcmp(timeold, dateTime_) != 0));
@@ -1148,7 +1148,7 @@ void Thermostat::process_RCError(std::shared_ptr<const Telegram> telegram) {
buf[2] = telegram->message_data[2]; buf[2] = telegram->message_data[2];
buf[3] = 0; buf[3] = 0;
has_update(telegram->read_value(errorNumber_, 3)); has_update(telegram->read_value(errorNumber_, 3));
snprintf_P(errorCode_, sizeof(errorCode_), "%s(%d)", buf, errorNumber_); snprintf(errorCode_, sizeof(errorCode_), "%s(%d)", buf, errorNumber_);
} }
// 0x12 error log // 0x12 error log
@@ -1170,7 +1170,7 @@ void Thermostat::process_RCErrorMessage(std::shared_ptr<const Telegram> telegram
uint8_t day = telegram->message_data[7]; uint8_t day = telegram->message_data[7];
uint8_t hour = telegram->message_data[6]; uint8_t hour = telegram->message_data[6];
uint8_t min = telegram->message_data[8]; uint8_t min = telegram->message_data[8];
snprintf_P(lastCode_, sizeof(lastCode_), "%s(%d) %02d.%02d.%d %02d:%02d", code, codeNo, day, month, year, hour, min); snprintf(lastCode_, sizeof(lastCode_), "%s(%d) %02d.%02d.%d %02d:%02d", code, codeNo, day, month, year, hour, min);
} }
} }

View File

@@ -126,7 +126,7 @@ void Shower::send_mqtt_stat(bool state, bool force) {
ids.add("ems-esp"); ids.add("ems-esp");
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), "binary_sensor/%s/shower_active/config", Mqtt::base().c_str()); snprintf(topic, sizeof(topic), "binary_sensor/%s/shower_active/config", Mqtt::base().c_str());
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
} }
} }
@@ -161,7 +161,7 @@ void Shower::publish_values() {
// only publish shower duration if there is a value // only publish shower duration if there is a value
if (duration_ > SHOWER_MIN_DURATION) { if (duration_ > SHOWER_MIN_DURATION) {
char s[50]; char s[50];
snprintf_P(s, 50, "%d minutes and %d seconds", (uint8_t)(duration_ / 60000), (uint8_t)((duration_ / 1000) % 60)); snprintf(s, 50, "%d minutes and %d seconds", (uint8_t)(duration_ / 60000), (uint8_t)((duration_ / 1000) % 60));
doc["duration"] = s; doc["duration"] = s;
} }