remove PSTR()

This commit is contained in:
proddy
2021-09-15 18:04:58 +02:00
parent 442202d978
commit d0346e436a
16 changed files with 101 additions and 94 deletions

View File

@@ -4,12 +4,14 @@
## Added
- add system commands for syslog level and watch [#98](https://github.com/emsesp/EMS-ESP32/issues/98)
- Add system commands for syslog level and watch [#98](https://github.com/emsesp/EMS-ESP32/issues/98)
- Added pool data to telegrams 0x494 & 0x495 #102 [#102](https://github.com/emsesp/EMS-ESP32/issues/102) (@Sunbuzz)
- Add RC300 second summermode telegram [#108](https://github.com/emsesp/EMS-ESP32/issues/108)
## Fixed
- MQTT reconnecting after WiFi reconnect [#99](https://github.com/emsesp/EMS-ESP32/issues/99)
- Manually Controlling Solar Circuit [#107](https://github.com/emsesp/EMS-ESP32/issues/107)
## Changed

View File

@@ -77,7 +77,7 @@ void EMSESPShell::display_banner() {
if (console_hostname_.empty()) {
console_hostname_.resize(16, '\0');
snprintf_P(&console_hostname_[0], console_hostname_.capacity() + 1, PSTR("ems-esp"));
snprintf_P(&console_hostname_[0], console_hostname_.capacity() + 1, "ems-esp");
}
// load the list of commands
@@ -841,7 +841,7 @@ EMSESPStreamConsole::EMSESPStreamConsole(Stream & stream, const IPAddress & addr
ptys_[pty_] = true;
}
snprintf_P(text.data(), text.size(), PSTR("pty%u"), pty_);
snprintf_P(text.data(), text.size(), "pty%u", pty_);
name_ = text.data();
#ifndef EMSESP_STANDALONE
logger().info(F("Allocated console %s for connection from [%s]:%u"), name_.c_str(), uuid::printable_to_string(addr_).c_str(), port_);

View File

@@ -301,7 +301,7 @@ std::string DallasSensor::Sensor::id_string() const {
std::string str(20, '\0');
snprintf_P(&str[0],
str.capacity() + 1,
PSTR("%02X-%04X-%04X-%04X"),
"%02X-%04X-%04X-%04X",
(unsigned int)(id_ >> 48) & 0xFF,
(unsigned int)(id_ >> 32) & 0xFFFF,
(unsigned int)(id_ >> 16) & 0xFFFF,
@@ -347,7 +347,7 @@ void DallasSensor::delete_ha_config(uint8_t index, const char * name) {
std::string topicname = name;
std::replace(topicname.begin(), topicname.end(), '-', '_');
snprintf_P(topic, sizeof(topic), PSTR("homeassistant/sensor/%s/dallassensor_%s/config"), Mqtt::base().c_str(), topicname.c_str());
snprintf_P(topic, sizeof(topic), "homeassistant/sensor/%s/dallassensor_%s/config", Mqtt::base().c_str(), topicname.c_str());
Mqtt::publish(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
for (const auto & sensor : sensors_) {
char sensorID[10]; // sensor{1-n}
snprintf_P(sensorID, 10, PSTR("sensor%d"), i++);
snprintf_P(sensorID, 10, "sensor%d", i++);
if (id == -1) { // show number and id
JsonObject dataSensor = json.createNestedObject(sensorID);
dataSensor["id"] = sensor.to_string();
@@ -493,7 +493,7 @@ void DallasSensor::publish_values(const bool force) {
for (const auto & sensor : sensors_) {
char sensorID[10]; // sensor{1-n}
snprintf_P(sensorID, 10, PSTR("sensor%d"), sensor_no);
snprintf_P(sensorID, 10, "sensor%d", sensor_no);
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}}
JsonObject dataSensor = doc.createNestedObject(sensorID);
@@ -513,28 +513,28 @@ void DallasSensor::publish_values(const bool force) {
config["dev_cla"] = FJSON("temperature");
char stat_t[50];
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/dallassensor_data"), Mqtt::base().c_str());
snprintf_P(stat_t, sizeof(stat_t), "%s/dallassensor_data", Mqtt::base().c_str());
config["stat_t"] = stat_t;
config["unit_of_meas"] = FJSON("°C");
char str[50];
if (dallas_format_ != Dallas_Format::NUMBER) {
snprintf_P(str, sizeof(str), PSTR("{{value_json['%s']}}"), sensor.to_string().c_str());
snprintf_P(str, sizeof(str), "{{value_json['%s']}}", sensor.to_string().c_str());
} else {
snprintf_P(str, sizeof(str), PSTR("{{value_json.sensor%d.temp}}"), sensor_no);
snprintf_P(str, sizeof(str), "{{value_json.sensor%d.temp}}", sensor_no);
}
config["val_tpl"] = str;
// name as sensor number not the long unique ID
if (dallas_format_ != Dallas_Format::NUMBER) {
snprintf_P(str, sizeof(str), PSTR("Dallas Sensor %s"), sensor.to_string().c_str());
snprintf_P(str, sizeof(str), "Dallas Sensor %s", sensor.to_string().c_str());
} else {
snprintf_P(str, sizeof(str), PSTR("Dallas Sensor %d"), sensor_no);
snprintf_P(str, sizeof(str), "Dallas Sensor %d", sensor_no);
}
config["name"] = str;
snprintf_P(str, sizeof(str), PSTR("dallasensor_%s"), sensor.to_string().c_str());
snprintf_P(str, sizeof(str), "dallasensor_%s", sensor.to_string().c_str());
config["uniq_id"] = str;
JsonObject dev = config.createNestedObject("dev");
@@ -543,12 +543,12 @@ void DallasSensor::publish_values(const bool force) {
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
if (dallas_format_ == Dallas_Format::NUMBER) {
snprintf_P(topic, sizeof(topic), PSTR("sensor/%s/dallassensor_%d/config"), Mqtt::base().c_str(), sensor_no);
snprintf_P(topic, sizeof(topic), "sensor/%s/dallassensor_%d/config", Mqtt::base().c_str(), sensor_no);
} else {
// use '_' as HA doesn't like '-' in the topic name
std::string topicname = sensor.to_string();
std::replace(topicname.begin(), topicname.end(), '-', '_');
snprintf_P(topic, sizeof(topic), PSTR("sensor/%s/dallassensor_%s/config"), Mqtt::base().c_str(), topicname.c_str());
snprintf_P(topic, sizeof(topic), "sensor/%s/dallassensor_%s/config", Mqtt::base().c_str(), topicname.c_str());
}
Mqtt::publish_ha(topic, config.as<JsonObject>());

View File

@@ -287,7 +287,7 @@ bool Boiler::publish_ha_config() {
doc["ic"] = F_(icondevice);
char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s"), Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
snprintf_P(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;
char name_s[40];
@@ -304,7 +304,7 @@ bool Boiler::publish_ha_config() {
ids.add("ems-esp-boiler");
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), PSTR("sensor/%s/boiler/config"), Mqtt::base().c_str());
snprintf_P(topic, sizeof(topic), "sensor/%s/boiler/config", Mqtt::base().c_str());
Mqtt::publish_ha(topic,
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
if (Helpers::hasValue(message_code) && message_code > 0) {
snprintf_P(maintenanceMessage_, sizeof(maintenanceMessage_), PSTR("H%02d"), message_code);
snprintf_P(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;
// store only the newest code from telegrams 10 and 11
if (date > lastCodeDate_) {
snprintf_P(lastCode_, sizeof(lastCode_), PSTR("%s(%d) %02d.%02d.%d %02d:%02d"), code, codeNo, day, month, year, hour, min);
snprintf_P(lastCode_, sizeof(lastCode_), "%s(%d) %02d.%02d.%d %02d:%02d", code, codeNo, day, month, year, hour, min);
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 year = telegram->message_data[4];
if (day > 0 && month > 0) {
snprintf_P(maintenanceDate_, sizeof(maintenanceDate_), PSTR("%02d.%02d.%04d"), day, month, year + 2000);
snprintf_P(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);
char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s"), Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
snprintf_P(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;
char name_s[40];
@@ -64,7 +64,7 @@ bool Heatpump::publish_ha_config() {
ids.add("ems-esp-heatpump");
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), PSTR("sensor/%s/heatpump/config"), Mqtt::base().c_str());
snprintf_P(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
return true;

View File

@@ -26,7 +26,6 @@ uuid::log::Logger Mixer::logger_{F_(mixer), uuid::log::Facility::CONSOLE};
Mixer::Mixer(uint8_t device_type, uint8_t device_id, uint8_t product_id, const std::string & version, const std::string & name, uint8_t flags, uint8_t brand)
: EMSdevice(device_type, device_id, product_id, version, name, flags, brand) {
LOG_DEBUG(F("Adding new Mixer with device ID 0x%02X"), device_id);
// Pool module
@@ -111,23 +110,23 @@ bool Mixer::publish_ha_config() {
char uniq_id[20];
if (type_ == Type::MP) {
snprintf_P(uniq_id, sizeof(uniq_id), PSTR("MixerMP"));
snprintf_P(uniq_id, sizeof(uniq_id), "MixerMP");
} else {
snprintf_P(uniq_id, sizeof(uniq_id), PSTR("Mixer%02X"), device_id() - 0x20 + 1);
snprintf_P(uniq_id, sizeof(uniq_id), "Mixer%02X", device_id() - 0x20 + 1);
}
doc["uniq_id"] = uniq_id;
doc["ic"] = F_(icondevice);
char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s"), Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
snprintf_P(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;
char name[20];
if (type_ == Type::MP) {
snprintf_P(name, sizeof(name), PSTR("Mixer MP"));
snprintf_P(name, sizeof(name), "Mixer MP");
} else {
snprintf_P(name, sizeof(name), PSTR("Mixer %02X"), device_id() - 0x20 + 1);
snprintf_P(name, sizeof(name), "Mixer %02X", device_id() - 0x20 + 1);
}
doc["name"] = name;
@@ -152,11 +151,11 @@ bool Mixer::publish_ha_config() {
// 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');
if (type_ == Type::HC) {
snprintf_P(&topic[0], topic.capacity() + 1, PSTR("sensor/%s/mixer_hc%d/config"), Mqtt::base().c_str(), hc_);
snprintf_P(&topic[0], topic.capacity() + 1, "sensor/%s/mixer_hc%d/config", Mqtt::base().c_str(), hc_);
} else if (type_ == Type::WWC) {
snprintf_P(&topic[0], topic.capacity() + 1, PSTR("sensor/%s/mixer_wwc%d/config"), Mqtt::base().c_str(), hc_); // WWC
snprintf_P(&topic[0], topic.capacity() + 1, "sensor/%s/mixer_wwc%d/config", Mqtt::base().c_str(), hc_); // WWC
} else if (type_ == Type::MP) {
snprintf_P(&topic[0], topic.capacity() + 1, PSTR("sensor/%s/mixer_mp/config"), Mqtt::base().c_str());
snprintf_P(&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
@@ -228,7 +227,7 @@ void Mixer::process_MMStatusMessage(std::shared_ptr<const Telegram> telegram) {
void Mixer::process_HpPoolStatus(std::shared_ptr<const Telegram> telegram) {
has_update(telegram->read_value(poolTemp_, 0));
has_update(telegram->read_value(poolShuntStatus__, 2));
has_update(telegram->read_value(poolShunt_, 3)); // 0-100% how much is the shunt open?
has_update(telegram->read_value(poolShunt_, 3)); // 0-100% how much is the shunt open?
poolShuntStatus_ = poolShunt_ == 100 ? 3 : (poolShunt_ == 0 ? 4 : poolShuntStatus__);
}
@@ -272,7 +271,7 @@ bool Mixer::set_flowSetTemp(const char * value, const int8_t id) {
return true;
}
if (flags() == EMSdevice::EMS_DEVICE_FLAG_MMPLUS) {
uint8_t hc = device_id() -0x20;
uint8_t hc = device_id() - 0x20;
write_command(0x2E1 + hc, 1, v, 0x2D7 + hc);
return true;
}

View File

@@ -109,8 +109,13 @@ Solar::Solar(uint8_t device_type, uint8_t device_id, uint8_t product_id, const s
register_device_value(TAG_NONE, &solarPumpMinMod_, DeviceValueType::UINT, nullptr, FL_(pumpMinMod), DeviceValueUOM::PERCENT, MAKE_CF_CB(set_PumpMinMod));
register_device_value(
TAG_NONE, &solarPumpTurnonDiff_, DeviceValueType::UINT, FL_(div10), FL_(solarPumpTurnonDiff), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_TurnonDiff));
register_device_value(
TAG_NONE, &solarPumpTurnoffDiff_, DeviceValueType::UINT, FL_(div10), FL_(solarPumpTurnoffDiff), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_TurnoffDiff));
register_device_value(TAG_NONE,
&solarPumpTurnoffDiff_,
DeviceValueType::UINT,
FL_(div10),
FL_(solarPumpTurnoffDiff),
DeviceValueUOM::DEGREES,
MAKE_CF_CB(set_TurnoffDiff));
register_device_value(TAG_NONE, &tankBottomTemp2_, DeviceValueType::SHORT, FL_(div10), FL_(tank2BottomTemp), DeviceValueUOM::DEGREES);
register_device_value(TAG_NONE, &heatExchangerTemp_, DeviceValueType::SHORT, FL_(div10), FL_(heatExchangerTemp), DeviceValueUOM::DEGREES);
register_device_value(TAG_NONE, &cylinderPumpModulation_, DeviceValueType::UINT, nullptr, FL_(cylinderPumpModulation), DeviceValueUOM::PERCENT);
@@ -189,7 +194,7 @@ bool Solar::publish_ha_config() {
doc["ic"] = F_(icondevice);
char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s"), Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
snprintf_P(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;
char name_s[40];
@@ -206,7 +211,7 @@ bool Solar::publish_ha_config() {
ids.add("ems-esp-solar");
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), PSTR("sensor/%s/solar/config"), Mqtt::base().c_str());
snprintf_P(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
return true;

View File

@@ -53,7 +53,7 @@ bool Switch::publish_ha_config() {
doc["ic"] = F_(icondevice);
char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s"), Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
snprintf_P(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;
char name_s[40];
@@ -70,7 +70,7 @@ bool Switch::publish_ha_config() {
ids.add("ems-esp-switch");
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), PSTR("sensor/%s/switch/config"), Mqtt::base().c_str());
snprintf_P(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
return true;

View File

@@ -202,7 +202,7 @@ bool Thermostat::publish_ha_config() {
doc["ic"] = F_(icondevice);
char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s"), Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
snprintf_P(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;
char name_s[40];
@@ -219,7 +219,7 @@ bool Thermostat::publish_ha_config() {
ids.add("ems-esp-thermostat");
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), PSTR("sensor/%s/thermostat/config"), Mqtt::base().c_str());
snprintf_P(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
return true;
@@ -385,13 +385,13 @@ void Thermostat::publish_ha_config_hc(uint8_t hc_num) {
StaticJsonDocument<EMSESP_JSON_SIZE_HA_CONFIG> doc;
char str1[20];
snprintf_P(str1, sizeof(str1), PSTR("Thermostat hc%d"), hc_num);
snprintf_P(str1, sizeof(str1), "Thermostat hc%d", hc_num);
char str2[20];
snprintf_P(str2, sizeof(str2), PSTR("thermostat_hc%d"), hc_num);
snprintf_P(str2, sizeof(str2), "thermostat_hc%d", hc_num);
char str3[25];
snprintf_P(str3, sizeof(str3), PSTR("~/%s"), str2);
snprintf_P(str3, sizeof(str3), "~/%s", str2);
doc["mode_cmd_t"] = str3;
doc["temp_cmd_t"] = str3;
doc["name"] = str1;
@@ -402,23 +402,23 @@ void Thermostat::publish_ha_config_hc(uint8_t hc_num) {
char topic_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
if (Mqtt::nested_format() == 1) {
snprintf_P(topic_t, sizeof(topic_t), PSTR("~/%s"), Mqtt::tag_to_topic(EMSdevice::DeviceType::THERMOSTAT, DeviceValueTAG::TAG_NONE).c_str());
snprintf_P(topic_t, sizeof(topic_t), "~/%s", Mqtt::tag_to_topic(EMSdevice::DeviceType::THERMOSTAT, DeviceValueTAG::TAG_NONE).c_str());
char mode_str_tpl[40];
snprintf_P(mode_str_tpl, sizeof(mode_str_tpl), PSTR("{{value_json.hc%d.hamode}}"), hc_num);
snprintf_P(mode_str_tpl, sizeof(mode_str_tpl), "{{value_json.hc%d.hamode}}", hc_num);
doc["mode_stat_tpl"] = mode_str_tpl;
char seltemp_str[30];
snprintf_P(seltemp_str, sizeof(seltemp_str), PSTR("{{value_json.hc%d.seltemp}}"), hc_num);
snprintf_P(seltemp_str, sizeof(seltemp_str), "{{value_json.hc%d.seltemp}}", hc_num);
doc["temp_stat_tpl"] = seltemp_str;
char currtemp_str[30];
snprintf_P(currtemp_str, sizeof(currtemp_str), PSTR("{{value_json.hc%d.hatemp}}"), hc_num);
snprintf_P(currtemp_str, sizeof(currtemp_str), "{{value_json.hc%d.hatemp}}", hc_num);
doc["curr_temp_tpl"] = currtemp_str;
} else {
snprintf_P(topic_t, sizeof(topic_t), PSTR("~/%s"), Mqtt::tag_to_topic(EMSdevice::DeviceType::THERMOSTAT, DeviceValueTAG::TAG_HC1 + hc_num - 1).c_str());
snprintf_P(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["temp_stat_tpl"] = FJSON("{{value_json.seltemp}}");
@@ -447,12 +447,12 @@ void Thermostat::publish_ha_config_hc(uint8_t hc_num) {
ids.add("ems-esp-thermostat");
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), PSTR("climate/%s/thermostat_hc%d/config"), Mqtt::base().c_str(), hc_num);
snprintf_P(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
// 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');
snprintf_P(&topic2[0], topic2.capacity() + 1, PSTR("thermostat_hc%d"), hc_num);
snprintf_P(&topic2[0], topic2.capacity() + 1, "thermostat_hc%d", hc_num);
register_mqtt_topic(topic2, [=](const char * m) { return thermostat_ha_cmd(m, hc_num); });
}
@@ -1117,7 +1117,7 @@ void Thermostat::process_RCTime(std::shared_ptr<const Telegram> telegram) {
char buf6[6];
snprintf_P(dateTime_,
sizeof(dateTime_),
PSTR("%s:%s:%s %s/%s/%s"),
"%s:%s:%s %s/%s/%s",
Helpers::smallitoa(buf1, telegram->message_data[2]), // hour
Helpers::smallitoa(buf2, telegram->message_data[4]), // minute
Helpers::smallitoa(buf3, telegram->message_data[5]), // second
@@ -1143,7 +1143,7 @@ void Thermostat::process_RCError(std::shared_ptr<const Telegram> telegram) {
buf[2] = telegram->message_data[2];
buf[3] = 0;
has_update(telegram->read_value(errorNumber_, 3));
snprintf_P(errorCode_, sizeof(errorCode_), PSTR("%s(%d)"), buf, errorNumber_);
snprintf_P(errorCode_, sizeof(errorCode_), "%s(%d)", buf, errorNumber_);
}
// 0x12 error log
@@ -1165,7 +1165,7 @@ void Thermostat::process_RCErrorMessage(std::shared_ptr<const Telegram> telegram
uint8_t day = telegram->message_data[7];
uint8_t hour = telegram->message_data[6];
uint8_t min = telegram->message_data[8];
snprintf_P(lastCode_, sizeof(lastCode_), PSTR("%s(%d) %02d.%02d.%d %02d:%02d"), code, codeNo, day, month, year, hour, min);
snprintf_P(lastCode_, sizeof(lastCode_), "%s(%d) %02d.%02d.%d %02d:%02d", code, codeNo, day, month, year, hour, min);
}
}
@@ -2652,7 +2652,8 @@ void Thermostat::register_device_values_hc(std::shared_ptr<Thermostat::HeatingCi
register_device_value(tag, &hc->minflowtemp, DeviceValueType::UINT, nullptr, FL_(minflowtemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_minflowtemp));
register_device_value(tag, &hc->maxflowtemp, DeviceValueType::UINT, nullptr, FL_(maxflowtemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_maxflowtemp));
register_device_value(tag, &hc->tempautotemp, DeviceValueType::UINT, FL_(div2), FL_(tempautotemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_tempautotemp));
register_device_value(tag, &hc->heatingtype, DeviceValueType::ENUM, FL_(enum_heatingtype), FL_(heatingtype), DeviceValueUOM::LIST, MAKE_CF_CB(set_heatingtype));
register_device_value(
tag, &hc->heatingtype, DeviceValueType::ENUM, FL_(enum_heatingtype), FL_(heatingtype), DeviceValueUOM::LIST, MAKE_CF_CB(set_heatingtype));
register_device_value(tag, &hc->summertemp, DeviceValueType::UINT, nullptr, FL_(summertemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_summertemp));
register_device_value(tag, &hc->summermode, DeviceValueType::BOOL, nullptr, FL_(summermode), DeviceValueUOM::BOOLEAN);
break;

View File

@@ -304,16 +304,16 @@ std::string EMSdevice::to_string() const {
// for devices that haven't been lookup yet, don't show all details
if (product_id_ == 0) {
snprintf_P(&str[0], str.capacity() + 1, PSTR("%s (DeviceID:0x%02X)"), name_.c_str(), device_id_);
snprintf_P(&str[0], str.capacity() + 1, "%s (DeviceID:0x%02X)", name_.c_str(), device_id_);
return str;
}
if (brand_ == Brand::NO_BRAND) {
snprintf_P(&str[0], str.capacity() + 1, PSTR("%s (DeviceID:0x%02X, ProductID:%d, Version:%s)"), name_.c_str(), device_id_, product_id_, version_.c_str());
snprintf_P(&str[0], str.capacity() + 1, "%s (DeviceID:0x%02X, ProductID:%d, Version:%s)", name_.c_str(), device_id_, product_id_, version_.c_str());
} else {
snprintf_P(&str[0],
str.capacity() + 1,
PSTR("%s %s (DeviceID:0x%02X ProductID:%d, Version:%s)"),
"%s %s (DeviceID:0x%02X ProductID:%d, Version:%s)",
brand_to_string().c_str(),
name_.c_str(),
device_id_,
@@ -328,9 +328,9 @@ std::string EMSdevice::to_string() const {
std::string EMSdevice::to_string_short() const {
std::string str(160, '\0');
if (brand_ == Brand::NO_BRAND) {
snprintf_P(&str[0], str.capacity() + 1, PSTR("%s: %s"), device_type_name().c_str(), name_.c_str());
snprintf_P(&str[0], str.capacity() + 1, "%s: %s", device_type_name().c_str(), name_.c_str());
} else {
snprintf_P(&str[0], str.capacity() + 1, PSTR("%s: %s %s"), device_type_name().c_str(), brand_to_string().c_str(), name_.c_str());
snprintf_P(&str[0], str.capacity() + 1, "%s: %s %s", device_type_name().c_str(), brand_to_string().c_str(), name_.c_str());
}
return str;
}
@@ -413,7 +413,7 @@ char * EMSdevice::show_telegram_handlers(char * result) {
char str[10];
uint8_t i = 0;
for (const auto & tf : telegram_functions_) {
snprintf_P(str, sizeof(str), PSTR("0x%02X"), tf.telegram_type_id_);
snprintf_P(str, sizeof(str), "0x%02X", tf.telegram_type_id_);
strlcat(result, str, 200);
if (++i < size) {
strlcat(result, " ", 200);
@@ -961,7 +961,7 @@ bool EMSdevice::generate_values_json(JsonObject & root, const uint8_t tag_filter
time_value = (divider) ? time_value / divider : time_value; // sometimes we need to divide by 60
if (console) {
char time_s[40];
snprintf_P(time_s, sizeof(time_s), PSTR("%d days %d hours %d minutes"), (time_value / 1440), ((time_value % 1440) / 60), (time_value % 60));
snprintf_P(time_s, sizeof(time_s), "%d days %d hours %d minutes", (time_value / 1440), ((time_value % 1440) / 60), (time_value % 60));
json[name] = time_s;
} else {
json[name] = time_value;

View File

@@ -520,7 +520,7 @@ void EMSESP::publish_device_values(uint8_t device_type) {
// publish it under a single topic, only if we have data to publish
if (need_publish) {
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), PSTR("%s_data"), EMSdevice::device_type_2_device_name(device_type).c_str());
snprintf_P(topic, sizeof(topic), "%s_data", EMSdevice::device_type_2_device_name(device_type).c_str());
Mqtt::publish(topic, json);
}
}
@@ -580,7 +580,7 @@ bool EMSESP::get_device_value_info(JsonObject & root, const char * cmd, const in
uint8_t i = 1;
for (const auto & sensor : EMSESP::sensor_devices()) {
char sensorID[10];
snprintf_P(sensorID, 10, PSTR("sensor%d"), i++);
snprintf_P(sensorID, 10, "sensor%d", i++);
if ((strcmp(cmd, sensorID) == 0) || (strcmp(cmd, Helpers::toLower(sensor.to_string()).c_str()) == 0)) {
root["name"] = sensor.to_string();
if (Helpers::hasValue(sensor.temperature_c)) {
@@ -669,7 +669,7 @@ std::string EMSESP::pretty_telegram(std::shared_ptr<const Telegram> telegram) {
if (offset) {
snprintf_P(&str[0],
str.capacity() + 1,
PSTR("%s(0x%02X) %s %s(0x%02X), %s(0x%02X), data: %s (offset %d)"),
"%s(0x%02X) %s %s(0x%02X), %s(0x%02X), data: %s (offset %d)",
src_name.c_str(),
src,
direction.c_str(),
@@ -682,7 +682,7 @@ std::string EMSESP::pretty_telegram(std::shared_ptr<const Telegram> telegram) {
} else {
snprintf_P(&str[0],
str.capacity() + 1,
PSTR("%s(0x%02X) %s %s(0x%02X), %s(0x%02X), data: %s"),
"%s(0x%02X) %s %s(0x%02X), %s(0x%02X), data: %s",
src_name.c_str(),
src,
direction.c_str(),
@@ -759,7 +759,7 @@ void EMSESP::process_version(std::shared_ptr<const Telegram> telegram) {
// get version as XX.XX
std::string version(6, '\0');
snprintf_P(&version[0], version.capacity() + 1, PSTR("%02d.%02d"), telegram->message_data[offset + 1], telegram->message_data[offset + 2]);
snprintf_P(&version[0], version.capacity() + 1, "%02d.%02d", telegram->message_data[offset + 1], telegram->message_data[offset + 2]);
// some devices store the protocol type (HT3, Buderus) in the last byte
uint8_t brand;

View File

@@ -265,9 +265,9 @@ void Mqtt::show_mqtt(uuid::console::Shell & shell) {
auto content = message.content_;
char topic[MQTT_TOPIC_MAX_SIZE];
if ((strncmp(content->topic.c_str(), "homeassistant/", 13) != 0)) {
snprintf_P(topic, sizeof(topic), PSTR("%s/%s"), Mqtt::base().c_str(), content->topic.c_str());
snprintf_P(topic, sizeof(topic), "%s/%s", Mqtt::base().c_str(), content->topic.c_str());
} else {
snprintf_P(topic, sizeof(topic), PSTR("%s"), content->topic.c_str());
snprintf_P(topic, sizeof(topic), "%s", content->topic.c_str());
}
if (content->operation == Operation::PUBLISH) {
@@ -553,7 +553,7 @@ void Mqtt::start() {
// create will_topic with the base prefixed. It has to be static because asyncmqttclient destroys the reference
static char will_topic[MQTT_TOPIC_MAX_SIZE];
snprintf_P(will_topic, MQTT_TOPIC_MAX_SIZE, PSTR("%s/status"), mqtt_base_.c_str());
snprintf_P(will_topic, MQTT_TOPIC_MAX_SIZE, "%s/status", mqtt_base_.c_str());
mqttClient_->setWill(will_topic, 1, true, "offline"); // with qos 1, retain true
mqttClient_->onMessage([this](char * topic, char * payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
@@ -707,7 +707,7 @@ void Mqtt::ha_status() {
ids.add("ems-esp");
char topic[MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), PSTR("sensor/%s/system/config"), mqtt_base_.c_str());
snprintf_P(topic, sizeof(topic), "sensor/%s/system/config", mqtt_base_.c_str());
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
// create the sensors - must match the MQTT payload keys
@@ -868,7 +868,7 @@ void Mqtt::process_queue() {
// leave topic as it is
strcpy(topic, message->topic.c_str());
} else {
snprintf_P(topic, MQTT_TOPIC_MAX_SIZE, PSTR("%s/%s"), mqtt_base_.c_str(), message->topic.c_str());
snprintf_P(topic, MQTT_TOPIC_MAX_SIZE, "%s/%s", mqtt_base_.c_str(), message->topic.c_str());
}
// if we're subscribing...
@@ -966,29 +966,29 @@ void Mqtt::publish_mqtt_ha_sensor(uint8_t type, // EMSdevice
// create entity by add the tag if present, seperating with a .
char new_entity[50];
if (have_tag) {
snprintf_P(new_entity, sizeof(new_entity), PSTR("%s.%s"), EMSdevice::tag_to_string(tag).c_str(), uuid::read_flash_string(entity).c_str());
snprintf_P(new_entity, sizeof(new_entity), "%s.%s", EMSdevice::tag_to_string(tag).c_str(), uuid::read_flash_string(entity).c_str());
} else {
snprintf_P(new_entity, sizeof(new_entity), PSTR("%s"), uuid::read_flash_string(entity).c_str());
snprintf_P(new_entity, sizeof(new_entity), "%s", uuid::read_flash_string(entity).c_str());
}
// build unique identifier which will be used in the topic
// and replacing all . with _ as not to break HA
std::string uniq(50, '\0');
snprintf_P(&uniq[0], uniq.capacity() + 1, PSTR("%s_%s"), device_name, new_entity);
snprintf_P(&uniq[0], uniq.capacity() + 1, "%s_%s", device_name, new_entity);
std::replace(uniq.begin(), uniq.end(), '.', '_');
doc["uniq_id"] = uniq;
// state topic
char stat_t[MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), PSTR("~/%s"), tag_to_topic(device_type, tag).c_str());
snprintf_P(stat_t, sizeof(stat_t), "~/%s", tag_to_topic(device_type, tag).c_str());
doc["stat_t"] = stat_t;
// name = <device> <tag> <name>
char new_name[80];
if (have_tag) {
snprintf_P(new_name, sizeof(new_name), PSTR("%s %s %s"), device_name, EMSdevice::tag_to_string(tag).c_str(), uuid::read_flash_string(name).c_str());
snprintf_P(new_name, sizeof(new_name), "%s %s %s", device_name, EMSdevice::tag_to_string(tag).c_str(), uuid::read_flash_string(name).c_str());
} else {
snprintf_P(new_name, sizeof(new_name), PSTR("%s %s"), device_name, uuid::read_flash_string(name).c_str());
snprintf_P(new_name, sizeof(new_name), "%s %s", device_name, uuid::read_flash_string(name).c_str());
}
new_name[0] = toupper(new_name[0]); // capitalize first letter
doc["name"] = new_name;
@@ -997,9 +997,9 @@ void Mqtt::publish_mqtt_ha_sensor(uint8_t type, // EMSdevice
// if its nested mqtt format then use the appended entity name, otherwise take the original
char val_tpl[50];
if (is_nested) {
snprintf_P(val_tpl, sizeof(val_tpl), PSTR("{{value_json.%s}}"), new_entity);
snprintf_P(val_tpl, sizeof(val_tpl), "{{value_json.%s}}", new_entity);
} else {
snprintf_P(val_tpl, sizeof(val_tpl), PSTR("{{value_json.%s}}"), uuid::read_flash_string(entity).c_str());
snprintf_P(val_tpl, sizeof(val_tpl), "{{value_json.%s}}", uuid::read_flash_string(entity).c_str());
}
doc["val_tpl"] = val_tpl;
@@ -1008,7 +1008,7 @@ void Mqtt::publish_mqtt_ha_sensor(uint8_t type, // EMSdevice
// look at the device value type
if (type == DeviceValueType::BOOL) {
// binary sensor
snprintf_P(topic, sizeof(topic), PSTR("binary_sensor/%s/%s/config"), mqtt_base_.c_str(), uniq.c_str()); // topic
snprintf_P(topic, sizeof(topic), "binary_sensor/%s/%s/config", mqtt_base_.c_str(), uniq.c_str()); // topic
// how to render boolean. HA only accepts String values
char result[10];
@@ -1016,7 +1016,7 @@ void Mqtt::publish_mqtt_ha_sensor(uint8_t type, // EMSdevice
doc[F("payload_off")] = Helpers::render_boolean(result, false);
} else {
// normal HA sensor, not a boolean one
snprintf_P(topic, sizeof(topic), PSTR("sensor/%s/%s/config"), mqtt_base_.c_str(), uniq.c_str()); // topic
snprintf_P(topic, sizeof(topic), "sensor/%s/%s/config", mqtt_base_.c_str(), uniq.c_str()); // topic
bool set_state_class = false;
@@ -1089,7 +1089,7 @@ void Mqtt::publish_mqtt_ha_sensor(uint8_t type, // EMSdevice
ids.add("ems-esp");
} else {
char ha_device[40];
snprintf_P(ha_device, sizeof(ha_device), PSTR("ems-esp-%s"), device_name);
snprintf_P(ha_device, sizeof(ha_device), "ems-esp-%s", device_name);
ids.add(ha_device);
}

View File

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

View File

@@ -797,8 +797,8 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
// fit it up, to its limit of the Json buffer (which is about 169 records)
for (uint8_t i = 0; i < 200; i++) {
snprintf_P(key, 7, PSTR("key%03d"), i);
snprintf_P(value, 7, PSTR("val%03d"), i);
snprintf_P(key, 7, "key%03d", i);
snprintf_P(value, 7, "val%03d", i);
doc[key] = value;
}
doc.shrinkToFit();

View File

@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.2.2b4"
#define EMSESP_APP_VERSION "3.2.2b5"

View File

@@ -69,11 +69,11 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) {
for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) {
char buf[20];
snprintf_P(buf, sizeof(buf), PSTR("sensor_id%d"), i);
snprintf_P(buf, sizeof(buf), "sensor_id%d", i);
root[buf] = settings.sensor[i].id;
snprintf_P(buf, sizeof(buf), PSTR("sensor_name%d"), i);
snprintf_P(buf, sizeof(buf), "sensor_name%d", i);
root[buf] = settings.sensor[i].name;
snprintf_P(buf, sizeof(buf), PSTR("sensor_offset%d"), i);
snprintf_P(buf, sizeof(buf), "sensor_offset%d", i);
root[buf] = settings.sensor[i].offset;
}
}
@@ -207,11 +207,11 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) {
char buf[20];
snprintf_P(buf, sizeof(buf), PSTR("sensor_id%d"), i);
snprintf_P(buf, sizeof(buf), "sensor_id%d", i);
settings.sensor[i].id = root[buf] | EMSESP_DEFAULT_SENSOR_NAME;
snprintf_P(buf, sizeof(buf), PSTR("sensor_name%d"), i);
snprintf_P(buf, sizeof(buf), "sensor_name%d", i);
settings.sensor[i].name = root[buf] | EMSESP_DEFAULT_SENSOR_NAME;
snprintf_P(buf, sizeof(buf), PSTR("sensor_offset%d"), i);
snprintf_P(buf, sizeof(buf), "sensor_offset%d", i);
settings.sensor[i].offset = root[buf] | 0;
}