From aa7f8b2e398300d9be1ed8765d6f7541850e4aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Bo=CC=88hm?= Date: Wed, 4 Dec 2024 08:58:04 +0100 Subject: [PATCH] use 'migrateOnBattery()' for config migration --- include/Configuration.h | 2 +- src/Configuration.cpp | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/Configuration.h b/include/Configuration.h index 716432b62..97f0725c8 100644 --- a/include/Configuration.h +++ b/include/Configuration.h @@ -10,7 +10,7 @@ #define CONFIG_FILENAME "/config.json" #define CONFIG_VERSION 0x00011d00 // 0.1.29 // make sure to clean all after change -#define CONFIG_VERSION_ONBATTERY 2 +#define CONFIG_VERSION_ONBATTERY 3 #define WIFI_MAX_SSID_STRLEN 32 #define WIFI_MAX_PASSWORD_STRLEN 64 diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 6961f0d79..3b1f8d565 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -670,15 +670,6 @@ bool ConfigurationClass::read() deserializeSolarChargerConfig(doc["solarcharger"], config.SolarCharger); - // process settings from legacy config if they are present - // TODO(andreasboehm): remove end of 2025. - if (!doc["vedirect"].isNull()) { - JsonObject vedirect = doc["vedirect"]; - config.SolarCharger.Enabled = vedirect["enabled"] | SOLAR_CHARGER_ENABLED; - config.SolarCharger.VerboseLogging = vedirect["verbose_logging"] | SOLAR_CHARGER_VERBOSE_LOGGING; - config.SolarCharger.PublishUpdatesOnly = vedirect["updates_only"] | SOLAR_CHARGER_PUBLISH_UPDATES_ONLY; - } - JsonObject powermeter = doc["powermeter"]; config.PowerMeter.Enabled = powermeter["enabled"] | POWERMETER_ENABLED; config.PowerMeter.VerboseLogging = powermeter["verbose_logging"] | VERBOSE_LOGGING; @@ -919,6 +910,13 @@ void ConfigurationClass::migrateOnBattery() config.PowerLimiter.ConductionLosses = doc["powerlimiter"]["solar_passthrough_losses"].as(); } + if (config.Cfg.VersionOnBattery < 3) { + JsonObject vedirect = doc["vedirect"]; + config.SolarCharger.Enabled = vedirect["enabled"] | SOLAR_CHARGER_ENABLED; + config.SolarCharger.VerboseLogging = vedirect["verbose_logging"] | SOLAR_CHARGER_VERBOSE_LOGGING; + config.SolarCharger.PublishUpdatesOnly = vedirect["updates_only"] | SOLAR_CHARGER_PUBLISH_UPDATES_ONLY; + } + f.close(); config.Cfg.VersionOnBattery = CONFIG_VERSION_ONBATTERY;