[DISCOVERY] Improve method checks (#1620)
Check if char array is not null before reading their first char.
This commit is contained in:
1 parent
acc0d91ca8
commit
4b8dfbea42
1 file changed
+7
-7
@@ -109,21 +109,21 @@ void announceDeviceTrigger(bool use_gateway_info, char* topic, char* type, char*
|
|||||||
sensor["automation_type"] = "trigger"; // The type of automation, must be ‘trigger’.
|
sensor["automation_type"] = "trigger"; // The type of automation, must be ‘trigger’.
|
||||||
|
|
||||||
//SET TYPE
|
//SET TYPE
|
||||||
if (type[0] != 0) {
|
if (type && type[0] != 0) {
|
||||||
sensor["type"] = type;
|
sensor["type"] = type;
|
||||||
} else {
|
} else {
|
||||||
sensor["type"] = "button_short_press";
|
sensor["type"] = "button_short_press";
|
||||||
}
|
}
|
||||||
|
|
||||||
//SET SUBTYPE
|
//SET SUBTYPE
|
||||||
if (subtype[0] != 0) {
|
if (subtype && subtype[0] != 0) {
|
||||||
sensor["subtype"] = subtype;
|
sensor["subtype"] = subtype;
|
||||||
} else {
|
} else {
|
||||||
sensor["subtype"] = "turn_on";
|
sensor["subtype"] = "turn_on";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set The topic */
|
/* Set The topic */
|
||||||
if (topic[0]) {
|
if (topic && topic[0]) {
|
||||||
char state_topic[mqtt_topic_max_size];
|
char state_topic[mqtt_topic_max_size];
|
||||||
|
|
||||||
strcpy(state_topic, mqtt_topic);
|
strcpy(state_topic, mqtt_topic);
|
||||||
@@ -160,7 +160,7 @@ void announceDeviceTrigger(bool use_gateway_info, char* topic, char* type, char*
|
|||||||
identifiers.add(deviceid);
|
identifiers.add(deviceid);
|
||||||
|
|
||||||
/*Set Connection */
|
/*Set Connection */
|
||||||
if (device_id[0] != 0) {
|
if (device_id && device_id[0] != 0) {
|
||||||
JsonArray connections = device.createNestedArray("connections");
|
JsonArray connections = device.createNestedArray("connections");
|
||||||
JsonArray connection_mac = connections.createNestedArray();
|
JsonArray connection_mac = connections.createNestedArray();
|
||||||
connection_mac.add("mac");
|
connection_mac.add("mac");
|
||||||
@@ -168,17 +168,17 @@ void announceDeviceTrigger(bool use_gateway_info, char* topic, char* type, char*
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Set manufacturer
|
//Set manufacturer
|
||||||
if (device_manufacturer[0]) {
|
if (device_manufacturer && device_manufacturer[0]) {
|
||||||
device["manufacturer"] = device_manufacturer;
|
device["manufacturer"] = device_manufacturer;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set name
|
//Set name
|
||||||
if (device_name[0]) {
|
if (device_name && device_name[0]) {
|
||||||
device["name"] = device_name;
|
device["name"] = device_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set The Model
|
// set The Model
|
||||||
if (device_model[0]) {
|
if (device_model && device_model[0]) {
|
||||||
device["model"] = device_model;
|
device["model"] = device_model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user