diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 52eb1dab4..15791d283 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -26,10 +26,13 @@ - Add commands for analog sensors outputs - Support for multiple EMS-ESPs with MQTT and HA [[#759](https://github.com/emsesp/EMS-ESP32/issues/759)] - Settings for heatpump silent mode and additional heater [[#802](https://github.com/emsesp/EMS-ESP32/issues/802)] [[#803](https://github.com/emsesp/EMS-ESP32/issues/803)] +- Zone module MZ100 [#826](https://github.com/emsesp/EMS-ESP32/issues/826) ## Fixed - Factory Reset not working [#628](https://github.com/emsesp/EMS-ESP32/issues/628) +- Valid 4 byte values [#820](https://github.com/emsesp/EMS-ESP32/issues/820) +- Commands for multiple thermostats [#826](https://github.com/emsesp/EMS-ESP32/issues/826) ## Changed diff --git a/src/analogsensor.cpp b/src/analogsensor.cpp index fccaf23a5..de744e002 100644 --- a/src/analogsensor.cpp +++ b/src/analogsensor.cpp @@ -47,6 +47,7 @@ void AnalogSensor::start() { CommandFlag::HIDDEN); // this command is hidden Command::add( EMSdevice::DeviceType::ANALOGSENSOR, + 0, F_(setvalue), [&](const char * value, const int8_t id) { return command_setvalue(value, id); }, FL_(setiovalue_cmd), @@ -120,6 +121,7 @@ void AnalogSensor::reload() { if (sensor.type == AnalogType::COUNTER || sensor.type >= AnalogType::DIGITAL_OUT) { Command::add( EMSdevice::DeviceType::ANALOGSENSOR, + 0, sensor.name.c_str(), [&](const char * value, const int8_t id) { return command_setvalue(value, sensor.gpio); }, sensor.type == AnalogType::COUNTER ? FL_(counter) diff --git a/src/command.cpp b/src/command.cpp index eebbd7730..196d6b88f 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -251,8 +251,15 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * 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(); + } + } + // see if there is a command registered - auto cf = find_command(device_type, cmd); + auto cf = find_command(device_type, device_id, cmd); // check if its a call to and end-point to a device // except for system commands as this is a special device without any queryable entities (device values) @@ -287,7 +294,7 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * LOG_DEBUG(("%sCalling command %s"), ro.c_str(), info_s); } else { if (id > 0) { - LOG_DEBUG(("%sCalling command %s with value %s and id %d"), ro.c_str(), info_s, value, id); + LOG_DEBUG(("%sCalling command %s with value %s and id %d on device 0x%02X"), ro.c_str(), info_s, value, id, device_id); } else { LOG_DEBUG(("%sCalling command %s with value %s"), ro.c_str(), info_s, value); } @@ -321,9 +328,9 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * } // add a command to the list, which does not return json -void Command::add(const uint8_t device_type, const char * cmd, const cmd_function_p cb, const char * const * description, uint8_t flags) { +void Command::add(const uint8_t device_type, const uint8_t device_id, const char * cmd, const cmd_function_p cb, const char * const * description, uint8_t flags) { // if the command already exists for that device type don't add it - if (find_command(device_type, cmd) != nullptr) { + if (find_command(device_type, device_id, cmd) != nullptr) { return; } @@ -332,28 +339,28 @@ void Command::add(const uint8_t device_type, const char * cmd, const cmd_functio flags |= CommandFlag::HIDDEN; } - cmdfunctions_.emplace_back(device_type, flags, cmd, cb, nullptr, description); // callback for json is nullptr + cmdfunctions_.emplace_back(device_type, device_id, flags, cmd, cb, nullptr, description); // callback for json is nullptr } // add a command to the list, which does return a json object as output void Command::add(const uint8_t device_type, const char * cmd, const cmd_json_function_p cb, const char * const * description, uint8_t flags) { // if the command already exists for that device type don't add it - if (find_command(device_type, cmd) != nullptr) { + if (find_command(device_type, 0, cmd) != nullptr) { return; } - cmdfunctions_.emplace_back(device_type, flags, cmd, nullptr, cb, description); // callback for json is included + cmdfunctions_.emplace_back(device_type, 0, flags, cmd, nullptr, cb, description); // callback for json is included } // see if a command exists for that device type // is not case sensitive -Command::CmdFunction * Command::find_command(const uint8_t device_type, const char * cmd) { +Command::CmdFunction * Command::find_command(const uint8_t device_type, const uint8_t device_id, const char * cmd) { if ((cmd == nullptr) || (strlen(cmd) == 0) || (cmdfunctions_.empty())) { return nullptr; } for (auto & cf : cmdfunctions_) { - if (Helpers::toLower(cmd) == Helpers::toLower(cf.cmd_) && (cf.device_type_ == device_type)) { + if (Helpers::toLower(cmd) == Helpers::toLower(cf.cmd_) && (cf.device_type_ == device_type) && (!device_id || cf.device_id_ == device_id)) { return &cf; } } diff --git a/src/command.h b/src/command.h index 187a213d7..60234a250 100644 --- a/src/command.h +++ b/src/command.h @@ -55,19 +55,22 @@ class Command { public: struct CmdFunction { uint8_t device_type_; // DeviceType:: - uint8_t flags_; // mqtt flags for command subscriptions + uint8_t device_id_; + uint8_t flags_; // mqtt flags for command subscriptions const char * cmd_; cmd_function_p cmdfunction_; cmd_json_function_p cmdfunction_json_; const char * const * description_; CmdFunction(const uint8_t device_type, + const uint8_t device_id, const uint8_t flags, const char * cmd, const cmd_function_p cmdfunction, const cmd_json_function_p cmdfunction_json, const char * const * description) : device_type_(device_type) + , device_id_(device_id) , flags_(flags) , cmd_(cmd) , cmdfunction_(cmdfunction) @@ -98,6 +101,7 @@ class Command { // with normal call back function taking a value and id static void add(const uint8_t device_type, + const uint8_t device_id, const char * cmd, const cmd_function_p cb, const char * const * description, @@ -111,7 +115,7 @@ class Command { uint8_t flags = CommandFlag::MQTT_SUB_FLAG_DEFAULT); static void show_all(uuid::console::Shell & shell); - static Command::CmdFunction * find_command(const uint8_t device_type, const char * cmd); + static Command::CmdFunction * find_command(const uint8_t device_type, const uint8_t device_id, const char * cmd); static void erase_command(const uint8_t device_type, const char * cmd); static void show(uuid::console::Shell & shell, uint8_t device_type, bool verbose); diff --git a/src/device_library.h b/src/device_library.h index cf4793ca1..6cbe3c568 100644 --- a/src/device_library.h +++ b/src/device_library.h @@ -135,7 +135,7 @@ {159, DeviceType::MIXER, "MM50", DeviceFlags::EMS_DEVICE_FLAG_MMPLUS}, {160, DeviceType::MIXER, "MM100", DeviceFlags::EMS_DEVICE_FLAG_MMPLUS}, {161, DeviceType::MIXER, "MM200", DeviceFlags::EMS_DEVICE_FLAG_MMPLUS}, -{193, DeviceType::MIXER, "MM300", DeviceFlags::EMS_DEVICE_FLAG_MMPLUS}, +{193, DeviceType::MIXER, "MZ100", DeviceFlags::EMS_DEVICE_FLAG_MMPLUS}, {204, DeviceType::MIXER, "MP100", DeviceFlags::EMS_DEVICE_FLAG_MP}, // pool // Heat Pumps - 0x38? diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index a49a427ae..f1b02a253 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -273,6 +273,17 @@ bool EMSdevice::has_tag(const uint8_t tag) const { return false; } +// check if the device has a command on the with this tag. +bool EMSdevice::has_cmd(const int8_t id, const char * cmd) const { + uint8_t tag = DeviceValueTAG::TAG_HC1 + id - 1; + for (const auto & dv : devicevalues_) { + if ((id < 1 || dv.tag == tag) && dv.has_cmd && strcmp(dv.short_name, cmd) == 0) { + return true; + } + } + return false; +} + // list of registered device entries // called from the command 'entities' void EMSdevice::list_device_entries(JsonObject & output) const { @@ -507,7 +518,7 @@ void EMSdevice::add_device_value(uint8_t tag, } // add the command to our library - Command::add(device_type_, short_name, f, fullname, flags); + Command::add(device_type_, device_id_, short_name, f, fullname, flags); } // single list of options diff --git a/src/emsdevice.h b/src/emsdevice.h index 49c54e7fc..fa571c9eb 100644 --- a/src/emsdevice.h +++ b/src/emsdevice.h @@ -53,6 +53,7 @@ class EMSdevice { static std::string tag_to_mqtt(uint8_t tag); bool has_tag(const uint8_t tag) const; + bool has_cmd(const int8_t id, const char * cmd) const; inline uint8_t device_id() const { return device_id_; diff --git a/src/system.cpp b/src/system.cpp index bfba78c6e..d86961433 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -253,7 +253,7 @@ void System::syslog_init() { syslog_.hostname(hostname().c_str()); // register the command - Command::add(EMSdevice::DeviceType::SYSTEM, F_(syslog), System::command_syslog_level, FL_(changeloglevel_cmd), CommandFlag::ADMIN_ONLY); + Command::add(EMSdevice::DeviceType::SYSTEM, 0, F_(syslog), System::command_syslog_level, FL_(changeloglevel_cmd), CommandFlag::ADMIN_ONLY); } else if (was_enabled) { // in case service is still running, this flushes the queue @@ -728,13 +728,13 @@ void System::system_check() { // commands - takes static function pointers void System::commands_init() { - Command::add(EMSdevice::DeviceType::SYSTEM, F_(send), System::command_send, FL_(send_cmd), CommandFlag::ADMIN_ONLY); - Command::add(EMSdevice::DeviceType::SYSTEM, F_(fetch), System::command_fetch, FL_(fetch_cmd), CommandFlag::ADMIN_ONLY); - 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)); + Command::add(EMSdevice::DeviceType::SYSTEM, 0, F_(send), System::command_send, FL_(send_cmd), CommandFlag::ADMIN_ONLY); + Command::add(EMSdevice::DeviceType::SYSTEM, 0, F_(fetch), System::command_fetch, FL_(fetch_cmd), CommandFlag::ADMIN_ONLY); + Command::add(EMSdevice::DeviceType::SYSTEM, 0, F_(restart), System::command_restart, FL_(restart_cmd), CommandFlag::ADMIN_ONLY); + Command::add(EMSdevice::DeviceType::SYSTEM, 0, F_(watch), System::command_watch, FL_(watch_cmd)); if (Mqtt::enabled()) { - Command::add(EMSdevice::DeviceType::SYSTEM, F_(publish), System::command_publish, FL_(publish_cmd)); + Command::add(EMSdevice::DeviceType::SYSTEM, 0, F_(publish), System::command_publish, FL_(publish_cmd)); } // these commands will return data in JSON format @@ -742,7 +742,7 @@ void System::commands_init() { Command::add(EMSdevice::DeviceType::SYSTEM, F_(commands), System::command_commands, FL_(commands_cmd)); #if defined(EMSESP_DEBUG) - Command::add(EMSdevice::DeviceType::SYSTEM, ("test"), System::command_test, FL_(test_cmd)); + Command::add(EMSdevice::DeviceType::SYSTEM, 0, ("test"), System::command_test, FL_(test_cmd)); #endif // MQTT subscribe "ems-esp/system/#" diff --git a/src/version.h b/src/version.h index de55b8304..e37ede30a 100644 --- a/src/version.h +++ b/src/version.h @@ -1,4 +1,4 @@ -#define EMSESP_APP_VERSION "3.5.0b12" +#define EMSESP_APP_VERSION "3.5.0b13" #if CONFIG_IDF_TARGET_ESP32C3 #define EMSESP_PLATFORM "ESP32-C3";