mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 01:09:51 +03:00
fix crashes, clean up, update packages
This commit is contained in:
@@ -249,14 +249,8 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char *
|
||||
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 return_code = CommandRet::OK;
|
||||
|
||||
auto dname = EMSdevice::device_type_2_device_name(device_type);
|
||||
|
||||
uint8_t device_id = 0;
|
||||
for (const auto & emsdevice : emsesp::EMSESP::emsdevices) {
|
||||
if (emsdevice->device_type() == device_type && emsdevice->has_cmd(id, cmd)) {
|
||||
device_id = emsdevice->device_id();
|
||||
}
|
||||
}
|
||||
auto dname = EMSdevice::device_type_2_device_name(device_type);
|
||||
uint8_t device_id = EMSESP::device_id_from_cmd(device_type, id, cmd);
|
||||
|
||||
// see if there is a command registered
|
||||
auto cf = find_command(device_type, device_id, cmd);
|
||||
|
||||
@@ -813,9 +813,9 @@ void EMSdevice::generate_values_web(JsonObject & output) {
|
||||
} else if ((dv.type == DeviceValueType::USHORT) && Helpers::hasValue(*(uint16_t *)(dv.value_p))) {
|
||||
obj["v"] = Helpers::transformNumFloat(*(uint16_t *)(dv.value_p), dv.numeric_operator, fahrenheit);
|
||||
} else if ((dv.type == DeviceValueType::ULONG) && Helpers::hasValue(*(uint32_t *)(dv.value_p))) {
|
||||
obj["v"] = (*(uint32_t *)(dv.value_p) / dv.numeric_operator); // ULONG always have positive num_op
|
||||
obj["v"] = dv.numeric_operator > 0 ? *(uint32_t *)(dv.value_p) / dv.numeric_operator : *(uint32_t *)(dv.value_p);
|
||||
} else if ((dv.type == DeviceValueType::TIME) && Helpers::hasValue(*(uint32_t *)(dv.value_p))) {
|
||||
obj["v"] = (*(uint32_t *)(dv.value_p) / dv.numeric_operator);
|
||||
obj["v"] = dv.numeric_operator > 0 ? *(uint32_t *)(dv.value_p) / dv.numeric_operator : *(uint32_t *)(dv.value_p);
|
||||
} else {
|
||||
obj["v"] = ""; // must have a value for sorting to work
|
||||
}
|
||||
@@ -923,9 +923,9 @@ void EMSdevice::generate_values_web_customization(JsonArray & output) {
|
||||
} else if (dv.type == DeviceValueType::USHORT) {
|
||||
obj["v"] = Helpers::transformNumFloat(*(uint16_t *)(dv.value_p), dv.numeric_operator, fahrenheit);
|
||||
} else if (dv.type == DeviceValueType::ULONG) {
|
||||
obj["v"] = (*(uint32_t *)(dv.value_p) / dv.numeric_operator);
|
||||
obj["v"] = dv.numeric_operator > 0 ? *(uint32_t *)(dv.value_p) / dv.numeric_operator : *(uint32_t *)(dv.value_p);
|
||||
} else if (dv.type == DeviceValueType::TIME) {
|
||||
obj["v"] = (*(uint32_t *)(dv.value_p) / dv.numeric_operator);
|
||||
obj["v"] = dv.numeric_operator > 0 ? *(uint32_t *)(dv.value_p) / dv.numeric_operator : *(uint32_t *)(dv.value_p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +114,15 @@ 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) {
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
if (emsdevice && emsdevice->device_type() == device_type && emsdevice->has_cmd(id, cmd)) {
|
||||
return emsdevice->device_id();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// clears list of recognized devices
|
||||
void EMSESP::clear_all_devices() {
|
||||
// temporarily removed: clearing the list causes a crash, the associated commands and mqtt should also be removed.
|
||||
|
||||
@@ -131,6 +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 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);
|
||||
|
||||
Reference in New Issue
Block a user