diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index f78bf2f60..71b6ccad7 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -557,10 +557,10 @@ uint8_t Thermostat::HeatingCircuit::get_mode_type() const { return HeatingCircuit::Mode::DAY; } -std::shared_ptr Thermostat::dhw_circuit(const uint8_t offset, const uint8_t dhw_num, const bool create) { +std::shared_ptr Thermostat::dhw_circuit(const uint8_t offset, const bool create) { // check for existing circuit for (const auto & dhw_circuit : dhw_circuits_) { - if (dhw_circuit->dhw() == dhw_num - 1 || dhw_circuit->offset() == offset) { + if (dhw_circuit->offset() == offset) { return dhw_circuit; } } @@ -568,7 +568,7 @@ std::shared_ptr Thermostat::dhw_circuit(const uint8_t of return nullptr; } // create a new circuit object and add to the list - auto new_dhw = std::make_shared(offset, dhw_num == 255 ? offset + 1 : dhw_num); + auto new_dhw = std::make_shared(offset); dhw_circuits_.push_back(new_dhw); // register the device values register_device_values_dhw(new_dhw); @@ -600,7 +600,7 @@ void Thermostat::process_RC10Set(std::shared_ptr telegram) { if (hc == nullptr) { return; } - auto dhw = dhw_circuit(0, 1, true); + auto dhw = dhw_circuit(0, true); has_update(telegram, ibaCalIntTemperature_, 0); has_update(telegram, backlight_, 1); has_update(telegram, dhw->wwMode_, 2); @@ -867,7 +867,7 @@ void Thermostat::process_IBASettings(std::shared_ptr telegram) { // Settings WW 0x37 - RC35 void Thermostat::process_RC35wwSettings(std::shared_ptr telegram) { - auto dhw = dhw_circuit(0, 1, true); + auto dhw = dhw_circuit(0, true); has_update(telegram, dhw->wwProgMode_, 0); // 0-like hc, 0xFF own prog has_update(telegram, dhw->wwCircProg_, 1); // 0-like hc, 0xFF own prog has_update(telegram, dhw->wwMode_, 2); // 0-off, 1-on, 2-auto @@ -881,7 +881,7 @@ void Thermostat::process_RC35wwSettings(std::shared_ptr telegram // Settings WW 0x3A - RC30 void Thermostat::process_RC30wwSettings(std::shared_ptr telegram) { - auto dhw = dhw_circuit(0, 1, true); + auto dhw = dhw_circuit(0, true); has_update(telegram, dhw->wwMode_, 0); // 0-on, 1-off, 2-auto has_update(telegram, dhw->wwWhenModeOff_, 1); // 0-off, 0xFF on has_update(telegram, dhw->wwDisinfecting_, 2); // 0-off, 0xFF on @@ -891,7 +891,7 @@ void Thermostat::process_RC30wwSettings(std::shared_ptr telegram // type 0x38 (ww) and 0x39 (circ) void Thermostat::process_RC35wwTimer(std::shared_ptr telegram) { - auto dhw = dhw_circuit(0, 1, true); + auto dhw = dhw_circuit(0, true); if ((telegram->message_length == 2 && telegram->offset < 83 && !(telegram->offset & 1)) || (!telegram->offset && telegram->type_id == 0x38 && !strlen(dhw->wwSwitchTime_) && telegram->message_length > 1) || (!telegram->offset && telegram->type_id == 0x39 && !strlen(dhw->wwCircSwitchTime_) && telegram->message_length > 1)) { @@ -1004,7 +1004,7 @@ void Thermostat::process_JunkersSetMixer(std::shared_ptr telegra } void Thermostat::process_JunkersWW(std::shared_ptr telegram) { - auto dhw = dhw_circuit(0, 1, true); + auto dhw = dhw_circuit(0, true); has_bitupdate(telegram, dhw->wwCharge_, 0, 3); } @@ -1185,7 +1185,7 @@ void Thermostat::process_RC300Curve(std::shared_ptr telegram) { // types 0x31B void Thermostat::process_RC300WWtemp(std::shared_ptr telegram) { - auto dhw = dhw_circuit(0, 1, true); + auto dhw = dhw_circuit(0, true); has_update(telegram, dhw->wwSetTemp_, 0); has_update(telegram, dhw->wwSetTempLow_, 1); } @@ -1196,7 +1196,7 @@ void Thermostat::process_RC300WWtemp(std::shared_ptr telegram) { void Thermostat::process_RC300WWmode(std::shared_ptr telegram) { uint8_t circuit = 0; telegram->read_value(circuit, 0); // 00-no circuit, 01-boiler, 02-mixer - auto dhw = dhw_circuit(telegram->type_id - 0x2F5, 255, circuit != 0); + auto dhw = dhw_circuit(telegram->type_id - 0x2F5, circuit != 0); if (dhw == nullptr) { return; } @@ -2105,7 +2105,7 @@ bool Thermostat::set_roomsensor(const char * value, const int8_t id) { // sets the thermostat ww working mode, where mode is a string, ems and ems+ bool Thermostat::set_wwmode(const char * value, const int8_t id) { - auto dhw = dhw_circuit(255, id2dhw(id)); + auto dhw = dhw_circuit(id2dhw(id)); if (dhw == nullptr) { return false; } @@ -2192,7 +2192,7 @@ bool Thermostat::set_wwtemplow(const char * value, const int8_t id) { // Set ww charge RC300, ems+ bool Thermostat::set_wwcharge(const char * value, const int8_t id) { - auto dhw = dhw_circuit(255, id2dhw(id)); + auto dhw = dhw_circuit(id2dhw(id)); if (dhw == nullptr) { return false; } @@ -2212,7 +2212,7 @@ bool Thermostat::set_wwcharge(const char * value, const int8_t id) { // Set ww charge duration in steps of 15 min, ems+ bool Thermostat::set_wwchargeduration(const char * value, const int8_t id) { - auto dhw = dhw_circuit(255, id2dhw(id)); + auto dhw = dhw_circuit(id2dhw(id)); if (dhw == nullptr) { return false; } @@ -2305,7 +2305,7 @@ bool Thermostat::set_switchProgMode(const char * value, const int8_t id) { // sets the thermostat ww circulation working mode, where mode is a string bool Thermostat::set_wwcircmode(const char * value, const int8_t id) { - auto dhw = dhw_circuit(255, id2dhw(id)); + auto dhw = dhw_circuit(id2dhw(id)); if (dhw == nullptr) { return false; } @@ -2328,7 +2328,7 @@ bool Thermostat::set_wwcircmode(const char * value, const int8_t id) { } bool Thermostat::set_wwDailyHeating(const char * value, const int8_t id) { - auto dhw = dhw_circuit(255, id2dhw(id)); + auto dhw = dhw_circuit(id2dhw(id)); if (dhw == nullptr) { return false; } @@ -2342,7 +2342,7 @@ bool Thermostat::set_wwDailyHeating(const char * value, const int8_t id) { } bool Thermostat::set_wwDailyHeatTime(const char * value, const int8_t id) { - auto dhw = dhw_circuit(255, id2dhw(id)); + auto dhw = dhw_circuit(id2dhw(id)); if (dhw == nullptr) { return false; } @@ -2363,7 +2363,7 @@ bool Thermostat::set_wwDailyHeatTime(const char * value, const int8_t id) { } bool Thermostat::set_wwDisinfect(const char * value, const int8_t id) { - auto dhw = dhw_circuit(255, id2dhw(id)); + auto dhw = dhw_circuit(id2dhw(id)); if (dhw == nullptr) { return false; } @@ -2384,7 +2384,7 @@ bool Thermostat::set_wwDisinfect(const char * value, const int8_t id) { } bool Thermostat::set_wwDisinfectDay(const char * value, const int8_t id) { - auto dhw = dhw_circuit(255, id2dhw(id)); + auto dhw = dhw_circuit(id2dhw(id)); if (dhw == nullptr) { return false; } @@ -2405,7 +2405,7 @@ bool Thermostat::set_wwDisinfectDay(const char * value, const int8_t id) { } bool Thermostat::set_wwDisinfectHour(const char * value, const int8_t id) { - auto dhw = dhw_circuit(255, id2dhw(id)); + auto dhw = dhw_circuit( id2dhw(id)); if (dhw == nullptr) { return false; } @@ -3428,7 +3428,7 @@ bool Thermostat::set_switchtime2(const char * value, const int8_t id) { } // sets a single switchtime in the thermostat dhw program for RC35 bool Thermostat::set_wwCircSwitchTime(const char * value, const int8_t id) { - auto dhw = dhw_circuit(255, id2dhw(id)); + auto dhw = dhw_circuit(id2dhw(id)); if (dhw == nullptr) { return false; } @@ -3445,7 +3445,7 @@ bool Thermostat::set_wwCircSwitchTime(const char * value, const int8_t id) { // sets a single switchtime in the thermostat circulation program for RC35 bool Thermostat::set_wwSwitchTime(const char * value, const int8_t id) { - auto dhw = dhw_circuit(255, id2dhw(id)); + auto dhw = dhw_circuit(id2dhw(id)); if (dhw != nullptr) { return false; } @@ -4393,7 +4393,7 @@ void Thermostat::register_device_values() { register_device_values_hc(new_hc); // also a dhw circuit... - auto new_dhw = std::make_shared(0, 1); // offset 0, dhw num 1 + auto new_dhw = std::make_shared(0); // offset 0, dhw num 1 dhw_circuits_.push_back(new_dhw); register_device_values_dhw(new_dhw); #endif @@ -4863,7 +4863,7 @@ void Thermostat::register_device_values_hc(std::shared_ptr dhw) { - int8_t tag = DeviceValueTAG::TAG_DHW1 + dhw->dhw(); + int8_t tag = dhw->id(); switch (this->model()) { case EMSdevice::EMS_DEVICE_FLAG_RC100: case EMSdevice::EMS_DEVICE_FLAG_RC300: diff --git a/src/devices/thermostat.h b/src/devices/thermostat.h index 3643d61b7..0b01687a9 100644 --- a/src/devices/thermostat.h +++ b/src/devices/thermostat.h @@ -173,9 +173,8 @@ class Thermostat : public EMSdevice { class DhwCircuit { public: - DhwCircuit(const uint8_t offset, const uint8_t dhw_num) - : offset_(offset) - , dhw_num_(dhw_num) { + DhwCircuit(const uint8_t offset) + : dhw_num_(offset) { } ~DhwCircuit() = default; uint8_t wwExtra_; @@ -201,16 +200,16 @@ class Thermostat : public EMSdevice { char wwHoliday_[22]; char wwVacation_[22]; - uint8_t dhw() const { - return dhw_num_ - 1; + uint8_t id() const { // returns TAG(id) + return DeviceValueTAG::TAG_DHW1 + dhw_num_; } - uint8_t offset() const { - return offset_; + + uint8_t offset() const { // returns telegram offset + return dhw_num_; } private: - uint8_t offset_; // telegram offset to base telegram - uint8_t dhw_num_; // dhw circuit number 1..10 + uint8_t dhw_num_; // dhw circuit number 0..10 }; private: @@ -230,8 +229,8 @@ class Thermostat : public EMSdevice { || (model() == EMSdevice::EMS_DEVICE_FLAG_CR120)); } - inline uint8_t id2dhw(const int8_t id) const { - return id - DeviceValueTAG::TAG_DHW1 + 1; + inline uint8_t id2dhw(const int8_t id) const { // returns telegram offset for TAG(id) + return id - DeviceValueTAG::TAG_DHW1; } // each thermostat has a list of heating controller type IDs for reading and writing @@ -394,7 +393,7 @@ class Thermostat : public EMSdevice { std::shared_ptr heating_circuit(std::shared_ptr telegram); std::shared_ptr heating_circuit(const int8_t id); - std::shared_ptr dhw_circuit(const uint8_t offset = 0, const uint8_t dhw_num = 255, const bool create = false); + std::shared_ptr dhw_circuit(const uint8_t offset, const bool create = false); void register_device_values_hc(std::shared_ptr hc); void register_device_values_dhw(std::shared_ptr dhw);