Merge pull request #1638 from MichaelDvP/dev

fix command attribute #1637
This commit is contained in:
Proddy
2024-02-27 08:25:16 +01:00
committed by GitHub
7 changed files with 20 additions and 19 deletions

View File

@@ -650,10 +650,9 @@ bool AnalogSensor::get_value_info(JsonObject output, const char * cmd, const int
// this is for a specific sensor
// make a copy of the string command for parsing, and lowercase it
char sensor_name[30] = {'\0'};
char sensor_name[COMMAND_MAX_LENGTH] = {'\0'};
char * attribute_s = nullptr;
strlcpy(sensor_name, cmd, sizeof(sensor_name));
auto sensor_lowercase = Helpers::toLower(sensor_name);
strlcpy(sensor_name, Helpers::toLower(cmd).c_str(), sizeof(sensor_name));
// check specific attribute to fetch instead of the complete record
char * breakp = strchr(sensor_name, '/');
@@ -663,7 +662,7 @@ bool AnalogSensor::get_value_info(JsonObject output, const char * cmd, const int
}
for (const auto & sensor : sensors_) {
if (sensor_lowercase == Helpers::toLower(sensor.name().c_str()) || Helpers::atoint(sensor_name) == sensor.gpio()) {
if (sensor_name == Helpers::toLower(sensor.name()) || Helpers::atoint(sensor_name) == sensor.gpio()) {
// add the details
addSensorJson(output, sensor);

View File

@@ -88,12 +88,12 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
command_p = p.paths()[1].c_str();
} else if (num_paths == 3) {
// concatenate the path into one string as it could be in the format 'hc/XXX'
char command[50];
char command[COMMAND_MAX_LENGTH];
snprintf(command, sizeof(command), "%s/%s", p.paths()[1].c_str(), p.paths()[2].c_str());
command_p = command;
} else if (num_paths > 3) {
// concatenate the path into one string as it could be in the format 'hc/XXX/attribute'
char command[50];
char command[COMMAND_MAX_LENGTH];
snprintf(command, sizeof(command), "%s/%s/%s", p.paths()[1].c_str(), p.paths()[2].c_str(), p.paths()[3].c_str());
command_p = command;
} else {
@@ -151,7 +151,7 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
if (strlen(d)) {
char * device_end = (char *)strchr(d, '/');
if (device_end != nullptr) {
char device_s[15] = {'\0'};
char device_s[20] = {'\0'};
const char * device_p = device_s;
const char * data_p = nullptr;
strlcpy(device_s, d, device_end - d + 1);
@@ -161,7 +161,7 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
if (data_p == nullptr) {
return CommandRet::INVALID;
}
char data_s[40];
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");

View File

@@ -27,6 +27,8 @@ using uuid::console::Shell;
namespace emsesp {
#define COMMAND_MAX_LENGTH 50
// mqtt flags for command subscriptions
enum CommandFlag : uint8_t {
MQTT_SUB_FLAG_DEFAULT = 0, // 0 no flags set, always subscribe to MQTT

View File

@@ -1200,7 +1200,8 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
node["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
node["uptime (seconds)"] = uuid::get_uptime_sec();
#ifndef EMSESP_STANDALONE
node["platform"] = ARDUINO_VERSION;
node["platform"] = EMSESP_PLATFORM;
node["arduino"] = ARDUINO_VERSION;
node["sdk"] = ESP.getSdkVersion();
node["free mem"] = getHeapMem();
node["max alloc"] = getMaxAllocMem();

View File

@@ -377,10 +377,9 @@ bool TemperatureSensor::get_value_info(JsonObject output, const char * cmd, cons
// this is for a specific sensor
// make a copy of the string command for parsing, and lowercase it
char sensor_name[30] = {'\0'};
char sensor_name[COMMAND_MAX_LENGTH] = {'\0'};
char * attribute_s = nullptr;
strlcpy(sensor_name, cmd, sizeof(sensor_name));
auto sensor_lowercase = Helpers::toLower(sensor_name);
strlcpy(sensor_name, Helpers::toLower(cmd).c_str(), sizeof(sensor_name));
// check for a specific attribute to fetch instead of the complete record
char * breakp = strchr(sensor_name, '/');
@@ -391,7 +390,7 @@ bool TemperatureSensor::get_value_info(JsonObject output, const char * cmd, cons
for (const auto & sensor : sensors_) {
// match custom name or sensor ID
if (sensor_lowercase == Helpers::toLower(sensor.name().c_str()) || sensor_lowercase == Helpers::toLower(sensor.id().c_str())) {
if (sensor_name == Helpers::toLower(sensor.name()) || sensor_name == Helpers::toLower(sensor.id())) {
// add values
addSensorJson(output, sensor);
// if we're filtering on an attribute, go find it

View File

@@ -278,8 +278,8 @@ bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd)
return true;
}
char command_s[30];
strlcpy(command_s, cmd, sizeof(command_s));
char command_s[COMMAND_MAX_LENGTH];
strlcpy(command_s, Helpers::toLower(cmd).c_str(), sizeof(command_s));
char * attribute_s = nullptr;
// check specific attribute to fetch instead of the complete record
char * breakp = strchr(command_s, '/');
@@ -289,7 +289,7 @@ bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd)
}
for (const auto & entity : *customEntityItems) {
if (Helpers::toLower(entity.name) == Helpers::toLower(command_s)) {
if (Helpers::toLower(entity.name) == command_s) {
output["name"] = entity.name;
output["ram"] = entity.ram;
output["type"] = entity.value_type == DeviceValueType::BOOL ? "boolean" : entity.value_type == DeviceValueType::STRING ? "string" : F_(number);

View File

@@ -168,8 +168,8 @@ bool WebSchedulerService::get_value_info(JsonObject output, const char * cmd) {
return (output.size() > 0);
}
char command_s[30];
strlcpy(command_s, cmd, sizeof(command_s));
char command_s[COMMAND_MAX_LENGTH];
strlcpy(command_s, Helpers::toLower(cmd).c_str(), sizeof(command_s));
char * attribute_s = nullptr;
// check specific attribute to fetch instead of the complete record
@@ -180,7 +180,7 @@ bool WebSchedulerService::get_value_info(JsonObject output, const char * cmd) {
}
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
if (Helpers::toLower(scheduleItem.name) == Helpers::toLower(command_s)) {
if (Helpers::toLower(scheduleItem.name) == command_s) {
output["name"] = scheduleItem.name;
output["type"] = "boolean";
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {