diff --git a/interface/src/app/main/CustomEntities.tsx b/interface/src/app/main/CustomEntities.tsx index a928d8181..59fc4f204 100644 --- a/interface/src/app/main/CustomEntities.tsx +++ b/interface/src/app/main/CustomEntities.tsx @@ -310,13 +310,15 @@ const CustomEntities = () => { /> )} + {ei.ram > 0 ? '' : showHex(ei.device_id as number, 2)} + {ei.ram > 0 ? '' : showHex(ei.type_id as number, 3)} + {ei.ram > 0 ? '' : ei.offset} - {ei.ram === 1 ? '' : showHex(ei.device_id as number, 2)} - - {ei.ram === 1 ? '' : showHex(ei.type_id as number, 3)} - {ei.ram === 1 ? '' : ei.offset} - - {ei.ram === 1 ? 'RAM' : DeviceValueTypeNames[ei.value_type]} + {ei.ram === 1 + ? 'RAM' + : ei.ram === 2 + ? 'NVS' + : DeviceValueTypeNames[ei.value_type]} {formatValue(ei.value, ei.uom)} diff --git a/interface/src/app/main/CustomEntitiesDialog.tsx b/interface/src/app/main/CustomEntitiesDialog.tsx index 3041f0bba..1ec409d6e 100644 --- a/interface/src/app/main/CustomEntitiesDialog.tsx +++ b/interface/src/app/main/CustomEntitiesDialog.tsx @@ -205,9 +205,10 @@ const CustomEntitiesDialog = ({ > EMS-{LL.VALUE(1)} RAM-{LL.VALUE(1)} + NVS-{LL.VALUE(1)} - {editItem.ram === 1 && ( + {editItem.ram > 0 && ( <> (); + entityItem.data = ei["value"].as().c_str(); strlcpy(entityItem.name, ei["name"].as(), sizeof(entityItem.name)); - if (entityItem.ram == 1) { + if (entityItem.ram > 0) { entityItem.device_id = 0; entityItem.type_id = 0; entityItem.value_type = DeviceValueType::STRING; @@ -127,7 +132,15 @@ StateUpdateResult WebCustomEntity::update(JsonObject root, WebCustomEntity & web if (entityItem.factor == 0) { entityItem.factor = 1; } - + if (entityItem.ram == 2) { // NVS + char key[sizeof(entityItem.name) + 2]; + snprintf(key, sizeof(key), "c:%s", entityItem.name); + if (EMSESP::nvs_.isKey(key)) { + entityItem.data = EMSESP::nvs_.getString(key).c_str(); + } else { + EMSESP::nvs_.putString(key, entityItem.data.c_str()); + } + } webCustomEntity.customEntityItems.push_back(entityItem); // add to list if (entityItem.writeable && entityItem.name[0] != '\0') { @@ -163,6 +176,13 @@ bool WebCustomEntityService::command_setvalue(const char * value, const int8_t i if (Helpers::toLower(entityItem.name) == Helpers::toLower(name)) { if (entityItem.ram == 1) { entityItem.data = value; + } else if (entityItem.ram == 2) { // NVS + entityItem.data = value; + char key[sizeof(entityItem.name) + 2]; + snprintf(key, sizeof(key), "c:%s", entityItem.name); + if (EMSESP::nvs_.getString(key) != entityItem.data.c_str()) { + EMSESP::nvs_.putString(key, entityItem.data.c_str()); + } } else if (entityItem.value_type == DeviceValueType::STRING) { auto telegram = strdup(value); uint8_t length = strlen(telegram) / 3 + 1; @@ -335,10 +355,13 @@ bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd) // build the json for specific entity void WebCustomEntityService::get_value_json(JsonObject output, CustomEntityItem const & entity) { - output["name"] = (const char *)entity.name; - output["fullname"] = (const char *)entity.name; - output["storage"] = entity.ram ? "ram" : "ems"; - output["type"] = entity.value_type == DeviceValueType::BOOL ? "boolean" : entity.value_type == DeviceValueType::STRING ? "string" : F_(number); + output["name"] = (const char *)entity.name; + output["fullname"] = (const char *)entity.name; + output["storage"] = entity.ram == 1 ? "ram" : entity.ram == 2 ? "nvs" : "ems"; + output["type"] = entity.value_type == DeviceValueType::BOOL ? "boolean" : entity.value_type == DeviceValueType::STRING ? "string" : F_(number); + if (entity.uom) { + output["uom"] = EMSdevice::uom_to_string(entity.uom); + } output["readable"] = true; output["writeable"] = entity.writeable; output["visible"] = true;