Command returns as enum

This commit is contained in:
MichaelDvP
2021-07-22 13:00:16 +02:00
parent fc1cb00523
commit 694f647a2c
5 changed files with 24 additions and 14 deletions

View File

@@ -348,10 +348,10 @@ void Mqtt::on_message(const char * fulltopic, const char * payload, size_t len)
// LOG_INFO(F("devicetype= %d, topic = %s, cmd = %s, message = %s), mf.device_type_, topic, cmd_only, message);
// call command, assume admin authentication is allowed
uint8_t cmd_return = Command::call(mf.device_type_, cmd_only, message, true);
if (cmd_return == 2) {
if (cmd_return == CommandRet::NOT_FOUND) {
LOG_ERROR(F("No matching cmd (%s) in topic %s"), cmd_only, topic);
Mqtt::publish(F_(response), "unknown");
} else if (cmd_return == 3) {
} else if (cmd_return == CommandRet::ERROR) {
LOG_ERROR(F("Invalid data with cmd (%s) in topic %s"), cmd_only, topic);
Mqtt::publish(F_(response), "unknown");
}
@@ -381,7 +381,7 @@ void Mqtt::on_message(const char * fulltopic, const char * payload, size_t len)
n = doc["id"];
}
uint8_t cmd_return = 1; // OK
uint8_t cmd_return = CommandRet::OK;
JsonVariant data = doc["data"];
if (data.is<const char *>()) {
@@ -402,10 +402,10 @@ void Mqtt::on_message(const char * fulltopic, const char * payload, size_t len)
}
}
if (cmd_return == 2) {
if (cmd_return == CommandRet::NOT_FOUND) {
LOG_ERROR(F("No matching cmd (%s)"), command);
Mqtt::publish(F_(response), "unknown");
} else if (cmd_return == 3) {
} else if (cmd_return == CommandRet::ERROR) {
LOG_ERROR(F("Invalid data for cmd (%s)"), command);
Mqtt::publish(F_(response), "unknown");
}