Skip to content

Commit

Permalink
fix crashes, clean up, update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Dec 22, 2022
1 parent d300ed3 commit f66e771
Show file tree
Hide file tree
Showing 7 changed files with 781 additions and 542 deletions.
2 changes: 1 addition & 1 deletion interface/.typesafe-i18n.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"adapter": "react",
"baseLocale": "pl",
"$schema": "https://unpkg.com/typesafe-i18n@5.17.2/schema/typesafe-i18n.json"
"$schema": "https://unpkg.com/typesafe-i18n@5.18.0/schema/typesafe-i18n.json"
}
1,287 changes: 761 additions & 526 deletions interface/package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@emotion/styled": "^11.10.5",
"@msgpack/msgpack": "^2.8.0",
"@mui/icons-material": "^5.11.0",
"@mui/material": "^5.11.0",
"@mui/material": "^5.11.1",
"@table-library/react-table-library": "4.0.23",
"@types/lodash": "^4.14.191",
"@types/node": "^18.11.17",
Expand All @@ -27,10 +27,10 @@
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"react-icons": "^4.7.1",
"react-router-dom": "^6.5.0",
"react-router-dom": "^6.6.0",
"react-scripts": "5.0.1",
"sockette": "^2.0.6",
"typesafe-i18n": "^5.17.2",
"typesafe-i18n": "^5.18.0",
"typescript": "^4.9.4"
},
"scripts": {
Expand Down
10 changes: 2 additions & 8 deletions src/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/emsdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/emsesp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/emsesp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f66e771

Please sign in to comment.