show sensor command commands

This commit is contained in:
MichaelDvP
2024-01-30 08:05:50 +01:00
parent 0f799d5922
commit de9c224a23
3 changed files with 16 additions and 18 deletions

View File

@@ -623,6 +623,11 @@ void AnalogSensor::publish_values(const bool force) {
// called from emsesp.cpp for commands
// searches sensor by name
bool AnalogSensor::get_value_info(JsonObject output, const char * cmd, const int8_t id) {
// check of it a 'commmands' command
if (Helpers::toLower(cmd) == F_(commands)) {
return Command::list(EMSdevice::DeviceType::ANALOGSENSOR, output);
}
if (sensors_.empty()) {
return true; // no sensors, return true
}
@@ -647,11 +652,6 @@ bool AnalogSensor::get_value_info(JsonObject output, const char * cmd, const int
return true;
}
// check of it a 'commmands' command
if (Helpers::toLower(cmd) == F_(commands)) {
return Command::list(EMSdevice::DeviceType::TEMPERATURESENSOR, output);
}
// this is for a specific sensor
// make a copy of the string command for parsing, and lowercase it
char sensor_name[30] = {'\0'};

View File

@@ -176,7 +176,7 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
String dat = output["api_data"];
output.clear();
input["data"] = dat.c_str();
data = input["data"];
data = input["data"];
}
}
}
@@ -439,7 +439,11 @@ void Command::erase_command(const uint8_t device_type, const char * cmd) {
// list all commands for a specific device, output as json
bool Command::list(const uint8_t device_type, JsonObject output) {
if (cmdfunctions_.empty()) {
// force add info and commands for those non-EMS devices
if (device_type == EMSdevice::DeviceType::TEMPERATURESENSOR || device_type == EMSdevice::DeviceType::ANALOGSENSOR) {
output[F_(info)] = Helpers::translated_word(FL_(info_cmd));
output[F_(commands)] = Helpers::translated_word(FL_(commands_cmd));
} else if (cmdfunctions_.empty()) {
output["message"] = "no commands available";
return false;
}
@@ -453,12 +457,6 @@ bool Command::list(const uint8_t device_type, JsonObject output) {
}
sorted_cmds.sort();
// force add info and commands for those non-EMS devices
if (device_type == EMSdevice::DeviceType::TEMPERATURESENSOR) {
output[F_(info)] = Helpers::translated_word(FL_(info_cmd));
output[F_(commands)] = Helpers::translated_word(FL_(commands_cmd));
}
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_))) {

View File

@@ -345,6 +345,11 @@ bool TemperatureSensor::updated_values() {
// called from emsesp.cpp for commands
bool TemperatureSensor::get_value_info(JsonObject output, const char * cmd, const int8_t id) {
// check of it a 'commmands' command
if (Helpers::toLower(cmd) == F_(commands)) {
return Command::list(EMSdevice::DeviceType::TEMPERATURESENSOR, output);
}
if (sensors_.empty()) {
return true; // no sensors, return true
}
@@ -372,11 +377,6 @@ bool TemperatureSensor::get_value_info(JsonObject output, const char * cmd, cons
return true;
}
// check of it a 'commmands' command
if (Helpers::toLower(cmd) == F_(commands)) {
return Command::list(EMSdevice::DeviceType::TEMPERATURESENSOR, output);
}
// this is for a specific sensor
// make a copy of the string command for parsing, and lowercase it
char sensor_name[30] = {'\0'};