refactor: improved updating OT sensors

This commit is contained in:
Yurii
2024-11-13 01:00:04 +03:00
parent c0c631aab4
commit 640935a2b7

View File

@@ -454,20 +454,16 @@ protected:
Sensors::getAmountByType(Sensors::Type::OT_MODULATION_LEVEL) || Sensors::getAmountByType(Sensors::Type::OT_MODULATION_LEVEL) ||
Sensors::getAmountByType(Sensors::Type::OT_CURRENT_POWER) Sensors::getAmountByType(Sensors::Type::OT_CURRENT_POWER)
) { ) {
float power = 0.0f;
bool result = false;
if (vars.slave.flame) { if (vars.slave.flame) {
result = this->updateModulationLevel(); if (this->updateModulationLevel()) {
float power = 0.0f;
if (result) { if (vars.slave.modulation.current > 0 && settings.opentherm.maxPower > 0.1f) {
if (settings.opentherm.maxPower > 0.1f) {
float modulatedPower = settings.opentherm.maxPower - settings.opentherm.minPower; float modulatedPower = settings.opentherm.maxPower - settings.opentherm.minPower;
power = settings.opentherm.minPower + (modulatedPower / 100.0f * vars.slave.modulation.current); power = settings.opentherm.minPower + (modulatedPower / 100.0f * vars.slave.modulation.current);
} }
Log.snoticeln( Log.snoticeln(
FPSTR(L_OT), F("Received modulation level: %.2f%%, power: %.2f of %.2f kW (min: %.2f kW)"), FPSTR(L_OT), F("Received modulation level: %hhu%%, power: %.2f of %.2f kW (min: %.2f kW)"),
vars.slave.modulation.current, power, settings.opentherm.maxPower, settings.opentherm.minPower vars.slave.modulation.current, power, settings.opentherm.maxPower, settings.opentherm.minPower
); );
@@ -487,123 +483,101 @@ protected:
Log.swarningln(FPSTR(L_OT), F("Failed receive modulation level")); Log.swarningln(FPSTR(L_OT), F("Failed receive modulation level"));
} }
} else if (vars.slave.modulation.current > 0) { } else {
vars.slave.modulation.current = 0; vars.slave.modulation.current = 0;
// Modulation level sensors // Modulation level sensors
Sensors::setValueByType( Sensors::setValueByType(
Sensors::Type::OT_MODULATION_LEVEL, vars.slave.modulation.current, Sensors::Type::OT_MODULATION_LEVEL, 0.0f,
Sensors::ValueType::PRIMARY, true, true Sensors::ValueType::PRIMARY, true, true
); );
// Power sensors // Power sensors
Sensors::setValueByType( Sensors::setValueByType(
Sensors::Type::OT_CURRENT_POWER, power, Sensors::Type::OT_CURRENT_POWER, 0.0f,
Sensors::ValueType::PRIMARY, true, true Sensors::ValueType::PRIMARY, true, true
); );
} }
} }
// Update DHW temp // Update DHW temp
if (Sensors::getAmountByType(Sensors::Type::OT_DHW_TEMP)) { if (settings.opentherm.dhwPresent && Sensors::getAmountByType(Sensors::Type::OT_DHW_TEMP)) {
float convertedDhwTemp = 0.0f; bool result = this->updateDhwTemp();
bool result = false;
if (settings.opentherm.dhwPresent) { if (result) {
result = this->updateDhwTemp(); float convertedDhwTemp = convertTemp(
vars.slave.dhw.currentTemp,
settings.opentherm.unitSystem,
settings.system.unitSystem
);
if (result) { Log.snoticeln(
convertedDhwTemp = convertTemp( FPSTR(L_OT_DHW), F("Received temp: %.2f (converted: %.2f)"),
vars.slave.dhw.currentTemp, vars.slave.dhw.currentTemp, convertedDhwTemp
settings.opentherm.unitSystem, );
settings.system.unitSystem
);
Log.snoticeln( Sensors::setValueByType(
FPSTR(L_OT_DHW), F("Received temp: %.2f (converted: %.2f)"), Sensors::Type::OT_DHW_TEMP, convertedDhwTemp,
vars.slave.dhw.currentTemp, convertedDhwTemp Sensors::ValueType::PRIMARY, true, true
); );
Sensors::setValueByType( } else {
Sensors::Type::OT_DHW_TEMP, convertedDhwTemp, Log.swarningln(FPSTR(L_OT_DHW), F("Failed receive temp"));
Sensors::ValueType::PRIMARY, true, true
);
} else {
Log.swarningln(FPSTR(L_OT_DHW), F("Failed receive temp"));
}
} }
} }
// Update DHW temp 2 // Update DHW temp 2
if (Sensors::getAmountByType(Sensors::Type::OT_DHW_TEMP2)) { if (settings.opentherm.dhwPresent && Sensors::getAmountByType(Sensors::Type::OT_DHW_TEMP2)) {
float convertedDhwTemp2 = 0.0f; if (this->updateDhwTemp2()) {
bool result = false; float convertedDhwTemp2 = convertTemp(
vars.slave.dhw.currentTemp2,
settings.opentherm.unitSystem,
settings.system.unitSystem
);
if (settings.opentherm.dhwPresent) { Log.snoticeln(
result = this->updateDhwTemp2(); FPSTR(L_OT_DHW), F("Received temp 2: %.2f (converted: %.2f)"),
vars.slave.dhw.currentTemp2, convertedDhwTemp2
);
if (result) { Sensors::setValueByType(
convertedDhwTemp2 = convertTemp( Sensors::Type::OT_DHW_TEMP2, convertedDhwTemp2,
vars.slave.dhw.currentTemp2, Sensors::ValueType::PRIMARY, true, true
settings.opentherm.unitSystem, );
settings.system.unitSystem
);
Log.snoticeln( } else {
FPSTR(L_OT_DHW), F("Received temp 2: %.2f (converted: %.2f)"), Log.swarningln(FPSTR(L_OT_DHW), F("Failed receive temp 2"));
vars.slave.dhw.currentTemp2, convertedDhwTemp2
);
Sensors::setValueByType(
Sensors::Type::OT_DHW_TEMP2, convertedDhwTemp2,
Sensors::ValueType::PRIMARY, true, true
);
} else {
Log.swarningln(FPSTR(L_OT_DHW), F("Failed receive temp 2"));
}
} }
} }
// Update DHW flow rate // Update DHW flow rate
if (Sensors::getAmountByType(Sensors::Type::OT_DHW_FLOW_RATE)) { if (settings.opentherm.dhwPresent && Sensors::getAmountByType(Sensors::Type::OT_DHW_FLOW_RATE)) {
float convertedDhwFlowRate = 0.0f; if (this->updateDhwFlowRate()) {
bool result = false; float convertedDhwFlowRate = convertVolume(
vars.slave.dhw.flowRate,
if (settings.opentherm.dhwPresent) { settings.opentherm.unitSystem,
result = this->updateDhwFlowRate(); settings.system.unitSystem
);
if (result) { Log.snoticeln(
convertedDhwFlowRate = convertVolume( FPSTR(L_OT_DHW), F("Received flow rate: %.2f (converted: %.2f)"),
vars.slave.dhw.flowRate, vars.slave.dhw.flowRate, convertedDhwFlowRate
settings.opentherm.unitSystem, );
settings.system.unitSystem
);
Log.snoticeln( Sensors::setValueByType(
FPSTR(L_OT_DHW), F("Received flow rate: %.2f (converted: %.2f)"), Sensors::Type::OT_DHW_FLOW_RATE, convertedDhwFlowRate,
vars.slave.dhw.flowRate, convertedDhwFlowRate Sensors::ValueType::PRIMARY, true, true
); );
Sensors::setValueByType( } else {
Sensors::Type::OT_DHW_FLOW_RATE, convertedDhwFlowRate, Log.swarningln(FPSTR(L_OT_DHW), F("Failed receive flow rate"));
Sensors::ValueType::PRIMARY, true, true
);
} else {
Log.swarningln(FPSTR(L_OT_DHW), F("Failed receive flow rate"));
}
} }
} }
// Update heating temp // Update heating temp
if (Sensors::getAmountByType(Sensors::Type::OT_HEATING_TEMP)) { if (Sensors::getAmountByType(Sensors::Type::OT_HEATING_TEMP)) {
float convertedHeatingTemp = 0.0f; if (this->updateHeatingTemp()) {
bool result = this->updateHeatingTemp(); float convertedHeatingTemp = convertTemp(
if (result) {
convertedHeatingTemp = convertTemp(
vars.slave.heating.currentTemp, vars.slave.heating.currentTemp,
settings.opentherm.unitSystem, settings.opentherm.unitSystem,
settings.system.unitSystem settings.system.unitSystem
@@ -626,11 +600,8 @@ protected:
// Update heating return temp // Update heating return temp
if (Sensors::getAmountByType(Sensors::Type::OT_HEATING_RETURN_TEMP)) { if (Sensors::getAmountByType(Sensors::Type::OT_HEATING_RETURN_TEMP)) {
float convertedHeatingReturnTemp = 0.0f; if (this->updateHeatingReturnTemp()) {
bool result = this->updateHeatingReturnTemp(); float convertedHeatingReturnTemp = convertTemp(
if (result) {
convertedHeatingReturnTemp = convertTemp(
vars.slave.heating.returnTemp, vars.slave.heating.returnTemp,
settings.opentherm.unitSystem, settings.opentherm.unitSystem,
settings.system.unitSystem settings.system.unitSystem
@@ -653,14 +624,9 @@ protected:
// Update CH2 temp // Update CH2 temp
if (Sensors::getAmountByType(Sensors::Type::OT_CH2_TEMP)) { if (Sensors::getAmountByType(Sensors::Type::OT_CH2_TEMP)) {
float convertedCh2Temp = 0.0f;
bool result = false;
if (vars.master.ch2.enabled && !settings.opentherm.nativeHeatingControl) { if (vars.master.ch2.enabled && !settings.opentherm.nativeHeatingControl) {
result = this->updateCh2Temp(); if (this->updateCh2Temp()) {
float convertedCh2Temp = convertTemp(
if (result) {
convertedCh2Temp = convertTemp(
vars.slave.ch2.currentTemp, vars.slave.ch2.currentTemp,
settings.opentherm.unitSystem, settings.opentherm.unitSystem,
settings.system.unitSystem settings.system.unitSystem
@@ -684,11 +650,8 @@ protected:
// Update exhaust temp // Update exhaust temp
if (Sensors::getAmountByType(Sensors::Type::OT_EXHAUST_TEMP)) { if (Sensors::getAmountByType(Sensors::Type::OT_EXHAUST_TEMP)) {
float convertedExhaustTemp = 0.0f; if (this->updateExhaustTemp()) {
bool result = this->updateExhaustTemp(); float convertedExhaustTemp = convertTemp(
if (result) {
convertedExhaustTemp = convertTemp(
vars.slave.exhaustTemp, vars.slave.exhaustTemp,
settings.opentherm.unitSystem, settings.opentherm.unitSystem,
settings.system.unitSystem settings.system.unitSystem
@@ -711,11 +674,8 @@ protected:
// Update heat exchanger temp // Update heat exchanger temp
if (Sensors::getAmountByType(Sensors::Type::OT_HEAT_EXCHANGER_TEMP)) { if (Sensors::getAmountByType(Sensors::Type::OT_HEAT_EXCHANGER_TEMP)) {
float convertedHeatExchTemp = 0.0f; if (this->updateHeatExchangerTemp()) {
bool result = this->updateHeatExchangerTemp(); float convertedHeatExchTemp = convertTemp(
if (result) {
convertedHeatExchTemp = convertTemp(
vars.slave.heatExchangerTemp, vars.slave.heatExchangerTemp,
settings.opentherm.unitSystem, settings.opentherm.unitSystem,
settings.system.unitSystem settings.system.unitSystem
@@ -738,11 +698,8 @@ protected:
// Update outdoor temp // Update outdoor temp
if (Sensors::getAmountByType(Sensors::Type::OT_OUTDOOR_TEMP)) { if (Sensors::getAmountByType(Sensors::Type::OT_OUTDOOR_TEMP)) {
bool result = this->updateOutdoorTemp(); if (this->updateOutdoorTemp()) {
float convertedOutdoorTemp = 0.0f; float convertedOutdoorTemp = convertTemp(
if (result) {
convertedOutdoorTemp = convertTemp(
vars.slave.heating.outdoorTemp, vars.slave.heating.outdoorTemp,
settings.opentherm.unitSystem, settings.opentherm.unitSystem,
settings.system.unitSystem settings.system.unitSystem
@@ -765,11 +722,8 @@ protected:
// Update pressure // Update pressure
if (Sensors::getAmountByType(Sensors::Type::OT_PRESSURE)) { if (Sensors::getAmountByType(Sensors::Type::OT_PRESSURE)) {
float convertedPressure = 0.0f; if (this->updatePressure()) {
bool result = this->updatePressure(); float convertedPressure = convertPressure(
if (result) {
convertedPressure = convertPressure(
vars.slave.pressure, vars.slave.pressure,
settings.opentherm.unitSystem, settings.opentherm.unitSystem,
settings.system.unitSystem settings.system.unitSystem