mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
added hidden commands, sort commands
This commit is contained in:
@@ -140,13 +140,14 @@ void Command::add(const uint8_t device_type, const __FlashStringHelper * cmd, cm
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add a command to the list, which does return json object as output
|
// add a command to the list, which does return json object as output
|
||||||
void Command::add_with_json(const uint8_t device_type, const __FlashStringHelper * cmd, cmdfunction_json_p cb) {
|
// optional parameter hidden for commands that will not show up on the Console
|
||||||
|
void Command::add_with_json(const uint8_t device_type, const __FlashStringHelper * cmd, cmdfunction_json_p cb, bool hidden) {
|
||||||
// if the command already exists for that device type don't add it
|
// if the command already exists for that device type don't add it
|
||||||
if (find_command(device_type, uuid::read_flash_string(cmd).c_str()) != nullptr) {
|
if (find_command(device_type, uuid::read_flash_string(cmd).c_str()) != nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdfunctions_.emplace_back(device_type, MqttSubFlag::FLAG_NOSUB, cmd, nullptr, cb); // add command
|
cmdfunctions_.emplace_back(device_type, MqttSubFlag::FLAG_NOSUB, cmd, nullptr, cb, hidden); // add command
|
||||||
}
|
}
|
||||||
|
|
||||||
// see if a command exists for that device type
|
// see if a command exists for that device type
|
||||||
@@ -175,14 +176,23 @@ Command::CmdFunction * Command::find_command(const uint8_t device_type, const ch
|
|||||||
// output list of all commands to console for a specific DeviceType
|
// output list of all commands to console for a specific DeviceType
|
||||||
void Command::show(uuid::console::Shell & shell, uint8_t device_type) {
|
void Command::show(uuid::console::Shell & shell, uint8_t device_type) {
|
||||||
if (cmdfunctions_.empty()) {
|
if (cmdfunctions_.empty()) {
|
||||||
shell.println(F("No commands"));
|
shell.println(F("No commands available"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create a list of commands, sort them, print them
|
||||||
|
std::list<std::string> sorted_cmds;
|
||||||
for (const auto & cf : cmdfunctions_) {
|
for (const auto & cf : cmdfunctions_) {
|
||||||
if (cf.device_type_ == device_type) {
|
if ((cf.device_type_ == device_type) && !cf.hidden_) {
|
||||||
shell.printf("%s ", uuid::read_flash_string(cf.cmd_).c_str());
|
sorted_cmds.push_back(uuid::read_flash_string(cf.cmd_));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sorted_cmds.sort();
|
||||||
|
for (auto & cl : sorted_cmds) {
|
||||||
|
shell.print(cl);
|
||||||
|
shell.print(" ");
|
||||||
|
}
|
||||||
|
|
||||||
shell.println();
|
shell.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,13 +45,20 @@ class Command {
|
|||||||
const __FlashStringHelper * cmd_;
|
const __FlashStringHelper * cmd_;
|
||||||
cmdfunction_p cmdfunction_;
|
cmdfunction_p cmdfunction_;
|
||||||
cmdfunction_json_p cmdfunction_json_;
|
cmdfunction_json_p cmdfunction_json_;
|
||||||
|
bool hidden_; // if its command not to be shown on the Console
|
||||||
|
|
||||||
CmdFunction(const uint8_t device_type, const uint8_t flag, const __FlashStringHelper * cmd, cmdfunction_p cmdfunction, cmdfunction_json_p cmdfunction_json)
|
CmdFunction(const uint8_t device_type,
|
||||||
|
const uint8_t flag,
|
||||||
|
const __FlashStringHelper * cmd,
|
||||||
|
cmdfunction_p cmdfunction,
|
||||||
|
cmdfunction_json_p cmdfunction_json,
|
||||||
|
bool hidden = false)
|
||||||
: device_type_(device_type)
|
: device_type_(device_type)
|
||||||
, flag_(flag)
|
, flag_(flag)
|
||||||
, cmd_(cmd)
|
, cmd_(cmd)
|
||||||
, cmdfunction_(cmdfunction)
|
, cmdfunction_(cmdfunction)
|
||||||
, cmdfunction_json_(cmdfunction_json) {
|
, cmdfunction_json_(cmdfunction_json)
|
||||||
|
, hidden_(hidden) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -62,7 +69,7 @@ class Command {
|
|||||||
static bool call(const uint8_t device_type, const char * cmd, const char * value, const int8_t id, JsonObject & json);
|
static bool call(const uint8_t device_type, const char * cmd, const char * value, const int8_t id, JsonObject & json);
|
||||||
static bool call(const uint8_t device_type, const char * cmd, const char * value, const int8_t id = 0);
|
static bool call(const uint8_t device_type, const char * cmd, const char * value, const int8_t id = 0);
|
||||||
static void add(const uint8_t device_type, const __FlashStringHelper * cmd, cmdfunction_p cb, uint8_t flag = 0);
|
static void add(const uint8_t device_type, const __FlashStringHelper * cmd, cmdfunction_p cb, uint8_t flag = 0);
|
||||||
static void add_with_json(const uint8_t device_type, const __FlashStringHelper * cmd, cmdfunction_json_p cb);
|
static void add_with_json(const uint8_t device_type, const __FlashStringHelper * cmd, cmdfunction_json_p cb, bool hidden = false);
|
||||||
static void show_all(uuid::console::Shell & shell);
|
static void show_all(uuid::console::Shell & shell);
|
||||||
static Command::CmdFunction * find_command(const uint8_t device_type, const char * cmd);
|
static Command::CmdFunction * find_command(const uint8_t device_type, const char * cmd);
|
||||||
static char * check_command(char * out, const char * cmd, int8_t & id);
|
static char * check_command(char * out, const char * cmd, int8_t & id);
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ class EMSESP {
|
|||||||
static void process_version(std::shared_ptr<const Telegram> telegram);
|
static void process_version(std::shared_ptr<const Telegram> telegram);
|
||||||
static void publish_response(std::shared_ptr<const Telegram> telegram);
|
static void publish_response(std::shared_ptr<const Telegram> telegram);
|
||||||
static void publish_all_loop();
|
static void publish_all_loop();
|
||||||
static bool command_info(uint8_t device_type, JsonObject & json, const int8_t id);
|
static bool command_info(uint8_t device_type, JsonObject & json, const int8_t id, bool verbose = true);
|
||||||
|
|
||||||
static constexpr uint32_t EMS_FETCH_FREQUENCY = 60000; // check every minute
|
static constexpr uint32_t EMS_FETCH_FREQUENCY = 60000; // check every minute
|
||||||
static uint32_t last_fetch_;
|
static uint32_t last_fetch_;
|
||||||
|
|||||||
Reference in New Issue
Block a user