mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
some case and nullptr checks
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user