From ba793e0408714adbeb5622ba6aa471646e63c69f Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sat, 14 Nov 2020 10:31:55 +0100 Subject: [PATCH] commands "fetch" and "publish ha" as call (#608) --- CHANGELOG_LATEST.md | 2 ++ src/console.cpp | 30 ------------------------------ src/system.cpp | 21 +++++++++++++++++++-- src/system.h | 1 + 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 996a1f35a..4f49d423c 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -4,6 +4,7 @@ - function keys in editor: cursor, del, home, end. F1=help, F2=show, and other shortcuts - SM100 pump working time and energy units - heating curve parameters for RC300 +- `wwonetime` for RC300 thermostat ### Fixed - mixer IPM pumpstatus @@ -12,6 +13,7 @@ - optimized MQTT for HA to reduce mem fragmentation issues - change syslog settings without reboot - HA-config split in smaller blocks +- commands `fetch` and `publish [ha]` as call ### Removed - old scripts diff --git a/src/console.cpp b/src/console.cpp index 7a24f8294..4e39942dd 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -108,28 +108,6 @@ void EMSESPShell::add_console_commands() { // commands->remove_context_commands(ShellContext::MAIN); commands->remove_all_commands(); - commands->add_command(ShellContext::MAIN, - CommandFlags::USER, - flash_string_vector{F_(fetch)}, - [&](Shell & shell, const std::vector & arguments __attribute__((unused))) { - shell.printfln(F("Requesting data from EMS devices")); - EMSESP::fetch_device_values(); - }); - - commands->add_command(ShellContext::MAIN, - CommandFlags::ADMIN, - flash_string_vector{F_(publish)}, - flash_string_vector{F_(ha_optional)}, - [&](Shell & shell, const std::vector & arguments) { - if (arguments.empty()) { - EMSESP::publish_all(); - shell.printfln(F("Published all data to MQTT")); - } else { - EMSESP::publish_all(true); - shell.printfln(F("Published all data to MQTT, including HA configs")); - } - }); - commands->add_command(ShellContext::MAIN, CommandFlags::USER, flash_string_vector{F_(show)}, @@ -312,14 +290,6 @@ void EMSESPShell::add_console_commands() { }); #endif - commands->add_command(ShellContext::MAIN, - CommandFlags::ADMIN, - flash_string_vector{F_(send), F_(telegram)}, - flash_string_vector{F_(data_mandatory)}, - [](Shell & shell __attribute__((unused)), const std::vector & arguments) { - EMSESP::send_raw_telegram(arguments.front().c_str()); - }); - commands->add_command(ShellContext::MAIN, CommandFlags::USER, flash_string_vector{F_(watch)}, diff --git a/src/system.cpp b/src/system.cpp index 524561998..45a40d633 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -59,15 +59,31 @@ bool System::command_pin(const char * value, const int8_t id) { return false; } -// send raw +// send raw to ems bool System::command_send(const char * value, const int8_t id) { EMSESP::send_raw_telegram(value); // ignore id return true; } -// publish +// fetch device values +bool System::command_fetch(const char * value, const int8_t id) { + LOG_INFO(F("Requesting data from EMS devices")); + EMSESP::fetch_device_values(); + return true; +} + +// mqtt publish bool System::command_publish(const char * value, const int8_t id) { + std::string ha(10, '\0'); + if (Helpers::value2string(value, ha)) { + if (ha == "ha") { + EMSESP::publish_all(true); // includes HA + LOG_INFO(F("Published all data to MQTT, including HA configs")); + return true; + } + } EMSESP::publish_all(); // ignore value and id + LOG_INFO(F("Published all data to MQTT")); return true; } @@ -172,6 +188,7 @@ void System::start() { Command::add(EMSdevice::DeviceType::SYSTEM, settings.ems_bus_id, F_(pin), System::command_pin); Command::add(EMSdevice::DeviceType::SYSTEM, settings.ems_bus_id, F_(send), System::command_send); Command::add(EMSdevice::DeviceType::SYSTEM, settings.ems_bus_id, F_(publish), System::command_publish); + Command::add(EMSdevice::DeviceType::SYSTEM, settings.ems_bus_id, F_(fetch), System::command_fetch); Command::add_with_json(EMSdevice::DeviceType::SYSTEM, F_(info), System::command_info); Command::add_with_json(EMSdevice::DeviceType::SYSTEM, F_(report), System::command_report); }); diff --git a/src/system.h b/src/system.h index a5f5c44e7..0af8a8aae 100644 --- a/src/system.h +++ b/src/system.h @@ -51,6 +51,7 @@ class System { static bool command_pin(const char * value, const int8_t id); static bool command_send(const char * value, const int8_t id); static bool command_publish(const char * value, const int8_t id); + static bool command_fetch(const char * value, const int8_t id); static bool command_info(const char * value, const int8_t id, JsonObject & json); static bool command_report(const char * value, const int8_t id, JsonObject & json);