Merge pull request #842 from MichaelDvP/dev

fix #841
This commit is contained in:
Proddy
2022-12-27 10:27:37 +01:00
committed by GitHub
8 changed files with 24 additions and 27 deletions

View File

@@ -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 // 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 // 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) { 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; uint8_t return_code = CommandRet::OK;
auto dname = EMSdevice::device_type_2_device_name(device_type); 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 // see if there is a command registered
auto cf = find_command(device_type, device_id, cmd); auto cf = find_command(device_type, device_id, cmd);

View File

@@ -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. // 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; uint8_t tag = DeviceValueTAG::TAG_HC1 + id - 1;
for (const auto & dv : devicevalues_) { for (const auto & dv : devicevalues_) {
if ((id < 1 || dv.tag == tag) && dv.has_cmd && strcmp(dv.short_name, cmd) == 0) { if ((id < 1 || dv.tag == tag) && dv.has_cmd && strcmp(dv.short_name, cmd) == 0) {

View File

@@ -53,7 +53,7 @@ class EMSdevice {
static std::string tag_to_mqtt(uint8_t tag); static std::string tag_to_mqtt(uint8_t tag);
bool has_tag(const uint8_t tag) const; 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 { inline uint8_t device_id() const {
return device_id_; return device_id_;

View File

@@ -114,9 +114,9 @@ bool EMSESP::cmd_is_readonly(const uint8_t device_type, const uint8_t device_id,
return false; 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) { 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(); return emsdevice->device_id();
} }
} }

View File

@@ -131,7 +131,7 @@ class EMSESP {
static bool device_exists(const uint8_t device_id); 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 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(const uint8_t device_type);
static uint8_t count_devices(); static uint8_t count_devices();
static uint8_t device_index(const uint8_t device_type, const uint8_t unique_id); static uint8_t device_index(const uint8_t device_type, const uint8_t unique_id);

View File

@@ -101,14 +101,12 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) {
} }
// output json buffer // output json buffer
auto * response = new PrettyAsyncJsonResponse(false, EMSESP_JSON_SIZE_XXLARGE_DYN); size_t buffer = EMSESP_JSON_SIZE_XXLARGE_DYN;
if (!response->getSize()) { auto * response = new PrettyAsyncJsonResponse(false, buffer);
while (!response->getSize()) {
delete response; delete response;
response = new PrettyAsyncJsonResponse(false, 256); buffer -= 1024;
response->setCode(507); // Insufficient Storage response = new PrettyAsyncJsonResponse(false, buffer);
response->setLength();
request->send(response);
return;
} }
JsonObject output = response->getRoot(); JsonObject output = response->getRoot();

View File

@@ -200,14 +200,12 @@ void WebCustomizationService::devices(AsyncWebServerRequest * request) {
// send back list of device entities // send back list of device entities
void WebCustomizationService::device_entities(AsyncWebServerRequest * request, JsonVariant & json) { void WebCustomizationService::device_entities(AsyncWebServerRequest * request, JsonVariant & json) {
if (json.is<JsonObject>()) { if (json.is<JsonObject>()) {
auto * response = new MsgpackAsyncJsonResponse(true, EMSESP_JSON_SIZE_XXXLARGE_DYN); size_t buffer = EMSESP_JSON_SIZE_XXXLARGE_DYN;
if (!response->getSize()) { auto * response = new PrettyAsyncJsonResponse(true, buffer);
while (!response->getSize()) {
delete response; delete response;
response = new MsgpackAsyncJsonResponse(true, 256); buffer -= 1024;
response->setCode(507); // Insufficient Storage response = new PrettyAsyncJsonResponse(true, buffer);
response->setLength();
request->send(response);
return;
} }
for (const auto & emsdevice : EMSESP::emsdevices) { for (const auto & emsdevice : EMSESP::emsdevices) {
if (emsdevice->unique_id() == json["id"]) { if (emsdevice->unique_id() == json["id"]) {

View File

@@ -165,14 +165,12 @@ void WebDataService::sensor_data(AsyncWebServerRequest * request) {
// Compresses the JSON using MsgPack https://msgpack.org/index.html // Compresses the JSON using MsgPack https://msgpack.org/index.html
void WebDataService::device_data(AsyncWebServerRequest * request, JsonVariant & json) { void WebDataService::device_data(AsyncWebServerRequest * request, JsonVariant & json) {
if (json.is<JsonObject>()) { if (json.is<JsonObject>()) {
auto * response = new MsgpackAsyncJsonResponse(false, EMSESP_JSON_SIZE_XXXLARGE_DYN); size_t buffer = EMSESP_JSON_SIZE_XXXLARGE_DYN;
if (!response->getSize()) { auto * response = new PrettyAsyncJsonResponse(false, buffer);
while (!response->getSize()) {
delete response; delete response;
response = new MsgpackAsyncJsonResponse(false, 256); buffer -= 1024;
response->setCode(507); // Insufficient Storage response = new PrettyAsyncJsonResponse(false, buffer);
response->setLength();
request->send(response);
return;
} }
for (const auto & emsdevice : EMSESP::emsdevices) { for (const auto & emsdevice : EMSESP::emsdevices) {
if (emsdevice->unique_id() == json["id"]) { if (emsdevice->unique_id() == json["id"]) {