Add Qt6 support

This commit is contained in:
Simon Stürz 2024-04-08 08:50:13 +02:00
parent de073f9b59
commit f7cc492fd6
17 changed files with 134 additions and 103 deletions

View File

@ -7,4 +7,15 @@ gcc {
top_srcdir = $$PWD top_srcdir = $$PWD
top_builddir = $$shadowed($$PWD) top_builddir = $$shadowed($$PWD)
CONFIG += c++11 greaterThan(QT_MAJOR_VERSION, 5) {
message("Building using Qt6 support")
CONFIG *= c++17
QMAKE_LFLAGS *= -std=c++17
QMAKE_CXXFLAGS *= -std=c++17
} else {
message("Building using Qt5 support")
CONFIG *= c++11
QMAKE_LFLAGS *= -std=c++11
QMAKE_CXXFLAGS *= -std=c++11
DEFINES += QT_DISABLE_DEPRECATED_UP_TO=0x050F00
}

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2024, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2024, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2024, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2024, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -64,7 +64,7 @@ public:
virtual double totalAcquisition() const = 0; virtual double totalAcquisition() const = 0;
virtual double totalReturn() const = 0; virtual double totalReturn() const = 0;
virtual EnergyLogs* logs() const = 0; virtual EnergyLogs *logs() const = 0;
signals: signals:
void rootMeterChanged(); void rootMeterChanged();

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2024, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2024, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -48,9 +48,9 @@ public:
virtual void init() = 0; virtual void init() = 0;
protected: protected:
EnergyManager* energyManager() const; EnergyManager *energyManager() const;
ThingManager* thingManager() const; ThingManager *thingManager() const;
JsonRPCServer* jsonRpcServer() const; JsonRPCServer *jsonRpcServer() const;
private: private:
friend class ExperiencePluginEnergy; friend class ExperiencePluginEnergy;

View File

@ -7,7 +7,6 @@ NYMEA_ENERGY_VERSION_STRING = "0.0.1"
CONFIG += link_pkgconfig CONFIG += link_pkgconfig
PKGCONFIG += nymea PKGCONFIG += nymea
HEADERS += \ HEADERS += \
energylogs.h \ energylogs.h \
energymanager.h \ energymanager.h \
@ -37,4 +36,3 @@ QMAKE_PKGCONFIG_LIBDIR = $$target.path
QMAKE_PKGCONFIG_VERSION = $$NYMEA_ENERGY_VERSION_STRING QMAKE_PKGCONFIG_VERSION = $$NYMEA_ENERGY_VERSION_STRING
QMAKE_PKGCONFIG_FILE = nymea-energy QMAKE_PKGCONFIG_FILE = nymea-energy
QMAKE_PKGCONFIG_DESTDIR = pkgconfig QMAKE_PKGCONFIG_DESTDIR = pkgconfig

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2024, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2024, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -32,7 +32,7 @@
#define ENERGYJSONHANDLER_H #define ENERGYJSONHANDLER_H
#include <QObject> #include <QObject>
#include "jsonrpc/jsonhandler.h" #include <jsonrpc/jsonhandler.h>
class EnergyManager; class EnergyManager;
@ -44,11 +44,11 @@ public:
QString name() const override; QString name() const override;
Q_INVOKABLE JsonReply* GetRootMeter(const QVariantMap &params); Q_INVOKABLE JsonReply *GetRootMeter(const QVariantMap &params);
Q_INVOKABLE JsonReply* SetRootMeter(const QVariantMap &params); Q_INVOKABLE JsonReply *SetRootMeter(const QVariantMap &params);
Q_INVOKABLE JsonReply* GetPowerBalance(const QVariantMap &params); Q_INVOKABLE JsonReply *GetPowerBalance(const QVariantMap &params);
Q_INVOKABLE JsonReply* GetPowerBalanceLogs(const QVariantMap &params); Q_INVOKABLE JsonReply *GetPowerBalanceLogs(const QVariantMap &params);
Q_INVOKABLE JsonReply* GetThingPowerLogs(const QVariantMap &params); Q_INVOKABLE JsonReply *GetThingPowerLogs(const QVariantMap &params);
signals: signals:
void RootMeterChanged(const QVariantMap &params); void RootMeterChanged(const QVariantMap &params);

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2024, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -43,7 +43,8 @@
#include <QLoggingCategory> #include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(dcEnergyExperience) Q_DECLARE_LOGGING_CATEGORY(dcEnergyExperience)
EnergyLogger::EnergyLogger(QObject *parent) : EnergyLogs(parent) EnergyLogger::EnergyLogger(QObject *parent)
: EnergyLogs(parent)
{ {
if (!initDB()) { if (!initDB()) {
qCCritical(dcEnergyExperience()) << "Unable to open energy log. Energy logs will not be available."; qCCritical(dcEnergyExperience()) << "Unable to open energy log. Energy logs will not be available.";
@ -152,7 +153,7 @@ PowerBalanceLogEntries EnergyLogger::powerBalanceLogs(SampleRate sampleRate, con
} }
while (query.next()) { while (query.next()) {
// qCDebug(dcEnergyExperience()) << "Adding result"; // qCDebug(dcEnergyExperience()) << "Adding result";
result.append(queryResultToBalanceLogEntry(query.record())); result.append(queryResultToBalanceLogEntry(query.record()));
} }
return result; return result;
@ -198,11 +199,11 @@ ThingPowerLogEntries EnergyLogger::thingPowerLogs(SampleRate sampleRate, const Q
while (query.next()) { while (query.next()) {
result.append(ThingPowerLogEntry( result.append(ThingPowerLogEntry(
QDateTime::fromMSecsSinceEpoch(query.value("timestamp").toLongLong()), QDateTime::fromMSecsSinceEpoch(query.value("timestamp").toLongLong()),
query.value("thingId").toUuid(), query.value("thingId").toUuid(),
query.value("currentPower").toDouble(), query.value("currentPower").toDouble(),
query.value("totalConsumption").toDouble(), query.value("totalConsumption").toDouble(),
query.value("totalProduction").toDouble())); query.value("totalProduction").toDouble()));
} }
return result; return result;
@ -489,89 +490,110 @@ bool EnergyLogger::initDB()
{ {
m_db.close(); m_db.close();
m_db = QSqlDatabase::addDatabase("QSQLITE", "energylogs"); m_db = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), "energylogs");
QDir path = QDir(NymeaSettings::storagePath()); QDir path = QDir(NymeaSettings::storagePath());
if (!path.exists()) { if (!path.exists())
path.mkpath(path.path()); path.mkpath(path.path());
}
m_db.setDatabaseName(path.filePath("energylogs.sqlite")); m_db.setDatabaseName(path.filePath("energylogs.sqlite"));
bool opened = m_db.open(); if (!m_db.isValid()) {
if (!opened) { qCWarning(dcEnergyExperience()) << "The energy database is not valid" << m_db.databaseName();
return false;
}
qCDebug(dcEnergyExperience()) << "Opening energy database" << m_db.databaseName();
if (!m_db.open()) {
qCWarning(dcEnergyExperience()) << "Cannot open energy log DB at" << m_db.databaseName() << m_db.lastError(); qCWarning(dcEnergyExperience()) << "Cannot open energy log DB at" << m_db.databaseName() << m_db.lastError();
return false; return false;
} }
if (!m_db.tables().contains("metadata")) { if (!m_db.tables().contains("metadata")) {
qCDebug(dcEnergyExperience()) << "No \"metadata\" table in database. Creating it."; qCDebug(dcEnergyExperience()) << "No \"metadata\" table in database. Creating it.";
m_db.exec("CREATE TABLE metadata (version INT);");
m_db.exec("INSERT INTO metadata (version) VALUES (1);");
if (m_db.lastError().isValid()) { QString queryString = "CREATE TABLE IF NOT EXISTS metadata (version INT);";
qCWarning(dcEnergyExperience()) << "Error creating metadata table in energy log database. Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText(); QSqlQuery createTableMetadataVersionQuery(queryString, m_db);
if (!createTableMetadataVersionQuery.exec()) {
qCWarning(dcEnergyExperience()) << "Error creating metadata table in energy log database. Query:" << queryString << createTableMetadataVersionQuery.lastError().text() << "Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText();
return false;
}
queryString = "INSERT INTO metadata (version) VALUES (1);";
QSqlQuery writeVersionQuery(queryString, m_db);
if (!writeVersionQuery.exec()) {
qCWarning(dcEnergyExperience()) << "Error writing metadata table in energy log database. Query:" << queryString << writeVersionQuery.lastError().text() << "Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText();
return false; return false;
} }
} }
if (!m_db.tables().contains("powerBalance")) { if (!m_db.tables().contains("powerBalance")) {
qCDebug(dcEnergyExperience()) << "No \"powerBalance\" table in database. Creating it."; qCDebug(dcEnergyExperience()) << "No \"powerBalance\" table in database. Creating it.";
m_db.exec("CREATE TABLE powerBalance " QString query("CREATE TABLE IF NOT EXISTS powerBalance "
"(" "("
"timestamp BIGINT," "timestamp BIGINT,"
"sampleRate INT," "sampleRate INT,"
"consumption FLOAT," "consumption FLOAT,"
"production FLOAT," "production FLOAT,"
"acquisition FLOAT," "acquisition FLOAT,"
"storage FLOAT," "storage FLOAT,"
"totalConsumption FLOAT," "totalConsumption FLOAT,"
"totalProduction FLOAT," "totalProduction FLOAT,"
"totalAcquisition FLOAT," "totalAcquisition FLOAT,"
"totalReturn FLOAT" "totalReturn FLOAT"
");"); ");");
if (m_db.lastError().isValid()) { QSqlQuery createTableQuery(query, m_db);
qCWarning(dcEnergyExperience()) << "Error creating powerBalance table in energy log database. Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText(); if (!createTableQuery.exec()) {
qCWarning(dcEnergyExperience()) << "Error creating powerBalance table in energy log database." << query << createTableQuery.lastError().text() << "Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText();
return false; return false;
} }
} }
m_db.exec("CREATE INDEX IF NOT EXISTS idx_powerBalance ON powerBalance(sampleRate, timestamp);");
if (m_db.lastError().isValid()) { QSqlQuery createPowerBalanceIndexQuery("CREATE INDEX IF NOT EXISTS idx_powerBalance ON powerBalance(sampleRate, timestamp);", m_db);
qCWarning(dcEnergyExperience()) << "Error creating powerBalance table index in energy log database. Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText(); if (!createPowerBalanceIndexQuery.exec()) {
qCWarning(dcEnergyExperience()) << "Error creating powerBalance table index in energy log database. Query:" << createPowerBalanceIndexQuery.lastQuery() << createPowerBalanceIndexQuery.lastError().text() << "Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText();
return false; return false;
} }
if (!m_db.tables().contains("thingPower")) { if (!m_db.tables().contains("thingPower")) {
qCDebug(dcEnergyExperience()) << "No \"thingPower\" table in database. Creating it."; qCDebug(dcEnergyExperience()) << "No \"thingPower\" table in database. Creating it.";
m_db.exec("CREATE TABLE thingPower " QString query("CREATE TABLE IF NOT EXISTS thingPower "
"(" "("
"timestamp BIGINT," "timestamp BIGINT,"
"sampleRate INT," "sampleRate INT,"
"thingId VARCHAR(38)," "thingId VARCHAR(38),"
"currentPower FLOAT," "currentPower FLOAT,"
"totalConsumption FLOAT," "totalConsumption FLOAT,"
"totalProduction FLOAT" "totalProduction FLOAT"
");"); ");");
if (m_db.lastError().isValid()) {
qCWarning(dcEnergyExperience()) << "Error creating thingPower table in energy log database. Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText(); QSqlQuery createThingPowerTableQuery(query, m_db);
if (!createThingPowerTableQuery.exec()) {
qCWarning(dcEnergyExperience()) << "Error creating thingPower table in energy log database. Query:" << query << createThingPowerTableQuery.lastError().text() << "Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText();
return false; return false;
} }
} }
m_db.exec("CREATE INDEX IF NOT EXISTS idx_thingPower ON thingPower(thingId, sampleRate, timestamp);");
if (m_db.lastError().isValid()) { QSqlQuery createThingPowerIndexQuery("CREATE INDEX IF NOT EXISTS idx_thingPower ON thingPower(thingId, sampleRate, timestamp);", m_db);
qCWarning(dcEnergyExperience()) << "Error creating thingPower table index in energy log database. Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText(); if (!createThingPowerIndexQuery.exec()) {
qCWarning(dcEnergyExperience()) << "Error creating thingPower table index in energy log database. Query:" << createThingPowerIndexQuery.lastQuery() << createThingPowerIndexQuery.lastError().text() << "Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText();
return false; return false;
} }
if (!m_db.tables().contains("thingCache")) { if (!m_db.tables().contains("thingCache")) {
qCDebug(dcEnergyExperience()) << "No \"thingCache\" table in database. Creating it."; qCDebug(dcEnergyExperience()) << "No \"thingCache\" table in database. Creating it.";
m_db.exec("CREATE TABLE thingCache " QString query("CREATE TABLE IF NOT EXISTS thingCache "
"(" "("
"thingId VARCHAR(38) PRIMARY KEY," "thingId VARCHAR(38) PRIMARY KEY,"
"totalEnergyConsumed FLOAT," "totalEnergyConsumed FLOAT,"
"totalEnergyProduced FLOAT" "totalEnergyProduced FLOAT"
");"); ");");
if (m_db.lastError().isValid()) {
qCWarning(dcEnergyExperience()) << "Error creating thingCache table in energy log database. Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText(); QSqlQuery createThingCacheTableQuery(query, m_db);
if (!createThingCacheTableQuery.exec()) {
qCWarning(dcEnergyExperience()) << "Error creating thingCache table in energy log database. Query:" << query << createThingCacheTableQuery.lastError().text() << "Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText();
return false; return false;
} }
} }
@ -672,8 +694,8 @@ void EnergyLogger::rectifySamples(SampleRate sampleRate, SampleRate baseSampleRa
newestSample = oldestBaseSample; newestSample = oldestBaseSample;
} }
// qCDebug(dcEnergyExperience()) << "next sample after last in series:" << nextSampleTimestamp(sampleRate, newestSample).toString(); // qCDebug(dcEnergyExperience()) << "next sample after last in series:" << nextSampleTimestamp(sampleRate, newestSample).toString();
// qCDebug(dcEnergyExperience()) << "next scheduled sample:" << m_nextSamples.value(sampleRate).toString(); // qCDebug(dcEnergyExperience()) << "next scheduled sample:" << m_nextSamples.value(sampleRate).toString();
if (!newestSample.isNull() && nextSampleTimestamp(sampleRate, newestSample) < m_nextSamples[sampleRate]) { if (!newestSample.isNull() && nextSampleTimestamp(sampleRate, newestSample) < m_nextSamples[sampleRate]) {
// regularly sample one sample as there may be some valid samples in the base series // regularly sample one sample as there may be some valid samples in the base series
QDateTime nextSample = nextSampleTimestamp(sampleRate, newestSample.addMSecs(1000)); QDateTime nextSample = nextSampleTimestamp(sampleRate, newestSample.addMSecs(1000));
@ -713,8 +735,8 @@ void EnergyLogger::rectifySamples(SampleRate sampleRate, SampleRate baseSampleRa
} }
newestSample = oldestBaseSample; newestSample = oldestBaseSample;
} }
// qCDebug(dcEnergyExperience()) << "T next sample after last in series:" << nextSampleTimestamp(sampleRate, newestSample).toString(); // qCDebug(dcEnergyExperience()) << "T next sample after last in series:" << nextSampleTimestamp(sampleRate, newestSample).toString();
// qCDebug(dcEnergyExperience()) << "T next scheduled sample:" << m_nextSamples.value(sampleRate).toString(); // qCDebug(dcEnergyExperience()) << "T next scheduled sample:" << m_nextSamples.value(sampleRate).toString();
if (!newestSample.isNull() && nextSampleTimestamp(sampleRate, newestSample) < m_nextSamples[sampleRate]) { if (!newestSample.isNull() && nextSampleTimestamp(sampleRate, newestSample) < m_nextSamples[sampleRate]) {
QDateTime nextSample = nextSampleTimestamp(sampleRate, newestSample.addMSecs(1000)); QDateTime nextSample = nextSampleTimestamp(sampleRate, newestSample.addMSecs(1000));
sampleThingPower(thingId, sampleRate, baseSampleRate, nextSample); sampleThingPower(thingId, sampleRate, baseSampleRate, nextSample);

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2024, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2024, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -180,8 +180,8 @@ void EnergyManagerImpl::watchThing(Thing *thing)
m_powerBalanceTotalEnergyConsumedCache[thing] = stateEntry.totalConsumption(); m_powerBalanceTotalEnergyConsumedCache[thing] = stateEntry.totalConsumption();
m_powerBalanceTotalEnergyProducedCache[thing] = stateEntry.totalProduction(); m_powerBalanceTotalEnergyProducedCache[thing] = stateEntry.totalProduction();
m_thingsTotalEnergyConsumedCache[thing] = qMakePair<double, double>(stateEntry.totalConsumption(), entry.totalConsumption()); m_thingsTotalEnergyConsumedCache[thing] = QPair<double, double>(stateEntry.totalConsumption(), entry.totalConsumption());
m_thingsTotalEnergyProducedCache[thing] = qMakePair<double, double>(stateEntry.totalProduction(), entry.totalProduction()); m_thingsTotalEnergyProducedCache[thing] = QPair<double, double>(stateEntry.totalProduction(), entry.totalProduction());
qCDebug(dcEnergyExperience()) << "Loaded thing power totals for" << thing->name() << "Consumption:" << entry.totalConsumption() << "Production:" << entry.totalProduction() << "Last thing state consumption:" << stateEntry.totalConsumption() << "production:" << stateEntry.totalProduction(); qCDebug(dcEnergyExperience()) << "Loaded thing power totals for" << thing->name() << "Consumption:" << entry.totalConsumption() << "Production:" << entry.totalProduction() << "Last thing state consumption:" << stateEntry.totalConsumption() << "production:" << stateEntry.totalProduction();
updateThingPower(thing); updateThingPower(thing);
@ -315,7 +315,7 @@ void EnergyManagerImpl::updateThingPower(Thing *thing)
} }
double consumptionDiff = newThingConsumptionState - oldThingConsumptionState; double consumptionDiff = newThingConsumptionState - oldThingConsumptionState;
double newThingConsumptionInternal = oldThingConsumptionInternal + consumptionDiff; double newThingConsumptionInternal = oldThingConsumptionInternal + consumptionDiff;
m_thingsTotalEnergyConsumedCache[thing] = qMakePair<double, double>(newThingConsumptionState, newThingConsumptionInternal); m_thingsTotalEnergyConsumedCache[thing] = QPair<double, double>(newThingConsumptionState, newThingConsumptionInternal);
// Production // Production
@ -334,7 +334,7 @@ void EnergyManagerImpl::updateThingPower(Thing *thing)
} }
double productionDiff = newThingProductionState - oldThingProductionState; double productionDiff = newThingProductionState - oldThingProductionState;
double newThingProductionInternal = oldThingProductionInternal + productionDiff; double newThingProductionInternal = oldThingProductionInternal + productionDiff;
m_thingsTotalEnergyProducedCache[thing] = qMakePair<double, double>(newThingProductionState, newThingProductionInternal); m_thingsTotalEnergyProducedCache[thing] = QPair<double, double>(newThingProductionState, newThingProductionInternal);
// Write to log // Write to log

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2024, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -35,7 +35,7 @@
#include <QHash> #include <QHash>
#include <QTimer> #include <QTimer>
#include "integrations/thingmanager.h" #include <integrations/thingmanager.h>
#include "energymanager.h" #include "energymanager.h"
@ -59,7 +59,7 @@ public:
double totalAcquisition() const override; double totalAcquisition() const override;
double totalReturn() const override; double totalReturn() const override;
EnergyLogs* logs() const override; EnergyLogs *logs() const override;
private: private:
void watchThing(Thing *thing); void watchThing(Thing *thing);
@ -94,14 +94,14 @@ private:
// For things totals we need to cache 2 values: // For things totals we need to cache 2 values:
// The last thing state values we've processed // The last thing state values we've processed
QHash<Thing*, double> m_powerBalanceTotalEnergyConsumedCache; QHash<Thing *, double> m_powerBalanceTotalEnergyConsumedCache;
QHash<Thing*, double> m_powerBalanceTotalEnergyProducedCache; QHash<Thing *, double> m_powerBalanceTotalEnergyProducedCache;
// - The last thing state value we've read and processed // - The last thing state value we've read and processed
// - The last entry in our internal counters we've processed and logged // - The last entry in our internal counters we've processed and logged
// QHash<Thing*, Pair<thingStateValue, internalValue>> // QHash<Thing *, Pair<thingStateValue, internalValue>>
QHash<Thing*, QPair<double, double>> m_thingsTotalEnergyConsumedCache; QHash<Thing *, QPair<double, double>> m_thingsTotalEnergyConsumedCache;
QHash<Thing*, QPair<double, double>> m_thingsTotalEnergyProducedCache; QHash<Thing *, QPair<double, double>> m_thingsTotalEnergyProducedCache;
}; };
#endif // ENERGYMANAGERIMPL_H #endif // ENERGYMANAGERIMPL_H

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2024, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -117,7 +117,7 @@ void ExperiencePluginEnergy::loadEnergyPlugin(const QString &file)
qCWarning(dcExperiences()) << loader.errorString(); qCWarning(dcExperiences()) << loader.errorString();
return; return;
} }
EnergyPlugin *plugin = qobject_cast<EnergyPlugin*>(loader.instance()); EnergyPlugin *plugin = qobject_cast<EnergyPlugin *>(loader.instance());
if (!plugin) { if (!plugin) {
qCWarning(dcEnergyExperience()) << "Could not get plugin instance of" << loader.fileName(); qCWarning(dcEnergyExperience()) << "Could not get plugin instance of" << loader.fileName();
loader.unload(); loader.unload();

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2024, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -56,7 +56,7 @@ private:
void loadPlugins(); void loadPlugins();
void loadEnergyPlugin(const QString &file); void loadEnergyPlugin(const QString &file);
QList<EnergyPlugin*> m_plugins; QList<EnergyPlugin *> m_plugins;
EnergyManagerImpl *m_energyManager = nullptr; EnergyManagerImpl *m_energyManager = nullptr;
}; };

View File

@ -1,14 +1,14 @@
TEMPLATE = lib TEMPLATE = lib
TARGET = $$qtLibraryTarget(nymea_experiencepluginenergy) TARGET = $$qtLibraryTarget(nymea_experiencepluginenergy)
CONFIG += plugin link_pkgconfig c++11 include(../config.pri)
CONFIG += plugin link_pkgconfig
PKGCONFIG += nymea PKGCONFIG += nymea
QT -= gui QT -= gui
QT += network sql QT += network sql
include(../config.pri)
INCLUDEPATH += $$top_srcdir/libnymea-energy INCLUDEPATH += $$top_srcdir/libnymea-energy
LIBS += -L$$top_builddir/libnymea-energy -lnymea-energy LIBS += -L$$top_builddir/libnymea-energy -lnymea-energy