Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix api_data as command data #2043

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
const char * device_p = device_s;
const char * data_p = nullptr;
strlcpy(device_s, d, device_end - d + 1);
data_p = device_end + 1;
int8_t id_d = -1;
uint8_t device_type = EMSdevice::device_name_2_device_type(device_p);
if (device_type >= EMSdevice::DeviceType::BOILER) {
data_p = device_end + 1;
int8_t id_d = -1;
uint8_t device_type1 = EMSdevice::device_name_2_device_type(device_p);
if (device_type1 >= EMSdevice::DeviceType::BOILER) {
data_p = parse_command_string(data_p, id_d);
}
if (data_p == nullptr) {
Expand All @@ -161,17 +161,17 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
char data_s[COMMAND_MAX_LENGTH];
strlcpy(data_s, Helpers::toLower(data_p).c_str(), 30);
if (strstr(data_s, "/value") == nullptr) {
strcat(data_s, "/value");
strlcat(data_s, "/value", sizeof(data_s) - 6);
}

if (Command::call(device_type, data_s, "", true, id_d, output) != CommandRet::OK) {
if (Command::call(device_type1, data_s, "", true, id_d, output) != CommandRet::OK) {
return CommandRet::INVALID;
}

const char * api_data = output["api_data"];
if (api_data) {
if (output["api_data"].is<std::string>()) {
std::string api_data = output["api_data"];
output.clear();
return Command::call(device_type, command_p, api_data, is_admin, id_n, output);
return Command::call(device_type, command_p, api_data.c_str(), is_admin, id_n, output);
}

return CommandRet::INVALID;
Expand Down