refactor: cosmetic changes; move maxModulation setting to opentherm section

This commit is contained in:
Yurii
2024-10-15 05:09:20 +03:00
parent c32c643442
commit 57cf98ca19
8 changed files with 91 additions and 110 deletions

View File

@@ -266,30 +266,6 @@ public:
return this->publish(this->getTopic(FPSTR(HA_ENTITY_NUMBER), F("heating_max_temp")).c_str(), doc);
}
bool publishNumberHeatingMaxModulation(bool enabledByDefault = true) {
JsonDocument doc;
doc[FPSTR(HA_ENABLED_BY_DEFAULT)] = enabledByDefault;
doc[FPSTR(HA_UNIQUE_ID)] = this->getObjectId(F("heating_max_modulation"));
doc[FPSTR(HA_OBJECT_ID)] = this->getObjectId(F("heating_max_modulation"));
doc[FPSTR(HA_ENTITY_CATEGORY)] = F("config");
doc[FPSTR(HA_DEVICE_CLASS)] = F("power_factor");
doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = F("%");
doc[FPSTR(HA_NAME)] = F("Max modulation");
doc[FPSTR(HA_ICON)] = F("mdi:speedometer");
doc[FPSTR(HA_STATE_TOPIC)] = this->getDeviceTopic(F("settings"));
doc[FPSTR(HA_VALUE_TEMPLATE)] = F("{{ value_json.heating.maxModulation|int(1) }}");
doc[FPSTR(HA_COMMAND_TOPIC)] = this->getDeviceTopic(F("settings/set"));
doc[FPSTR(HA_COMMAND_TEMPLATE)] = F("{\"heating\": {\"maxModulation\" : {{ value }}}}");
doc[FPSTR(HA_MIN)] = 1;
doc[FPSTR(HA_MAX)] = 100;
doc[FPSTR(HA_STEP)] = 1;
doc[FPSTR(HA_MODE)] = "box";
doc[FPSTR(HA_EXPIRE_AFTER)] = 120;
doc.shrinkToFit();
return this->publish(this->getTopic(FPSTR(HA_ENTITY_NUMBER), F("heating_max_modulation")).c_str(), doc);
}
bool publishSwitchDhw(bool enabledByDefault = true) {
JsonDocument doc;

View File

@@ -329,7 +329,6 @@ protected:
this->haHelper->publishSensorBoilerHeatingMaxTemp(settings.system.unitSystem, false);
this->haHelper->publishNumberHeatingMinTemp(settings.system.unitSystem, false);
this->haHelper->publishNumberHeatingMaxTemp(settings.system.unitSystem, false);
this->haHelper->publishNumberHeatingMaxModulation(false);
// pid
this->haHelper->publishSwitchPid();

View File

@@ -271,10 +271,10 @@ protected:
vars.parameters.maxPower
);
if (settings.heating.maxModulation < vars.parameters.minModulation) {
settings.heating.maxModulation = vars.parameters.minModulation;
if (settings.opentherm.maxModulation < vars.parameters.minModulation) {
settings.opentherm.maxModulation = vars.parameters.minModulation;
fsSettings.update();
Log.swarningln(FPSTR(L_SETTINGS_OT), F("Updated min modulation: %hhu%%"), settings.heating.maxModulation);
Log.swarningln(FPSTR(L_SETTINGS_OT), F("Updated min modulation: %hhu%%"), settings.opentherm.maxModulation);
}
if (fabsf(settings.opentherm.maxPower) < 0.1f && vars.parameters.maxPower > 0) {
@@ -289,18 +289,18 @@ protected:
if (!heatingEnabled && settings.opentherm.modulationSyncWithHeating) {
if (this->setMaxModulationLevel(0)) {
Log.snoticeln(FPSTR(L_OT_HEATING), F("Set max modulation: 0% (off)"));
Log.snoticeln(FPSTR(L_OT), F("Set max modulation: 0% (off)"));
} else {
Log.swarningln(FPSTR(L_OT_HEATING), F("Failed set max modulation: 0% (off)"));
Log.swarningln(FPSTR(L_OT), F("Failed set max modulation: 0% (off)"));
}
} else {
if (this->setMaxModulationLevel(settings.heating.maxModulation)) {
Log.snoticeln(FPSTR(L_OT_HEATING), F("Set max modulation: %hhu%%"), settings.heating.maxModulation);
if (this->setMaxModulationLevel(settings.opentherm.maxModulation)) {
Log.snoticeln(FPSTR(L_OT), F("Set max modulation: %hhu%%"), settings.opentherm.maxModulation);
} else {
Log.swarningln(FPSTR(L_OT_HEATING), F("Failed set max modulation: %hhu%%"), settings.heating.maxModulation);
Log.swarningln(FPSTR(L_OT), F("Failed set max modulation: %hhu%%"), settings.opentherm.maxModulation);
}
}

View File

@@ -54,6 +54,7 @@ struct Settings {
byte faultStateGpio = DEFAULT_OT_FAULT_STATE_GPIO;
byte invertFaultState = false;
unsigned int memberIdCode = 0;
uint8_t maxModulation = 100;
float pressureFactor = 1.0f;
float dhwFlowRateFactor = 1.0f;
float minPower = 0.0f;
@@ -105,7 +106,6 @@ struct Settings {
float hysteresis = 0.5f;
byte minTemp = DEFAULT_HEATING_MIN_TEMP;
byte maxTemp = DEFAULT_HEATING_MAX_TEMP;
byte maxModulation = 100;
} heating;
struct {

View File

@@ -345,6 +345,7 @@ void settingsToJson(const Settings& src, JsonVariant dst, bool safe = false) {
dst["opentherm"]["faultStateGpio"] = src.opentherm.faultStateGpio;
dst["opentherm"]["invertFaultState"] = src.opentherm.invertFaultState;
dst["opentherm"]["memberIdCode"] = src.opentherm.memberIdCode;
dst["opentherm"]["maxModulation"] = src.opentherm.maxModulation;
dst["opentherm"]["pressureFactor"] = roundd(src.opentherm.pressureFactor, 2);
dst["opentherm"]["dhwFlowRateFactor"] = roundd(src.opentherm.dhwFlowRateFactor, 2);
dst["opentherm"]["minPower"] = roundd(src.opentherm.minPower, 2);
@@ -388,7 +389,6 @@ void settingsToJson(const Settings& src, JsonVariant dst, bool safe = false) {
dst["heating"]["hysteresis"] = roundd(src.heating.hysteresis, 2);
dst["heating"]["minTemp"] = src.heating.minTemp;
dst["heating"]["maxTemp"] = src.heating.maxTemp;
dst["heating"]["maxModulation"] = src.heating.maxModulation;
dst["dhw"]["enable"] = src.dhw.enable;
dst["dhw"]["target"] = roundd(src.dhw.target, 1);
@@ -700,6 +700,15 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false
}
}
if (!src["opentherm"]["maxModulation"].isNull()) {
unsigned char value = src["opentherm"]["maxModulation"].as<unsigned char>();
if (value > 0 && value <= 100 && value != dst.opentherm.maxModulation) {
dst.opentherm.maxModulation = value;
changed = true;
}
}
if (!src["opentherm"]["pressureFactor"].isNull()) {
float value = src["opentherm"]["pressureFactor"].as<float>();
@@ -1205,15 +1214,6 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false
}
}
if (!src["heating"]["maxModulation"].isNull()) {
unsigned char value = src["heating"]["maxModulation"].as<unsigned char>();
if (value > 0 && value <= 100 && value != dst.heating.maxModulation) {
dst.heating.maxModulation = value;
changed = true;
}
}
// dhw
if (src["dhw"]["enable"].is<bool>()) {