commands "fetch" and "publish ha" as call (#608)

This commit is contained in:
MichaelDvP
2020-11-14 10:31:55 +01:00
parent 18d8d223fb
commit ba793e0408
4 changed files with 22 additions and 32 deletions

View File

@@ -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

View File

@@ -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<std::string> & 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<std::string> & 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<std::string> & arguments) {
EMSESP::send_raw_telegram(arguments.front().c_str());
});
commands->add_command(ShellContext::MAIN,
CommandFlags::USER,
flash_string_vector{F_(watch)},

View File

@@ -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);
});

View File

@@ -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);