better fix for ha climate Optimize flash with ESP32 #646

This commit is contained in:
Proddy
2022-10-01 16:03:04 +02:00
parent 90d2144588
commit 4c70da28e6
4 changed files with 11 additions and 16 deletions

View File

@@ -390,7 +390,7 @@ void EMSdevice::register_telegram_type(const uint16_t telegram_type_id, const ch
// type: one of DeviceValueType // type: one of DeviceValueType
// options: options for enum, which are translated as a list of lists // options: options for enum, which are translated as a list of lists
// options_single: list of names // options_single: list of names
// numeric_operatpr: to divide or multiply, see DeviceValueNumOps:: // numeric_operator: to divide or multiply, see DeviceValueNumOps::
// short_name: used in Mqtt as keys // short_name: used in Mqtt as keys
// fullname: used in Web and Console unless empty (nullptr) - can be translated // fullname: used in Web and Console unless empty (nullptr) - can be translated
// uom: unit of measure from DeviceValueUOM // uom: unit of measure from DeviceValueUOM

View File

@@ -264,7 +264,7 @@ MAKE_PSTR(response, "response")
MAKE_PSTR(tag_boiler_data_ww_mqtt, "ww") MAKE_PSTR(tag_boiler_data_ww_mqtt, "ww")
MAKE_PSTR(tag_device_data_ww_mqtt, "") MAKE_PSTR(tag_device_data_ww_mqtt, "")
MAKE_PSTR_LIST(climate, "HA climate config creation") MAKE_PSTR_LIST(climate, "HA climate config creation", "")
// syslog // syslog
MAKE_PSTR_LIST(list_syslog_level, "off", "emerg", "alert", "crit", "error", "warn", "notice", "info", "debug", "trace", "all") MAKE_PSTR_LIST(list_syslog_level, "off", "emerg", "alert", "crit", "error", "warn", "notice", "info", "debug", "trace", "all")

View File

@@ -755,12 +755,8 @@ void Mqtt::publish_retain(const char * topic, const JsonObject & payload, bool r
} }
} }
void Mqtt::publish_ha(const char * topic, const JsonObject & payload) {
publish_ha(std::string(topic), payload);
}
// publish empty payload to remove the topic // publish empty payload to remove the topic
void Mqtt::publish_ha(const std::string & topic) { void Mqtt::publish_ha(const char * topic) {
if (!enabled()) { if (!enabled()) {
return; return;
} }
@@ -774,7 +770,7 @@ void Mqtt::publish_ha(const std::string & topic) {
} }
// publish a Home Assistant config topic and payload, with retain flag off. // publish a Home Assistant config topic and payload, with retain flag off.
void Mqtt::publish_ha(const std::string & topic, const JsonObject & payload) { void Mqtt::publish_ha(const char * topic, const JsonObject & payload) {
if (!enabled()) { if (!enabled()) {
return; return;
} }
@@ -928,7 +924,7 @@ void Mqtt::publish_ha_sensor_config(DeviceValue & dv, const std::string & model,
publish_ha_sensor_config(dv.type, publish_ha_sensor_config(dv.type,
dv.tag, dv.tag,
dv.get_fullname(), dv.get_fullname().c_str(),
dv.fullname[0], dv.fullname[0],
dv.device_type, dv.device_type,
dv.short_name, dv.short_name,
@@ -950,7 +946,7 @@ void Mqtt::publish_system_ha_sensor_config(uint8_t type, const char * name, cons
JsonArray ids = dev_json.createNestedArray("ids"); JsonArray ids = dev_json.createNestedArray("ids");
ids.add("ems-esp"); ids.add("ems-esp");
publish_ha_sensor_config(type, DeviceValueTAG::TAG_HEARTBEAT, std::string(name), name, EMSdevice::DeviceType::SYSTEM, entity, uom, false, false, nullptr, 0, 0, 0, dev_json); publish_ha_sensor_config(type, DeviceValueTAG::TAG_HEARTBEAT, name, name, EMSdevice::DeviceType::SYSTEM, entity, uom, false, false, nullptr, 0, 0, 0, dev_json);
} }
// MQTT discovery configs // MQTT discovery configs
@@ -958,7 +954,7 @@ void Mqtt::publish_system_ha_sensor_config(uint8_t type, const char * name, cons
// note: some extra string copying done here, it looks messy but does help with heap fragmentation issues // note: some extra string copying done here, it looks messy but does help with heap fragmentation issues
void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdevice::DeviceValueType void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdevice::DeviceValueType
uint8_t tag, // EMSdevice::DeviceValueTAG uint8_t tag, // EMSdevice::DeviceValueTAG
const std::string & fullname, // fullname, already translated const char * const fullname, // fullname, already translated
const char * const en_name, const char * const en_name,
const uint8_t device_type, // EMSdevice::DeviceType const uint8_t device_type, // EMSdevice::DeviceType
const char * const entity, // same as shortname const char * const entity, // same as shortname
@@ -971,7 +967,7 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdevice
const int16_t dv_set_max, const int16_t dv_set_max,
const JsonObject & dev_json) { const JsonObject & dev_json) {
// ignore if name (fullname) is empty // ignore if name (fullname) is empty
if (fullname.empty() || en_name == nullptr) { if (fullname == nullptr || en_name == nullptr) {
return; return;
} }
@@ -1106,7 +1102,7 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdevice
// friendly name = <tag> <name> // friendly name = <tag> <name>
char ha_name[70]; char ha_name[70];
char * F_name = strdup(fullname.c_str()); char * F_name = strdup(fullname);
F_name[0] = toupper(F_name[0]); // capitalize first letter F_name[0] = toupper(F_name[0]); // capitalize first letter
if (have_tag) { if (have_tag) {
snprintf(ha_name, sizeof(ha_name), "%s %s", EMSdevice::tag_to_string(tag).c_str(), F_name); snprintf(ha_name, sizeof(ha_name), "%s %s", EMSdevice::tag_to_string(tag).c_str(), F_name);

View File

@@ -86,15 +86,14 @@ class Mqtt {
static void publish_retain(const std::string & topic, const JsonObject & payload, bool retain); static void publish_retain(const std::string & topic, const JsonObject & payload, bool retain);
static void publish_retain(const char * topic, const std::string & payload, bool retain); static void publish_retain(const char * topic, const std::string & payload, bool retain);
static void publish_retain(const char * topic, const JsonObject & payload, bool retain); static void publish_retain(const char * topic, const JsonObject & payload, bool retain);
static void publish_ha(const std::string & topic, const JsonObject & payload);
static void publish_ha(const char * topic, const JsonObject & payload); static void publish_ha(const char * topic, const JsonObject & payload);
static void publish_ha(const std::string & topic); static void publish_ha(const char * topic);
static void static void
publish_ha_sensor_config(DeviceValue & dv, const std::string & model, const std::string & brand, const bool remove, const bool create_device_config = false); publish_ha_sensor_config(DeviceValue & dv, const std::string & model, const std::string & brand, const bool remove, const bool create_device_config = false);
static void publish_ha_sensor_config(uint8_t type, static void publish_ha_sensor_config(uint8_t type,
uint8_t tag, uint8_t tag,
const std::string & fullname, const char * const fullname,
const char * const en_name, const char * const en_name,
const uint8_t device_type, const uint8_t device_type,
const char * const entity, const char * const entity,