From 7d5a654f52c8d940fa202c81368215c8c5a69f67 Mon Sep 17 00:00:00 2001 From: proddy Date: Thu, 8 Oct 2020 10:03:01 +0200 Subject: [PATCH] fix thermostat flag detection - #537 --- src/devices/thermostat.cpp | 6 +++--- src/devices/thermostat.h | 4 ++-- src/emsdevice.h | 13 +++++++++---- src/emsesp.cpp | 2 +- src/test/test.cpp | 3 ++- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index aaae8936c..59ebff1cd 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -131,7 +131,7 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i register_telegram_type(monitor_typeids[i], F("JunkersMonitor"), false, [&](std::shared_ptr t) { process_JunkersMonitor(t); }); register_telegram_type(set_typeids[i], F("JunkersSet"), false, [&](std::shared_ptr t) { process_JunkersSet(t); }); } - + // JUNKERS/HT3 older models } else if (model == (EMSdevice::EMS_DEVICE_FLAG_JUNKERS | EMSdevice::EMS_DEVICE_FLAG_JUNKERS_2)) { monitor_typeids = {0x016F, 0x0170, 0x0171, 0x0172}; set_typeids = {0x0179, 0x017A, 0x017B, 0x017C}; @@ -1671,7 +1671,7 @@ bool Thermostat::set_mode_n(const uint8_t mode, const uint8_t hc_num) { } break; case EMSdevice::EMS_DEVICE_FLAG_JUNKERS: - if ((this->flags() & EMS_DEVICE_FLAG_JUNKERS_2) == EMS_DEVICE_FLAG_JUNKERS_2) { + if (this->has_flags(EMS_DEVICE_FLAG_JUNKERS_2)) { offset = EMS_OFFSET_JunkersSetMessage2_set_mode; } else { offset = EMS_OFFSET_JunkersSetMessage_set_mode; @@ -1882,7 +1882,7 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co } else if (model == EMS_DEVICE_FLAG_JUNKERS) { // figure out if we have older or new thermostats, Heating Circuits on 0x65 or 0x79 // see https://github.com/proddy/EMS-ESP/issues/335#issuecomment-593324716) - bool old_junkers = ((this->flags() & EMS_DEVICE_FLAG_JUNKERS_2) == EMS_DEVICE_FLAG_JUNKERS_2); + bool old_junkers = (this->has_flags(EMS_DEVICE_FLAG_JUNKERS_2)); if (!old_junkers) { switch (mode) { case HeatingCircuit::Mode::NOFROST: diff --git a/src/devices/thermostat.h b/src/devices/thermostat.h index 265041d02..07e69e8ff 100644 --- a/src/devices/thermostat.h +++ b/src/devices/thermostat.h @@ -110,9 +110,9 @@ class Thermostat : public EMSdevice { bool export_values_main(JsonObject & doc); bool export_values_hc(uint8_t mqtt_format, JsonObject & doc); - // specific thermostat characteristics, stripping the option bits at pos 6 and 7 + // specific thermostat characteristics, stripping the write option at bit 7 inline uint8_t model() const { - return (this->flags() & 0x0F); + return (this->flags() & 0x7F); } // each thermostat has a list of heating controller type IDs for reading and writing diff --git a/src/emsdevice.h b/src/emsdevice.h index e9a5dface..b07117071 100644 --- a/src/emsdevice.h +++ b/src/emsdevice.h @@ -67,14 +67,19 @@ class EMSdevice { return ((device_id & 0x7F) == (device_id_ & 0x7F)); } + inline void add_flags(uint8_t flags) { + flags_ |= flags; + } + inline bool has_flags(uint8_t flags) const { + return (flags_ & flags) == flags; + } + inline void remove_flags(uint8_t flags) { + flags_ &= ~flags; + } inline uint8_t flags() const { return flags_; } - inline void flags(uint8_t flags) { - flags_ = flags; - } - // see enum DeviceType below inline uint8_t device_type() const { return device_type_; diff --git a/src/emsesp.cpp b/src/emsesp.cpp index b63c7cbc4..d8448993f 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -652,7 +652,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, std:: for (const auto & device : device_library_) { if (device.product_id == product_id) { emsdevice->name(uuid::read_flash_string(device.name)); - emsdevice->flags(device.flags); + emsdevice->add_flags(device.flags); } } diff --git a/src/test/test.cpp b/src/test/test.cpp index 9cb4126a4..2865e3444 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -28,7 +28,7 @@ namespace emsesp { // used with the 'test' command, under su/admin void Test::run_test(uuid::console::Shell & shell, const std::string & command) { if (command == "default") { - run_test(shell, "web"); // add the default test case here + run_test(shell, "fr120"); // add the default test case here } if (command.empty()) { @@ -278,6 +278,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & command) { 0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03}); shell.invoke_command("show"); + shell.invoke_command("show devices"); } if (command == "thermostat") {