Skip to content

Commit

Permalink
use 'migrateOnBattery()' for config migration
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBoehm committed Dec 4, 2024
1 parent a7615d1 commit aa7f8b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -919,6 +910,13 @@ void ConfigurationClass::migrateOnBattery()
config.PowerLimiter.ConductionLosses = doc["powerlimiter"]["solar_passthrough_losses"].as<uint8_t>();
}

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;
Expand Down

0 comments on commit aa7f8b2

Please sign in to comment.