Add Qt6 support
parent
de073f9b59
commit
f7cc492fd6
13
config.pri
13
config.pri
|
|
@ -7,4 +7,15 @@ gcc {
|
|||
top_srcdir = $$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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2024, nymea GmbH
|
||||
* Copyright 2013 - 2025, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2024, nymea GmbH
|
||||
* Copyright 2013 - 2025, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2024, nymea GmbH
|
||||
* Copyright 2013 - 2025, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2024, nymea GmbH
|
||||
* Copyright 2013 - 2025, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
|
|
@ -64,7 +64,7 @@ public:
|
|||
virtual double totalAcquisition() const = 0;
|
||||
virtual double totalReturn() const = 0;
|
||||
|
||||
virtual EnergyLogs* logs() const = 0;
|
||||
virtual EnergyLogs *logs() const = 0;
|
||||
|
||||
signals:
|
||||
void rootMeterChanged();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2024, nymea GmbH
|
||||
* Copyright 2013 - 2025, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2024, nymea GmbH
|
||||
* Copyright 2013 - 2025, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
|
|
@ -48,9 +48,9 @@ public:
|
|||
virtual void init() = 0;
|
||||
|
||||
protected:
|
||||
EnergyManager* energyManager() const;
|
||||
ThingManager* thingManager() const;
|
||||
JsonRPCServer* jsonRpcServer() const;
|
||||
EnergyManager *energyManager() const;
|
||||
ThingManager *thingManager() const;
|
||||
JsonRPCServer *jsonRpcServer() const;
|
||||
|
||||
private:
|
||||
friend class ExperiencePluginEnergy;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ NYMEA_ENERGY_VERSION_STRING = "0.0.1"
|
|||
CONFIG += link_pkgconfig
|
||||
PKGCONFIG += nymea
|
||||
|
||||
|
||||
HEADERS += \
|
||||
energylogs.h \
|
||||
energymanager.h \
|
||||
|
|
@ -37,4 +36,3 @@ QMAKE_PKGCONFIG_LIBDIR = $$target.path
|
|||
QMAKE_PKGCONFIG_VERSION = $$NYMEA_ENERGY_VERSION_STRING
|
||||
QMAKE_PKGCONFIG_FILE = nymea-energy
|
||||
QMAKE_PKGCONFIG_DESTDIR = pkgconfig
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2024, nymea GmbH
|
||||
* Copyright 2013 - 2025, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2024, nymea GmbH
|
||||
* Copyright 2013 - 2025, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
#define ENERGYJSONHANDLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include "jsonrpc/jsonhandler.h"
|
||||
#include <jsonrpc/jsonhandler.h>
|
||||
|
||||
class EnergyManager;
|
||||
|
||||
|
|
@ -44,11 +44,11 @@ public:
|
|||
|
||||
QString name() const override;
|
||||
|
||||
Q_INVOKABLE JsonReply* GetRootMeter(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply* SetRootMeter(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply* GetPowerBalance(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply* GetPowerBalanceLogs(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply* GetThingPowerLogs(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *GetRootMeter(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *SetRootMeter(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *GetPowerBalance(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *GetPowerBalanceLogs(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *GetThingPowerLogs(const QVariantMap ¶ms);
|
||||
|
||||
signals:
|
||||
void RootMeterChanged(const QVariantMap ¶ms);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2024, nymea GmbH
|
||||
* Copyright 2013 - 2025, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
|
|
@ -43,7 +43,8 @@
|
|||
#include <QLoggingCategory>
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcEnergyExperience)
|
||||
|
||||
EnergyLogger::EnergyLogger(QObject *parent) : EnergyLogs(parent)
|
||||
EnergyLogger::EnergyLogger(QObject *parent)
|
||||
: EnergyLogs(parent)
|
||||
{
|
||||
if (!initDB()) {
|
||||
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()) {
|
||||
// qCDebug(dcEnergyExperience()) << "Adding result";
|
||||
// qCDebug(dcEnergyExperience()) << "Adding result";
|
||||
result.append(queryResultToBalanceLogEntry(query.record()));
|
||||
}
|
||||
return result;
|
||||
|
|
@ -198,11 +199,11 @@ ThingPowerLogEntries EnergyLogger::thingPowerLogs(SampleRate sampleRate, const Q
|
|||
|
||||
while (query.next()) {
|
||||
result.append(ThingPowerLogEntry(
|
||||
QDateTime::fromMSecsSinceEpoch(query.value("timestamp").toLongLong()),
|
||||
query.value("thingId").toUuid(),
|
||||
query.value("currentPower").toDouble(),
|
||||
query.value("totalConsumption").toDouble(),
|
||||
query.value("totalProduction").toDouble()));
|
||||
QDateTime::fromMSecsSinceEpoch(query.value("timestamp").toLongLong()),
|
||||
query.value("thingId").toUuid(),
|
||||
query.value("currentPower").toDouble(),
|
||||
query.value("totalConsumption").toDouble(),
|
||||
query.value("totalProduction").toDouble()));
|
||||
}
|
||||
return result;
|
||||
|
||||
|
|
@ -489,89 +490,110 @@ bool EnergyLogger::initDB()
|
|||
{
|
||||
m_db.close();
|
||||
|
||||
m_db = QSqlDatabase::addDatabase("QSQLITE", "energylogs");
|
||||
m_db = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), "energylogs");
|
||||
QDir path = QDir(NymeaSettings::storagePath());
|
||||
if (!path.exists()) {
|
||||
if (!path.exists())
|
||||
path.mkpath(path.path());
|
||||
}
|
||||
|
||||
m_db.setDatabaseName(path.filePath("energylogs.sqlite"));
|
||||
|
||||
bool opened = m_db.open();
|
||||
if (!opened) {
|
||||
if (!m_db.isValid()) {
|
||||
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();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_db.tables().contains("metadata")) {
|
||||
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()) {
|
||||
qCWarning(dcEnergyExperience()) << "Error creating metadata table in energy log database. Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText();
|
||||
QString queryString = "CREATE TABLE IF NOT EXISTS metadata (version INT);";
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_db.tables().contains("powerBalance")) {
|
||||
qCDebug(dcEnergyExperience()) << "No \"powerBalance\" table in database. Creating it.";
|
||||
m_db.exec("CREATE TABLE powerBalance "
|
||||
"("
|
||||
"timestamp BIGINT,"
|
||||
"sampleRate INT,"
|
||||
"consumption FLOAT,"
|
||||
"production FLOAT,"
|
||||
"acquisition FLOAT,"
|
||||
"storage FLOAT,"
|
||||
"totalConsumption FLOAT,"
|
||||
"totalProduction FLOAT,"
|
||||
"totalAcquisition FLOAT,"
|
||||
"totalReturn FLOAT"
|
||||
");");
|
||||
QString query("CREATE TABLE IF NOT EXISTS powerBalance "
|
||||
"("
|
||||
"timestamp BIGINT,"
|
||||
"sampleRate INT,"
|
||||
"consumption FLOAT,"
|
||||
"production FLOAT,"
|
||||
"acquisition FLOAT,"
|
||||
"storage FLOAT,"
|
||||
"totalConsumption FLOAT,"
|
||||
"totalProduction FLOAT,"
|
||||
"totalAcquisition FLOAT,"
|
||||
"totalReturn FLOAT"
|
||||
");");
|
||||
|
||||
if (m_db.lastError().isValid()) {
|
||||
qCWarning(dcEnergyExperience()) << "Error creating powerBalance table in energy log database. Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText();
|
||||
QSqlQuery createTableQuery(query, m_db);
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
m_db.exec("CREATE INDEX IF NOT EXISTS idx_powerBalance ON powerBalance(sampleRate, timestamp);");
|
||||
if (m_db.lastError().isValid()) {
|
||||
qCWarning(dcEnergyExperience()) << "Error creating powerBalance table index in energy log database. Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText();
|
||||
|
||||
QSqlQuery createPowerBalanceIndexQuery("CREATE INDEX IF NOT EXISTS idx_powerBalance ON powerBalance(sampleRate, timestamp);", m_db);
|
||||
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;
|
||||
}
|
||||
|
||||
if (!m_db.tables().contains("thingPower")) {
|
||||
qCDebug(dcEnergyExperience()) << "No \"thingPower\" table in database. Creating it.";
|
||||
m_db.exec("CREATE TABLE thingPower "
|
||||
"("
|
||||
"timestamp BIGINT,"
|
||||
"sampleRate INT,"
|
||||
"thingId VARCHAR(38),"
|
||||
"currentPower FLOAT,"
|
||||
"totalConsumption 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();
|
||||
QString query("CREATE TABLE IF NOT EXISTS thingPower "
|
||||
"("
|
||||
"timestamp BIGINT,"
|
||||
"sampleRate INT,"
|
||||
"thingId VARCHAR(38),"
|
||||
"currentPower FLOAT,"
|
||||
"totalConsumption FLOAT,"
|
||||
"totalProduction FLOAT"
|
||||
");");
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
m_db.exec("CREATE INDEX IF NOT EXISTS idx_thingPower ON thingPower(thingId, sampleRate, timestamp);");
|
||||
if (m_db.lastError().isValid()) {
|
||||
qCWarning(dcEnergyExperience()) << "Error creating thingPower table index in energy log database. Driver error:" << m_db.lastError().driverText() << "Database error:" << m_db.lastError().databaseText();
|
||||
|
||||
QSqlQuery createThingPowerIndexQuery("CREATE INDEX IF NOT EXISTS idx_thingPower ON thingPower(thingId, sampleRate, timestamp);", m_db);
|
||||
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;
|
||||
}
|
||||
|
||||
if (!m_db.tables().contains("thingCache")) {
|
||||
qCDebug(dcEnergyExperience()) << "No \"thingCache\" table in database. Creating it.";
|
||||
m_db.exec("CREATE TABLE thingCache "
|
||||
"("
|
||||
"thingId VARCHAR(38) PRIMARY KEY,"
|
||||
"totalEnergyConsumed 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();
|
||||
QString query("CREATE TABLE IF NOT EXISTS thingCache "
|
||||
"("
|
||||
"thingId VARCHAR(38) PRIMARY KEY,"
|
||||
"totalEnergyConsumed FLOAT,"
|
||||
"totalEnergyProduced FLOAT"
|
||||
");");
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -672,8 +694,8 @@ void EnergyLogger::rectifySamples(SampleRate sampleRate, SampleRate baseSampleRa
|
|||
newestSample = oldestBaseSample;
|
||||
}
|
||||
|
||||
// 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 sample after last in series:" << nextSampleTimestamp(sampleRate, newestSample).toString();
|
||||
// qCDebug(dcEnergyExperience()) << "next scheduled sample:" << m_nextSamples.value(sampleRate).toString();
|
||||
if (!newestSample.isNull() && nextSampleTimestamp(sampleRate, newestSample) < m_nextSamples[sampleRate]) {
|
||||
// regularly sample one sample as there may be some valid samples in the base series
|
||||
QDateTime nextSample = nextSampleTimestamp(sampleRate, newestSample.addMSecs(1000));
|
||||
|
|
@ -713,8 +735,8 @@ void EnergyLogger::rectifySamples(SampleRate sampleRate, SampleRate baseSampleRa
|
|||
}
|
||||
newestSample = oldestBaseSample;
|
||||
}
|
||||
// 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 sample after last in series:" << nextSampleTimestamp(sampleRate, newestSample).toString();
|
||||
// qCDebug(dcEnergyExperience()) << "T next scheduled sample:" << m_nextSamples.value(sampleRate).toString();
|
||||
if (!newestSample.isNull() && nextSampleTimestamp(sampleRate, newestSample) < m_nextSamples[sampleRate]) {
|
||||
QDateTime nextSample = nextSampleTimestamp(sampleRate, newestSample.addMSecs(1000));
|
||||
sampleThingPower(thingId, sampleRate, baseSampleRate, nextSample);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2024, nymea GmbH
|
||||
* Copyright 2013 - 2025, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2024, nymea GmbH
|
||||
* Copyright 2013 - 2025, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
|
|
@ -180,8 +180,8 @@ void EnergyManagerImpl::watchThing(Thing *thing)
|
|||
m_powerBalanceTotalEnergyConsumedCache[thing] = stateEntry.totalConsumption();
|
||||
m_powerBalanceTotalEnergyProducedCache[thing] = stateEntry.totalProduction();
|
||||
|
||||
m_thingsTotalEnergyConsumedCache[thing] = qMakePair<double, double>(stateEntry.totalConsumption(), entry.totalConsumption());
|
||||
m_thingsTotalEnergyProducedCache[thing] = qMakePair<double, double>(stateEntry.totalProduction(), entry.totalProduction());
|
||||
m_thingsTotalEnergyConsumedCache[thing] = QPair<double, double>(stateEntry.totalConsumption(), entry.totalConsumption());
|
||||
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();
|
||||
|
||||
updateThingPower(thing);
|
||||
|
|
@ -315,7 +315,7 @@ void EnergyManagerImpl::updateThingPower(Thing *thing)
|
|||
}
|
||||
double consumptionDiff = newThingConsumptionState - oldThingConsumptionState;
|
||||
double newThingConsumptionInternal = oldThingConsumptionInternal + consumptionDiff;
|
||||
m_thingsTotalEnergyConsumedCache[thing] = qMakePair<double, double>(newThingConsumptionState, newThingConsumptionInternal);
|
||||
m_thingsTotalEnergyConsumedCache[thing] = QPair<double, double>(newThingConsumptionState, newThingConsumptionInternal);
|
||||
|
||||
|
||||
// Production
|
||||
|
|
@ -334,7 +334,7 @@ void EnergyManagerImpl::updateThingPower(Thing *thing)
|
|||
}
|
||||
double productionDiff = newThingProductionState - oldThingProductionState;
|
||||
double newThingProductionInternal = oldThingProductionInternal + productionDiff;
|
||||
m_thingsTotalEnergyProducedCache[thing] = qMakePair<double, double>(newThingProductionState, newThingProductionInternal);
|
||||
m_thingsTotalEnergyProducedCache[thing] = QPair<double, double>(newThingProductionState, newThingProductionInternal);
|
||||
|
||||
|
||||
// Write to log
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2024, nymea GmbH
|
||||
* Copyright 2013 - 2025, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
#include <QHash>
|
||||
#include <QTimer>
|
||||
|
||||
#include "integrations/thingmanager.h"
|
||||
#include <integrations/thingmanager.h>
|
||||
|
||||
#include "energymanager.h"
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ public:
|
|||
double totalAcquisition() const override;
|
||||
double totalReturn() const override;
|
||||
|
||||
EnergyLogs* logs() const override;
|
||||
EnergyLogs *logs() const override;
|
||||
|
||||
private:
|
||||
void watchThing(Thing *thing);
|
||||
|
|
@ -94,14 +94,14 @@ private:
|
|||
|
||||
// For things totals we need to cache 2 values:
|
||||
// The last thing state values we've processed
|
||||
QHash<Thing*, double> m_powerBalanceTotalEnergyConsumedCache;
|
||||
QHash<Thing*, double> m_powerBalanceTotalEnergyProducedCache;
|
||||
QHash<Thing *, double> m_powerBalanceTotalEnergyConsumedCache;
|
||||
QHash<Thing *, double> m_powerBalanceTotalEnergyProducedCache;
|
||||
|
||||
// - The last thing state value we've read and processed
|
||||
// - The last entry in our internal counters we've processed and logged
|
||||
// QHash<Thing*, Pair<thingStateValue, internalValue>>
|
||||
QHash<Thing*, QPair<double, double>> m_thingsTotalEnergyConsumedCache;
|
||||
QHash<Thing*, QPair<double, double>> m_thingsTotalEnergyProducedCache;
|
||||
// QHash<Thing *, Pair<thingStateValue, internalValue>>
|
||||
QHash<Thing *, QPair<double, double>> m_thingsTotalEnergyConsumedCache;
|
||||
QHash<Thing *, QPair<double, double>> m_thingsTotalEnergyProducedCache;
|
||||
};
|
||||
|
||||
#endif // ENERGYMANAGERIMPL_H
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2024, nymea GmbH
|
||||
* Copyright 2013 - 2025, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
|
|
@ -117,7 +117,7 @@ void ExperiencePluginEnergy::loadEnergyPlugin(const QString &file)
|
|||
qCWarning(dcExperiences()) << loader.errorString();
|
||||
return;
|
||||
}
|
||||
EnergyPlugin *plugin = qobject_cast<EnergyPlugin*>(loader.instance());
|
||||
EnergyPlugin *plugin = qobject_cast<EnergyPlugin *>(loader.instance());
|
||||
if (!plugin) {
|
||||
qCWarning(dcEnergyExperience()) << "Could not get plugin instance of" << loader.fileName();
|
||||
loader.unload();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2024, nymea GmbH
|
||||
* Copyright 2013 - 2025, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
|
|
@ -56,7 +56,7 @@ private:
|
|||
void loadPlugins();
|
||||
void loadEnergyPlugin(const QString &file);
|
||||
|
||||
QList<EnergyPlugin*> m_plugins;
|
||||
QList<EnergyPlugin *> m_plugins;
|
||||
|
||||
EnergyManagerImpl *m_energyManager = nullptr;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
TEMPLATE = lib
|
||||
TARGET = $$qtLibraryTarget(nymea_experiencepluginenergy)
|
||||
|
||||
CONFIG += plugin link_pkgconfig c++11
|
||||
include(../config.pri)
|
||||
|
||||
CONFIG += plugin link_pkgconfig
|
||||
PKGCONFIG += nymea
|
||||
|
||||
QT -= gui
|
||||
QT += network sql
|
||||
|
||||
include(../config.pri)
|
||||
|
||||
INCLUDEPATH += $$top_srcdir/libnymea-energy
|
||||
LIBS += -L$$top_builddir/libnymea-energy -lnymea-energy
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue