mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
text changes and formatting
This commit is contained in:
@@ -301,9 +301,14 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char *
|
|||||||
auto cf = find_command(device_type, device_id, cmd);
|
auto cf = find_command(device_type, device_id, cmd);
|
||||||
|
|
||||||
// check if its a call to and end-point to a device
|
// check if its a call to and end-point to a device
|
||||||
// except for system commands as this is a special device without any queryable entities (device values)
|
// this is used to fetch the attributes of the device entity, or call a command directly
|
||||||
if ((device_type > EMSdevice::DeviceType::SYSTEM) && (!value || !strlen(value))) {
|
bool single_command = (!value || !strlen(value));
|
||||||
if (!cf || !cf->cmdfunction_json_) {
|
if (single_command) {
|
||||||
|
// exception 1: anything that is from System
|
||||||
|
// exception 2: boiler coldshot command
|
||||||
|
bool get_attributes = (!cf || !cf->cmdfunction_json_) && (device_type > EMSdevice::DeviceType::SYSTEM) && (strcmp(cmd, F_(coldshot)) != 0);
|
||||||
|
|
||||||
|
if (get_attributes) {
|
||||||
LOG_DEBUG("Calling %s command '%s' to retrieve attributes", dname, cmd);
|
LOG_DEBUG("Calling %s command '%s' to retrieve attributes", dname, cmd);
|
||||||
return EMSESP::get_device_value_info(output, cmd, id, device_type) ? CommandRet::OK : CommandRet::ERROR; // entity = cmd
|
return EMSESP::get_device_value_info(output, cmd, id, device_type) ? CommandRet::OK : CommandRet::ERROR; // entity = cmd
|
||||||
}
|
}
|
||||||
@@ -344,7 +349,7 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char *
|
|||||||
|
|
||||||
// check if read-only. This also checks for valid tags (e.g. heating circuits)
|
// check if read-only. This also checks for valid tags (e.g. heating circuits)
|
||||||
if (cf->cmdfunction_) {
|
if (cf->cmdfunction_) {
|
||||||
if (EMSESP::cmd_is_readonly(device_type, device_id, cmd, id)) {
|
if (!single_command && EMSESP::cmd_is_readonly(device_type, device_id, cmd, id)) {
|
||||||
return_code = CommandRet::INVALID; // readonly or invalid hc
|
return_code = CommandRet::INVALID; // readonly or invalid hc
|
||||||
} else {
|
} else {
|
||||||
return_code = ((cf->cmdfunction_)(value, id)) ? CommandRet::OK : CommandRet::ERROR;
|
return_code = ((cf->cmdfunction_)(value, id)) ? CommandRet::OK : CommandRet::ERROR;
|
||||||
@@ -593,7 +598,7 @@ void Command::show_devices(uuid::console::Shell & shell) {
|
|||||||
// output list of all commands to console
|
// output list of all commands to console
|
||||||
// calls show with verbose mode set
|
// calls show with verbose mode set
|
||||||
void Command::show_all(uuid::console::Shell & shell) {
|
void Command::show_all(uuid::console::Shell & shell) {
|
||||||
shell.println("Available commands (*=do not need authorization): ");
|
shell.println("Available commands (*=authorization not required): ");
|
||||||
|
|
||||||
// show system first
|
// show system first
|
||||||
shell.print(COLOR_BOLD_ON);
|
shell.print(COLOR_BOLD_ON);
|
||||||
|
|||||||
@@ -278,9 +278,13 @@ void Mqtt::on_message(const char * topic, const uint8_t * payload, size_t len) c
|
|||||||
if (return_code != CommandRet::OK) {
|
if (return_code != CommandRet::OK) {
|
||||||
char error[100];
|
char error[100];
|
||||||
if (output.size()) {
|
if (output.size()) {
|
||||||
snprintf(error, sizeof(error), "Call failed with error: %s (%s)", (const char *)output["message"], Command::return_code_string(return_code).c_str());
|
snprintf(error,
|
||||||
|
sizeof(error),
|
||||||
|
"MQTT command failed with error: %s (%s)",
|
||||||
|
(const char *)output["message"],
|
||||||
|
Command::return_code_string(return_code).c_str());
|
||||||
} else {
|
} else {
|
||||||
snprintf(error, sizeof(error), "Call failed with error code (%s)", Command::return_code_string(return_code).c_str());
|
snprintf(error, sizeof(error), "MQTT command failed with error code (%s)", Command::return_code_string(return_code).c_str());
|
||||||
}
|
}
|
||||||
LOG_ERROR(error);
|
LOG_ERROR(error);
|
||||||
Mqtt::queue_publish("response", error);
|
Mqtt::queue_publish("response", error);
|
||||||
|
|||||||
@@ -121,9 +121,9 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) {
|
|||||||
if (return_code != CommandRet::OK) {
|
if (return_code != CommandRet::OK) {
|
||||||
char error[100];
|
char error[100];
|
||||||
if (output.size()) {
|
if (output.size()) {
|
||||||
snprintf(error, sizeof(error), "Call failed with error: %s (%s)", (const char *)output["message"], Command::return_code_string(return_code).c_str());
|
snprintf(error, sizeof(error), "API failed with error: %s (%s)", (const char *)output["message"], Command::return_code_string(return_code).c_str());
|
||||||
} else {
|
} else {
|
||||||
snprintf(error, sizeof(error), "Call failed with error code (%s)", Command::return_code_string(return_code).c_str());
|
snprintf(error, sizeof(error), "API failed with error code (%s)", Command::return_code_string(return_code).c_str());
|
||||||
}
|
}
|
||||||
emsesp::EMSESP::logger().err(error);
|
emsesp::EMSESP::logger().err(error);
|
||||||
api_fails_++;
|
api_fails_++;
|
||||||
|
|||||||
@@ -219,8 +219,8 @@ bool WebEntityService::get_value_info(JsonObject & output, const char * cmd) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Helpers::toLower(cmd) == "commands") {
|
if (Helpers::toLower(cmd) == "commands") {
|
||||||
output["info"] = "lists all values";
|
output["info"] = "list all values";
|
||||||
output["commands"] = "lists all commands";
|
output["commands"] = "list all commands";
|
||||||
for (const auto & entity : *entityItems) {
|
for (const auto & entity : *entityItems) {
|
||||||
output[entity.name] = "custom entitiy";
|
output[entity.name] = "custom entitiy";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user