diff --git a/lib/uuid-console/src/commands.cpp b/lib/uuid-console/src/commands.cpp index b611c1d73..68bfbd4f2 100644 --- a/lib/uuid-console/src/commands.cpp +++ b/lib/uuid-console/src/commands.cpp @@ -425,7 +425,7 @@ Commands::Completion Commands::complete_command(Shell & shell, const CommandLine if (commands.exact.count(longest->first) == 1) { for (auto & name : longest->second->name_) { - result.replacement->push_back(std::move((name))); // TODO remove all moves? + result.replacement->push_back(name); } // Add a space because there are sub-commands for a command that has matched exactly diff --git a/src/analogsensor.cpp b/src/analogsensor.cpp index abdf084ec..4145f51eb 100644 --- a/src/analogsensor.cpp +++ b/src/analogsensor.cpp @@ -31,7 +31,6 @@ void AnalogSensor::start() { } analogSetAttenuation(ADC_2_5db); // for all channels 1.5V - LOG_INFO("Starting Analog sensor service"); // Add API call for /info @@ -39,18 +38,18 @@ void AnalogSensor::start() { EMSdevice::DeviceType::ANALOGSENSOR, F_(info), [&](const char * value, const int8_t id, JsonObject & output) { return command_info(value, id, output); }, - F_(info_cmd)); + FL_(info_cmd)); Command::add( EMSdevice::DeviceType::ANALOGSENSOR, F_(setvalue), [&](const char * value, const int8_t id) { return command_setvalue(value, id); }, - ("set io value"), // TODO translate this + FL_(setiovalue_cmd), CommandFlag::ADMIN_ONLY); Command::add( EMSdevice::DeviceType::ANALOGSENSOR, F_(commands), [&](const char * value, const int8_t id, JsonObject & output) { return command_commands(value, id, output); }, - F_(commands_cmd)); + FL_(commands_cmd)); Mqtt::subscribe(EMSdevice::DeviceType::ANALOGSENSOR, "analogsensor/#", nullptr); // use empty function callback } diff --git a/src/command.cpp b/src/command.cpp index 41754ec45..ae4c7137f 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -299,7 +299,7 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * } // add a command to the list, which does not return json -void Command::add(const uint8_t device_type, const char * cmd, const cmd_function_p cb, const char * description, uint8_t flags) { +void Command::add(const uint8_t device_type, const char * cmd, const cmd_function_p cb, const char * const * description, uint8_t flags) { // if the command already exists for that device type don't add it if (find_command(device_type, cmd) != nullptr) { return; @@ -314,7 +314,7 @@ void Command::add(const uint8_t device_type, const char * cmd, const cmd_functio } // add a command to the list, which does return a json object as output -void Command::add(const uint8_t device_type, const char * cmd, const cmd_json_function_p cb, const char * description, uint8_t flags) { +void Command::add(const uint8_t device_type, const char * cmd, const cmd_json_function_p cb, const char * const * description, uint8_t flags) { // if the command already exists for that device type don't add it if (find_command(device_type, cmd) != nullptr) { return; @@ -348,7 +348,6 @@ Command::CmdFunction * Command::find_command(const uint8_t device_type, const ch // list all commands for a specific device, output as json bool Command::list(const uint8_t device_type, JsonObject & output) { - if (cmdfunctions_.empty()) { output["message"] = "no commands available"; return false; @@ -366,7 +365,7 @@ bool Command::list(const uint8_t device_type, JsonObject & output) { for (const auto & cl : sorted_cmds) { for (const auto & cf : cmdfunctions_) { if ((cf.device_type_ == device_type) && !cf.has_flags(CommandFlag::HIDDEN) && cf.description_ && (cl == std::string(cf.cmd_))) { - output[cl] = cf.description_; + output[cl] = Helpers::translated_fullname(cf.description_); } } } @@ -425,7 +424,7 @@ void Command::show(uuid::console::Shell & shell, uint8_t device_type, bool verbo shell.print(EMSdevice::tag_to_string(DeviceValueTAG::TAG_DEVICE_DATA_WW)); shell.print(' '); } - shell.print((cf.description_)); + shell.print(Helpers::translated_fullname(cf.description_)); if (!cf.has_flags(CommandFlag::ADMIN_ONLY)) { shell.print(' '); shell.print(COLOR_BRIGHT_RED); diff --git a/src/command.h b/src/command.h index 098648ee1..3aa0da6d7 100644 --- a/src/command.h +++ b/src/command.h @@ -59,14 +59,14 @@ class Command { const char * cmd_; const cmd_function_p cmdfunction_; const cmd_json_function_p cmdfunction_json_; - const char * description_; + const char * const * description_; CmdFunction(const uint8_t device_type, const uint8_t flags, const char * cmd, const cmd_function_p cmdfunction, const cmd_json_function_p cmdfunction_json, - const char * description) + const char * const * description) : device_type_(device_type) , flags_(flags) , cmd_(cmd) @@ -97,12 +97,18 @@ class Command { static uint8_t call(const uint8_t device_type, const char * cmd, const char * value); // with normal call back function taking a value and id - static void - add(const uint8_t device_type, const char * cmd, const cmd_function_p cb, const char * description, uint8_t flags = CommandFlag::MQTT_SUB_FLAG_DEFAULT); + static void add(const uint8_t device_type, + const char * cmd, + const cmd_function_p cb, + const char * const * description, + uint8_t flags = CommandFlag::MQTT_SUB_FLAG_DEFAULT); // callback function taking value, id and a json object for its output - static void - add(const uint8_t device_type, const char * cmd, const cmd_json_function_p cb, const char * description, uint8_t flags = CommandFlag::MQTT_SUB_FLAG_DEFAULT); + static void add(const uint8_t device_type, + const char * cmd, + const cmd_json_function_p cb, + const char * const * description, + uint8_t flags = CommandFlag::MQTT_SUB_FLAG_DEFAULT); static void show_all(uuid::console::Shell & shell); static Command::CmdFunction * find_command(const uint8_t device_type, const char * cmd); diff --git a/src/dallassensor.cpp b/src/dallassensor.cpp index 84af25e49..0b843562b 100644 --- a/src/dallassensor.cpp +++ b/src/dallassensor.cpp @@ -50,12 +50,12 @@ void DallasSensor::start() { EMSdevice::DeviceType::DALLASSENSOR, F_(info), [&](const char * value, const int8_t id, JsonObject & output) { return command_info(value, id, output); }, - F_(info_cmd)); + FL_(info_cmd)); Command::add( EMSdevice::DeviceType::DALLASSENSOR, F_(commands), [&](const char * value, const int8_t id, JsonObject & output) { return command_commands(value, id, output); }, - F_(commands_cmd)); + FL_(commands_cmd)); Mqtt::subscribe(EMSdevice::DeviceType::DALLASSENSOR, "dallasssensor/#", nullptr); // use empty function callback } diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 7dadafc66..7fdb48186 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -495,8 +495,7 @@ void EMSdevice::add_device_value(uint8_t tag, } // add the command to our library - // cmd is the short_name and the description is the fullname (not the custom fullname) - Command::add(device_type_, short_name, f, Helpers::translated_fullname(fullname), flags); + Command::add(device_type_, short_name, f, fullname, flags); } // single list of options diff --git a/src/emsesp.cpp b/src/emsesp.cpp index b09b9a8f4..9e12cb41c 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -1052,7 +1052,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const [device_type](const char * value, const int8_t id, JsonObject & output) { return command_info(device_type, output, id, EMSdevice::OUTPUT_TARGET::API_VERBOSE); }, - F_(info_cmd)); + FL_(info_cmd)); Command::add( device_type, ("values"), @@ -1065,12 +1065,12 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const device_type, F_(commands), [device_type](const char * value, const int8_t id, JsonObject & output) { return command_commands(device_type, output, id); }, - F_(commands_cmd)); + FL_(commands_cmd)); Command::add( device_type, F_(entities), [device_type](const char * value, const int8_t id, JsonObject & output) { return command_entities(device_type, output, id); }, - F_(entities_cmd)); + FL_(entities_cmd)); // MQTT subscribe to the device e.g. "ems-esp/boiler/#" Mqtt::subscribe(device_type, EMSdevice::device_type_2_device_name(device_type) + "/#", nullptr); diff --git a/src/locale_common.h b/src/locale_common.h index 543938b14..6cbdca30f 100644 --- a/src/locale_common.h +++ b/src/locale_common.h @@ -219,11 +219,6 @@ MAKE_PSTR(uom_sqm, "sqm") MAKE_PSTR(uom_m3, "m3") MAKE_PSTR(uom_l, "l") -// commands -MAKE_PSTR(info_cmd, "lists all values") -MAKE_PSTR(commands_cmd, "lists all commands") -MAKE_PSTR(entities_cmd, "lists all entities") - // TAG mapping - maps to DeviceValueTAG_s in emsdevice.cpp // use empty string if want to suppress showing tags // mqtt tags must not have spaces diff --git a/src/locale_translations.h b/src/locale_translations.h index 40066f5cb..5861b0c65 100644 --- a/src/locale_translations.h +++ b/src/locale_translations.h @@ -31,6 +31,23 @@ // translations are in order en, de,nl, se.... // if there is no translation, it will default to en +// commands +MAKE_PSTR_LIST(info_cmd, "lists all values") +MAKE_PSTR_LIST(commands_cmd, "lists all commands") +MAKE_PSTR_LIST(entities_cmd, "lists all entities") +MAKE_PSTR_LIST(send_cmd, "send a telegram") +MAKE_PSTR_LIST(setiovalue_cmd, "set io value") +MAKE_PSTR_LIST(changeloglevel_cmd, "change log level") +MAKE_PSTR_LIST(fetch_cmd, "refresh all EMS values") +MAKE_PSTR_LIST(restart_cmd, "restart EMS-ESP") +MAKE_PSTR_LIST(watch_cmd, "watch incoming telegrams") +MAKE_PSTR_LIST(publish_cmd, "publish all to MQTT") +MAKE_PSTR_LIST(system_info_cmd, "show system status") + +#if defined(EMSESP_DEBUG) +MAKE_PSTR_LIST(test_cmd, "run a test") +#endif + // General MAKE_PSTR_LIST(on, "on", "an", "aan", "på") MAKE_PSTR_LIST(off, "off", "aus", "uit", "av") diff --git a/src/system.cpp b/src/system.cpp index 7ddf9fe2d..691489008 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -249,8 +249,7 @@ void System::syslog_init() { syslog_.hostname(hostname().c_str()); // register the command - // TODO translate this - Command::add(EMSdevice::DeviceType::SYSTEM, F_(syslog), System::command_syslog_level, ("change the syslog level"), CommandFlag::ADMIN_ONLY); + Command::add(EMSdevice::DeviceType::SYSTEM, F_(syslog), System::command_syslog_level, FL_(changeloglevel_cmd), CommandFlag::ADMIN_ONLY); } else if (was_enabled) { // in case service is still running, this flushes the queue @@ -664,25 +663,21 @@ void System::system_check() { // commands - takes static function pointers void System::commands_init() { - // TODO translate this - Command::add(EMSdevice::DeviceType::SYSTEM, F_(send), System::command_send, ("send a telegram"), CommandFlag::ADMIN_ONLY); - Command::add(EMSdevice::DeviceType::SYSTEM, F_(fetch), System::command_fetch, ("refresh all EMS values"), CommandFlag::ADMIN_ONLY); - Command::add(EMSdevice::DeviceType::SYSTEM, F_(restart), System::command_restart, ("restart EMS-ESP"), CommandFlag::ADMIN_ONLY); - Command::add(EMSdevice::DeviceType::SYSTEM, F_(watch), System::command_watch, ("watch incoming telegrams")); - - // register syslog command in syslog init - // Command::add(EMSdevice::DeviceType::SYSTEM, F_(syslog), System::command_syslog_level, ("set syslog level"), CommandFlag::ADMIN_ONLY); + Command::add(EMSdevice::DeviceType::SYSTEM, F_(send), System::command_send, FL_(send_cmd), CommandFlag::ADMIN_ONLY); + Command::add(EMSdevice::DeviceType::SYSTEM, F_(fetch), System::command_fetch, FL_(fetch_cmd), CommandFlag::ADMIN_ONLY); + Command::add(EMSdevice::DeviceType::SYSTEM, F_(restart), System::command_restart, FL_(restart_cmd), CommandFlag::ADMIN_ONLY); + Command::add(EMSdevice::DeviceType::SYSTEM, F_(watch), System::command_watch, FL_(watch_cmd)); if (Mqtt::enabled()) { - Command::add(EMSdevice::DeviceType::SYSTEM, F_(publish), System::command_publish, ("force a MQTT publish")); + Command::add(EMSdevice::DeviceType::SYSTEM, F_(publish), System::command_publish, FL_(publish_cmd)); } // these commands will return data in JSON format - Command::add(EMSdevice::DeviceType::SYSTEM, F_(info), System::command_info, ("show system status")); - Command::add(EMSdevice::DeviceType::SYSTEM, F_(commands), System::command_commands, ("fetch system commands")); + Command::add(EMSdevice::DeviceType::SYSTEM, F_(info), System::command_info, FL_(system_info_cmd)); + Command::add(EMSdevice::DeviceType::SYSTEM, F_(commands), System::command_commands, FL_(commands_cmd)); #if defined(EMSESP_DEBUG) - Command::add(EMSdevice::DeviceType::SYSTEM, ("test"), System::command_test, ("run a specific test")); + Command::add(EMSdevice::DeviceType::SYSTEM, ("test"), System::command_test, FL_(test_cmd)); #endif // MQTT subscribe "ems-esp/system/#"