mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
Merge branch 'dev' of https://github.com/emsesp/EMS-ESP32 into dev2x
This commit is contained in:
15
.github/workflows/github-releases-to-discord.yml
vendored
15
.github/workflows/github-releases-to-discord.yml
vendored
@@ -9,16 +9,15 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
- name: Github Releases To Discord
|
||||
uses: SethCohen/github-releases-to-discord@v1.13.1
|
||||
with:
|
||||
webhook_url: ${{ secrets.WEBHOOK_URL }}
|
||||
color: "2105893"
|
||||
username: "Release Changelog"
|
||||
avatar_url: "https://cdn.discordapp.com/icons/816637840644505620/0b14718532d855c452903851b4f0c9a2.png"
|
||||
content: "||@everyone||"
|
||||
footer_title: "Changelog"
|
||||
footer_icon_url: "https://cdn.discordapp.com/icons/816637840644505620/0b14718532d855c452903851b4f0c9a2.png"
|
||||
color: '2105893'
|
||||
username: 'Release Changelog'
|
||||
avatar_url: 'https://cdn.discordapp.com/icons/816637840644505620/0b14718532d855c452903851b4f0c9a2.png'
|
||||
content: '||@everyone||'
|
||||
footer_title: 'Changelog'
|
||||
footer_icon_url: 'https://cdn.discordapp.com/icons/816637840644505620/0b14718532d855c452903851b4f0c9a2.png'
|
||||
footer_timestamp: true
|
||||
|
||||
|
||||
2
.github/workflows/pre_release.yml
vendored
2
.github/workflows/pre_release.yml
vendored
@@ -12,7 +12,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
2
.github/workflows/sonar_check.yml
vendored
2
.github/workflows/sonar_check.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
||||
env:
|
||||
BUILD_WRAPPER_OUT_DIR: bw-output
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
||||
- name: Install sonar-scanner and build-wrapper
|
||||
|
||||
2
.github/workflows/tagged_release.yml
vendored
2
.github/workflows/tagged_release.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
2
.github/workflows/test_release.yml
vendored
2
.github/workflows/test_release.yml
vendored
@@ -12,7 +12,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
47
.vscode/settings.json
vendored
47
.vscode/settings.json
vendored
@@ -10,7 +10,6 @@
|
||||
"eslint.nodePath": "interface/.yarn/sdks",
|
||||
"eslint.workingDirectories": ["interface"],
|
||||
"prettier.prettierPath": "",
|
||||
"typescript.tsdk": "interface/.yarn/sdks/typescript/lib",
|
||||
"typescript.enablePromptUseWorkspaceTsdk": true,
|
||||
"files.associations": {
|
||||
"*.tsx": "typescriptreact",
|
||||
@@ -27,7 +26,51 @@
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"string": "cpp",
|
||||
"string_view": "cpp"
|
||||
"string_view": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bitset": "cpp",
|
||||
"cctype": "cpp",
|
||||
"chrono": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"list": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"unordered_set": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"iterator": "cpp",
|
||||
"map": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"random": "cpp",
|
||||
"set": "cpp",
|
||||
"fstream": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"limits": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"thread": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeinfo": "cpp"
|
||||
},
|
||||
"todo-tree.filtering.excludeGlobs": [
|
||||
"**/vendor/**",
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## **IMPORTANT! BREAKING CHANGES**
|
||||
|
||||
Writeable Text entities have moved from type `sensor` to `text` in Home Assistant to make them also editable within an HA dashboard. Examples are `datetime`, `holidays`, `switchtime`, `vacations`, `maintenancedate`...). You will need to manually remove any old discovery topics from your MQTT broker using an application like MQTT Explorer.
|
||||
Writeable Text entities have moved from type `sensor` to `text` in Home Assistant to make them also editable within an HA dashboard. Examples are `datetime`, `holidays`, `switchtime`, `vacations`, `maintenancedate`... You will need to manually remove any old discovery topics from your MQTT broker using an application like MQTT Explorer.
|
||||
|
||||
## Added
|
||||
|
||||
@@ -19,12 +19,14 @@ Writeable Text entities have moved from type `sensor` to `text` in Home Assistan
|
||||
- heatpump high res energy counters [#1348, #1349. #1350](https://github.com/emsesp/EMS-ESP32/issues/1348)
|
||||
- optional bssid in network settings
|
||||
- extension module EM100 [#1315](https://github.com/emsesp/EMS-ESP32/discussions/1315)
|
||||
- Added 'system allvalues' command that dumps all the EMS device values, plus sensors and any custom entities
|
||||
|
||||
## Fixed
|
||||
|
||||
- remove command `remoteseltemp`, thermostat accept it only from remote thermostat
|
||||
- shower_data MQTT payload contains the timestamp [#1329](https://github.com/emsesp/EMS-ESP32/issues/1329)
|
||||
- fixed helper text in Web Device Entity dialog box for numerical ranges
|
||||
- MQTT base with paths not working in HA [#1393](https://github.com/emsesp/EMS-ESP32/issues/1393)
|
||||
|
||||
## Changed
|
||||
|
||||
|
||||
@@ -65,8 +65,8 @@
|
||||
"eslint-plugin-prettier": "alpha",
|
||||
"eslint-plugin-react": "^7.33.2",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"preact": "^10.18.2",
|
||||
"prettier": "^3.0.3",
|
||||
"preact": "^10.19.1",
|
||||
"prettier": "^3.1.0",
|
||||
"rollup-plugin-visualizer": "^5.9.2",
|
||||
"terser": "^5.24.0",
|
||||
"vite": "^4.5.0",
|
||||
|
||||
@@ -1678,8 +1678,8 @@ __metadata:
|
||||
jwt-decode: "npm:^4.0.0"
|
||||
lodash-es: "npm:^4.17.21"
|
||||
mime-types: "npm:^2.1.35"
|
||||
preact: "npm:^10.18.2"
|
||||
prettier: "npm:^3.0.3"
|
||||
preact: "npm:^10.19.1"
|
||||
prettier: "npm:^3.1.0"
|
||||
react: "npm:latest"
|
||||
react-dom: "npm:latest"
|
||||
react-dropzone: "npm:^14.2.3"
|
||||
@@ -6758,10 +6758,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"preact@npm:^10.18.2":
|
||||
version: 10.18.2
|
||||
resolution: "preact@npm:10.18.2"
|
||||
checksum: c7dcd6ea812adb0bdc215366b14aadc44724b6dd6c4e9aadd986126d94abde62f3e02e18d6157a9984873be9877f206c0afa10a09346178c4c828a103a66a0e1
|
||||
"preact@npm:^10.19.1":
|
||||
version: 10.19.1
|
||||
resolution: "preact@npm:10.19.1"
|
||||
checksum: 1dce5b00d9031aca2266ef64cc38b27a4696f1c4d78baecc1f66a9bf2798c022a792b97257d64db450723edb69c12bc967e993d3b516734eff57895b9258c419
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -6795,12 +6795,12 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"prettier@npm:^3.0.3":
|
||||
version: 3.0.3
|
||||
resolution: "prettier@npm:3.0.3"
|
||||
"prettier@npm:^3.1.0":
|
||||
version: 3.1.0
|
||||
resolution: "prettier@npm:3.1.0"
|
||||
bin:
|
||||
prettier: bin/prettier.cjs
|
||||
checksum: ccf1ead9794b017be6b42d0873f459070beef2069eb393c8b4c0d11aa3430acefc54f6d5f44a5b7ce9af05ad8daf694b912f0aa2808d1c22dfa86e61e9d563f8
|
||||
checksum: e95e8f93c6b9aea2ac1e86bebe329bee90c8c50d9a23d1f593eba8d7f39b33b3641eb28785001505b6723c47895a5322ad12a2fb855b289cb7bae450ffc34425
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
@@ -616,6 +616,7 @@ void AnalogSensor::publish_values(const bool force) {
|
||||
}
|
||||
|
||||
JsonObject dev = config.createNestedObject("dev");
|
||||
dev["name"] = name;
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
ids.add(Mqtt::basename());
|
||||
|
||||
|
||||
@@ -156,6 +156,9 @@ class AnalogSensor {
|
||||
bool get_value_info(JsonObject & output, const char * cmd, const int8_t id) const;
|
||||
void store_counters();
|
||||
|
||||
bool command_info(const char * value, const int8_t id, JsonObject & output) const;
|
||||
|
||||
|
||||
#if defined(EMSESP_TEST)
|
||||
void test();
|
||||
#endif
|
||||
@@ -169,7 +172,6 @@ class AnalogSensor {
|
||||
void remove_ha_topic(const int8_t type, const uint8_t id) const;
|
||||
bool command_setvalue(const char * value, const int8_t gpio);
|
||||
void measure();
|
||||
bool command_info(const char * value, const int8_t id, JsonObject & output) const;
|
||||
bool command_commands(const char * value, const int8_t id, JsonObject & output);
|
||||
|
||||
std::vector<Sensor> sensors_; // our list of sensors
|
||||
|
||||
@@ -510,7 +510,7 @@ void Command::show(uuid::console::Shell & shell, uint8_t device_type, bool verbo
|
||||
}
|
||||
shell.print(cl);
|
||||
// pad with spaces
|
||||
while (i++ < 22) {
|
||||
while (i++ < 30) {
|
||||
shell.print(' ');
|
||||
}
|
||||
shell.print(COLOR_BRIGHT_CYAN);
|
||||
@@ -521,7 +521,7 @@ void Command::show(uuid::console::Shell & shell, uint8_t device_type, bool verbo
|
||||
shell.print(Helpers::translated_word(cf.description_));
|
||||
if (!cf.has_flags(CommandFlag::ADMIN_ONLY)) {
|
||||
shell.print(' ');
|
||||
shell.print(COLOR_BRIGHT_RED);
|
||||
shell.print(COLOR_BRIGHT_GREEN);
|
||||
shell.print('*');
|
||||
}
|
||||
shell.print(COLOR_RESET);
|
||||
@@ -601,7 +601,7 @@ void Command::show_devices(uuid::console::Shell & shell) {
|
||||
// output list of all commands to console
|
||||
// calls show with verbose mode set
|
||||
void Command::show_all(uuid::console::Shell & shell) {
|
||||
shell.println("Available commands (*=authorization not required): ");
|
||||
shell.printfln("Showing all available commands (%s*%s=authentication not required):", COLOR_BRIGHT_GREEN, COLOR_RESET);
|
||||
|
||||
// show system first
|
||||
shell.print(COLOR_BOLD_ON);
|
||||
@@ -615,9 +615,9 @@ void Command::show_all(uuid::console::Shell & shell) {
|
||||
shell.print(COLOR_YELLOW);
|
||||
shell.printf(" %s: ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::CUSTOM));
|
||||
shell.println(COLOR_RESET);
|
||||
shell.printf(" info: %slists all values %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_RED);
|
||||
shell.printf(" info:\t\t\t\t%slists all values %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_GREEN);
|
||||
shell.println(COLOR_RESET);
|
||||
shell.printf(" commands: %slists all commands %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_RED);
|
||||
shell.printf(" commands:\t\t\t%slists all commands %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_GREEN);
|
||||
shell.print(COLOR_RESET);
|
||||
show(shell, EMSdevice::DeviceType::CUSTOM, true);
|
||||
|
||||
@@ -626,9 +626,9 @@ void Command::show_all(uuid::console::Shell & shell) {
|
||||
shell.print(COLOR_YELLOW);
|
||||
shell.printf(" %s: ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::SCHEDULER));
|
||||
shell.println(COLOR_RESET);
|
||||
shell.printf(" info: %slists all values %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_RED);
|
||||
shell.printf(" info:\t\t\t\t%slists all values %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_GREEN);
|
||||
shell.println(COLOR_RESET);
|
||||
shell.printf(" commands: %slists all commands %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_RED);
|
||||
shell.printf(" commands:\t\t\t%slists all commands %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_GREEN);
|
||||
shell.print(COLOR_RESET);
|
||||
show(shell, EMSdevice::DeviceType::SCHEDULER, true);
|
||||
|
||||
|
||||
@@ -348,15 +348,6 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
||||
"local");
|
||||
});
|
||||
|
||||
commands->add_command(ShellContext::MAIN, CommandFlags::USER, string_vector{F_(set)}, [](Shell & shell, const std::vector<std::string> & arguments) {
|
||||
to_app(shell).webSettingsService.read([&](WebSettings & settings) {
|
||||
shell.printfln("Language: %s", settings.locale.c_str());
|
||||
shell.printfln(F_(tx_mode_fmt), settings.tx_mode);
|
||||
shell.printfln(F_(bus_id_fmt), settings.ems_bus_id);
|
||||
shell.printfln(F_(board_profile_fmt), settings.board_profile.c_str());
|
||||
});
|
||||
});
|
||||
|
||||
//
|
||||
// EMS device commands
|
||||
//
|
||||
@@ -609,12 +600,13 @@ void EMSESPShell::stopped() {
|
||||
// show welcome banner
|
||||
void EMSESPShell::display_banner() {
|
||||
println();
|
||||
printfln("┌────────────────────────────────────────┐");
|
||||
printfln("┌───────────────────────────────────────┐");
|
||||
printfln("│ %sEMS-ESP version %-12s%s │", COLOR_BOLD_ON, EMSESP_APP_VERSION, COLOR_BOLD_OFF);
|
||||
printfln("│ %s%shttps://github.com/emsesp/EMS-ESP32%s │", COLOR_BRIGHT_GREEN, COLOR_UNDERLINE, COLOR_RESET);
|
||||
printfln("│ │");
|
||||
printfln("│ type %shelp%s to show available commands │", COLOR_UNDERLINE, COLOR_RESET);
|
||||
printfln("└────────────────────────────────────────┘");
|
||||
printfln("│ use %ssu%s to access Admin commands │", COLOR_UNDERLINE, COLOR_RESET);
|
||||
printfln("└───────────────────────────────────────┘");
|
||||
println();
|
||||
|
||||
// set console name
|
||||
|
||||
@@ -803,29 +803,9 @@ void EMSdevice::publish_value(void * value_p) const {
|
||||
}
|
||||
|
||||
// looks up the UOM for a given key from the device value table
|
||||
// key is the fullname
|
||||
std::string EMSdevice::get_value_uom(const char * key) const {
|
||||
// the key may have a TAG string prefixed at the beginning. If so, remove it
|
||||
char new_key[80];
|
||||
strlcpy(new_key, key, sizeof(new_key));
|
||||
char * key_p = new_key;
|
||||
|
||||
for (uint8_t i = 0; i < DeviceValue::NUM_TAGS; i++) {
|
||||
auto tag = Helpers::translated_word(DeviceValue::DeviceValueTAG_s[i]);
|
||||
if (tag) {
|
||||
std::string key2 = key; // copy string to a std::string so we can use the find function
|
||||
uint8_t length = strlen(tag);
|
||||
if ((key2.find(tag) != std::string::npos) && (key[length] == ' ')) {
|
||||
key_p += length + 1; // remove the tag
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// look up key in our device value list
|
||||
std::string EMSdevice::get_value_uom(const std::string & shortname) const {
|
||||
for (const auto & dv : devicevalues_) {
|
||||
auto fullname = dv.get_fullname();
|
||||
if ((!dv.has_state(DeviceValueState::DV_WEB_EXCLUDE) && !fullname.empty()) && (fullname == key_p)) {
|
||||
if ((!dv.has_state(DeviceValueState::DV_WEB_EXCLUDE)) && (dv.short_name == shortname)) {
|
||||
// ignore TIME since "minutes" is already added to the string value
|
||||
if ((dv.uom == DeviceValueUOM::NONE) || (dv.uom == DeviceValueUOM::MINUTES)) {
|
||||
break;
|
||||
@@ -837,6 +817,43 @@ std::string EMSdevice::get_value_uom(const char * key) const {
|
||||
return std::string{}; // not found
|
||||
}
|
||||
|
||||
bool EMSdevice::export_values(uint8_t device_type, JsonObject & output, const int8_t id, const uint8_t output_target) {
|
||||
bool has_value = false;
|
||||
uint8_t tag;
|
||||
if (id >= 1 && id <= (1 + DeviceValueTAG::TAG_HS16 - DeviceValueTAG::TAG_HC1)) {
|
||||
tag = DeviceValueTAG::TAG_HC1 + id - 1; // this sets also WWC and HS
|
||||
} else if (id == -1 || id == 0) {
|
||||
tag = DeviceValueTAG::TAG_NONE;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (id > 0 || output_target == EMSdevice::OUTPUT_TARGET::API_VERBOSE) {
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
if (emsdevice && (emsdevice->device_type() == device_type)) {
|
||||
has_value |= emsdevice->generate_values(output, tag, (id < 1), output_target); // use nested for id -1 and 0
|
||||
}
|
||||
}
|
||||
return has_value;
|
||||
}
|
||||
|
||||
// for nested output add for each tag
|
||||
for (tag = DeviceValueTAG::TAG_BOILER_DATA_WW; tag <= DeviceValueTAG::TAG_HS16; tag++) {
|
||||
JsonObject output_hc = output;
|
||||
bool nest_created = false;
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
if (emsdevice && (emsdevice->device_type() == device_type)) {
|
||||
if (!nest_created && emsdevice->has_tags(tag)) {
|
||||
output_hc = output.createNestedObject(EMSdevice::tag_to_mqtt(tag));
|
||||
nest_created = true;
|
||||
}
|
||||
has_value |= emsdevice->generate_values(output_hc, tag, true, output_target); // use nested for id -1 and 0
|
||||
}
|
||||
}
|
||||
}
|
||||
return has_value;
|
||||
}
|
||||
|
||||
// prepare array of device values used for the WebUI
|
||||
// this is loosely based of the function generate_values used for the MQTT and Console
|
||||
// except additional data is stored in the JSON document needed for the Web UI like the UOM and command
|
||||
|
||||
@@ -47,12 +47,13 @@ class EMSdevice {
|
||||
// static functions, used outside the class like in console.cpp, command.cpp, emsesp.cpp, mqtt.cpp
|
||||
static const char * device_type_2_device_name(const uint8_t device_type);
|
||||
static uint8_t device_name_2_device_type(const char * topic);
|
||||
|
||||
static const char * tag_to_string(uint8_t tag, const bool translate = true);
|
||||
static const char * uom_to_string(uint8_t uom);
|
||||
static const char * tag_to_mqtt(uint8_t tag);
|
||||
|
||||
static uint8_t decode_brand(uint8_t value);
|
||||
static bool export_values(uint8_t device_type, JsonObject & output, const int8_t id, const uint8_t output_target);
|
||||
|
||||
// non static
|
||||
|
||||
const char * device_type_name(); // returns short non-translated device type name
|
||||
const char * device_type_2_device_name_translated(); // returns translated device type name
|
||||
@@ -213,7 +214,8 @@ class EMSdevice {
|
||||
void register_telegram_type(const uint16_t telegram_type_id, const char * telegram_type_name, bool fetch, const process_function_p cb);
|
||||
bool handle_telegram(std::shared_ptr<const Telegram> telegram);
|
||||
|
||||
std::string get_value_uom(const char * key) const;
|
||||
std::string get_value_uom(const std::string & shortname) const;
|
||||
|
||||
bool get_value_info(JsonObject & root, const char * cmd, const int8_t id);
|
||||
void get_dv_info(JsonObject & json);
|
||||
|
||||
|
||||
@@ -386,28 +386,32 @@ void EMSESP::show_device_values(uuid::console::Shell & shell) {
|
||||
|
||||
// print line
|
||||
for (JsonPair p : json) {
|
||||
const char * key = p.key().c_str();
|
||||
shell.printf(" %s: ", key);
|
||||
JsonVariant data = p.value();
|
||||
shell.print(COLOR_BRIGHT_GREEN);
|
||||
shell.print(data.as<std::string>());
|
||||
// if there is a uom print it
|
||||
std::string uom = emsdevice->get_value_uom(key);
|
||||
if (uom == "°C" && EMSESP::system_.fahrenheit()) {
|
||||
uom = "°F";
|
||||
std::string key = p.key().c_str(); // this will be fullname and the shortname in brackets
|
||||
|
||||
// extract the shortname from the key, which is in brackets
|
||||
std::size_t first_bracket = key.find_last_of('(');
|
||||
std::size_t last_bracket = key.find_last_of(')');
|
||||
std::string shortname = key.substr(first_bracket + 1, last_bracket - first_bracket - 1);
|
||||
std::string uom = emsdevice->get_value_uom(key.substr(first_bracket + 1, last_bracket - first_bracket - 1));
|
||||
|
||||
shell.printfln(" %s: %s%s %s%s", key.c_str(), COLOR_BRIGHT_GREEN, p.value().as<std::string>().c_str(), uom.c_str(), COLOR_RESET);
|
||||
}
|
||||
shell.println();
|
||||
}
|
||||
}
|
||||
if (!uom.empty()) {
|
||||
shell.print(' ');
|
||||
shell.print(uom);
|
||||
}
|
||||
|
||||
shell.print(COLOR_RESET);
|
||||
shell.println();
|
||||
// show any custom entities
|
||||
if (webCustomEntityService.count_entities() > 0) {
|
||||
shell.printfln("Custom entities:");
|
||||
StaticJsonDocument<EMSESP_JSON_SIZE_MEDIUM> custom_doc; // use max size
|
||||
JsonObject custom_output = custom_doc.to<JsonObject>();
|
||||
webCustomEntityService.show_values(custom_output);
|
||||
for (JsonPair p : custom_output) {
|
||||
shell.printfln(" %s: %s%s%s", p.key().c_str(), COLOR_BRIGHT_GREEN, p.value().as<std::string>().c_str(), COLOR_RESET);
|
||||
}
|
||||
shell.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// show temperature sensors and Analog sensors
|
||||
@@ -1166,14 +1170,17 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const
|
||||
device_type,
|
||||
F_(info),
|
||||
[device_type](const char * value, const int8_t id, JsonObject & output) {
|
||||
return command_info(device_type, output, id, EMSdevice::OUTPUT_TARGET::API_VERBOSE);
|
||||
return EMSdevice::export_values(device_type, output, id, EMSdevice::OUTPUT_TARGET::API_VERBOSE);
|
||||
},
|
||||
FL_(info_cmd));
|
||||
Command::add(
|
||||
device_type,
|
||||
F_(values),
|
||||
[device_type](const char * value, const int8_t id, JsonObject & output) {
|
||||
return command_info(device_type, output, id, EMSdevice::OUTPUT_TARGET::API_SHORTNAMES); // HIDDEN command showing short names, used in e.g. /api/boiler
|
||||
return EMSdevice::export_values(device_type,
|
||||
output,
|
||||
id,
|
||||
EMSdevice::OUTPUT_TARGET::API_SHORTNAMES); // HIDDEN command showing short names, used in e.g. /api/boiler
|
||||
},
|
||||
nullptr,
|
||||
CommandFlag::HIDDEN); // this command is hidden
|
||||
@@ -1214,43 +1221,6 @@ bool EMSESP::command_commands(uint8_t device_type, JsonObject & output, const in
|
||||
return Command::list(device_type, output);
|
||||
}
|
||||
|
||||
// export all values for a specific device
|
||||
bool EMSESP::command_info(uint8_t device_type, JsonObject & output, const int8_t id, const uint8_t output_target) {
|
||||
bool has_value = false;
|
||||
uint8_t tag;
|
||||
if (id >= 1 && id <= (1 + DeviceValueTAG::TAG_HS16 - DeviceValueTAG::TAG_HC1)) {
|
||||
tag = DeviceValueTAG::TAG_HC1 + id - 1; // this sets also WWC and HS
|
||||
} else if (id == -1 || id == 0) {
|
||||
tag = DeviceValueTAG::TAG_NONE;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (id > 0 || output_target == EMSdevice::OUTPUT_TARGET::API_VERBOSE) {
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
if (emsdevice && (emsdevice->device_type() == device_type)) {
|
||||
has_value |= emsdevice->generate_values(output, tag, (id < 1), output_target); // use nested for id -1 and 0
|
||||
}
|
||||
}
|
||||
return has_value;
|
||||
}
|
||||
// for nested output add for each tag
|
||||
for (tag = DeviceValueTAG::TAG_BOILER_DATA_WW; tag <= DeviceValueTAG::TAG_HS16; tag++) {
|
||||
JsonObject output_hc = output;
|
||||
bool nest_created = false;
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
if (emsdevice && (emsdevice->device_type() == device_type)) {
|
||||
if (!nest_created && emsdevice->has_tags(tag)) {
|
||||
output_hc = output.createNestedObject(EMSdevice::tag_to_mqtt(tag));
|
||||
nest_created = true;
|
||||
}
|
||||
has_value |= emsdevice->generate_values(output_hc, tag, true, output_target); // use nested for id -1 and 0
|
||||
}
|
||||
}
|
||||
}
|
||||
return has_value;
|
||||
}
|
||||
|
||||
// send a read request, passing it into to the Tx Service, with optional offset and length
|
||||
void EMSESP::send_read_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset, const uint8_t length, const bool front) {
|
||||
txservice_.read_request(type_id, dest, offset, length, front);
|
||||
|
||||
@@ -245,7 +245,6 @@ class EMSESP {
|
||||
static void process_version(std::shared_ptr<const Telegram> telegram);
|
||||
static void publish_response(std::shared_ptr<const Telegram> telegram);
|
||||
static void publish_all_loop();
|
||||
static bool command_info(uint8_t device_type, JsonObject & output, const int8_t id, const uint8_t output_target);
|
||||
static bool command_commands(uint8_t device_type, JsonObject & output, const int8_t id);
|
||||
static bool command_entities(uint8_t device_type, JsonObject & output, const int8_t id);
|
||||
|
||||
|
||||
@@ -123,7 +123,6 @@ MAKE_WORD_CUSTOM(EMSESP, "EMS-ESP")
|
||||
MAKE_WORD_CUSTOM(host_fmt, "Host: %s")
|
||||
MAKE_WORD_CUSTOM(port_fmt, "Port: %d")
|
||||
MAKE_WORD_CUSTOM(hostname_fmt, "Hostname: %s")
|
||||
MAKE_WORD_CUSTOM(board_profile_fmt, "Board Profile: %s")
|
||||
MAKE_WORD_CUSTOM(mark_interval_fmt, "Mark interval: %lus")
|
||||
MAKE_WORD_CUSTOM(wifi_ssid_fmt, "WiFi SSID: %s")
|
||||
MAKE_WORD_CUSTOM(wifi_password_fmt, "WiFi Password: %S")
|
||||
|
||||
@@ -57,7 +57,6 @@ MAKE_WORD_TRANSLATION(ventilation_device, "Ventilation", "Lüftung", "Ventilatie
|
||||
|
||||
|
||||
// commands
|
||||
// TODO translate
|
||||
MAKE_WORD_TRANSLATION(info_cmd, "lists all values", "Liste aller Werte", "lijst van alle waardes", "", "wyświetl wszystkie wartości", "Viser alle verdier", "", "Tüm değerleri listele", "elenca tutti i valori") // TODO translate
|
||||
MAKE_WORD_TRANSLATION(commands_cmd, "lists all commands", "Liste aller Kommandos", "lijst van alle commando's", "", "wyświetl wszystkie komendy", "Viser alle kommandoer", "", "Tüm komutları listele", "elencaa tutti i comandi") // TODO translate
|
||||
MAKE_WORD_TRANSLATION(entities_cmd, "lists all entities", "Liste aller Entitäten", "lijst van alle entiteiten", "", "wyświetl wszsytkie encje", "Viser alle enheter", "", "Tüm varlıkları listele", "elenca tutte le entità") // TODO translate
|
||||
@@ -73,6 +72,7 @@ MAKE_WORD_TRANSLATION(schedule_cmd, "enable schedule item", "Aktiviere Zeitplan"
|
||||
MAKE_WORD_TRANSLATION(entity_cmd, "set custom value on ems", "Sende eigene Entitäten zu EMS", "verstuur custom waarde naar EMS", "", "wyślij własną wartość na EMS", "", "", "emp üzerinde özel değer ayarla", "imposta valori personalizzati su EMS") // TODO translate
|
||||
MAKE_WORD_TRANSLATION(commands_response, "get response","Hole Antwort","Verzoek om antwoord", "", "", "", "uzyskaj odpowiedź", "", "", "gelen cevap", "") // TODO translate
|
||||
MAKE_WORD_TRANSLATION(coldshot_cmd, "send a cold shot of water", "", "", "", "uruchom tryśnięcie zimnej wody", "", "", "soğuk su gönder", "") // TODO translate
|
||||
MAKE_WORD_TRANSLATION(allvalues_cmd, "output all values", "", "", "", "", "", "", "", "") // TODO translate
|
||||
|
||||
// tags
|
||||
MAKE_WORD_TRANSLATION(tag_boiler_data_ww, "dhw", "WW", "dhw", "VV", "CWU", "dhw", "ecs", "SKS", "dhw")
|
||||
|
||||
13
src/mqtt.cpp
13
src/mqtt.cpp
@@ -730,21 +730,24 @@ bool Mqtt::queue_ha(const char * topic, const JsonObject & payload) {
|
||||
bool Mqtt::publish_ha_sensor_config(DeviceValue & dv, const char * model, const char * brand, const bool remove, const bool create_device_config) {
|
||||
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE> dev_json;
|
||||
|
||||
// always create the ids
|
||||
// always create the ids (discovery indentifiers)
|
||||
// with the name always
|
||||
// and the manufacturer and model if we're creating the device config for the first entity
|
||||
JsonArray ids = dev_json.createNestedArray("ids");
|
||||
char ha_device[40];
|
||||
auto device_type_name = EMSdevice::device_type_2_device_name(dv.device_type);
|
||||
snprintf(ha_device, sizeof(ha_device), "%s-%s", Mqtt::basename().c_str(), device_type_name);
|
||||
ids.add(ha_device);
|
||||
|
||||
if (create_device_config) {
|
||||
auto cap_name = strdup(device_type_name);
|
||||
Helpers::CharToUpperUTF8(cap_name); // capitalize first letter
|
||||
dev_json["name"] = Mqtt::basename() + " " + cap_name;
|
||||
free(cap_name);
|
||||
|
||||
if (create_device_config) {
|
||||
dev_json["mf"] = brand;
|
||||
dev_json["mdl"] = model;
|
||||
dev_json["via_device"] = "ems-esp";
|
||||
free(cap_name);
|
||||
}
|
||||
|
||||
// calculate the min and max
|
||||
@@ -779,6 +782,7 @@ bool Mqtt::publish_system_ha_sensor_config(uint8_t type, const char * name, cons
|
||||
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE> doc;
|
||||
JsonObject dev_json = doc.createNestedObject("dev");
|
||||
|
||||
dev_json["name"] = Mqtt::basename();
|
||||
JsonArray ids = dev_json.createNestedArray("ids");
|
||||
ids.add(Mqtt::basename());
|
||||
|
||||
@@ -1246,6 +1250,9 @@ bool Mqtt::publish_ha_climate_config(const uint8_t tag, const bool has_roomtemp,
|
||||
snprintf(ha_device, sizeof(ha_device), "%s-thermostat", Mqtt::basename().c_str());
|
||||
ids.add(ha_device);
|
||||
|
||||
// device name must be different to the entity name, take the ids value we just created
|
||||
dev["name"] = ha_device;
|
||||
|
||||
// add "availability" section
|
||||
add_avty_to_doc(topic_t, doc.as<JsonObject>(), seltemp_cond, has_roomtemp ? currtemp_cond : nullptr, hc_mode_cond);
|
||||
|
||||
|
||||
@@ -211,6 +211,7 @@ void Shower::set_shower_state(bool state, bool force) {
|
||||
}
|
||||
|
||||
JsonObject dev = doc.createNestedObject("dev");
|
||||
dev["name"] = "EMS-ESP";
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
ids.add(Mqtt::basename());
|
||||
|
||||
@@ -240,6 +241,7 @@ void Shower::set_shower_state(bool state, bool force) {
|
||||
doc["ent_cat"] = "diagnostic";
|
||||
|
||||
JsonObject dev2 = doc.createNestedObject("dev");
|
||||
dev2["name"] = "EMS-ESP";
|
||||
JsonArray ids2 = dev2.createNestedArray("ids");
|
||||
ids2.add(Mqtt::basename());
|
||||
|
||||
@@ -266,6 +268,7 @@ void Shower::set_shower_state(bool state, bool force) {
|
||||
doc["ent_cat"] = "diagnostic";
|
||||
|
||||
JsonObject dev3 = doc.createNestedObject("dev");
|
||||
dev3["name"] = "EMS-ESP";
|
||||
JsonArray ids3 = dev3.createNestedArray("ids");
|
||||
ids3.add(Mqtt::basename());
|
||||
|
||||
|
||||
@@ -106,6 +106,35 @@ bool System::command_response(const char * value, const int8_t id, JsonObject &
|
||||
return true;
|
||||
}
|
||||
|
||||
// output all the EMS devices and their values, plus the sensors and any custom entities
|
||||
// not scheduler as these are records with no output data
|
||||
bool System::command_allvalues(const char * value, const int8_t id, JsonObject & output) {
|
||||
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XXXLARGE);
|
||||
JsonObject device_output;
|
||||
|
||||
for (const auto & device_class : EMSFactory::device_handlers()) {
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
if (emsdevice->device_type() == device_class.first) {
|
||||
std::string title = emsdevice->device_type_2_device_name_translated() + std::string(" ") + emsdevice->to_string();
|
||||
device_output = output.createNestedObject(title);
|
||||
emsesp::EMSdevice::export_values(emsdevice->device_type(), device_output, id, EMSdevice::OUTPUT_TARGET::API_VERBOSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Custom entities
|
||||
device_output = output.createNestedObject("Custom Entities");
|
||||
EMSESP::webCustomEntityService.get_value_info(device_output, "");
|
||||
|
||||
// Sensors
|
||||
device_output = output.createNestedObject("Analog Sensors");
|
||||
EMSESP::analogsensor_.command_info(nullptr, 0, device_output);
|
||||
device_output = output.createNestedObject("Temperature Sensors");
|
||||
EMSESP::temperaturesensor_.command_info(nullptr, 0, device_output);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// fetch device values
|
||||
bool System::command_fetch(const char * value, const int8_t id) {
|
||||
std::string value_s;
|
||||
@@ -764,6 +793,7 @@ void System::commands_init() {
|
||||
// restart and watch (and test) are also exposed as Console commands
|
||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(restart), System::command_restart, FL_(restart_cmd), CommandFlag::ADMIN_ONLY);
|
||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(watch), System::command_watch, FL_(watch_cmd));
|
||||
|
||||
#if defined(EMSESP_TEST)
|
||||
Command::add(EMSdevice::DeviceType::SYSTEM, ("test"), System::command_test, FL_(test_cmd));
|
||||
#endif
|
||||
@@ -772,6 +802,8 @@ void System::commands_init() {
|
||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(info), System::command_info, FL_(system_info_cmd));
|
||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(commands), System::command_commands, FL_(commands_cmd));
|
||||
Command::add(EMSdevice::DeviceType::SYSTEM, F("response"), System::command_response, FL_(commands_response));
|
||||
Command::add(EMSdevice::DeviceType::SYSTEM, F("allvalues"), System::command_allvalues, FL_(allvalues_cmd));
|
||||
|
||||
|
||||
// MQTT subscribe "ems-esp/system/#"
|
||||
Mqtt::subscribe(EMSdevice::DeviceType::SYSTEM, "system/#", nullptr); // use empty function callback
|
||||
@@ -903,6 +935,8 @@ void System::show_system(uuid::console::Shell & shell) {
|
||||
refreshHeapMem(); // refresh free heap and max alloc heap
|
||||
|
||||
shell.println("System:");
|
||||
shell.printfln(" Version: %s", EMSESP_APP_VERSION);
|
||||
shell.printfln(" Language: %s", locale().c_str());
|
||||
shell.printfln(" Board profile: %s", board_profile().c_str());
|
||||
shell.printfln(" Uptime: %s", uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3).c_str());
|
||||
#ifndef EMSESP_STANDALONE
|
||||
|
||||
@@ -60,6 +60,8 @@ class System {
|
||||
static bool command_info(const char * value, const int8_t id, JsonObject & output);
|
||||
static bool command_commands(const char * value, const int8_t id, JsonObject & output);
|
||||
static bool command_response(const char * value, const int8_t id, JsonObject & output);
|
||||
static bool command_allvalues(const char * value, const int8_t id, JsonObject & output);
|
||||
|
||||
#if defined(EMSESP_TEST)
|
||||
static bool command_test(const char * value, const int8_t id);
|
||||
#endif
|
||||
|
||||
@@ -544,6 +544,7 @@ void TemperatureSensor::publish_values(const bool force) {
|
||||
config["name"] = name;
|
||||
|
||||
JsonObject dev = config.createNestedObject("dev");
|
||||
dev["name"] = Mqtt::basename();
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
ids.add(Mqtt::basename());
|
||||
|
||||
|
||||
@@ -111,6 +111,8 @@ class TemperatureSensor {
|
||||
|
||||
bool update(const std::string & id, const std::string & name, int16_t offset);
|
||||
|
||||
bool command_info(const char * value, const int8_t id, JsonObject & output);
|
||||
|
||||
#if defined(EMSESP_TEST)
|
||||
void test();
|
||||
#endif
|
||||
@@ -152,7 +154,6 @@ class TemperatureSensor {
|
||||
uint64_t get_id(const uint8_t addr[]);
|
||||
void remove_ha_topic(const std::string & id);
|
||||
|
||||
bool command_info(const char * value, const int8_t id, JsonObject & output);
|
||||
bool command_commands(const char * value, const int8_t id, JsonObject & output);
|
||||
|
||||
std::vector<Sensor> sensors_; // our list of active sensors
|
||||
|
||||
@@ -275,11 +275,17 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
bool ok = false;
|
||||
|
||||
if (command == "general") {
|
||||
shell.printfln("Testing adding a general boiler & thermostat...");
|
||||
shell.printfln("Testing adding a boiler, thermostat and sensors...");
|
||||
run_test("general");
|
||||
|
||||
// add sensors
|
||||
emsesp::EMSESP::analogsensor_.test();
|
||||
emsesp::EMSESP::temperaturesensor_.test();
|
||||
|
||||
// shell.invoke_command("show devices");
|
||||
shell.invoke_command("show values");
|
||||
shell.invoke_command("call system publish");
|
||||
shell.invoke_command("call system allvalues");
|
||||
// shell.invoke_command("call system publish");
|
||||
// shell.invoke_command("show mqtt");
|
||||
ok = true;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace emsesp {
|
||||
|
||||
static QueueHandle_t uart_queue;
|
||||
uint8_t tx_mode_ = 0xFF;
|
||||
uint32_t inverse_mask = 0;
|
||||
|
||||
/*
|
||||
* receive task, wait for break and call incoming_telegram
|
||||
@@ -82,8 +83,15 @@ void EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
||||
.source_clk = UART_SCLK_APB,
|
||||
};
|
||||
#if defined(EMSUART_RX_INVERT)
|
||||
inverse_mask |= UART_SIGNAL_RXD_INV;
|
||||
#endif
|
||||
#if defined(EMSUART_TX_INVERT)
|
||||
inverse_mask |= UART_SIGNAL_TXD_INV;
|
||||
#endif
|
||||
uart_param_config(EMSUART_NUM, &uart_config);
|
||||
uart_set_pin(EMSUART_NUM, tx_gpio, rx_gpio, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||
uart_set_line_inverse(EMSUART_NUM, inverse_mask);
|
||||
uart_driver_install(EMSUART_NUM, 129, 0, (EMS_MAXBUFFERSIZE + 1) * 2, &uart_queue, 0); // buffer must be > fifo
|
||||
uart_set_rx_full_threshold(EMSUART_NUM, 1);
|
||||
uart_set_rx_timeout(EMSUART_NUM, 0); // disable
|
||||
@@ -136,9 +144,9 @@ uint16_t EMSuart::transmit(const uint8_t * buf, const uint8_t len) {
|
||||
uart_write_bytes(EMSUART_NUM, &buf[i], 1);
|
||||
delayMicroseconds(EMSUART_TX_WAIT_PLUS);
|
||||
}
|
||||
uart_set_line_inverse(EMSUART_NUM, UART_SIGNAL_TXD_INV);
|
||||
uart_set_line_inverse(EMSUART_NUM, UART_SIGNAL_TXD_INV ^ inverse_mask);
|
||||
delayMicroseconds(EMSUART_TX_BRK_PLUS);
|
||||
uart_set_line_inverse(EMSUART_NUM, 0);
|
||||
uart_set_line_inverse(EMSUART_NUM, inverse_mask);
|
||||
return EMS_TX_STATUS_OK;
|
||||
}
|
||||
|
||||
@@ -147,9 +155,9 @@ uint16_t EMSuart::transmit(const uint8_t * buf, const uint8_t len) {
|
||||
uart_write_bytes(EMSUART_NUM, &buf[i], 1);
|
||||
delayMicroseconds(EMSUART_TX_WAIT_HT3);
|
||||
}
|
||||
uart_set_line_inverse(EMSUART_NUM, UART_SIGNAL_TXD_INV);
|
||||
uart_set_line_inverse(EMSUART_NUM, UART_SIGNAL_TXD_INV ^ inverse_mask);
|
||||
delayMicroseconds(EMSUART_TX_BRK_HT3);
|
||||
uart_set_line_inverse(EMSUART_NUM, 0);
|
||||
uart_set_line_inverse(EMSUART_NUM, inverse_mask);
|
||||
return EMS_TX_STATUS_OK;
|
||||
}
|
||||
|
||||
@@ -164,9 +172,9 @@ uint16_t EMSuart::transmit(const uint8_t * buf, const uint8_t len) {
|
||||
uart_get_buffered_data_len(EMSUART_NUM, &rx1);
|
||||
} while ((rx1 == rx0) && (--timeoutcnt));
|
||||
}
|
||||
uart_set_line_inverse(EMSUART_NUM, UART_SIGNAL_TXD_INV);
|
||||
uart_set_line_inverse(EMSUART_NUM, UART_SIGNAL_TXD_INV ^ inverse_mask);
|
||||
delayMicroseconds(EMSUART_TX_BRK_EMS);
|
||||
uart_set_line_inverse(EMSUART_NUM, 0);
|
||||
uart_set_line_inverse(EMSUART_NUM, inverse_mask);
|
||||
return EMS_TX_STATUS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define EMSESP_APP_VERSION "3.6.3-test.7"
|
||||
#define EMSESP_APP_VERSION "3.6.3-test.8"
|
||||
|
||||
@@ -182,7 +182,8 @@ bool WebCustomEntityService::command_setvalue(const char * value, const std::str
|
||||
}
|
||||
|
||||
// output of a single value
|
||||
void WebCustomEntityService::render_value(JsonObject & output, CustomEntityItem entity, const bool useVal, const bool web) {
|
||||
// if add_uom is true it will add the UOM string to the value
|
||||
void WebCustomEntityService::render_value(JsonObject & output, CustomEntityItem entity, const bool useVal, const bool web, const bool add_uom) {
|
||||
char payload[12];
|
||||
std::string name = useVal ? "value" : entity.name;
|
||||
switch (entity.value_type) {
|
||||
@@ -201,28 +202,33 @@ void WebCustomEntityService::render_value(JsonObject & output, CustomEntityItem
|
||||
break;
|
||||
case DeviceValueType::INT:
|
||||
if ((int8_t)entity.value != EMS_VALUE_INT_NOTSET) {
|
||||
output[name] = serialized(Helpers::render_value(payload, entity.factor * (int8_t)entity.value, 2));
|
||||
std::string v = Helpers::render_value(payload, entity.factor * (int8_t)entity.value, 2);
|
||||
output[name] = add_uom ? serialized(v + ' ' + EMSdevice::uom_to_string(entity.uom)) : serialized(v);
|
||||
}
|
||||
break;
|
||||
case DeviceValueType::UINT:
|
||||
if ((uint8_t)entity.value != EMS_VALUE_UINT_NOTSET) {
|
||||
output[name] = serialized(Helpers::render_value(payload, entity.factor * (uint8_t)entity.value, 2));
|
||||
std::string v = Helpers::render_value(payload, entity.factor * (uint8_t)entity.value, 2);
|
||||
output[name] = add_uom ? serialized(v + ' ' + EMSdevice::uom_to_string(entity.uom)) : serialized(v);
|
||||
}
|
||||
break;
|
||||
case DeviceValueType::SHORT:
|
||||
if ((int16_t)entity.value != EMS_VALUE_SHORT_NOTSET) {
|
||||
output[name] = serialized(Helpers::render_value(payload, entity.factor * (int16_t)entity.value, 2));
|
||||
std::string v = Helpers::render_value(payload, entity.factor * (int16_t)entity.value, 2);
|
||||
output[name] = add_uom ? serialized(v + ' ' + EMSdevice::uom_to_string(entity.uom)) : serialized(v);
|
||||
}
|
||||
break;
|
||||
case DeviceValueType::USHORT:
|
||||
if ((uint16_t)entity.value != EMS_VALUE_USHORT_NOTSET) {
|
||||
output[name] = serialized(Helpers::render_value(payload, entity.factor * (uint16_t)entity.value, 2));
|
||||
std::string v = Helpers::render_value(payload, entity.factor * (uint16_t)entity.value, 2);
|
||||
output[name] = add_uom ? serialized(v + ' ' + EMSdevice::uom_to_string(entity.uom)) : serialized(v);
|
||||
}
|
||||
break;
|
||||
case DeviceValueType::ULONG:
|
||||
case DeviceValueType::TIME:
|
||||
if (entity.value != EMS_VALUE_ULONG_NOTSET) {
|
||||
output[name] = serialized(Helpers::render_value(payload, entity.factor * entity.value, 2));
|
||||
std::string v = Helpers::render_value(payload, entity.factor * entity.value, 2);
|
||||
output[name] = add_uom ? serialized(v + ' ' + EMSdevice::uom_to_string(entity.uom)) : serialized(v);
|
||||
}
|
||||
break;
|
||||
case DeviceValueType::STRING:
|
||||
@@ -236,6 +242,15 @@ void WebCustomEntityService::render_value(JsonObject & output, CustomEntityItem
|
||||
}
|
||||
}
|
||||
|
||||
// display all custom entities
|
||||
// adding each one, with UOM to a json object string
|
||||
void WebCustomEntityService::show_values(JsonObject & output) {
|
||||
for (const CustomEntityItem & entity : *customEntityItems) {
|
||||
render_value(output, entity, false, false, true); // with add_uom
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// process json output for info/commands and value_info
|
||||
bool WebCustomEntityService::get_value_info(JsonObject & output, const char * cmd) {
|
||||
EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
|
||||
@@ -247,11 +262,13 @@ bool WebCustomEntityService::get_value_info(JsonObject & output, const char * cm
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// if no entries, return empty json
|
||||
// https://github.com/emsesp/EMS-ESP32/issues/1297
|
||||
if (customEntityItems->size() == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strlen(cmd) == 0 || Helpers::toLower(cmd) == F_(values) || Helpers::toLower(cmd) == F_(info)) {
|
||||
// list all names
|
||||
for (const CustomEntityItem & entity : *customEntityItems) {
|
||||
@@ -410,6 +427,7 @@ void WebCustomEntityService::publish(const bool force) {
|
||||
}
|
||||
}
|
||||
JsonObject dev = config.createNestedObject("dev");
|
||||
dev["name"] = Mqtt::basename();
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
ids.add(Mqtt::basename());
|
||||
|
||||
|
||||
@@ -59,15 +59,16 @@ class WebCustomEntityService : public StatefulService<WebCustomEntity> {
|
||||
bool get_value_info(JsonObject & output, const char * cmd);
|
||||
bool get_value(std::shared_ptr<const Telegram> telegram);
|
||||
void fetch();
|
||||
void render_value(JsonObject & output, CustomEntityItem entity, const bool useVal = false, const bool web = false);
|
||||
void render_value(JsonObject & output, CustomEntityItem entity, const bool useVal = false, const bool web = false, const bool add_uom = false);
|
||||
void show_values(JsonObject & output);
|
||||
void generate_value_web(JsonObject & output);
|
||||
|
||||
uint8_t count_entities();
|
||||
uint8_t has_commands();
|
||||
void generate_value_web(JsonObject & output);
|
||||
void ha_reset() {
|
||||
ha_registered_ = false;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
HttpEndpoint<WebCustomEntity> _httpEndpoint;
|
||||
FSPersistence<WebCustomEntity> _fsPersistence;
|
||||
|
||||
@@ -99,7 +99,7 @@ StateUpdateResult WebCustomization::update(JsonObject & root, WebCustomization &
|
||||
#ifdef EMSESP_STANDALONE
|
||||
// invoke some fake data for testing
|
||||
const char * json = "{\"ts\":[],\"as\":[],\"masked_entities\":[{\"product_id\":123,\"device_id\":8,\"entity_ids\":[\"08heatingactive|my custom "
|
||||
"name for heating active\",\"08tapwateractive\"]}]}";
|
||||
"name for heating active (HS1)\",\"08tapwateractive\"]}]}";
|
||||
StaticJsonDocument<500> doc;
|
||||
deserializeJson(doc, json);
|
||||
root = doc.as<JsonObject>();
|
||||
|
||||
@@ -288,6 +288,7 @@ void WebSchedulerService::publish(const bool force) {
|
||||
}
|
||||
|
||||
JsonObject dev = config.createNestedObject("dev");
|
||||
dev["name"] = Mqtt::basename();
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
ids.add(Mqtt::basename());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user