mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -101,14 +101,12 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) {
|
||||
}
|
||||
|
||||
// output json buffer
|
||||
auto * response = new PrettyAsyncJsonResponse(false, EMSESP_JSON_SIZE_XXLARGE_DYN);
|
||||
if (!response->getSize()) {
|
||||
size_t buffer = EMSESP_JSON_SIZE_XXLARGE_DYN;
|
||||
auto * response = new PrettyAsyncJsonResponse(false, buffer);
|
||||
while (!response->getSize()) {
|
||||
delete response;
|
||||
response = new PrettyAsyncJsonResponse(false, 256);
|
||||
response->setCode(507); // Insufficient Storage
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
return;
|
||||
buffer -= 1024;
|
||||
response = new PrettyAsyncJsonResponse(false, buffer);
|
||||
}
|
||||
JsonObject output = response->getRoot();
|
||||
|
||||
|
||||
@@ -200,14 +200,12 @@ void WebCustomizationService::devices(AsyncWebServerRequest * request) {
|
||||
// send back list of device entities
|
||||
void WebCustomizationService::device_entities(AsyncWebServerRequest * request, JsonVariant & json) {
|
||||
if (json.is<JsonObject>()) {
|
||||
auto * response = new MsgpackAsyncJsonResponse(true, EMSESP_JSON_SIZE_XXXLARGE_DYN);
|
||||
if (!response->getSize()) {
|
||||
size_t buffer = EMSESP_JSON_SIZE_XXXLARGE_DYN;
|
||||
auto * response = new PrettyAsyncJsonResponse(true, buffer);
|
||||
while (!response->getSize()) {
|
||||
delete response;
|
||||
response = new MsgpackAsyncJsonResponse(true, 256);
|
||||
response->setCode(507); // Insufficient Storage
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
return;
|
||||
buffer -= 1024;
|
||||
response = new PrettyAsyncJsonResponse(true, buffer);
|
||||
}
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
if (emsdevice->unique_id() == json["id"]) {
|
||||
|
||||
@@ -165,14 +165,12 @@ void WebDataService::sensor_data(AsyncWebServerRequest * request) {
|
||||
// Compresses the JSON using MsgPack https://msgpack.org/index.html
|
||||
void WebDataService::device_data(AsyncWebServerRequest * request, JsonVariant & json) {
|
||||
if (json.is<JsonObject>()) {
|
||||
auto * response = new MsgpackAsyncJsonResponse(false, EMSESP_JSON_SIZE_XXXLARGE_DYN);
|
||||
if (!response->getSize()) {
|
||||
size_t buffer = EMSESP_JSON_SIZE_XXXLARGE_DYN;
|
||||
auto * response = new PrettyAsyncJsonResponse(false, buffer);
|
||||
while (!response->getSize()) {
|
||||
delete response;
|
||||
response = new MsgpackAsyncJsonResponse(false, 256);
|
||||
response->setCode(507); // Insufficient Storage
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
return;
|
||||
buffer -= 1024;
|
||||
response = new PrettyAsyncJsonResponse(false, buffer);
|
||||
}
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
if (emsdevice->unique_id() == json["id"]) {
|
||||
|
||||
Reference in New Issue
Block a user