From 28de5bb097aa11592fdd6c5e2c7bbca4fd6ee15b Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Mon, 26 Dec 2022 15:42:31 +0100 Subject: [PATCH] fix #841 --- src/command.cpp | 5 ++++- src/emsdevice.cpp | 2 +- src/emsdevice.h | 2 +- src/emsesp.cpp | 4 ++-- src/emsesp.h | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/command.cpp b/src/command.cpp index 8f2b489ad..220b69006 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -247,10 +247,13 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * // id may be used to represent a heating circuit for example // returns 0 if the command errored, 1 (TRUE) if ok, 2 if not found, 3 if error or 4 if not allowed uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * value, const bool is_admin, const int8_t id, JsonObject & output) { + if (cmd == nullptr) { + return CommandRet::NOT_FOUND; + } uint8_t return_code = CommandRet::OK; auto dname = EMSdevice::device_type_2_device_name(device_type); - uint8_t device_id = EMSESP::device_id_from_cmd(device_type, id, cmd); + uint8_t device_id = EMSESP::device_id_from_cmd(device_type, cmd, id); // see if there is a command registered auto cf = find_command(device_type, device_id, cmd); diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 6f9e280e1..cf73f54d2 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -274,7 +274,7 @@ bool EMSdevice::has_tag(const uint8_t tag) const { } // check if the device has a command on the with this tag. -bool EMSdevice::has_cmd(const int8_t id, const char * cmd) const { +bool EMSdevice::has_cmd(const char * cmd, const int8_t id) const { uint8_t tag = DeviceValueTAG::TAG_HC1 + id - 1; for (const auto & dv : devicevalues_) { if ((id < 1 || dv.tag == tag) && dv.has_cmd && strcmp(dv.short_name, cmd) == 0) { diff --git a/src/emsdevice.h b/src/emsdevice.h index a826e9383..2eff48154 100644 --- a/src/emsdevice.h +++ b/src/emsdevice.h @@ -53,7 +53,7 @@ class EMSdevice { static std::string tag_to_mqtt(uint8_t tag); bool has_tag(const uint8_t tag) const; - bool has_cmd(const int8_t id, const char * cmd) const; + bool has_cmd(const char * cmd, const int8_t id) const; inline uint8_t device_id() const { return device_id_; diff --git a/src/emsesp.cpp b/src/emsesp.cpp index d4cc7a02f..3d5e77c6c 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -114,9 +114,9 @@ bool EMSESP::cmd_is_readonly(const uint8_t device_type, const uint8_t device_id, return false; } -uint8_t EMSESP::device_id_from_cmd(const uint8_t device_type, const int8_t id, const char * cmd) { +uint8_t EMSESP::device_id_from_cmd(const uint8_t device_type, const char * cmd, const int8_t id) { for (const auto & emsdevice : emsdevices) { - if (emsdevice && emsdevice->device_type() == device_type && emsdevice->has_cmd(id, cmd)) { + if (emsdevice && emsdevice->device_type() == device_type && emsdevice->has_cmd(cmd, id)) { return emsdevice->device_id(); } } diff --git a/src/emsesp.h b/src/emsesp.h index 876bdd795..661918ef1 100644 --- a/src/emsesp.h +++ b/src/emsesp.h @@ -131,7 +131,7 @@ class EMSESP { static bool device_exists(const uint8_t device_id); static bool cmd_is_readonly(const uint8_t device_type, const uint8_t device_id, const char * cmd, const int8_t id); - static uint8_t device_id_from_cmd(const uint8_t device_type, const int8_t id, const char * cmd); + static uint8_t device_id_from_cmd(const uint8_t device_type, const char * cmd, const int8_t id); static uint8_t count_devices(const uint8_t device_type); static uint8_t count_devices(); static uint8_t device_index(const uint8_t device_type, const uint8_t unique_id);