diff --git a/src/devices/heatpump.cpp b/src/devices/heatpump.cpp index 195d0da97..2fa66fabc 100644 --- a/src/devices/heatpump.cpp +++ b/src/devices/heatpump.cpp @@ -111,14 +111,14 @@ void Heatpump::register_mqtt_ha_config() { JsonObject dev = doc.createNestedObject("dev"); dev["name"] = F("EMS-ESP Heat Pump"); dev["sw"] = EMSESP_APP_VERSION; - dev["mf"] = this->brand_to_string(); + dev["mf"] = brand_to_string(); dev["mdl"] = this->name(); JsonArray ids = dev.createNestedArray("ids"); ids.add("ems-esp-heatpump"); Mqtt::publish_retain(F("homeassistant/sensor/ems-esp/heatpump/config"), doc.as(), true); // publish the config payload with retain flag - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(airHumidity), this->device_type(), "airHumidity", F_(percent), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(dewTemperature), this->device_type(), "dewTemperature", F_(degrees), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(airHumidity), device_type(), "airHumidity", F_(percent), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(dewTemperature), device_type(), "dewTemperature", F_(degrees), nullptr); mqtt_ha_config_ = true; // done } diff --git a/src/devices/mixer.cpp b/src/devices/mixer.cpp index db96d2c0a..e611b9193 100644 --- a/src/devices/mixer.cpp +++ b/src/devices/mixer.cpp @@ -187,30 +187,30 @@ void Mixer::register_mqtt_ha_config() { JsonObject dev = doc.createNestedObject("dev"); dev["name"] = F("EMS-ESP Mixer"); dev["sw"] = EMSESP_APP_VERSION; - dev["mf"] = this->brand_to_string(); + dev["mf"] = brand_to_string(); dev["mdl"] = this->name(); JsonArray ids = dev.createNestedArray("ids"); ids.add("ems-esp-mixer"); std::string topic(100, '\0'); - if (this->type() == Type::HC) { + if (type() == Type::HC) { snprintf_P(&topic[0], topic.capacity() + 1, PSTR("homeassistant/sensor/ems-esp/mixer_hc%d/config"), hc_); Mqtt::publish_retain(topic, doc.as(), true); // publish the config payload with retain flag char hc_name[10]; snprintf_P(hc_name, sizeof(hc_name), PSTR("hc%d"), hc_); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(flowTemp), this->device_type(), "flowTemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(flowSetTemp), this->device_type(), "flowSetTemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(pumpStatus), this->device_type(), "pumpStatus", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(valveStatus), this->device_type(), "valveStatus", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(flowTemp), device_type(), "flowTemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(flowSetTemp), device_type(), "flowSetTemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(pumpStatus), device_type(), "pumpStatus", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(valveStatus), device_type(), "valveStatus", nullptr, nullptr); } else { // WWC snprintf_P(&topic[0], topic.capacity() + 1, PSTR("homeassistant/sensor/ems-esp/mixer_wwc%d/config"), hc_); Mqtt::publish_retain(topic, doc.as(), true); // publish the config payload with retain flag char wwc_name[10]; snprintf_P(wwc_name, sizeof(wwc_name), PSTR("wwc%d"), hc_); - Mqtt::register_mqtt_ha_sensor(wwc_name, nullptr, F_(wwTemp), this->device_type(), "wwTemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(wwc_name, nullptr, F_(pumpStatus), this->device_type(), "pumpStatus", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(wwc_name, nullptr, F_(tempStatus), this->device_type(), "tempStatus", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(wwc_name, nullptr, F_(wwTemp), device_type(), "wwTemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(wwc_name, nullptr, F_(pumpStatus), device_type(), "pumpStatus", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(wwc_name, nullptr, F_(tempStatus), device_type(), "tempStatus", nullptr, nullptr); } mqtt_ha_config_ = true; // done @@ -224,14 +224,14 @@ bool Mixer::export_values(JsonObject & json) { // returns false if empty bool Mixer::export_values_format(uint8_t mqtt_format, JsonObject & json) { // check if there is data for the mixer unit - if (this->type() == Type::NONE) { + if (type() == Type::NONE) { return 0; } JsonObject json_hc; char hc_name[10]; // hc{1-4} - if (this->type() == Type::HC) { + if (type() == Type::HC) { snprintf_P(hc_name, sizeof(hc_name), PSTR("hc%d"), hc_); if (mqtt_format == Mqtt::Format::SINGLE) { json_hc = json; diff --git a/src/devices/solar.cpp b/src/devices/solar.cpp index c341e01c1..b714b0ade 100644 --- a/src/devices/solar.cpp +++ b/src/devices/solar.cpp @@ -172,27 +172,27 @@ void Solar::register_mqtt_ha_config() { JsonObject dev = doc.createNestedObject("dev"); dev["name"] = F("EMS-ESP Solar"); dev["sw"] = EMSESP_APP_VERSION; - dev["mf"] = this->brand_to_string(); - dev["mdl"] = this->name(); + dev["mf"] = brand_to_string(); + dev["mdl"] = name(); JsonArray ids = dev.createNestedArray("ids"); ids.add("ems-esp-solar"); Mqtt::publish_retain(F("homeassistant/sensor/ems-esp/solar/config"), doc.as(), true); // publish the config payload with retain flag - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(collectorTemp), this->device_type(), "collectorTemp", F_(degrees), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(tankBottomTemp), this->device_type(), "tankBottomTemp", F_(degrees), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(tankBottomTemp2), this->device_type(), "tankBottomTemp2", F_(degrees), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(tank1MaxTempCurrent), this->device_type(), "tank1MaxTempCurrent", F_(degrees), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(heatExchangerTemp), this->device_type(), "heatExchangerTemp", F_(degrees), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(solarPumpModulation), this->device_type(), "solarPumpModulation", F_(percent), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(cylinderPumpModulation), this->device_type(), "cylinderPumpModulation", F_(percent), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(pumpWorkMin), this->device_type(), "pumpWorkMin", F_(min), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(energyLastHour), this->device_type(), "energyLastHour", F_(wh), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(energyToday), this->device_type(), "energyToday", F_(wh), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(energyTotal), this->device_type(), "energyTotal", F_(kwh), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(solarPump), this->device_type(), "solarPump", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(valveStatus), this->device_type(), "valveStatus", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(tankHeated), this->device_type(), "tankHeated", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(collectorShutdown), this->device_type(), "collectorShutdown", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(collectorTemp), device_type(), "collectorTemp", F_(degrees), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(tankBottomTemp), device_type(), "tankBottomTemp", F_(degrees), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(tankBottomTemp2), device_type(), "tankBottomTemp2", F_(degrees), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(tank1MaxTempCurrent), device_type(), "tank1MaxTempCurrent", F_(degrees), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(heatExchangerTemp), device_type(), "heatExchangerTemp", F_(degrees), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(solarPumpModulation), device_type(), "solarPumpModulation", F_(percent), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(cylinderPumpModulation), device_type(), "cylinderPumpModulation", F_(percent), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(pumpWorkMin), device_type(), "pumpWorkMin", F_(min), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(energyLastHour), device_type(), "energyLastHour", F_(wh), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(energyToday), device_type(), "energyToday", F_(wh), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(energyTotal), device_type(), "energyTotal", F_(kwh), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(solarPump), device_type(), "solarPump", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(valveStatus), device_type(), "valveStatus", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(tankHeated), device_type(), "tankHeated", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(collectorShutdown), device_type(), "collectorShutdown", nullptr, nullptr); mqtt_ha_config_ = true; // done } diff --git a/src/devices/switch.cpp b/src/devices/switch.cpp index 93c9dce9e..60ca552a2 100644 --- a/src/devices/switch.cpp +++ b/src/devices/switch.cpp @@ -133,15 +133,15 @@ void Switch::register_mqtt_ha_config() { JsonObject dev = doc.createNestedObject("dev"); dev["name"] = F("EMS-ESP Switch"); dev["sw"] = EMSESP_APP_VERSION; - dev["mf"] = this->brand_to_string(); + dev["mf"] = brand_to_string(); dev["mdl"] = this->name(); JsonArray ids = dev.createNestedArray("ids"); ids.add("ems-esp-switch"); Mqtt::publish_retain(F("homeassistant/sensor/ems-esp/switch/config"), doc.as(), true); // publish the config payload with retain flag - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(activated), this->device_type(), "activated", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(flowTemp), this->device_type(), "flowTemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(status), this->device_type(), "status", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(activated), device_type(), "activated", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(flowTemp), device_type(), "flowTemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(status), device_type(), "status", nullptr, nullptr); mqtt_ha_config_ = true; // done } diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index b160aeb39..69a4fb87f 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -42,7 +42,7 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i && ((actual_master_thermostat == EMSESP_DEFAULT_MASTER_THERMOSTAT) || (device_id < actual_master_thermostat)))) { EMSESP::actual_master_thermostat(device_id); actual_master_thermostat = device_id; - this->reserve_mem(25); // reserve some space for the telegram registries, to avoid memory fragmentation + reserve_mem(25); // reserve some space for the telegram registries, to avoid memory fragmentation // common telegram handlers register_telegram_type(EMS_TYPE_RCOutdoorTemp, F("RCOutdoorTemp"), false, [&](std::shared_ptr t) { process_RCOutdoorTemp(t); }); @@ -137,7 +137,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); }); } - if (this->has_flags(EMS_DEVICE_FLAG_JUNKERS_2)) { + if (has_flags(EMS_DEVICE_FLAG_JUNKERS_OLD)) { // FR120, FR100 set_typeids = {0x0179, 0x017A, 0x017B, 0x017C}; for (uint8_t i = 0; i < monitor_typeids.size(); i++) { @@ -249,7 +249,7 @@ void Thermostat::device_info_web(JsonArray & root) { // we check if any of the thermostat values have changed and then republish if necessary bool Thermostat::updated_values() { // only publish on the master thermostat - if (EMSESP::actual_master_thermostat() != this->device_id()) { + if (EMSESP::actual_master_thermostat() != device_id()) { return false; } if (changed_) { @@ -336,7 +336,7 @@ void Thermostat::show_values(uuid::console::Shell & shell) { // publish values via MQTT void Thermostat::publish_values(JsonObject & json, bool force) { - if (EMSESP::actual_master_thermostat() != this->device_id()) { + if (EMSESP::actual_master_thermostat() != device_id()) { return; } @@ -527,7 +527,7 @@ bool Thermostat::export_values_main(JsonObject & rootThermostat) { // if the mqtt_format is 0 then it will not perform the MQTT publish // returns false if empty bool Thermostat::export_values_hc(uint8_t mqtt_format, JsonObject & rootThermostat) { - uint8_t flags = this->model(); + uint8_t model = this->model(); JsonObject dataThermostat; bool has_data = false; @@ -548,10 +548,10 @@ bool Thermostat::export_values_hc(uint8_t mqtt_format, JsonObject & rootThermost // different logic on how temperature values are stored, depending on model uint8_t setpoint_temp_divider; uint8_t curr_temp_divider; - if (flags == EMS_DEVICE_FLAG_EASY) { + if (model == EMS_DEVICE_FLAG_EASY) { setpoint_temp_divider = 100; curr_temp_divider = 100; - } else if (flags == EMS_DEVICE_FLAG_JUNKERS) { + } else if (model == EMS_DEVICE_FLAG_JUNKERS) { setpoint_temp_divider = 10; curr_temp_divider = 10; } else { @@ -570,10 +570,10 @@ bool Thermostat::export_values_hc(uint8_t mqtt_format, JsonObject & rootThermost } if (Helpers::hasValue(hc->daytemp)) { - if (flags == EMSdevice::EMS_DEVICE_FLAG_JUNKERS) { + if (model == EMSdevice::EMS_DEVICE_FLAG_JUNKERS) { // Heat temperature dataThermostat["heattemp"] = (float)hc->daytemp / 2; - } else if (flags == EMSdevice::EMS_DEVICE_FLAG_RC300 || flags == EMSdevice::EMS_DEVICE_FLAG_RC100) { + } else if (model == EMSdevice::EMS_DEVICE_FLAG_RC300 || model == EMSdevice::EMS_DEVICE_FLAG_RC100) { // Comfort temperature dataThermostat["comforttemp"] = (float)hc->daytemp / 2; } else { @@ -583,7 +583,7 @@ bool Thermostat::export_values_hc(uint8_t mqtt_format, JsonObject & rootThermost } if (Helpers::hasValue(hc->nighttemp)) { - if (flags == EMSdevice::EMS_DEVICE_FLAG_JUNKERS || flags == EMSdevice::EMS_DEVICE_FLAG_RC300 || flags == EMSdevice::EMS_DEVICE_FLAG_RC100) { + if (model == EMSdevice::EMS_DEVICE_FLAG_JUNKERS || model == EMSdevice::EMS_DEVICE_FLAG_RC300 || model == EMSdevice::EMS_DEVICE_FLAG_RC100) { // Eco temperature dataThermostat["ecotemp"] = (float)hc->nighttemp / 2; } else { @@ -604,7 +604,7 @@ bool Thermostat::export_values_hc(uint8_t mqtt_format, JsonObject & rootThermost // Nofrost temperature if (Helpers::hasValue(hc->nofrosttemp)) { - if (flags == EMSdevice::EMS_DEVICE_FLAG_JUNKERS) { + if (model == EMSdevice::EMS_DEVICE_FLAG_JUNKERS) { dataThermostat["nofrosttemp"] = (float)hc->nofrosttemp / 2; } else { dataThermostat["nofrosttemp"] = hc->nofrosttemp; @@ -623,7 +623,7 @@ bool Thermostat::export_values_hc(uint8_t mqtt_format, JsonObject & rootThermost // Offset temperature if (Helpers::hasValue(hc->offsettemp)) { - if (flags == EMSdevice::EMS_DEVICE_FLAG_RC300 || flags == EMSdevice::EMS_DEVICE_FLAG_RC100) { + if (model == EMSdevice::EMS_DEVICE_FLAG_RC300 || model == EMSdevice::EMS_DEVICE_FLAG_RC100) { dataThermostat["offsettemp"] = hc->offsettemp; } else { dataThermostat["offsettemp"] = hc->offsettemp / 2; @@ -668,7 +668,7 @@ bool Thermostat::export_values_hc(uint8_t mqtt_format, JsonObject & rootThermost // mode - always force showing this when in HA so not to break HA's climate component if ((Helpers::hasValue(hc->mode)) || (mqtt_format == Mqtt::Format::HA)) { - uint8_t hc_mode = hc->get_mode(flags); + uint8_t hc_mode = hc->get_mode(model); // if we're sending to HA the only valid mode types are heat, auto and off if (mqtt_format == Mqtt::Format::HA) { if ((hc_mode == HeatingCircuit::Mode::MANUAL) || (hc_mode == HeatingCircuit::Mode::DAY)) { @@ -691,7 +691,7 @@ bool Thermostat::export_values_hc(uint8_t mqtt_format, JsonObject & rootThermost } else if (Helpers::hasValue(hc->holiday_mode) && hc->holiday_mode) { dataThermostat["modetype"] = F("holiday"); } else if (Helpers::hasValue(hc->mode_type)) { - dataThermostat["modetype"] = mode_tostring(hc->get_mode_type(flags)); + dataThermostat["modetype"] = mode_tostring(hc->get_mode_type(model)); } // if format is single, send immediately and clear object for next hc @@ -880,40 +880,40 @@ void Thermostat::register_mqtt_ha_config() { JsonObject dev = doc.createNestedObject("dev"); dev["name"] = F("EMS-ESP Thermostat"); dev["sw"] = EMSESP_APP_VERSION; - dev["mf"] = this->brand_to_string(); - dev["mdl"] = this->name(); + dev["mf"] = brand_to_string(); + dev["mdl"] = name(); JsonArray ids = dev.createNestedArray("ids"); ids.add("ems-esp-thermostat"); Mqtt::publish_retain(F("homeassistant/sensor/ems-esp/thermostat/config"), doc.as(), true); // publish the config payload with retain flag - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(time), this->device_type(), "time", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(error), this->device_type(), "errorcode", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(time), device_type(), "time", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(error), device_type(), "errorcode", nullptr, nullptr); uint8_t model = this->model(); if (model == EMS_DEVICE_FLAG_RC30_1) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(display), this->device_type(), "display", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(language), this->device_type(), "language", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(display), device_type(), "display", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(language), device_type(), "language", nullptr, nullptr); } if (model == EMS_DEVICE_FLAG_RC300 || model == EMS_DEVICE_FLAG_RC100) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(dampedtemp), this->device_type(), "dampedtemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(building), this->device_type(), "building", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(minexttemp), this->device_type(), "minexttemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(floordry), this->device_type(), "floordry", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(floordrytemp), this->device_type(), "floordrytemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(wwmode), this->device_type(), "wwmode", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(wwtemp), this->device_type(), "wwtemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(wwcircmode), this->device_type(), "wwcircmode", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(dampedtemp), device_type(), "dampedtemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(building), device_type(), "building", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(minexttemp), device_type(), "minexttemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(floordry), device_type(), "floordry", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(floordrytemp), device_type(), "floordrytemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(wwmode), device_type(), "wwmode", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(wwtemp), device_type(), "wwtemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(wwcircmode), device_type(), "wwcircmode", nullptr, nullptr); } if (model == EMS_DEVICE_FLAG_RC35 || model == EMS_DEVICE_FLAG_RC30_1) { // excluding inttemp1, inttemp2, intoffset, minexttemp - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(dampedtemp), this->device_type(), "dampedtemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(building), this->device_type(), "building", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(minexttemp), this->device_type(), "minexttemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(wwmode), this->device_type(), "wwmode", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(wwcircmode), this->device_type(), "wwcircmode", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(dampedtemp), device_type(), "dampedtemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(building), device_type(), "building", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(minexttemp), device_type(), "minexttemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(wwmode), device_type(), "wwmode", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(wwcircmode), device_type(), "wwcircmode", nullptr, nullptr); } } @@ -963,32 +963,11 @@ void Thermostat::register_mqtt_ha_config(uint8_t hc_num) { modes.add(F("heat")); modes.add(F("off")); - /* - uint8_t model = this->model(); - if (model == EMSdevice::EMS_DEVICE_FLAG_RC20_2) { - modes.add(F("night")); - modes.add(F("day")); - } else if ((model == EMSdevice::EMS_DEVICE_FLAG_RC300) || (model == EMSdevice::EMS_DEVICE_FLAG_RC100)) { - modes.add(F("eco")); - modes.add(F("comfort")); - modes.add(F("auto")); - } else if (model == EMSdevice::EMS_DEVICE_FLAG_JUNKERS) { - modes.add(F("nofrost")); - modes.add(F("eco")); - modes.add(F("heat")); - modes.add(F("auto")); - } else { // default for all other thermostats - modes.add(F("night")); - modes.add(F("day")); - modes.add(F("auto")); - } - */ - JsonObject dev = doc.createNestedObject("dev"); dev["name"] = F("EMS-ESP Thermostat"); dev["sw"] = EMSESP_APP_VERSION; - dev["mf"] = this->brand_to_string(); - dev["mdl"] = this->name(); + dev["mf"] = brand_to_string(); + dev["mdl"] = name(); JsonArray ids = dev.createNestedArray("ids"); ids.add(F("ems-esp-thermostat")); @@ -1007,52 +986,52 @@ void Thermostat::register_mqtt_ha_config(uint8_t hc_num) { char s[3]; strlcat(hc_name, Helpers::itoa(s, hc_num), 10); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(mode), this->device_type(), "mode", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(mode), device_type(), "mode", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(seltemp), this->device_type(), "seltemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(currtemp), this->device_type(), "currtemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(seltemp), device_type(), "seltemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(currtemp), device_type(), "currtemp", F_(degrees), F_(icontemperature)); uint8_t model = this->model(); switch (model) { case EMS_DEVICE_FLAG_RC100: case EMS_DEVICE_FLAG_RC300: - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(modetype), this->device_type(), "modetype", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(ecotemp), this->device_type(), "ecotemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(manualtemp), this->device_type(), "manualtemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(comforttemp), this->device_type(), "comforttemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(summertemp), this->device_type(), "summertemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(designtemp), this->device_type(), "designtemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(offsettemp), this->device_type(), "offsettemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(minflowtemp), this->device_type(), "minflowtemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(maxflowtemp), this->device_type(), "maxflowtemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(roominfluence), this->device_type(), "roominfluence", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(nofrosttemp), this->device_type(), "nofrosttemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(targetflowtemp), this->device_type(), "targetflowtemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(modetype), device_type(), "modetype", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(ecotemp), device_type(), "ecotemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(manualtemp), device_type(), "manualtemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(comforttemp), device_type(), "comforttemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(summertemp), device_type(), "summertemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(designtemp), device_type(), "designtemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(offsettemp), device_type(), "offsettemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(minflowtemp), device_type(), "minflowtemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(maxflowtemp), device_type(), "maxflowtemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(roominfluence), device_type(), "roominfluence", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(nofrosttemp), device_type(), "nofrosttemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(targetflowtemp), device_type(), "targetflowtemp", F_(degrees), F_(icontemperature)); break; case EMS_DEVICE_FLAG_RC20_2: - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(daytemp), this->device_type(), "daytemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(nighttemp), this->device_type(), "nighttemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(daytemp), device_type(), "daytemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(nighttemp), device_type(), "nighttemp", F_(degrees), F_(icontemperature)); break; case EMS_DEVICE_FLAG_RC30_1: case EMS_DEVICE_FLAG_RC35: - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(modetype), this->device_type(), "modetype", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(nighttemp), this->device_type(), "nighttemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(daytemp), this->device_type(), "daytemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(designtemp), this->device_type(), "designtemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(offsettemp), this->device_type(), "offsettemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(holidaytemp), this->device_type(), "holidaytemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(targetflowtemp), this->device_type(), "targetflowtemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(summertemp), this->device_type(), "summertemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(nofrosttemp), this->device_type(), "nofrosttemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(roominfluence), this->device_type(), "roominfluence", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(minflowtemp), this->device_type(), "minflowtemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(maxflowtemp), this->device_type(), "maxflowtemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(modetype), device_type(), "modetype", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(nighttemp), device_type(), "nighttemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(daytemp), device_type(), "daytemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(designtemp), device_type(), "designtemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(offsettemp), device_type(), "offsettemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(holidaytemp), device_type(), "holidaytemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(targetflowtemp), device_type(), "targetflowtemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(summertemp), device_type(), "summertemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(nofrosttemp), device_type(), "nofrosttemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(roominfluence), device_type(), "roominfluence", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(minflowtemp), device_type(), "minflowtemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(maxflowtemp), device_type(), "maxflowtemp", F_(degrees), F_(icontemperature)); break; case EMS_DEVICE_FLAG_JUNKERS: - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(modetype), this->device_type(), "modetype", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(heattemp), this->device_type(), "heattemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(ecotemp), this->device_type(), "ecotemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(nofrosttemp), this->device_type(), "nofrosttemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(modetype), device_type(), "modetype", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(heattemp), device_type(), "heattemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(ecotemp), device_type(), "ecotemp", F_(degrees), F_(icontemperature)); + Mqtt::register_mqtt_ha_sensor(hc_name, nullptr, F_(nofrosttemp), device_type(), "nofrosttemp", F_(degrees), F_(icontemperature)); break; default: break; @@ -1080,14 +1059,12 @@ bool Thermostat::thermostat_ha_cmd(const char * message, uint8_t hc_num) { // decodes the thermostat mode for the heating circuit based on the thermostat type // modes are off, manual, auto, day and night -uint8_t Thermostat::HeatingCircuit::get_mode(uint8_t flags) const { +uint8_t Thermostat::HeatingCircuit::get_mode(uint8_t model) const { if (!Helpers::hasValue(mode)) { return HeatingCircuit::Mode::UNKNOWN; } - flags &= 0x0F; // strip top 4 bits - - if (flags == EMSdevice::EMS_DEVICE_FLAG_RC20) { + if (model == EMSdevice::EMS_DEVICE_FLAG_RC20) { if (mode == 0) { return HeatingCircuit::Mode::OFF; } else if (mode == 1) { @@ -1095,13 +1072,13 @@ uint8_t Thermostat::HeatingCircuit::get_mode(uint8_t flags) const { } else if (mode == 2) { return HeatingCircuit::Mode::AUTO; } - } else if ((flags == EMSdevice::EMS_DEVICE_FLAG_RC300) || (flags == EMSdevice::EMS_DEVICE_FLAG_RC100)) { + } else if ((model == EMSdevice::EMS_DEVICE_FLAG_RC300) || (model == EMSdevice::EMS_DEVICE_FLAG_RC100)) { if (mode == 0) { return HeatingCircuit::Mode::MANUAL; } else if (mode == 1) { return HeatingCircuit::Mode::AUTO; } - } else if (flags == EMSdevice::EMS_DEVICE_FLAG_JUNKERS) { + } else if (model == EMSdevice::EMS_DEVICE_FLAG_JUNKERS) { if (mode == 1) { return HeatingCircuit::Mode::MANUAL; } else if (mode == 2) { @@ -1124,10 +1101,8 @@ uint8_t Thermostat::HeatingCircuit::get_mode(uint8_t flags) const { // figures out the thermostat day/night mode depending on the thermostat type // mode types are day, night, eco, comfort -uint8_t Thermostat::HeatingCircuit::get_mode_type(uint8_t flags) const { - flags &= 0x0F; // strip top 4 bits - - if (flags == EMS_DEVICE_FLAG_JUNKERS) { +uint8_t Thermostat::HeatingCircuit::get_mode_type(uint8_t model) const { + if (model == EMS_DEVICE_FLAG_JUNKERS) { if (mode_type == 3) { return HeatingCircuit::Mode::HEAT; } else if (mode_type == 2) { @@ -1135,19 +1110,19 @@ uint8_t Thermostat::HeatingCircuit::get_mode_type(uint8_t flags) const { } else if (mode_type == 1) { return HeatingCircuit::Mode::NOFROST; } - } else if ((flags == EMS_DEVICE_FLAG_RC35) || (flags == EMS_DEVICE_FLAG_RC30_1)) { + } else if ((model == EMS_DEVICE_FLAG_RC35) || (model == EMS_DEVICE_FLAG_RC30_1)) { if (mode_type == 0) { return HeatingCircuit::Mode::NIGHT; } else if (mode_type == 1) { return HeatingCircuit::Mode::DAY; } - } else if (flags == EMS_DEVICE_FLAG_RC300) { + } else if (model == EMS_DEVICE_FLAG_RC300) { if (mode_type == 0) { return HeatingCircuit::Mode::ECO; } else if (mode_type == 1) { return HeatingCircuit::Mode::COMFORT; } - } else if (flags == EMS_DEVICE_FLAG_RC100) { + } else if (model == EMS_DEVICE_FLAG_RC100) { return HeatingCircuit::Mode::DAY; // no modes on these devices } @@ -1557,7 +1532,7 @@ void Thermostat::process_RC35Set(std::shared_ptr telegram) { // process_RCTime - type 0x06 - date and time from a thermostat - 14 bytes long void Thermostat::process_RCTime(std::shared_ptr telegram) { - if (this->flags() == EMS_DEVICE_FLAG_EASY) { + if (flags() == EMS_DEVICE_FLAG_EASY) { return; // not supported } if (telegram->message_length < 7) { @@ -1638,7 +1613,7 @@ bool Thermostat::set_minexttemp(const char * value, const int8_t id) { } LOG_INFO(F("Setting min external temperature to %d"), mt); - if ((this->model() == EMS_DEVICE_FLAG_RC300) || (this->model() == EMS_DEVICE_FLAG_RC100)) { + if ((model() == EMS_DEVICE_FLAG_RC300) || (model() == EMS_DEVICE_FLAG_RC100)) { write_command(0x240, 10, mt, 0x240); } else { write_command(EMS_TYPE_IBASettings, 5, mt, EMS_TYPE_IBASettings); @@ -1721,7 +1696,7 @@ bool Thermostat::set_building(const char * value, const int8_t id) { LOG_INFO(F("Setting building to %s"), value); - if ((this->model() == EMS_DEVICE_FLAG_RC300) || (this->model() == EMS_DEVICE_FLAG_RC100)) { + if ((model() == EMS_DEVICE_FLAG_RC300) || (model() == EMS_DEVICE_FLAG_RC100)) { write_command(0x240, 9, bd + 1, 0x240); } else { write_command(EMS_TYPE_IBASettings, 6, bd, EMS_TYPE_IBASettings); @@ -1767,7 +1742,7 @@ bool Thermostat::set_control(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) { uint8_t set = 0xFF; - if ((this->model() == EMS_DEVICE_FLAG_RC300) || (this->model() == EMS_DEVICE_FLAG_RC100)) { + if ((model() == EMS_DEVICE_FLAG_RC300) || (model() == EMS_DEVICE_FLAG_RC100)) { if (!Helpers::value2enum(value, set, {F("off"), F("low"), F("high"), F("auto"), F("own")})) { LOG_WARNING(F("Set warm water mode: Invalid mode")); return false; @@ -1826,7 +1801,7 @@ bool Thermostat::set_wwonetime(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) { uint8_t set = 0xFF; - if ((this->model() == EMS_DEVICE_FLAG_RC300) || (this->model() == EMS_DEVICE_FLAG_RC100)) { + if ((model() == EMS_DEVICE_FLAG_RC300) || (model() == EMS_DEVICE_FLAG_RC100)) { if (!Helpers::value2enum(value, set, {F("off"), F("on"), F("auto"), F("own")})) { LOG_WARNING(F("Set warm water circulation mode: Invalid mode")); return false; @@ -1854,7 +1829,7 @@ bool Thermostat::set_holiday(const char * value, const int8_t id) { uint8_t hc_num = (id == -1) ? AUTO_HEATING_CIRCUIT : id; std::shared_ptr hc = heating_circuit(hc_num); if (hc == nullptr) { - LOG_WARNING(F("Set holiday: Heating Circuit %d not found or activated for device ID 0x%02X"), hc_num, this->device_id()); + LOG_WARNING(F("Set holiday: Heating Circuit %d not found or activated for device ID 0x%02X"), hc_num, device_id()); return false; } @@ -1883,7 +1858,7 @@ bool Thermostat::set_pause(const char * value, const int8_t id) { uint8_t hc_num = (id == -1) ? AUTO_HEATING_CIRCUIT : id; std::shared_ptr hc = heating_circuit(hc_num); if (hc == nullptr) { - LOG_WARNING(F("Set pause: Heating Circuit %d not found or activated for device ID 0x%02X"), hc_num, this->device_id()); + LOG_WARNING(F("Set pause: Heating Circuit %d not found or activated for device ID 0x%02X"), hc_num, device_id()); return false; } @@ -1904,7 +1879,7 @@ bool Thermostat::set_party(const char * value, const int8_t id) { std::shared_ptr hc = heating_circuit(hc_num); if (hc == nullptr) { - LOG_WARNING(F("Set party: Heating Circuit %d not found or activated for device ID 0x%02X"), hc_num, this->device_id()); + LOG_WARNING(F("Set party: Heating Circuit %d not found or activated for device ID 0x%02X"), hc_num, device_id()); return false; } LOG_INFO(F("Setting party: %d hours, hc: %d"), hrs, hc->hc_num()); @@ -2045,7 +2020,7 @@ bool Thermostat::set_mode_n(const uint8_t mode, const uint8_t hc_num) { break; } - switch (this->model()) { + switch (model()) { case EMSdevice::EMS_DEVICE_FLAG_RC20: offset = EMS_OFFSET_RC20Set_mode; validate_typeid = set_typeids[hc_p]; @@ -2074,7 +2049,7 @@ bool Thermostat::set_mode_n(const uint8_t mode, const uint8_t hc_num) { } break; case EMSdevice::EMS_DEVICE_FLAG_JUNKERS: - if (this->has_flags(EMS_DEVICE_FLAG_JUNKERS_2)) { + if (has_flags(EMS_DEVICE_FLAG_JUNKERS_OLD)) { offset = EMS_OFFSET_JunkersSetMessage2_set_mode; } else { offset = EMS_OFFSET_JunkersSetMessage_set_mode; @@ -2181,7 +2156,7 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co // get hc based on number std::shared_ptr hc = heating_circuit(hc_num); if (hc == nullptr) { - LOG_WARNING(F("Set temperature: Heating Circuit %d not found or activated for device ID 0x%02X"), hc_num, this->device_id()); + LOG_WARNING(F("Set temperature: Heating Circuit %d not found or activated for device ID 0x%02X"), hc_num, device_id()); return false; } @@ -2264,7 +2239,7 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co break; default: case HeatingCircuit::Mode::AUTO: - uint8_t mode_ = hc->get_mode(this->flags()); + uint8_t mode_ = hc->get_mode(flags()); if (mode_ == HeatingCircuit::Mode::MANUAL) { offset = 0x0A; // manual offset } else { @@ -2284,7 +2259,7 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co break; default: case HeatingCircuit::Mode::AUTO: // automatic selection, if no type is defined, we use the standard code - uint8_t mode_type = hc->get_mode_type(this->flags()); + uint8_t mode_type = hc->get_mode_type(flags()); offset = (mode_type == HeatingCircuit::Mode::NIGHT) ? EMS_OFFSET_RC20_2_Set_temp_night : EMS_OFFSET_RC20_2_Set_temp_day; break; } @@ -2344,7 +2319,7 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co case HeatingCircuit::Mode::AUTO: // automatic selection, if no type is defined, we use the standard code validate_typeid = monitor_typeids[hc->hc_num() - 1]; //get setpoint roomtemp back if (model == EMS_DEVICE_FLAG_RC35) { - uint8_t mode_ = hc->get_mode(this->flags()); + uint8_t mode_ = hc->get_mode(flags()); if (mode_ == HeatingCircuit::Mode::NIGHT) { offset = EMS_OFFSET_RC35Set_temp_night; } else if (mode_ == HeatingCircuit::Mode::DAY) { @@ -2353,7 +2328,7 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co offset = EMS_OFFSET_RC35Set_seltemp; // https://github.com/proddy/EMS-ESP/issues/310 } } else { - uint8_t mode_type = hc->get_mode_type(this->flags()); + uint8_t mode_type = hc->get_mode_type(flags()); offset = (mode_type == HeatingCircuit::Mode::NIGHT) ? EMS_OFFSET_RC35Set_temp_night : EMS_OFFSET_RC35Set_temp_day; } break; @@ -2362,7 +2337,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->has_flags(EMS_DEVICE_FLAG_JUNKERS_2)); + bool old_junkers = (has_flags(EMS_DEVICE_FLAG_JUNKERS_OLD)); if (!old_junkers) { switch (mode) { case HeatingCircuit::Mode::NOFROST: @@ -2378,7 +2353,7 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co break; default: case HeatingCircuit::Mode::AUTO: // automatic selection, if no type is defined, we use the standard code - uint8_t mode_type = hc->get_mode_type(this->flags()); + uint8_t mode_type = hc->get_mode_type(flags()); if (mode_type == HeatingCircuit::Mode::NIGHT || mode_type == HeatingCircuit::Mode::ECO) { offset = EMS_OFFSET_JunkersSetMessage_night_temp; } else if (mode_type == HeatingCircuit::Mode::DAY || mode_type == HeatingCircuit::Mode::HEAT) { @@ -2405,7 +2380,7 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co break; default: case HeatingCircuit::Mode::AUTO: // automatic selection, if no type is defined, we use the standard code - uint8_t mode_type = hc->get_mode_type(this->flags()); + uint8_t mode_type = hc->get_mode_type(flags()); if (mode_type == HeatingCircuit::Mode::NIGHT || mode_type == HeatingCircuit::Mode::ECO) { offset = EMS_OFFSET_JunkersSetMessage2_eco_temp; } else if (mode_type == HeatingCircuit::Mode::DAY || mode_type == HeatingCircuit::Mode::HEAT) { @@ -2514,7 +2489,7 @@ bool Thermostat::set_roominfluence(const char * value, const int8_t id) { // API commands for MQTT and Console void Thermostat::add_commands() { // if this thermostat doesn't support write, don't add the commands - if ((this->flags() & EMSdevice::EMS_DEVICE_FLAG_NO_WRITE) == EMSdevice::EMS_DEVICE_FLAG_NO_WRITE) { + if (has_flags(EMS_DEVICE_FLAG_NO_WRITE)) { return; } diff --git a/src/devices/thermostat.h b/src/devices/thermostat.h index a098e4f26..c0560df20 100644 --- a/src/devices/thermostat.h +++ b/src/devices/thermostat.h @@ -85,8 +85,8 @@ class Thermostat : public EMSdevice { return Helpers::hasValue(setpoint_roomTemp); } - uint8_t get_mode(uint8_t flags) const; - uint8_t get_mode_type(uint8_t flags) const; + uint8_t get_mode(uint8_t model) const; + uint8_t get_mode_type(uint8_t model) const; enum Mode : uint8_t { UNKNOWN, @@ -142,9 +142,9 @@ class Thermostat : public EMSdevice { ha_registered_ = b; } - // specific thermostat characteristics, stripping the last 4 bits + // specific thermostat characteristics, stripping the top 4 bits inline uint8_t model() const { - return (this->flags() & 0x0F); + return (flags() & 0x0F); } // each thermostat has a list of heating controller type IDs for reading and writing diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 3c26d3d0e..a356057c4 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -284,16 +284,16 @@ char * EMSdevice::show_telegram_handlers(char * result) { // list all the mqtt handlers for this device void EMSdevice::show_mqtt_handlers(uuid::console::Shell & shell) { - Mqtt::show_topic_handlers(shell, this->device_type_); + Mqtt::show_topic_handlers(shell, device_type_); } void EMSdevice::register_mqtt_topic(const std::string & topic, mqtt_subfunction_p f) { - Mqtt::subscribe(this->device_type_, topic, f); + Mqtt::subscribe(device_type_, topic, f); } // add command to library void EMSdevice::register_mqtt_cmd(const __FlashStringHelper * cmd, cmdfunction_p f) { - Command::add(this->device_type_, this->device_id_, cmd, f); + Command::add(device_type_, device_id_, cmd, f); } // register a call back function for a specific telegram type @@ -342,17 +342,17 @@ bool EMSdevice::handle_telegram(std::shared_ptr telegram) { // send Tx write with a data block void EMSdevice::write_command(const uint16_t type_id, const uint8_t offset, uint8_t * message_data, const uint8_t message_length, const uint16_t validate_typeid) { - EMSESP::send_write_request(type_id, this->device_id(), offset, message_data, message_length, validate_typeid); + EMSESP::send_write_request(type_id, device_id(), offset, message_data, message_length, validate_typeid); } // send Tx write with a single value void EMSdevice::write_command(const uint16_t type_id, const uint8_t offset, const uint8_t value, const uint16_t validate_typeid) { - EMSESP::send_write_request(type_id, this->device_id(), offset, value, validate_typeid); + EMSESP::send_write_request(type_id, device_id(), offset, value, validate_typeid); } // send Tx write with a single value, with no post validation void EMSdevice::write_command(const uint16_t type_id, const uint8_t offset, const uint8_t value) { - EMSESP::send_write_request(type_id, this->device_id(), offset, value, 0); + EMSESP::send_write_request(type_id, device_id(), offset, value, 0); } // send Tx read command to the device