mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
prevent duplicate commands per device
This commit is contained in:
@@ -73,13 +73,16 @@ void Command::add(const uint8_t device_type, const uint8_t device_id, const __Fl
|
|||||||
|
|
||||||
// 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) {
|
void Command::add_with_json(const uint8_t device_type, const __FlashStringHelper * cmd, cmdfunction_json_p cb) {
|
||||||
cmdfunctions_.emplace_back(device_type, cmd, nullptr, cb);
|
// 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())) {
|
||||||
|
cmdfunctions_.emplace_back(device_type, cmd, nullptr, cb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// see if a command exists for that device type
|
// see if a command exists for that device type
|
||||||
bool Command::find_command(const uint8_t device_type, const char * cmd) {
|
bool Command::find_command(const uint8_t device_type, const char * cmd) {
|
||||||
for (const auto & cf : cmdfunctions_) {
|
for (const auto & cf : cmdfunctions_) {
|
||||||
if (strcmp(cmd, uuid::read_flash_string(cf.cmd_).c_str()) == 0) {
|
if ((strcmp(cmd, uuid::read_flash_string(cf.cmd_).c_str()) == 0) && (cf.device_type_ == device_type)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,6 +143,7 @@ void Command::show_devices(uuid::console::Shell & shell) {
|
|||||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||||
if ((emsdevice) && (emsdevice->device_type() == device_class.first)) {
|
if ((emsdevice) && (emsdevice->device_type() == device_class.first)) {
|
||||||
shell.printf("%s ", EMSdevice::device_type_2_device_name(device_class.first).c_str());
|
shell.printf("%s ", EMSdevice::device_type_2_device_name(device_class.first).c_str());
|
||||||
|
break; // we only want to show one (not multiple of the same device types)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user