mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
more minor changes to clean up messaging
This commit is contained in:
@@ -63,7 +63,6 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
||||
int8_t id_n = -1; // default hc
|
||||
|
||||
// check for a device as first item in the path
|
||||
// if its not a known device (thermostat, boiler etc) look for any special MQTT subscriptions
|
||||
const char * device_s = nullptr;
|
||||
if (!num_paths) {
|
||||
// we must look for the device in the JSON body
|
||||
@@ -72,7 +71,7 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
||||
}
|
||||
} else {
|
||||
// extract it from the path
|
||||
device_s = p.paths().front().c_str(); // get the device (boiler, thermostat, system etc)
|
||||
device_s = p.paths().front().c_str(); // get the device type name (boiler, thermostat, system etc)
|
||||
}
|
||||
|
||||
// validate the device, make sure it exists
|
||||
@@ -347,16 +346,13 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char *
|
||||
if (output["message"]) {
|
||||
LOG_WARNING("Command failed: %s", output["message"].as<const char *>());
|
||||
} else {
|
||||
std::string err = "no command " + std::string(cmd) + " in " + dname;
|
||||
std::string err = "no " + std::string(cmd) + " in " + dname;
|
||||
output["message"] = err;
|
||||
LOG_WARNING("Command failed: %s", err.c_str());
|
||||
}
|
||||
return CommandRet::ERROR;
|
||||
}
|
||||
|
||||
// TODO here
|
||||
output.clear(); // we have a command function, clear messages from device_value_info
|
||||
|
||||
// before calling the command, check permissions and abort if not authorized
|
||||
if (cf->has_flags(CommandFlag::ADMIN_ONLY) && !is_admin) {
|
||||
LOG_WARNING("Command failed: authentication failed");
|
||||
@@ -404,12 +400,15 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char *
|
||||
LOG_WARNING(error);
|
||||
} else {
|
||||
if (single_command) {
|
||||
LOG_DEBUG(("%sCalled command %s"), ro.c_str(), info_s);
|
||||
// TODO not sure if these should go to INFO as there may be a lot of calls, e.g. ioBroker
|
||||
// TODO for now using debug (regarles if compiled with EMSESP_DEBUG)
|
||||
// TODO mvdp ?
|
||||
logger_.debug(("%sCalled command %s"), ro.c_str(), info_s);
|
||||
} else {
|
||||
if (id > 0) {
|
||||
LOG_INFO(("%sCalled command %s with value %s and id %d on device 0x%02X"), ro.c_str(), info_s, value, id, device_id);
|
||||
logger_.debug(("%sCalled command %s with value %s and id %d on device 0x%02X"), ro.c_str(), info_s, value, id, device_id);
|
||||
} else {
|
||||
LOG_INFO(("%sCalled command %s with value %s"), ro.c_str(), info_s, value);
|
||||
logger_.debug(("%sCalled command %s with value %s"), ro.c_str(), info_s, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -549,7 +548,7 @@ void Command::show(uuid::console::Shell & shell, uint8_t device_type, bool verbo
|
||||
}
|
||||
}
|
||||
|
||||
// non EMS devices always have an info and commands command
|
||||
// non EMS devices always have an info, commands and values
|
||||
bool show_info = (device_type == EMSdevice::DeviceType::TEMPERATURESENSOR || device_type == EMSdevice::DeviceType::ANALOGSENSOR
|
||||
|| device_type == EMSdevice::DeviceType::SCHEDULER || device_type == EMSdevice::DeviceType::CUSTOM);
|
||||
|
||||
@@ -576,9 +575,11 @@ void Command::show(uuid::console::Shell & shell, uint8_t device_type, bool verbo
|
||||
|
||||
// we hard code 'info' and 'commands' commands so print them first
|
||||
if (show_info) {
|
||||
shell.printf(" info:\t\t\t\t%slists all values %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_GREEN);
|
||||
shell.printf(" info:\t\t\t\t%slist all values %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_GREEN);
|
||||
shell.println(COLOR_RESET);
|
||||
shell.printf(" commands:\t\t\t%slists all commands %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_GREEN);
|
||||
shell.printf(" commands:\t\t\t%slist all commands %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_GREEN);
|
||||
shell.println(COLOR_RESET);
|
||||
shell.printf(" values:\t\t\t%slist all values %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_GREEN);
|
||||
shell.println(COLOR_RESET);
|
||||
}
|
||||
|
||||
@@ -618,7 +619,6 @@ bool Command::device_has_commands(const uint8_t device_type) {
|
||||
return true; // we always have System
|
||||
}
|
||||
|
||||
// if there are no entries to scheduler/custom/temperaturesensor/analogsensor, don't error but return a message
|
||||
if (device_type == EMSdevice::DeviceType::SCHEDULER) {
|
||||
return true;
|
||||
}
|
||||
@@ -637,6 +637,7 @@ bool Command::device_has_commands(const uint8_t device_type) {
|
||||
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
if (emsdevice && (emsdevice->device_type() == device_type)) {
|
||||
// TODO will this work for info, values etc??
|
||||
// device found, now see if it has any commands
|
||||
for (const auto & cf : cmdfunctions_) {
|
||||
if (cf.device_type_ == device_type) {
|
||||
|
||||
Reference in New Issue
Block a user