Merge pull request #1101 from MichaelDvP/dev

some case and nullptr checks
This commit is contained in:
Proddy
2023-03-04 18:43:08 +01:00
committed by GitHub
4 changed files with 18 additions and 11 deletions

View File

@@ -580,7 +580,7 @@ bool AnalogSensor::get_value_info(JsonObject & output, const char * cmd, const i
}
for (const auto & sensor : sensors_) {
if (strcmp(command_s, sensor.name().c_str()) == 0 || Helpers::atoint(command_s) == sensor.gpio()) {
if (Helpers::toLower(command_s) == Helpers::toLower(sensor.name().c_str()) || Helpers::atoint(command_s) == sensor.gpio()) {
output["gpio"] = sensor.gpio();
output["name"] = sensor.name();
output["type"] = F_(number);

View File

@@ -158,15 +158,22 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
data_p = device_end + 1;
int8_t id_d = -1;
data_p = parse_command_string(data_p, id_d);
char data_s[50];
strcpy(data_s, data_p);
strcat(data_s, "/value");
uint8_t device_type = EMSdevice::device_name_2_device_type(device_p);
if (CommandRet::OK == Command::call(device_type, data_s, "", true, id_d, output)) {
if (output.containsKey("api_data")) {
data = output["api_data"];
}
if (data_p == nullptr) {
return CommandRet::INVALID;
}
char data_s[40];
strlcpy(data_s, Helpers::toLower(data_p).c_str(), 30);
if (strstr(data_s, "/value") == nullptr) {
strcat(data_s, "/value");
}
uint8_t device_type = EMSdevice::device_name_2_device_type(device_p);
if (CommandRet::OK != Command::call(device_type, data_s, "", true, id_d, output)) {
return CommandRet::INVALID;
}
if (!output.containsKey("api_data")) {
return CommandRet::INVALID;
}
data = output["api_data"];
output.clear();
}
}

View File

@@ -404,7 +404,7 @@ bool DallasSensor::get_value_info(JsonObject & output, const char * cmd, const i
}
for (const auto & sensor : sensors_) {
if (strcmp(command_s, sensor.name().c_str()) == 0 || strcmp(command_s, sensor.id().c_str()) == 0) {
if (Helpers::toLower(command_s) == Helpers::toLower(sensor.name().c_str()) || Helpers::toLower(command_s) == Helpers::toLower(sensor.id().c_str())) {
output["id"] = sensor.id();
output["name"] = sensor.name();
char val[10];

View File

@@ -1341,7 +1341,7 @@ bool EMSdevice::get_value_info(JsonObject & output, const char * cmd, const int8
// search device value with this tag
for (auto & dv : devicevalues_) {
if (!strcmp(command_s, dv.short_name) && (tag <= 0 || tag == dv.tag)) {
if (Helpers::toLower(command_s) == Helpers::toLower(dv.short_name) && (tag <= 0 || tag == dv.tag)) {
uint8_t fahrenheit = !EMSESP::system_.fahrenheit() ? 0 : (dv.uom == DeviceValueUOM::DEGREES) ? 2 : (dv.uom == DeviceValueUOM::DEGREES_R) ? 1 : 0;
const char * type = "type";