This commit is contained in:
MichaelDvP
2022-10-11 09:34:56 +02:00
13 changed files with 146 additions and 156 deletions

View File

@@ -81,7 +81,7 @@ std::string EMSdevice::brand_to_string() const {
}
// returns the name of the MQTT topic to use for a specific device, without the base
std::string EMSdevice::device_type_2_device_name(const uint8_t device_type) {
const char * EMSdevice::device_type_2_device_name(const uint8_t device_type) {
switch (device_type) {
case DeviceType::SYSTEM:
return F_(system);
@@ -259,7 +259,7 @@ bool EMSdevice::has_tag(const uint8_t tag) const {
// called from the command 'entities'
void EMSdevice::list_device_entries(JsonObject & output) const {
for (const auto & dv : devicevalues_) {
std::string fullname = dv.get_fullname();
auto fullname = dv.get_fullname();
if (!dv.has_state(DeviceValueState::DV_WEB_EXCLUDE) && dv.type != DeviceValueType::CMD && !fullname.empty()) {
// if we have a tag prefix it
char key[50];
@@ -637,9 +637,9 @@ void EMSdevice::publish_value(void * value_p) const {
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
if (Mqtt::publish_single2cmd()) {
if (dv.tag >= DeviceValueTAG::TAG_HC1) {
snprintf(topic, sizeof(topic), "%s/%s/%s", device_type_2_device_name(device_type_).c_str(), tag_to_mqtt(dv.tag).c_str(), dv.short_name);
snprintf(topic, sizeof(topic), "%s/%s/%s", device_type_2_device_name(device_type_), tag_to_mqtt(dv.tag).c_str(), dv.short_name);
} else {
snprintf(topic, sizeof(topic), "%s/%s", device_type_2_device_name(device_type_).c_str(), dv.short_name);
snprintf(topic, sizeof(topic), "%s/%s", device_type_2_device_name(device_type_), (dv.short_name));
}
} else if (Mqtt::is_nested() && dv.tag >= DeviceValueTAG::TAG_HC1) {
snprintf(topic, sizeof(topic), "%s/%s/%s", Mqtt::tag_to_topic(device_type_, dv.tag).c_str(), tag_to_mqtt(dv.tag).c_str(), dv.short_name);
@@ -662,7 +662,7 @@ void EMSdevice::publish_value(void * value_p) const {
Helpers::render_value(payload, *(uint8_t *)(value_p), 0);
} else {
auto enum_str = Helpers::translated_word(dv.options[*(uint8_t *)(value_p)]);
strlcpy(payload, enum_str.c_str(), sizeof(payload));
strlcpy(payload, enum_str, sizeof(payload));
}
}
break;
@@ -714,9 +714,9 @@ std::string EMSdevice::get_value_uom(const char * key) const {
for (uint8_t i = 0; i < DeviceValue::tag_count; i++) {
auto tag = Helpers::translated_word(DeviceValue::DeviceValueTAG_s[i]);
if (tag.empty()) {
if (tag) {
std::string key2 = key; // copy string to a std::string so we can use the find function
uint8_t length = tag.length();
uint8_t length = strlen(tag);
if ((key2.find(tag) != std::string::npos) && (key[length] == ' ')) {
key_p += length + 1; // remove the tag
break;
@@ -823,7 +823,7 @@ void EMSdevice::generate_values_web(JsonObject & output) {
JsonArray l = obj.createNestedArray("l");
for (uint8_t i = 0; i < dv.options_size; i++) {
auto enum_str = Helpers::translated_word(dv.options[i]);
if (!enum_str.empty()) {
if (enum_str) {
l.add(enum_str);
}
}
@@ -917,12 +917,12 @@ void EMSdevice::generate_values_web_customization(JsonArray & output) {
// don't add the fullname if its a command
auto fullname = Helpers::translated_word(dv.fullname);
if (dv.type != DeviceValueType::CMD) {
if (!fullname.empty()) {
if (fullname) {
if ((dv.tag == DeviceValueTAG::TAG_NONE) || tag_to_string(dv.tag).empty()) {
obj["n"] = fullname;
} else {
char name[50];
snprintf(name, sizeof(name), "%s %s", tag_to_string(dv.tag).c_str(), fullname.c_str());
snprintf(name, sizeof(name), "%s %s", tag_to_string(dv.tag).c_str(), fullname);
obj["n"] = name;
}
}
@@ -933,7 +933,7 @@ void EMSdevice::generate_values_web_customization(JsonArray & output) {
obj["cn"] = custom_fullname;
}
} else {
obj["n"] = "!" + fullname; // prefix commands with a !
obj["n"] = "!" + std::string(fullname); // prefix commands with a !
}
obj["m"] = dv.state >> 4; // send back the mask state. We're only interested in the high nibble
@@ -1357,11 +1357,11 @@ bool EMSdevice::generate_values(JsonObject & output, const uint8_t tag_filter, c
sizeof(time_s),
"%d %s %d %s %d %s",
(time_value / 1440),
Helpers::translated_word(FL_(days)).c_str(),
Helpers::translated_word(FL_(days)),
((time_value % 1440) / 60),
Helpers::translated_word(FL_(hours)).c_str(),
Helpers::translated_word(FL_(hours)),
(time_value % 60),
Helpers::translated_word(FL_(minutes)).c_str());
Helpers::translated_word(FL_(minutes)));
json[name] = time_s;
} else {
json[name] = time_value;