From de9c224a23d0d9ea445cf25e8b81b21b6b809912 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Tue, 30 Jan 2024 08:05:50 +0100 Subject: [PATCH] show sensor command commands --- src/analogsensor.cpp | 10 +++++----- src/command.cpp | 14 ++++++-------- src/temperaturesensor.cpp | 10 +++++----- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/analogsensor.cpp b/src/analogsensor.cpp index 46794b512..e61915a26 100644 --- a/src/analogsensor.cpp +++ b/src/analogsensor.cpp @@ -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'}; diff --git a/src/command.cpp b/src/command.cpp index 12b4e13a7..9b5037060 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -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_))) { diff --git a/src/temperaturesensor.cpp b/src/temperaturesensor.cpp index 096bb6538..841ef633c 100644 --- a/src/temperaturesensor.cpp +++ b/src/temperaturesensor.cpp @@ -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'};