rename DeviceValueType::TEXT to STRING and ignore UOM if its NONE

This commit is contained in:
proddy
2021-09-20 21:42:24 +02:00
parent 1a71921fd6
commit d8add7edcb
2 changed files with 17 additions and 13 deletions

View File

@@ -125,7 +125,7 @@ const std::string EMSdevice::tag_to_mqtt(uint8_t tag) {
} }
const std::string EMSdevice::uom_to_string(uint8_t uom) { const std::string EMSdevice::uom_to_string(uint8_t uom) {
if (uom == DeviceValueUOM::NONE) { if ((uom == DeviceValueUOM::NONE) || (uom == DeviceValueUOM::TEXT)) {
return std::string{}; return std::string{};
} }
return uuid::read_flash_string(DeviceValueUOM_s[uom - 1]); // offset by 1 to account for NONE return uuid::read_flash_string(DeviceValueUOM_s[uom - 1]); // offset by 1 to account for NONE
@@ -484,7 +484,7 @@ void EMSdevice::register_device_value(uint8_t tag,
int32_t min, int32_t min,
uint32_t max) { uint32_t max) {
// init the value depending on it's type // init the value depending on it's type
if (type == DeviceValueType::TEXT) { if (type == DeviceValueType::STRING) {
*(char *)(value_p) = {'\0'}; *(char *)(value_p) = {'\0'};
} else if (type == DeviceValueType::INT) { } else if (type == DeviceValueType::INT) {
*(int8_t *)(value_p) = EMS_VALUE_INT_NOTSET; *(int8_t *)(value_p) = EMS_VALUE_INT_NOTSET;
@@ -577,7 +577,7 @@ const std::string EMSdevice::get_value_uom(const char * key) {
if (dv.full_name != nullptr) { if (dv.full_name != nullptr) {
if (uuid::read_flash_string(dv.full_name) == p) { if (uuid::read_flash_string(dv.full_name) == p) {
// ignore TIME since "minutes" is already added to the string value // ignore TIME since "minutes" is already added to the string value
if ((dv.uom == DeviceValueUOM::NONE) || (dv.uom == DeviceValueUOM::MINUTES)) { if ((dv.uom == DeviceValueUOM::NONE) || (dv.uom == DeviceValueUOM::TEXT) || (dv.uom == DeviceValueUOM::MINUTES)) {
break; break;
} }
return EMSdevice::uom_to_string(dv.uom); return EMSdevice::uom_to_string(dv.uom);
@@ -606,7 +606,7 @@ void EMSdevice::generate_values_json_web(JsonObject & json) {
} }
// handle TEXT strings // handle TEXT strings
else if ((dv.type == DeviceValueType::TEXT) && (Helpers::hasValue((char *)(dv.value_p)))) { else if ((dv.type == DeviceValueType::STRING) && (Helpers::hasValue((char *)(dv.value_p)))) {
obj = data.createNestedObject(); obj = data.createNestedObject();
obj["v"] = (char *)(dv.value_p); obj["v"] = (char *)(dv.value_p);
} }
@@ -719,7 +719,9 @@ bool EMSdevice::get_value_info(JsonObject & root, const char * cmd, const int8_t
// search device value with this tag // search device value with this tag
for (auto & dv : devicevalues_) { for (auto & dv : devicevalues_) {
if (strcmp(cmd, Helpers::toLower(uuid::read_flash_string(dv.short_name)).c_str()) == 0 && (tag <= 0 || tag == dv.tag)) { // ignore any device values which have a uom of NONE as we use this to hide them
if ((dv.uom != DeviceValueUOM::NONE)
&& (strcmp(cmd, Helpers::toLower(uuid::read_flash_string(dv.short_name)).c_str()) == 0 && (tag <= 0 || tag == dv.tag))) {
uint8_t divider = 0; uint8_t divider = 0;
uint8_t factor = 1; uint8_t factor = 1;
if (dv.options_size == 1) { if (dv.options_size == 1) {
@@ -849,7 +851,7 @@ bool EMSdevice::get_value_info(JsonObject & root, const char * cmd, const int8_t
json[max] = divider ? EMS_VALUE_ULONG_NOTSET / divider : EMS_VALUE_ULONG_NOTSET; json[max] = divider ? EMS_VALUE_ULONG_NOTSET / divider : EMS_VALUE_ULONG_NOTSET;
break; break;
case DeviceValueType::TEXT: case DeviceValueType::STRING:
if (Helpers::hasValue((char *)(dv.value_p))) { if (Helpers::hasValue((char *)(dv.value_p))) {
json[value] = (char *)(dv.value_p); json[value] = (char *)(dv.value_p);
} }
@@ -906,9 +908,10 @@ bool EMSdevice::generate_values_json(JsonObject & root, const uint8_t tag_filter
bool has_value = false; bool has_value = false;
// only show if tag is either empty (TAG_NONE) or matches a value // only show if tag is either empty (TAG_NONE) or matches a value
// and don't show if full_name is empty unless we're outputing for mqtt payloads // and don't show if full_name is empty unless we're outputing for mqtt payloads
// and ignore anything that has an UOM of "NONE" as these are hidden values (e.g. id and hamode)
// for nested we use all values, dont show command only (have_cmd and no fullname) // for nested we use all values, dont show command only (have_cmd and no fullname)
if (((nested) || tag_filter == DeviceValueTAG::TAG_NONE || (tag_filter == dv.tag)) && (dv.full_name != nullptr || !console) if (((nested) || tag_filter == DeviceValueTAG::TAG_NONE || (tag_filter == dv.tag)) && (dv.full_name != nullptr || !console)
&& !(dv.full_name == nullptr && dv.has_cmd)) { && !(dv.full_name == nullptr && dv.has_cmd) && (dv.uom != DeviceValueUOM::NONE)) {
// we have a tag if it matches the filter given, and that the tag name is not empty/"" // we have a tag if it matches the filter given, and that the tag name is not empty/""
bool have_tag = ((dv.tag != tag_filter) && !tag_to_string(dv.tag).empty()); bool have_tag = ((dv.tag != tag_filter) && !tag_to_string(dv.tag).empty());
@@ -950,7 +953,7 @@ bool EMSdevice::generate_values_json(JsonObject & root, const uint8_t tag_filter
} }
// handle TEXT strings // handle TEXT strings
else if ((dv.type == DeviceValueType::TEXT) && (Helpers::hasValue((char *)(dv.value_p)))) { else if ((dv.type == DeviceValueType::STRING) && (Helpers::hasValue((char *)(dv.value_p)))) {
json[name] = (char *)(dv.value_p); json[name] = (char *)(dv.value_p);
has_value = true; has_value = true;
} }

View File

@@ -39,7 +39,7 @@ enum DeviceValueType : uint8_t {
ULONG, ULONG,
TIME, // same as ULONG (32 bits) TIME, // same as ULONG (32 bits)
ENUM, ENUM,
TEXT, STRING,
CMD // special for commands only CMD // special for commands only
}; };
@@ -66,7 +66,8 @@ enum DeviceValueUOM : uint8_t {
DBM, // 14 DBM, // 14
NUM, // 15 NUM, // 15
BOOLEAN, // 16 BOOLEAN, // 16
LIST // 17 LIST, // 17
TEXT // 18
}; };