From 1387353074f38b5f7fdfcf31b55cef4390a61487 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 6 May 2022 17:20:07 +0200 Subject: [PATCH] Fix energy logs sometimes resetting to 0 on reboots --- plugin/energylogger.cpp | 4 ++-- plugin/energymanagerimpl.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/energylogger.cpp b/plugin/energylogger.cpp index 713d95e..ebc2eb8 100644 --- a/plugin/energylogger.cpp +++ b/plugin/energylogger.cpp @@ -323,7 +323,7 @@ void EnergyLogger::sample() medianAcquisition /= sampleStart.msecsTo(sampleEnd); medianStorage /= sampleStart.msecsTo(sampleEnd); - PowerBalanceLogEntry newest = m_balanceLiveLog.count() > 0 ? m_balanceLiveLog.at(0) : PowerBalanceLogEntry(); + PowerBalanceLogEntry newest = latestLogEntry(SampleRateAny); double totalConsumption = newest.totalConsumption(); double totalProduction = newest.totalProduction(); double totalAcquisition = newest.totalAcquisition(); @@ -349,7 +349,7 @@ void EnergyLogger::sample() } medianPower /= sampleStart.msecsTo(sampleEnd); - ThingPowerLogEntry newest = entries.count() > 0 ? entries.first() : ThingPowerLogEntry(); + ThingPowerLogEntry newest = latestLogEntry(SampleRateAny, thingId); double totalConsumption = newest.totalConsumption(); double totalProduction = newest.totalProduction(); diff --git a/plugin/energymanagerimpl.cpp b/plugin/energymanagerimpl.cpp index 7b20d00..1f3c1bc 100644 --- a/plugin/energymanagerimpl.cpp +++ b/plugin/energymanagerimpl.cpp @@ -64,7 +64,7 @@ EnergyManager::EnergyError EnergyManagerImpl::setRootMeter(const ThingId &rootMe m_rootMeter = rootMeter; QSettings settings(NymeaSettings::settingsPath() + "/energy.conf", QSettings::IniFormat); - settings.setValue("rootMeterThingId", rootMeter->id()); + settings.setValue("rootMeterThingId", rootMeter->id().toString()); emit rootMeterChanged(); }