Add a check on device id before concatenating it to the device name (#1398)

to avoid concatenating an unknown array
This commit is contained in:
Florian authored and GitHub committed 2023-01-16 10:17:59 -06:00
1 parent cc81b0ba44
commit 76724240f4
1 file changed
+2 -2
+2 -2
View File
@@ -332,7 +332,7 @@ void createDiscovery(const char* sensor_type,
identifiers.add(String(getMacAddress()));
} else {
//The Connections
if (device_id[0] != 0) {
if (device_id[0]) {
JsonArray connections = device.createNestedArray("connections");
JsonArray connection_mac = connections.createNestedArray();
connection_mac.add("mac");
@@ -352,7 +352,7 @@ void createDiscovery(const char* sensor_type,
// generate unique device name by adding the second half of the device_id only if device_name and device_id are different
if (device_name[0]) {
if (strcmp(device_id, device_name) != 0) {
if (strcmp(device_id, device_name) != 0 && device_id[0]) {
device["name"] = device_name + String("-") + String(device_id + 6);
} else {
device["name"] = device_name;