whitespaces in name fix?

This commit is contained in:
Tester23
2023-09-06 17:40:07 +02:00
parent 540ad9d895
commit c82c6047cc
4 changed files with 22 additions and 1 deletions

View File

@ -90,6 +90,9 @@ void hass_populate_unique_id(ENTITY_TYPE type, int index, char* uniq_id) {
sprintf(uniq_id, "%s_%s_%d", longDeviceName, "sensor", index);
break;
}
// There can be no spaces in this name!
// See: https://www.elektroda.com/rtvforum/topic4000620.html
STR_ReplaceWhiteSpacesWithUnderscore(uniq_id);
}
/// @brief Prints HomeAssistant unique id for the entity.
@ -136,6 +139,9 @@ void hass_populate_device_config_channel(ENTITY_TYPE type, char* uniq_id, HassDe
sprintf(info->channel, "sensor/%s/config", uniq_id);
break;
}
// There can be no spaces in this name!
// See: https://www.elektroda.com/rtvforum/topic4000620.html
STR_ReplaceWhiteSpacesWithUnderscore(uniq_id);
}
/// @brief Builds HomeAssistant device discovery info. The caller needs to free the returned pointer.

View File

@ -1269,7 +1269,6 @@ int http_fn_cfg_wifi(http_request_t* request) {
poststr(request, NULL);
return 0;
}
int http_fn_cfg_name(http_request_t* request) {
// for a test, show password as well...
char tmpA[128];
@ -1279,6 +1278,9 @@ int http_fn_cfg_name(http_request_t* request) {
poststr_h2(request, "Change device names for display");
if (http_getArg(request->url, "shortName", tmpA, sizeof(tmpA))) {
if (STR_ReplaceWhiteSpacesWithUnderscore(tmpA)) {
poststr_h2(request, "You cannot have whitespaces in short name!");
}
CFG_SetShortDeviceName(tmpA);
}
if (http_getArg(request->url, "name", tmpA, sizeof(tmpA))) {