diff --git a/libnymea-app-core/devices.cpp b/libnymea-app-core/devices.cpp index d6398282..2b41170a 100644 --- a/libnymea-app-core/devices.cpp +++ b/libnymea-app-core/devices.cpp @@ -118,6 +118,15 @@ QVariant Devices::data(const QModelIndex &index, int role) const if (interfaces.contains("notifications")) { return "notifications"; } + if (interfaces.contains("smartmeter")) { + return "smartmeter"; + } + if (interfaces.contains("heating")) { + return "heating"; + } + if (interfaces.contains("evcharger")) { + return "evcharger"; + } return "uncategorized"; } diff --git a/libnymea-app-core/jsonrpc/jsonrpcclient.cpp b/libnymea-app-core/jsonrpc/jsonrpcclient.cpp index eddce39f..69656d5d 100644 --- a/libnymea-app-core/jsonrpc/jsonrpcclient.cpp +++ b/libnymea-app-core/jsonrpc/jsonrpcclient.cpp @@ -303,7 +303,7 @@ void JsonRpcClient::sendRequest(const QVariantMap &request) { QVariantMap newRequest = request; newRequest.insert("token", m_token); - qDebug() << "Sending request" << qUtf8Printable(QJsonDocument::fromVariant(newRequest).toJson()); +// qDebug() << "Sending request" << qUtf8Printable(QJsonDocument::fromVariant(newRequest).toJson()); m_connection->sendData(QJsonDocument::fromVariant(newRequest).toJson(QJsonDocument::Compact) + "\n"); } @@ -340,7 +340,7 @@ void JsonRpcClient::dataReceived(const QByteArray &data) // qWarning() << "Could not parse json data from nymea" << m_receiveBuffer.left(splitIndex) << error.errorString(); return; } - qDebug() << "received response" << qUtf8Printable(jsonDoc.toJson(QJsonDocument::Indented)); +// qDebug() << "received response" << qUtf8Printable(jsonDoc.toJson(QJsonDocument::Indented)); m_receiveBuffer = m_receiveBuffer.right(m_receiveBuffer.length() - splitIndex - 1); if (!m_receiveBuffer.isEmpty()) { staticMetaObject.invokeMethod(this, "dataReceived", Qt::QueuedConnection, Q_ARG(QByteArray, QByteArray())); diff --git a/libnymea-app-core/libnymea-app-core.pro b/libnymea-app-core/libnymea-app-core.pro index a0a3e3a0..514e2cce 100644 --- a/libnymea-app-core/libnymea-app-core.pro +++ b/libnymea-app-core/libnymea-app-core.pro @@ -15,7 +15,7 @@ include(../nymea-remoteproxy/libnymea-remoteproxyclient/libnymea-remoteproxyclie QT -= gui -QT += network websockets bluetooth +QT += network websockets bluetooth charts LIBS += -lssl -lcrypto diff --git a/libnymea-app-core/models/logsmodel.cpp b/libnymea-app-core/models/logsmodel.cpp index 3e08301c..d7ec31ef 100644 --- a/libnymea-app-core/models/logsmodel.cpp +++ b/libnymea-app-core/models/logsmodel.cpp @@ -213,7 +213,7 @@ void LogsModel::fetchEarlier(int hours) void LogsModel::logsReply(const QVariantMap &data) { - qDebug() << "logs reply";// << data; +// qDebug() << "logs reply" << data; beginResetModel(); qDeleteAll(m_list); m_list.clear(); @@ -242,7 +242,7 @@ void LogsModel::logsReply(const QVariantMap &data) void LogsModel::fetchEarlierReply(const QVariantMap &data) { - qDebug() << "logs reply";// << data; +// qDebug() << "logs reply" << data; QList logEntries = data.value("params").toMap().value("logEntries").toList(); QList newEntries; diff --git a/libnymea-app-core/models/logsmodel.h b/libnymea-app-core/models/logsmodel.h index 1d8b26f1..ee731d5a 100644 --- a/libnymea-app-core/models/logsmodel.h +++ b/libnymea-app-core/models/logsmodel.h @@ -19,6 +19,7 @@ class LogsModel : public QAbstractListModel Q_PROPERTY(QStringList typeIds READ typeIds WRITE setTypeIds NOTIFY typeIdsChanged) Q_PROPERTY(QDateTime startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged) Q_PROPERTY(QDateTime endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged) +// Q_PROPERTY(int paginationCount READ paginationCount WRITE setPaginationCount NOTIFY paginationCountChanged) Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged) @@ -56,6 +57,9 @@ public: QDateTime endTime() const; void setEndTime(const QDateTime &endTime); +// int paginationCount() const; +// void setPaginationCount(int paginationCount); + Q_INVOKABLE LogEntry* get(int index) const; Q_INVOKABLE void notificationReceived(const QVariantMap &data); @@ -69,6 +73,7 @@ signals: void typeIdsChanged(); void startTimeChanged(); void endTimeChanged(); +// void paginationCountChanged(); public slots: virtual void update(); diff --git a/libnymea-app-core/models/logsmodelng.cpp b/libnymea-app-core/models/logsmodelng.cpp index ec8b3891..af341100 100644 --- a/libnymea-app-core/models/logsmodelng.cpp +++ b/libnymea-app-core/models/logsmodelng.cpp @@ -5,22 +5,24 @@ #include "engine.h" #include "types/logentry.h" +#include "logmanager.h" LogsModelNg::LogsModelNg(QObject *parent) : QAbstractListModel(parent) { } -JsonRpcClient *LogsModelNg::jsonRpcClient() const +Engine *LogsModelNg::engine() const { - return m_jsonRpcClient; + return m_engine; } -void LogsModelNg::setJsonRpcClient(JsonRpcClient *jsonRpcClient) +void LogsModelNg::setEngine(Engine *engine) { - if (m_jsonRpcClient != jsonRpcClient) { - m_jsonRpcClient = jsonRpcClient; - emit jsonRpcClientChanged(); + if (m_engine != engine) { + m_engine = engine; + connect(engine->logManager(), &LogManager::logEntryReceived, this, &LogsModelNg::newLogEntryReceived); + emit engineChanged(); } } @@ -92,16 +94,16 @@ void LogsModelNg::setDeviceId(const QString &deviceId) } } -QString LogsModelNg::typeId() const +QStringList LogsModelNg::typeIds() const { - return m_typeId; + return m_typeIds; } -void LogsModelNg::setTypeId(const QString &typeId) +void LogsModelNg::setTypeIds(const QStringList &typeIds) { - if (m_typeId != typeId) { - m_typeId = typeId; - emit typeIdChanged(); + if (m_typeIds != typeIds) { + m_typeIds = typeIds; + emit typeIdsChanged(); } } @@ -115,7 +117,6 @@ void LogsModelNg::setStartTime(const QDateTime &startTime) if (m_startTime != startTime) { m_startTime = startTime; emit startTimeChanged(); - update(); } } @@ -129,80 +130,178 @@ void LogsModelNg::setEndTime(const QDateTime &endTime) if (m_endTime != endTime) { m_endTime = endTime; emit endTimeChanged(); - update(); } } -void LogsModelNg::update() +QtCharts::QXYSeries *LogsModelNg::graphSeries() const { - if (!m_jsonRpcClient) { - qWarning() << "Cannot update. JsonRpcClient not set"; + return m_graphSeries; +} + +void LogsModelNg::setGraphSeries(QtCharts::QXYSeries *graphSeries) +{ + m_graphSeries = graphSeries; +} + +QDateTime LogsModelNg::viewStartTime() const +{ + return m_viewStartTime; +} + +void LogsModelNg::setViewStartTime(const QDateTime &viewStartTime) +{ + if (m_viewStartTime != viewStartTime) { + m_viewStartTime = viewStartTime; + emit viewStartTimeChanged(); + if (m_list.count() == 0 || m_list.last()->timestamp() > m_viewStartTime) { + if (canFetchMore()) { + fetchMore(); + } + } + } +} + +QVariant LogsModelNg::minValue() const +{ +// qDebug() << "returning min value" << m_minValue; + return m_minValue; +} + +QVariant LogsModelNg::maxValue() const +{ +// qDebug() << "returning max value" << m_maxValue; + return m_maxValue; +} + +void LogsModelNg::logsReply(const QVariantMap &data) +{ +// qDebug() << "logs reply" << data; + + + int offset = data.value("params").toMap().value("offset").toInt(); + int count = data.value("params").toMap().value("count").toInt(); + + QList newBlock; + QList logEntries = data.value("params").toMap().value("logEntries").toList(); + foreach (const QVariant &logEntryVariant, logEntries) { + QVariantMap entryMap = logEntryVariant.toMap(); + QDateTime timeStamp = QDateTime::fromMSecsSinceEpoch(entryMap.value("timestamp").toLongLong()); + QString deviceId = entryMap.value("deviceId").toString(); + QString typeId = entryMap.value("typeId").toString(); + QMetaEnum sourceEnum = QMetaEnum::fromType(); + LogEntry::LoggingSource loggingSource = static_cast(sourceEnum.keyToValue(entryMap.value("source").toByteArray())); + QMetaEnum loggingEventTypeEnum = QMetaEnum::fromType(); + LogEntry::LoggingEventType loggingEventType = static_cast(loggingEventTypeEnum.keyToValue(entryMap.value("eventType").toByteArray())); + QVariant value = loggingEventType == LogEntry::LoggingEventTypeActiveChange ? entryMap.value("active").toBool() : entryMap.value("value"); + LogEntry *entry = new LogEntry(timeStamp, value, deviceId, typeId, loggingSource, loggingEventType, this); + newBlock.append(entry); + } + + if (count < m_blockSize) { + m_canFetchMore = false; + } + + if (newBlock.isEmpty()) { + m_busy = false; + emit busyChanged(); + return; + } + + beginInsertRows(QModelIndex(), offset, offset + newBlock.count() - 1); + QVariant newMin = m_minValue; + QVariant newMax = m_maxValue; + for (int i = 0; i < newBlock.count(); i++) { + LogEntry *entry = newBlock.at(i); + m_list.insert(offset + i, entry); + + if (m_graphSeries) { + Device *dev = m_engine->deviceManager()->devices()->getDevice(entry->deviceId()); + if (dev && dev->deviceClass()->stateTypes()->getStateType(entry->typeId())->type() == "Bool") { + // We don't want bools painting triangles, add a toggle point to keep lines straight + if (i > 0) { + LogEntry *newerEntry = newBlock.at(i - 1); + if (newerEntry->value().toBool() != entry->value().toBool()) { +// qDebug() << "Adding bool line series point:" << (newerEntry->timestamp().addSecs(-1)) << newerEntry->timestamp().addSecs(-1).toMSecsSinceEpoch() << (entry->value().toBool() ? 1 : 0) << "(correction)"; + m_graphSeries->append(QPointF(newerEntry->timestamp().addSecs(-1).toMSecsSinceEpoch(), entry->value().toBool() ? 1 : 0)); + } + } + if (m_graphSeries->count() == 0) { + // If it's the first one, make sure we add an ending point at 1 +// qDebug() << "Adding bool line series point:" << QDateTime::currentDateTime() << QDateTime::currentDateTime().toMSecsSinceEpoch() - 1 << (entry->value().toBool() ? 1 : 0) << "(beginning)"; + m_graphSeries->append(QPointF(QDateTime::currentDateTime().toMSecsSinceEpoch(), 1)); + m_graphSeries->append(QPointF(QDateTime::currentDateTime().toMSecsSinceEpoch(), entry->value().toBool() ? 1 : 0)); + } else if (i == 0) { + // Adding a new batch... remove the last appended 1 from the previous batch + m_graphSeries->remove(m_graphSeries->count() - 1); + } +// qDebug() << "Adding bool line series point:" << entry->timestamp() << entry->timestamp().toMSecsSinceEpoch() << (entry->value().toBool() ? 1 : 0); + m_graphSeries->append(QPointF(entry->timestamp().toMSecsSinceEpoch(), entry->value().toBool() ? 1 : 0)); + if (i == newBlock.count() - 1) { + // End the batch at 1 again + m_graphSeries->append(QPointF(entry->timestamp().addSecs(-1).toMSecsSinceEpoch(), 1)); + } + } else { +// if (i > 0) { +// LogEntry *newerEntry = newBlock.at(i - 1); +// if (newerEntry->value() != entry->value()) { +// qDebug() << "Adding line series point:" << (offset + i) << newerEntry->timestamp().toMSecsSinceEpoch() - 1 << (entry->value().toReal()) << "(correction)"; +// m_graphSeries->append(QPointF(newerEntry->timestamp().toMSecsSinceEpoch() - 1, entry->value().toReal())); +// } +// } + + if (m_graphSeries->count() == 0) { +// qDebug() << "Adding 1st line series point:" << (offset + i) << QDateTime::currentDateTime().toMSecsSinceEpoch() << entry->value().toReal(); + m_graphSeries->append(QPointF(QDateTime::currentDateTime().toMSecsSinceEpoch(), entry->value().toReal())); + } +// qDebug() << "Adding line series point:" << (offset + i) << entry->timestamp().toMSecsSinceEpoch() << (entry->value().toReal()); + m_graphSeries->append(QPointF(entry->timestamp().toMSecsSinceEpoch(), entry->value().toReal())); + } + } + if (!newMin.isValid() || newMin > entry->value()) { + newMin = entry->value().toReal(); + } + if (!newMax.isValid() || newMax < entry->value()) { + newMax = entry->value().toReal(); + } + } + endInsertRows(); + emit countChanged(); +// qDebug() << "min" << m_minValue << "max" << m_maxValue << "newMin" << newMin << "newMax" << newMax; + if (m_minValue != newMin) { + m_minValue = newMin; + emit minValueChanged(); + } + if (m_maxValue != newMax) { + m_maxValue = newMax; + emit maxValueChanged(); + } + + m_busy = false; + emit busyChanged(); + + if (m_viewStartTime.isValid() && m_list.count() > 0 && m_list.last()->timestamp() > m_viewStartTime && canFetchMore()) { + fetchMore(); + } +} + +void LogsModelNg::fetchMore(const QModelIndex &parent) +{ + Q_UNUSED(parent) +// qDebug() << "fetchMore called"; + + if (!m_engine) { + qWarning() << "Cannot update. Engine not set"; return; } if (m_busy) { return; } - if (m_startTime.isNull() || m_endTime.isNull()) { - // Need both, startTime and endTime set + if ((!m_startTime.isNull() && m_endTime.isNull()) || (m_startTime.isNull() && !m_endTime.isNull())) { + // Need neither or both, startTime and endTime set return; } - m_currentFetchStartTime = QDateTime(); - m_currentFetchEndTime = QDateTime(); - bool haveData = false; - for(int i = 0; i < m_fetchedPeriods.length(); i++) { - if (m_fetchedPeriods.at(i).first < m_startTime) { - if (m_fetchedPeriods.at(i).second == true) { - haveData = true; - continue; - } - if (m_fetchedPeriods.at(i).second == false) { - haveData = false; - continue; - } - } - if (m_fetchedPeriods.at(i).first == m_startTime) { - if (m_fetchedPeriods.at(i).second == true) { - haveData = true; - continue; - } - if (m_fetchedPeriods.at(i).second == false) { - m_currentFetchStartTime = m_startTime; - continue; - } - } - if (m_fetchedPeriods.at(i).first > m_startTime) { - if (m_fetchedPeriods.at(i).second == true) { - if (m_currentFetchStartTime.isNull()) { - m_currentFetchStartTime = m_startTime; - } - m_currentFetchEndTime = m_fetchedPeriods.at(i).first; - break; - } - if (m_fetchedPeriods.at(i).second == false) { - if (m_currentFetchStartTime.isNull()) { - haveData = false; - m_currentFetchStartTime = m_fetchedPeriods.at(i).first; - } - continue; - } - } - } - if (haveData) { - qDebug() << "all the data is fetched"; - m_busy = false; - emit busyChanged(); - return; - } - if (m_currentFetchStartTime.isNull()) { - m_currentFetchStartTime = m_startTime; - } - if (m_currentFetchEndTime.isNull()) { - m_currentFetchEndTime = m_endTime; - } - qDebug() << "Fetching from" << m_currentFetchStartTime << "to" << m_currentFetchEndTime; - m_busy = true; emit busyChanged(); @@ -212,103 +311,77 @@ void LogsModelNg::update() deviceIds.append(m_deviceId); params.insert("deviceIds", deviceIds); } - if (!m_typeId.isEmpty()) { + if (!m_typeIds.isEmpty()) { QVariantList typeIds; - typeIds.append(m_typeId); + foreach (const QString &typeId, m_typeIds) { + typeIds.append(typeId); + } params.insert("typeIds", typeIds); } - QVariantList timeFilters; - QVariantMap timeFilter; - timeFilter.insert("startDate", m_currentFetchStartTime.toSecsSinceEpoch()); - timeFilter.insert("endDate", m_currentFetchEndTime.toSecsSinceEpoch()); - timeFilters.append(timeFilter); - params.insert("timeFilters", timeFilters); - m_jsonRpcClient->sendCommand("Logging.GetLogEntries", params, this, "logsReply"); + if (!m_startTime.isNull() && !m_endTime.isNull()) { + QVariantList timeFilters; + QVariantMap timeFilter; + timeFilter.insert("startDate", m_startTime.toSecsSinceEpoch()); + timeFilter.insert("endDate", m_endTime.toSecsSinceEpoch()); + timeFilters.append(timeFilter); + params.insert("timeFilters", timeFilters); + } + + params.insert("limit", m_blockSize); + params.insert("offset", m_list.count()); + + m_engine->jsonRpcClient()->sendCommand("Logging.GetLogEntries", params, this, "logsReply"); +// qDebug() << "GetLogEntries called"; } -void LogsModelNg::logsReply(const QVariantMap &data) +bool LogsModelNg::canFetchMore(const QModelIndex &parent) const { - qDebug() << "logs reply";// << data; - - // First update the fetched periods information - int insertIndex = -1; - bool noNeedToInsert = false; - for (int i = 0; i < m_fetchedPeriods.count(); i++) { - if (m_fetchedPeriods.at(i).first < m_currentFetchStartTime) { - // skip it - insertIndex = i+1; - continue; - } - if (m_fetchedPeriods.at(i).first == m_currentFetchStartTime) { - if (m_fetchedPeriods.at(i).second == false) { - // Have an end marker where we start inserting. We can drop the existing end marker and just update the end marker - if (m_fetchedPeriods.count() > i+1) { - if (m_fetchedPeriods.at(i+1).first < m_currentFetchEndTime) { - qWarning() << "Overlap detected!"; - } else if (m_fetchedPeriods.at(i+1).first == m_currentFetchEndTime) { - if (m_fetchedPeriods.at(i+1).second == true) { - m_fetchedPeriods.removeAt(i+1); - } - } - } - m_fetchedPeriods.removeAt(i); - noNeedToInsert = true; - break; - } - } - if (m_fetchedPeriods.at(i).first > m_currentFetchStartTime) { - break; - } - } - - if (!noNeedToInsert) { - if (insertIndex == -1) { - insertIndex = 0; - } - m_fetchedPeriods.insert(insertIndex, qMakePair(m_currentFetchStartTime, true)); - m_fetchedPeriods.insert(insertIndex+1, qMakePair(m_currentFetchEndTime, false)); - } - qDebug() << "new fetched periods:" << m_fetchedPeriods << "insertIndex:" << insertIndex; - m_busy = false; - emit busyChanged(); - - - QList newBlock; - QList logEntries = data.value("params").toMap().value("logEntries").toList(); - foreach (const QVariant &logEntryVariant, logEntries) { - QVariantMap entryMap = logEntryVariant.toMap(); - QDateTime timeStamp = QDateTime::fromMSecsSinceEpoch(entryMap.value("timestamp").toLongLong()); - QString deviceId = entryMap.value("deviceId").toString(); - QString typeId = entryMap.value("typeId").toString(); - QMetaEnum sourceEnum = QMetaEnum::fromType(); - LogEntry::LoggingSource loggingSource = (LogEntry::LoggingSource)sourceEnum.keyToValue(entryMap.value("source").toByteArray()); - QMetaEnum loggingEventTypeEnum = QMetaEnum::fromType(); - LogEntry::LoggingEventType loggingEventType = (LogEntry::LoggingEventType)loggingEventTypeEnum.keyToValue(entryMap.value("eventType").toByteArray()); - QVariant value = loggingEventType == LogEntry::LoggingEventTypeActiveChange ? entryMap.value("active").toBool() : entryMap.value("value"); - LogEntry *entry = new LogEntry(timeStamp, value, deviceId, typeId, loggingSource, loggingEventType, this); - newBlock.append(entry); - } - - // Now let's find where to insert stuff in the model - if (!newBlock.isEmpty()) { - int indexToInsert = 0; - for (int i = 0; i < m_list.count(); i++) { - LogEntry *entry = m_list.at(i); - if (entry->timestamp() < newBlock.first()->timestamp()) { - continue; - } - indexToInsert = i; - break; - } - - beginInsertRows(QModelIndex(), indexToInsert, indexToInsert + newBlock.count() - 1); - for (int i = 0; i < newBlock.count(); i++) { - m_list.insert(indexToInsert + i, newBlock.at(i)); - } - endInsertRows(); - emit countChanged(); - } - - update(); + Q_UNUSED(parent) +// qDebug() << "canFetchMore" << (m_engine && m_canFetchMore); + return m_engine && m_canFetchMore; } +void LogsModelNg::newLogEntryReceived(const QVariantMap &data) +{ + if (!m_live) { + return; + } + + QVariantMap entryMap = data; + QString deviceId = entryMap.value("deviceId").toString(); + if (!m_deviceId.isNull() && deviceId != m_deviceId) { + return; + } + + QString typeId = entryMap.value("typeId").toString(); + if (!m_typeIds.isEmpty() && !m_typeIds.contains(typeId)) { + return; + } + + beginInsertRows(QModelIndex(), 0, 0); + QDateTime timeStamp = QDateTime::fromMSecsSinceEpoch(entryMap.value("timestamp").toLongLong()); + QMetaEnum sourceEnum = QMetaEnum::fromType(); + LogEntry::LoggingSource loggingSource = static_cast(sourceEnum.keyToValue(entryMap.value("source").toByteArray())); + QMetaEnum loggingEventTypeEnum = QMetaEnum::fromType(); + LogEntry::LoggingEventType loggingEventType = static_cast(loggingEventTypeEnum.keyToValue(entryMap.value("eventType").toByteArray())); + QVariant value = loggingEventType == LogEntry::LoggingEventTypeActiveChange ? entryMap.value("active").toBool() : entryMap.value("value"); + LogEntry *entry = new LogEntry(timeStamp, value, deviceId, typeId, loggingSource, loggingEventType, this); + m_list.prepend(entry); + if (m_graphSeries) { + m_graphSeries->insert(0, QPointF(entry->timestamp().toMSecsSinceEpoch(), entry->value().toReal())); + if (m_minValue > entry->value().toReal()) { + m_minValue = entry->value().toReal(); + emit minValueChanged(); + } + if (m_maxValue < entry->value().toReal()) { + m_maxValue = entry->value().toReal(); + emit maxValueChanged(); + } + + } + endInsertRows(); + emit countChanged(); + +} + + diff --git a/libnymea-app-core/models/logsmodelng.h b/libnymea-app-core/models/logsmodelng.h index eb89632a..120ea6ce 100644 --- a/libnymea-app-core/models/logsmodelng.h +++ b/libnymea-app-core/models/logsmodelng.h @@ -4,20 +4,27 @@ #include #include #include +#include class LogEntry; -class JsonRpcClient; +class Engine; class LogsModelNg : public QAbstractListModel { Q_OBJECT - Q_PROPERTY(JsonRpcClient* jsonRpcClient READ jsonRpcClient WRITE setJsonRpcClient NOTIFY jsonRpcClientChanged) + Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged) Q_PROPERTY(bool busy READ busy NOTIFY busyChanged) + Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged) Q_PROPERTY(int count READ rowCount NOTIFY countChanged) Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged) - Q_PROPERTY(QString typeId READ typeId WRITE setTypeId NOTIFY typeIdChanged) + Q_PROPERTY(QStringList typeIds READ typeIds WRITE setTypeIds NOTIFY typeIdsChanged) Q_PROPERTY(QDateTime startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged) Q_PROPERTY(QDateTime endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged) + Q_PROPERTY(QVariant minValue READ minValue NOTIFY minValueChanged) + Q_PROPERTY(QVariant maxValue READ maxValue NOTIFY maxValueChanged) + + Q_PROPERTY(QtCharts::QXYSeries *graphSeries READ graphSeries WRITE setGraphSeries NOTIFY graphSeriesChanged) + Q_PROPERTY(QDateTime viewStartTime READ viewStartTime WRITE setViewStartTime NOTIFY viewStartTimeChanged) public: enum Roles { @@ -31,8 +38,8 @@ public: explicit LogsModelNg(QObject *parent = nullptr); - JsonRpcClient *jsonRpcClient() const; - void setJsonRpcClient(JsonRpcClient* jsonRpcClient); + Engine *engine() const; + void setEngine(Engine* jsonRpcClient); int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role) const override; @@ -46,8 +53,8 @@ public: QString deviceId() const; void setDeviceId(const QString &deviceId); - QString typeId() const; - void setTypeId(const QString &typeId); + QStringList typeIds() const; + void setTypeIds(const QStringList &typeId); QDateTime startTime() const; void setStartTime(const QDateTime &startTime); @@ -55,34 +62,56 @@ public: QDateTime endTime() const; void setEndTime(const QDateTime &endTime); + QtCharts::QXYSeries *graphSeries() const; + void setGraphSeries(QtCharts::QXYSeries *lineSeries); + + QDateTime viewStartTime() const; + void setViewStartTime(const QDateTime &viewStartTime); + + QVariant minValue() const; + QVariant maxValue() const; + +protected: + virtual void fetchMore(const QModelIndex &parent = QModelIndex()) override; + virtual bool canFetchMore(const QModelIndex &parent = QModelIndex()) const override; signals: void busyChanged(); void liveChanged(); void deviceIdChanged(); - void typeIdChanged(); + void typeIdsChanged(); void countChanged(); void startTimeChanged(); void endTimeChanged(); - void jsonRpcClientChanged(); + void engineChanged(); + void graphSeriesChanged(); + void viewStartTimeChanged(); + void minValueChanged(); + void maxValueChanged(); + +private slots: + void newLogEntryReceived(const QVariantMap &data); + void logsReply(const QVariantMap &data); private: QList m_list; - JsonRpcClient *m_jsonRpcClient = nullptr; + Engine *m_engine = nullptr; bool m_busy = false; bool m_live = false; QString m_deviceId; - QString m_typeId; + QStringList m_typeIds; QDateTime m_startTime; QDateTime m_endTime; - QDateTime m_currentFetchStartTime; - QDateTime m_currentFetchEndTime; + int m_blockSize = 100; + bool m_canFetchMore = true; + QDateTime m_viewStartTime; + QVariant m_minValue; + QVariant m_maxValue; + + QtCharts::QXYSeries *m_graphSeries = nullptr; QList > m_fetchedPeriods; - - void update(); - Q_INVOKABLE void logsReply(const QVariantMap &data); }; diff --git a/nymea-app/images.qrc b/nymea-app/images.qrc index 0c1fbb22..eac9c6ad 100644 --- a/nymea-app/images.qrc +++ b/nymea-app/images.qrc @@ -148,5 +148,10 @@ ui/images/view-collapse.svg ui/images/view-expand.svg ui/images/weather-app-symbolic.svg + ui/images/zoom-out.svg + ui/images/zoom-in.svg + ui/images/smartmeter.svg + ui/images/radiator.svg + ui/images/ev-charger.svg diff --git a/nymea-app/main.cpp b/nymea-app/main.cpp index b317e307..b6561961 100644 --- a/nymea-app/main.cpp +++ b/nymea-app/main.cpp @@ -18,7 +18,7 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include +#include #include #include #include @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QGuiApplication application(argc, argv); + QApplication application(argc, argv); application.setApplicationName("nymea-app"); application.setOrganizationName("nymea"); @@ -71,7 +71,7 @@ int main(int argc, char *argv[]) applicationFont.setCapitalization(QFont::MixedCase); applicationFont.setPixelSize(16); applicationFont.setWeight(QFont::Normal); - QGuiApplication::setFont(applicationFont); + QApplication::setFont(applicationFont); QTranslator qtTranslator; qtTranslator.load("qt_" + QLocale::system().name(), diff --git a/nymea-app/nymea-app.pro b/nymea-app/nymea-app.pro index 5f2313bc..241270c3 100644 --- a/nymea-app/nymea-app.pro +++ b/nymea-app/nymea-app.pro @@ -2,7 +2,7 @@ TEMPLATE=app TARGET=nymea-app include(../config.pri) -QT += network qml quick quickcontrols2 svg websockets bluetooth +QT += network qml quick quickcontrols2 svg websockets bluetooth charts INCLUDEPATH += $$top_srcdir/libnymea-common \ $$top_srcdir/libnymea-app-core @@ -124,3 +124,6 @@ BR=$$BRANDING target.path = /usr/bin INSTALLS += target +DISTFILES += \ + ruletemplates/smartmetertemplates.json + diff --git a/nymea-app/resources.qrc b/nymea-app/resources.qrc index 0489361d..e3ef4ff8 100644 --- a/nymea-app/resources.qrc +++ b/nymea-app/resources.qrc @@ -57,12 +57,17 @@ ui/customviews/MediaControllerView.qml ui/customviews/SensorView.qml ui/customviews/NotificationsView.qml + ui/customviews/ExtendedVolumeController.qml ui/devicepages/MediaDevicePage.qml ui/devicepages/ButtonDevicePage.qml ui/devicepages/GenericDeviceStateDetailsPage.qml ui/devicepages/GenericDevicePage.qml + ui/devicepages/WeatherDevicePagePre110.qml + ui/devicepages/WeatherDevicePagePost110.qml ui/devicepages/WeatherDevicePage.qml ui/devicepages/SensorDevicePage.qml + ui/devicepages/SensorDevicePagePre110.qml + ui/devicepages/SensorDevicePagePost110.qml ui/devicepages/DevicePageBase.qml ui/devicepages/ConfigureThingPage.qml ui/devicepages/InputTriggerDevicePage.qml @@ -127,5 +132,9 @@ translations/nymea-app-de_DE.qm translations/nymea-app-en_US.qm ../LICENSE + ui/customviews/GenericTypeGraphPre110.qml + ui/customviews/GenericTypeGraph.qml + ui/devicepages/SmartMeterDevicePage.qml + ui/devicelistpages/SmartMeterDeviceListPage.qml diff --git a/nymea-app/ruletemplates.qrc b/nymea-app/ruletemplates.qrc index ee47f538..24df3a96 100644 --- a/nymea-app/ruletemplates.qrc +++ b/nymea-app/ruletemplates.qrc @@ -3,5 +3,6 @@ ruletemplates/buttontemplates.json ruletemplates/notificationtemplates.json ruletemplates/accesscontroltemplates.json + ruletemplates/smartmetertemplates.json diff --git a/nymea-app/ruletemplates/smartmetertemplates.json b/nymea-app/ruletemplates/smartmetertemplates.json new file mode 100644 index 00000000..99485521 --- /dev/null +++ b/nymea-app/ruletemplates/smartmetertemplates.json @@ -0,0 +1,84 @@ +{ + "templates": [ + { + "interfaceName": "extendedsmartmeterproducer", + "description": "Charge my car while producing energy.", + "ruleNameTemplate": "Smart car charging", + "stateEvaluatorTemplate": { + "stateDescriptorTemplate": { + "interfaceName": "extendedsmartmeterproducer", + "interfaceState": "currentPower", + "operator": "ValueOperatorGreater", + "value": 0, + "selectionId": 0 + } + }, + "ruleActionTemplates": [ + { + "interfaceName": "evcharger", + "interfaceAction": "power", + "selectionId": 1, + "params": [ + { + "name": "power", + "value": true + } + ] + } + ], + "ruleExitActionTemplates": [ + { + "interfaceName": "evcharger", + "interfaceAction": "power", + "selectionId": 1, + "params": [ + { + "name": "power", + "value": false + } + ] + } + ] + }, + { + "interfaceName": "extendedsmartmeterproducer", + "description": "Turn on heating while producing energy.", + "ruleNameTemplate": "Smart heating", + "stateEvaluatorTemplate": { + "stateDescriptorTemplate": { + "interfaceName": "extendedsmartmeterproducer", + "interfaceState": "currentPower", + "operator": "ValueOperatorGreater", + "value": 0, + "selectionId": 0 + } + }, + "ruleActionTemplates": [ + { + "interfaceName": "heating", + "interfaceAction": "power", + "selectionId": 1, + "params": [ + { + "name": "power", + "value": true + } + ] + } + ], + "ruleExitActionTemplates": [ + { + "interfaceName": "heating", + "interfaceAction": "power", + "selectionId": 1, + "params": [ + { + "name": "power", + "value": false + } + ] + } + ] + } + ] +} diff --git a/nymea-app/ruletemplates/template.json b/nymea-app/ruletemplates/template.json new file mode 100644 index 00000000..b3079327 --- /dev/null +++ b/nymea-app/ruletemplates/template.json @@ -0,0 +1,58 @@ +{ + "templates": [ + { + "interfaceName": "", + "description": "", + "ruleNameTemplate": "%0 ...", + "eventDescriptorTemplates": [ // optional + { + "interfaceName": "", + "interfaceEvent": "", + "selectionId": 0, + "params": [ // optional + { + "name": "", + "value": "", //optional + } + ] + } + ], + "stateEvaluatorTemplate": { + "stateDescriptorTemplate": { + "interfaceName": "", + "interfaceState": "", + "selectionId": 1, + "operator": "ValueOperatorEquals", + "value": true + } + }, + "ruleActionTemplates": [ + { + "interfaceName": "", + "interfaceAction": "", + "selectionId": 2, + "params": [ + { + "name": "", + "value": "" + } + ] + } + ], + "ruleExitActionTemplates": [ + { + "interfaceName": "", + "interfaceAction": "", + "selectionId": 2, + "params": [ + { + "name": "", + "value": "" + } + ] + } + ] + } + ] +} + diff --git a/nymea-app/ui/NewDeviceWizard.qml b/nymea-app/ui/NewDeviceWizard.qml index c4e90538..121683c7 100644 --- a/nymea-app/ui/NewDeviceWizard.qml +++ b/nymea-app/ui/NewDeviceWizard.qml @@ -36,6 +36,7 @@ Page { Connections { target: engine.deviceManager onPairDeviceReply: { + busyOverlay.shown = false switch (params["setupMethod"]) { case "SetupMethodPushButton": d.pairingTransactionId = params["pairingTransactionId"]; @@ -52,9 +53,11 @@ Page { } } onConfirmPairingReply: { + busyOverlay.shown = false internalPageStack.push(resultsPage, {success: params["deviceError"] === "DeviceErrorNoError", deviceId: params["deviceId"]}) } onAddDeviceReply: { + busyOverlay.shown = false; internalPageStack.push(resultsPage, {success: params["deviceError"] === "DeviceErrorNoError", deviceId: params["deviceId"]}) } } @@ -358,6 +361,8 @@ Page { break; } + busyOverlay.shown = true; + } } } @@ -448,4 +453,8 @@ Page { } } } + + BusyOverlay { + id: busyOverlay + } } diff --git a/nymea-app/ui/Nymea.qml b/nymea-app/ui/Nymea.qml index dd88c856..2ef02af4 100644 --- a/nymea-app/ui/Nymea.qml +++ b/nymea-app/ui/Nymea.qml @@ -53,7 +53,7 @@ ApplicationWindow { rootItem.handleCloseEvent(close) } - property var supportedInterfaces: ["light", "weather", "sensor", "media", "garagegate", "awning", "shutter", "blind", "accesscontrol", "button", "notifications", "inputtrigger", "outputtrigger", "gateway"] + property var supportedInterfaces: ["light", "weather", "sensor", "media", "garagegate", "awning", "shutter", "blind", "heating", "smartmeter", "evcharger", "accesscontrol", "button", "notifications", "inputtrigger", "outputtrigger", "gateway"] function interfaceToString(name) { switch(name) { case "light": @@ -93,6 +93,16 @@ ApplicationWindow { return qsTr("Garage gates"); case "accesscontrol": return qsTr("Access control"); + case "smartmeter": + case "smartmeterproducer": + case "smartmeterconsumer": + case "extendedsmartmeterproducer": + case "extendedsmartmeterconsumer": + return qsTr("Smart meters"); + case "heating": + return qsTr("Heatings"); + case "evcharger": + return qsTr("EV-chargers"); case "uncategorized": return qsTr("Uncategorized") default: @@ -149,8 +159,6 @@ ApplicationWindow { return Qt.resolvedUrl("images/network-wired-symbolic.svg") case "notifications": return Qt.resolvedUrl("images/notification.svg") - case "connectable": - return Qt.resolvedUrl("images/stock_link.svg") case "inputtrigger": return Qt.resolvedUrl("images/attention.svg") case "outputtrigger": @@ -175,6 +183,20 @@ ApplicationWindow { return Qt.resolvedUrl("images/fingerprint.svg") case "accesscontrol": return Qt.resolvedUrl("images/network-secure.svg"); + case "smartmeter": + case "smartmeterconsumer": + case "smartmeterproducer": + case "extendedsmartmeterconsumer": + case "extendedsmartmeterproducer": + return Qt.resolvedUrl("images/smartmeter.svg") + case "heating": + case "extendedheating": + return Qt.resolvedUrl("images/radiator.svg") + case "evcharger": + case "extendedevcharger": + return Qt.resolvedUrl("images/ev-charger.svg") + case "connectable": + return Qt.resolvedUrl("images/stock_link.svg") default: console.warn("InterfaceToIcon: Unhandled interface", name) } @@ -187,7 +209,11 @@ ApplicationWindow { "moisturesensor":"blue", "lightsensor": "orange", "conductivitysensor": "green", - "pressuresensor": "grey" + "pressuresensor": "grey", + "smartmeterproducer": "lightgreen", + "smartmeterconsumer": "orange", + "extendedsmartmeterproducer": "blue", + "extendedsmartmeterconsumer": "blue" } function interfaceToColor(name) { @@ -244,6 +270,8 @@ ApplicationWindow { page = "NotificationsDevicePage.qml"; } else if (interfaceList.indexOf("fingerprintreader") >= 0) { page = "FingerprintReaderDevicePage.qml"; + } else if (interfaceList.indexOf("smartmeter") >= 0) { + page = "SmartMeterDevicePage.qml" } else { page = "GenericDevicePage.qml"; } diff --git a/nymea-app/ui/appsettings/AppSettingsPage.qml b/nymea-app/ui/appsettings/AppSettingsPage.qml index b2389bc8..9d26fb33 100644 --- a/nymea-app/ui/appsettings/AppSettingsPage.qml +++ b/nymea-app/ui/appsettings/AppSettingsPage.qml @@ -81,23 +81,6 @@ Page { } } - RowLayout { - Layout.fillWidth: true; Layout.leftMargin: app.margins; Layout.rightMargin: app.margins - Label { - Layout.fillWidth: true - text: qsTr("Graph style") - } - RadioButton { - checked: settings.graphStyle === "bars" - text: qsTr("Bars") - onClicked: settings.graphStyle = "bars" - } - RadioButton { - checked: settings.graphStyle === "bezier" - text: qsTr("Lines") - onClicked: settings.graphStyle = "bezier" - } - } CheckDelegate { Layout.fillWidth: true text: qsTr("Return to home on idle") diff --git a/nymea-app/ui/components/HeaderButton.qml b/nymea-app/ui/components/HeaderButton.qml index 74d46cdf..d38d58d3 100644 --- a/nymea-app/ui/components/HeaderButton.qml +++ b/nymea-app/ui/components/HeaderButton.qml @@ -13,6 +13,7 @@ ToolButton { id: image anchors.fill: parent anchors.margins: app.margins / 2 + opacity: enabled ? 1 : .5 } } } diff --git a/nymea-app/ui/customviews/GenericTypeGraph.qml b/nymea-app/ui/customviews/GenericTypeGraph.qml new file mode 100644 index 00000000..cca5f4bc --- /dev/null +++ b/nymea-app/ui/customviews/GenericTypeGraph.qml @@ -0,0 +1,364 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.Material 2.2 +import QtQuick.Layouts 1.1 +import Nymea 1.0 +import "../components" +import "../customviews" +import QtCharts 2.2 + +Item { + id: root + implicitHeight: width * .6 + + property var device: null + property var stateType: null + property int roundTo: 2 + readonly property var valueState: device.states.getState(stateType.id) + readonly property var deviceClass: engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); + readonly property bool hasConnectable: deviceClass.interfaces.indexOf("connectable") >= 0 + readonly property var connectedStateType: hasConnectable ? deviceClass.stateTypes.findByName("connected") : null + + property color color: app.accentColor + property string iconSource: "" + + LogsModelNg { + id: logsModelNg + engine: _engine + deviceId: root.device.id + typeIds: [root.stateType.id] + live: true + graphSeries: lineSeries1 + viewStartTime: xAxis.min + } + + LogsModelNg { + id: connectedLogsModel + engine: root.hasConnectable ? _engine : null // don't even try to poll if we don't have a connectable interface + deviceId: root.device.id + typeIds: [root.connectedStateType.id] + live: true + graphSeries: connectedLineSeries + viewStartTime: xAxis.min + } + + ColumnLayout { + anchors.fill: parent + spacing: 0 + RowLayout { + Layout.leftMargin: app.margins; Layout.rightMargin: app.margins + ColorIcon { + Layout.preferredHeight: app.iconSize + Layout.preferredWidth: app.iconSize + name: root.iconSource + visible: root.iconSource.length > 0 + color: root.color + } + + Label { + Layout.fillWidth: true + text: 1.0 * Math.round(root.valueState.value * Math.pow(10, root.roundTo)) / Math.pow(10, root.roundTo) + " " + root.stateType.unitString + font.pixelSize: app.largeFont + } + + HeaderButton { + imageSource: "../images/zoom-out.svg" + onClicked: { + var newTime = new Date(xAxis.min.getTime() - (xAxis.timeDiff * 1000 / 4)) + xAxis.min = newTime; + } + } + + HeaderButton { + imageSource: "../images/zoom-in.svg" + enabled: xAxis.timeDiff > (60 * 30) + onClicked: { + var newTime = new Date(Math.min(xAxis.min.getTime() + (xAxis.timeDiff * 1000 / 4), xAxis.max.getTime() - (1000 * 60 * 30))) + xAxis.min = newTime; + } + } + } + + ChartView { + id: chartView + Layout.fillWidth: true + Layout.fillHeight: true + margins.top: 0 + margins.bottom: 0 + margins.left: 0 + margins.right: 0 + backgroundColor: Material.background + legend.visible: false + legend.labelColor: app.foregroundColor + + animationDuration: 300 + animationOptions: ChartView.SeriesAnimations + + ValueAxis { + id: yAxis + max: logsModelNg.maxValue + Math.abs(logsModelNg.maxValue * .05) + min: logsModelNg.minValue - Math.abs(logsModelNg.minValue * .05) + labelsFont.pixelSize: app.smallFont + labelsColor: app.foregroundColor + tickCount: chartView.height / 40 + color: Qt.rgba(app.foregroundColor.r, app.foregroundColor.g, app.foregroundColor.b, .2) + gridLineColor: color + } + + ValueAxis { + id: connectedAxis + min: 0 + max: 1 + visible: false + } + + DateTimeAxis { + id: xAxis + gridVisible: false + color: Qt.rgba(app.foregroundColor.r, app.foregroundColor.g, app.foregroundColor.b, .2) + tickCount: chartView.width / 70 + labelsFont.pixelSize: app.smallFont + labelsColor: app.foregroundColor + property int timeDiff: (xAxis.max.getTime() - xAxis.min.getTime()) / 1000 + onTimeDiffChanged: print("timeDiff is:", timeDiff) + + function getTimeSpanString() { + var td = timeDiff + if (td < 60) { + return qsTr("%1 seconds").arg(Math.round(td)); + } + td = td / 60 + if (td < 60) { + return qsTr("%1 minutes").arg(Math.round(td)); + } + td = td / 60 + if (td < 48) { + return qsTr("%1 hours").arg(Math.round(td)); + } + td = td / 24; + if (td < 14) { + return qsTr("%1 days").arg(Math.round(td)); + } + td = td / 7 + if (td < 9) { + return qsTr("%1 weeks").arg(Math.round(td)); + } + td = td * 7 / 30 + if (td < 24) { + return qsTr("%1 months").arg(Math.round(td)); + } + td = td * 30 / 356 + return qsTr("%1 years").arg(Math.round(td)) + } + + titleText: { + if (xAxis.min.getYear() === xAxis.max.getYear() + && xAxis.min.getMonth() === xAxis.max.getMonth() + && xAxis.min.getDate() === xAxis.max.getDate()) { + return Qt.formatDate(xAxis.min) + " (" + getTimeSpanString() + ")" + } + return Qt.formatDate(xAxis.min) + " - " + Qt.formatDate(xAxis.max) + " (" + getTimeSpanString() + ")" + } + titleBrush: app.foregroundColor + format: { + if (timeDiff < 60) { // one minute + return "mm:ss" + } + if (timeDiff < 60 * 60) { // one hour + return "hh:mm" + } + if (timeDiff < 60 * 60 * 24 * 2) { // two day + return "hh:mm" + } + if (timeDiff < 60 * 60 * 24 * 7) { // one week + return "ddd hh:mm" + } + if (timeDiff < 60 * 60 * 24 * 7 * 30) { // one month + return "dd.MM." + } + return "MMM yy" + } + + min: { + var date = new Date(); + date.setTime(date.getTime() - (1000 * 60 * 60 * 6) + 2000); + return date; + } + max: { + var date = new Date(); + date.setTime(date.getTime() + 2000) + return date; + } + } + + AreaSeries { + axisX: xAxis + axisY: connectedAxis + name: qsTr("Not connected") + visible: root.hasConnectable + upperSeries: LineSeries { + XYPoint {x: xAxis.min.getTime(); y: 1} + XYPoint {x: xAxis.max.getTime(); y: 1} + } + + lowerSeries: LineSeries { + id: connectedLineSeries + } + color: "#55ff0000" + borderWidth: 0 + } + + AreaSeries { + id: mainSeries + axisX: xAxis + axisY: yAxis + name: root.stateType.displayName + borderColor: root.color + borderWidth: 4 + lowerSeries: LineSeries { + id: lineSeries0 + XYPoint { x: xAxis.max.getTime(); y: 0 } + XYPoint { x: xAxis.min.getTime(); y: 0 } + } + + upperSeries: LineSeries { + id: lineSeries1 + onPointAdded: { + var newPoint = lineSeries1.at(index) + + if (newPoint.x > lineSeries0.at(0).x) { + lineSeries0.replace(0, newPoint.x, 0) + } + if (newPoint.x < lineSeries0.at(1).x) { + lineSeries0.replace(1, newPoint.x, 0) + } + + if (newPoint.x <= xAxis.max.getTime() || logsModelNg.busy) { + return; + } + + var diffMaxToNew = newPoint.x - xAxis.max.getTime(); + print("diffToNew is", diffMaxToNew) + if (diffMaxToNew < 1000 * 60 * 5) { + chartView.animationOptions = ChartView.NoAnimation + var newMin = xAxis.min.getTime() + diffMaxToNew; + xAxis.max = new Date(newPoint.x); + xAxis.min = new Date(newMin) + chartView.animationOptions = ChartView.SeriesAnimations + } + } + } + color: Qt.rgba(root.color.r, root.color.g, root.color.b, .3) + onHovered: { + markClosestPoint(point) + } + + function markClosestPoint(point) { + var found = false; + if (lineSeries1.count == 1) { + selectedHighlights.removePoints(0, selectedHighlights.count) + selectedHighlights.append(lineSeries1.at(0).x, lineSeries1.at(1).y) + return; + } + + var searchIndex = Math.floor(lineSeries1.count / 2) + var previousIndex = 0; + var nextIndex = lineSeries1.count - 1; + + while (previousIndex + 1 != nextIndex) { + if (point.x < lineSeries1.at(searchIndex).x) { + previousIndex = searchIndex; + } else if (point.x > lineSeries1.at(searchIndex).x) { + nextIndex = searchIndex; + } + searchIndex = previousIndex + Math.floor((nextIndex - previousIndex) / 2); + } + var diffToPrevious = Math.abs(point.x - lineSeries1.at(previousIndex).x) + var diffToNext = Math.abs(point.x - lineSeries1.at(nextIndex).x) + var closestPoint = diffToPrevious < diffToNext ? lineSeries1.at(previousIndex) : lineSeries1.at(nextIndex); + + selectedHighlights.removePoints(0, selectedHighlights.count) + selectedHighlights.append(closestPoint.x, closestPoint.y) + } + } + + ScatterSeries { + id: selectedHighlights + color: root.color + markerSize: 10 + borderWidth: 2 + borderColor: root.color + axisX: xAxis + axisY: yAxis + pointLabelsVisible: true + pointLabelsColor: app.foregroundColor + pointLabelsFont.pixelSize: app.smallFont + pointLabelsFormat: "@yPoint" + pointLabelsClipping: false + } + + BusyIndicator { + anchors.centerIn: parent + visible: logsModelNg.busy + } + + + MouseArea { + x: chartView.plotArea.x + y: chartView.plotArea.y + width: chartView.plotArea.width + height: chartView.plotArea.height + property int lastX: 0 + property int lastY: 0 + preventStealing: false + + function scrollRightLimited(dx) { + chartView.animationOptions = ChartView.NoAnimation + var now = new Date() + // if we're already at the limit, don't even start scrolling + if (dx < 0 || xAxis.max < now) { + chartView.scrollRight(dx) + } + // figure out if we scrolled too far + var overshoot = xAxis.max.getTime() - now.getTime() +// print("overshoot is:", overshoot, "oldMax", xAxis.max, "newMax", now, "oldMin", xAxis.min, "newMin", new Date(xAxis.min.getTime() - overshoot)) + if (overshoot > 0) { + var range = xAxis.max - xAxis.min + xAxis.max = now + xAxis.min = new Date(xAxis.max.getTime() - range) + } + chartView.animationOptions = ChartView.SeriesAnimations + } + + function zoomInLimited(dy) { + chartView.animationOptions = ChartView.NoAnimation + var oldMax = xAxis.max; + chartView.scrollRight(dy); + xAxis.min = new Date(xAxis.min.getTime() - xAxis.timeDiff * 1000 * 2) + chartView.animationOptions = ChartView.SeriesAnimations + } + + onPressed: { + lastX = mouse.x + lastY = mouse.y + } + onClicked: { + var pt = chartView.mapToValue(Qt.point(mouse.x + chartView.plotArea.x, mouse.y + chartView.plotArea.y), mainSeries) + mainSeries.markClosestPoint(pt) + } + + onWheel: { + scrollRightLimited(-wheel.pixelDelta.x) +// zoomInLimited(wheel.pixelDelta.y) + } + + onPositionChanged: { + if (lastX !== mouse.x) { + scrollRightLimited(lastX - mouseX) + lastX = mouse.x + } + } + } + } + } +} diff --git a/nymea-app/ui/customviews/GenericTypeGraphPre110.qml b/nymea-app/ui/customviews/GenericTypeGraphPre110.qml new file mode 100644 index 00000000..1a66b780 --- /dev/null +++ b/nymea-app/ui/customviews/GenericTypeGraphPre110.qml @@ -0,0 +1,84 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.Material 2.2 +import QtQuick.Layouts 1.1 +import Nymea 1.0 +import "../components" +import "../customviews" + +ColumnLayout { + id: root + + property var device: null + property var stateType: null + + TabBar { + id: zoomTabBar + Layout.fillWidth: true + TabButton { + text: qsTr("6 h") + property int avg: ValueLogsProxyModel.AverageQuarterHour + property date startTime: { + var date = new Date(); + date.setHours(new Date().getHours() - 6) + date.setMinutes(0) + date.setSeconds(0) + return date; + } + } + TabButton { + text: qsTr("24 h") + property int avg: ValueLogsProxyModel.AverageHourly + property date startTime: { + var date = new Date(); + date.setHours(new Date().getHours() - 24); + date.setMinutes(0) + date.setSeconds(0) + return date; + } + } + TabButton { + text: qsTr("7 d") + property int avg: ValueLogsProxyModel.AverageDayTime + property date startTime: { + var date = new Date(); + date.setDate(new Date().getDate() - 7); + date.setHours(0) + date.setMinutes(0) + date.setSeconds(0) + return date; + } + } + } + + Graph { + Layout.fillWidth: true + Layout.fillHeight: true + mode: settings.graphStyle + color: app.accentColor + + Timer { + id: updateTimer + interval: 10 + repeat: false + onTriggered: { + graphModel.update() + } + } + + model: ValueLogsProxyModel { + id: graphModel + deviceId: root.device.id + typeIds: [stateType.id] + average: zoomTabBar.currentItem.avg + startTime: zoomTabBar.currentItem.startTime + Component.onCompleted: updateTimer.start(); + onAverageChanged: updateTimer.start() + onStartTimeChanged: updateTimer.start(); + engine: _engine + + // Live doesn't work yet with ValueLogsProxyModel + // live: true + } + } +} diff --git a/nymea-app/ui/customviews/GenericTypeLogView.qml b/nymea-app/ui/customviews/GenericTypeLogView.qml index dc136765..954ecc0a 100644 --- a/nymea-app/ui/customviews/GenericTypeLogView.qml +++ b/nymea-app/ui/customviews/GenericTypeLogView.qml @@ -6,8 +6,6 @@ import "../components" Item { id: root - // %1 will be replaced with count - property string text signal addRuleClicked(var value) @@ -15,122 +13,74 @@ Item { property alias delegate: listView.delegate - property bool autoscroll: true - - ColumnLayout { + ListView { + id: listView anchors.fill: parent + model: logsModel + clip: true - Label { - id: titleLabel - Layout.fillWidth: true - Layout.margins: app.margins - wrapMode: Text.WordWrap - text: root.text.arg(logsModel.count).arg((logsModel.endTime.getTime() - logsModel.startTime.getTime())/ 1000 / 60 / 60 /24) - } + ScrollBar.vertical: ScrollBar {} - ThinDivider {} - - RulesFilterModel { - id: rulesFilterModel - rules: engine.ruleManager.rules - filterDeviceId: root.logsModel.deviceId - } - - ListView { - id: listView - Layout.fillWidth: true - Layout.fillHeight: true - model: logsModel - clip: true - onCountChanged: { - if (root.autoscroll) { - positionViewAtEnd() - } - } - - onContentYChanged: { + onContentYChanged: { + if (!engine.jsonRpcClient.ensureServerVersion("1.10")) { if (!logsModel.busy && contentY - originY < 5 * height) { logsModel.fetchEarlier(24) } } + } - delegate: SwipeDelegate { - id: logEntryDelegate - width: parent.width - implicitHeight: app.delegateHeight - property var device: engine.deviceManager.devices.getDevice(model.deviceId) - property var deviceClass: engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) - contentItem: RowLayout { - ColorIcon { - Layout.preferredHeight: app.iconSize - Layout.preferredWidth: height - name: "../images/event.svg" - color: app.accentColor - } - - ColumnLayout { - Label { - id: timeStampLabel - Layout.fillWidth: true - text: Qt.formatDateTime(model.timestamp,"dd.MM.yy - hh:mm:ss") - } - Label { - Layout.fillWidth: true - text: "%1: %2".arg(deviceClass.eventTypes.getEventType(model.typeId).displayName).arg(model.value.trim()) - elide: Text.ElideRight - font.pixelSize: app.smallFont - } - } -// ColorIcon { -// Layout.preferredWidth: app.iconSize -// Layout.preferredHeight: width -// name: "../images/magic.svg" -// color: { -// for (var i = 0; i < rulesFilterModel.count; i++) { -// var rule = rulesFilterModel.get(i); -// for (var j = 0; j < rule.eventDescriptors.count; j++) { -// var eventDescriptor = rule.eventDescriptors.get(j); -// if (eventDescriptor.eventTypeId === root.logsModel.typeId) { -// var matching = true; -// for (var k = 0; k < eventDescriptor.paramDescriptors.count; k++) { -// var paramDescriptor = eventDescriptor.paramDescriptors.get(k); -// if (paramDescriptor.value === model.value) { -// return app.accentColor; -// } -// } -// } -// } -// } -// return keyColor; -// } - -// } + delegate: SwipeDelegate { + id: logEntryDelegate + width: parent.width + implicitHeight: app.delegateHeight + property var device: engine.deviceManager.devices.getDevice(model.deviceId) + property var deviceClass: engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) + contentItem: RowLayout { + ColorIcon { + Layout.preferredHeight: app.iconSize + Layout.preferredWidth: height + name: "../images/event.svg" + color: app.accentColor } - swipe.right: MouseArea { - height: logEntryDelegate.height - width: height - anchors.right: parent.right - ColorIcon { - anchors.fill: parent - anchors.margins: app.margins - name: "../images/magic.svg" + + ColumnLayout { + Label { + id: timeStampLabel + Layout.fillWidth: true + text: Qt.formatDateTime(model.timestamp,"dd.MM.yy - hh:mm:ss") } - onClicked: root.addRuleClicked(model.value) - } - onClicked: { - if (swipe.complete) { - swipe.close() - } else { - swipe.open(SwipeDelegate.Right) + Label { + Layout.fillWidth: true + text: "%1: %2".arg(deviceClass.eventTypes.getEventType(model.typeId).displayName).arg(model.value.trim()) + elide: Text.ElideRight + font.pixelSize: app.smallFont } } } - - BusyIndicator { - anchors.centerIn: parent - visible: root.logsModel.busy - running: visible + swipe.right: MouseArea { + height: logEntryDelegate.height + width: height + anchors.right: parent.right + ColorIcon { + anchors.fill: parent + anchors.margins: app.margins + name: "../images/magic.svg" + } + onClicked: root.addRuleClicked(model.value) } + onClicked: { + if (swipe.complete) { + swipe.close() + } else { + swipe.open(SwipeDelegate.Right) + } + } + } + + BusyIndicator { + anchors.centerIn: parent + visible: root.logsModel.busy + running: visible } } } diff --git a/nymea-app/ui/delegates/ActionDelegate.qml b/nymea-app/ui/delegates/ActionDelegate.qml index de099023..7da1f75f 100644 --- a/nymea-app/ui/delegates/ActionDelegate.qml +++ b/nymea-app/ui/delegates/ActionDelegate.qml @@ -304,6 +304,7 @@ ItemDelegate { property var value: null text: root.actionType.displayName onClicked: { + print("ActionDelegate: Button clicked") var params = []; print("fooo", root.actionType.paramTypes.count) for (var i = 0; i < root.actionType.paramTypes.count; i++) { diff --git a/nymea-app/ui/devicelistpages/SmartMeterDeviceListPage.qml b/nymea-app/ui/devicelistpages/SmartMeterDeviceListPage.qml new file mode 100644 index 00000000..69aca325 --- /dev/null +++ b/nymea-app/ui/devicelistpages/SmartMeterDeviceListPage.qml @@ -0,0 +1,130 @@ +import QtQuick 2.5 +import QtQuick.Controls 2.1 +import QtQuick.Controls.Material 2.1 +import QtQuick.Layouts 1.1 +import Nymea 1.0 +import "../components" + +DeviceListPageBase { + id: root + + header: GuhHeader { + text: qsTr("Smart meters") + onBackPressed: pageStack.pop() + } + + ListView { + anchors.fill: parent + model: root.devicesProxy + + delegate: ItemDelegate { + id: itemDelegate + width: parent.width + + property bool inline: width > 500 + + property var device: devicesProxy.get(index); + property var deviceClass: engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); + + bottomPadding: index === ListView.view.count - 1 ? topPadding : 0 + contentItem: Pane { + id: contentItem + Material.elevation: 2 + leftPadding: 0 + rightPadding: 0 + topPadding: 0 + bottomPadding: 0 + + contentItem: ItemDelegate { + leftPadding: 0 + rightPadding: 0 + topPadding: 0 + bottomPadding: 0 + contentItem: ColumnLayout { + Rectangle { + Layout.fillWidth: true + Layout.preferredHeight: app.mediumFont + app.margins + color: Qt.rgba(app.foregroundColor.r, app.foregroundColor.g, app.foregroundColor.b, .05) + RowLayout { + anchors { verticalCenter: parent.verticalCenter; left: parent.left; right: parent.right; margins: app.margins } + Label { + Layout.fillWidth: true + text: model.name + elide: Text.ElideRight + } + ColorIcon { + Layout.preferredHeight: app.iconSize * .5 + Layout.preferredWidth: height + name: "../images/battery/battery-020.svg" + visible: itemDelegate.deviceClass.interfaces.indexOf("battery") >= 0 && itemDelegate.device.states.getState(itemDelegate.deviceClass.stateTypes.findByName("batteryCritical").id).value === true + } + ColorIcon { + Layout.preferredHeight: app.iconSize * .5 + Layout.preferredWidth: height + name: "../images/dialog-warning-symbolic.svg" + visible: itemDelegate.deviceClass.interfaces.indexOf("connectable") >= 0 && itemDelegate.device.states.getState(itemDelegate.deviceClass.stateTypes.findByName("connected").id).value === false + color: "red" + } + } + + } + GridLayout { + id: dataGrid + columns: Math.floor(contentItem.width / 120) + Layout.margins: app.margins + Repeater { + model: ListModel { + Component.onCompleted: { + if (itemDelegate.deviceClass.interfaces.indexOf("smartmeterproducer") >= 0) { + append( {interfaceName: "smartmeterproducer", stateName: "totalEnergyProduced" }) + } + if (itemDelegate.deviceClass.interfaces.indexOf("smartmeterconsumer") >= 0) { + append( {interfaceName: "smartmeterconsumer", stateName: "totalEnergyConsumed" }) + } + var added = false; + if (itemDelegate.deviceClass.interfaces.indexOf("extendedsmartmeterproducer") >= 0) { + append({interfaceName: "extendedsmartmeterconsumer", stateName: "currentPower"}); + added = true; + } + if (!added && itemDelegate.deviceClass.interfaces.indexOf("extendedsmartmeterconsumer") >= 0) { + append({interfaceName: "extendedsmartmeterconsumer", stateName: "currentPower"}); + } + } + } + + delegate: RowLayout { + id: sensorValueDelegate + Layout.preferredWidth: contentItem.width / dataGrid.columns + + property var stateType: itemDelegate.deviceClass.stateTypes.findByName(model.stateName) + property var stateValue: stateType ? itemDelegate.device.states.getState(stateType.id) : null + + ColorIcon { + Layout.preferredHeight: app.iconSize * .8 + Layout.preferredWidth: height + Layout.alignment: Qt.AlignVCenter + color: app.interfaceToColor(model.interfaceName) + name: app.interfaceToIcon(model.interfaceName) + } + + Label { + Layout.fillWidth: true + text: sensorValueDelegate.stateValue + ? "%1 %2".arg(1.0 * Math.round(sensorValueDelegate.stateValue.value * 100000) / 100000).arg(sensorValueDelegate.stateType.unitString) + : "" + elide: Text.ElideRight + verticalAlignment: Text.AlignVCenter + font.pixelSize: app.smallFont + } + } + } + } + } + onClicked: { + enterPage(index, false) + } + } + } + } + } +} diff --git a/nymea-app/ui/devicepages/ButtonDevicePage.qml b/nymea-app/ui/devicepages/ButtonDevicePage.qml index 7a8ee002..08e9184f 100644 --- a/nymea-app/ui/devicepages/ButtonDevicePage.qml +++ b/nymea-app/ui/devicepages/ButtonDevicePage.qml @@ -5,15 +5,29 @@ import Nymea 1.0 import "../components" import "../customviews" -GenericDevicePage { +DevicePageBase { id: root - GenericTypeLogView { anchors.fill: parent - text: qsTr("This button has been pressed %1 times in the last %2 days.") - logsModel: LogsModel { + logsModel: engine.jsonRpcClient.ensureServerVersion("1.10") ? logsModelNg : logsModel + LogsModelNg { + id: logsModelNg + engine: _engine + deviceId: root.device.id + live: true + typeIds: { + var ret = []; + ret.push(root.deviceClass.eventTypes.findByName("pressed").id) + if (root.deviceClass.eventTypes.findByName("longPressed")) { + ret.push(root.deviceClass.eventTypes.findByName("longPressed").id) + } + return ret; + } + } + LogsModel { + id: logsModel engine: _engine deviceId: root.device.id live: true diff --git a/nymea-app/ui/devicepages/FingerprintReaderDevicePage.qml b/nymea-app/ui/devicepages/FingerprintReaderDevicePage.qml index 4c395fbe..d3d51c5f 100644 --- a/nymea-app/ui/devicepages/FingerprintReaderDevicePage.qml +++ b/nymea-app/ui/devicepages/FingerprintReaderDevicePage.qml @@ -26,14 +26,28 @@ DevicePageBase { } } -// ThinDivider {} + ThinDivider {} + + Label { + Layout.fillWidth: true + Layout.margins: app.margins + text: qsTr("Access log:") + } GenericTypeLogView { Layout.fillHeight: true Layout.fillWidth: true - text: qsTr("%1 fingerprints recognized on this device in the last %2 days.") - logsModel: LogsModel { + logsModel: engine.jsonRpcClient.ensureServerVersion("1.10") ? logsModelNg : logsModel + LogsModelNg { + id: logsModelNg + deviceId: root.device.id + engine: _engine + live: true + typeIds: [root.accessGrantedEventType.id, root.accessDeniedEventType.id]; + } + LogsModel { + id: logsModel deviceId: root.device.id engine: _engine live: true diff --git a/nymea-app/ui/devicepages/InputTriggerDevicePage.qml b/nymea-app/ui/devicepages/InputTriggerDevicePage.qml index 0c011755..bc331295 100644 --- a/nymea-app/ui/devicepages/InputTriggerDevicePage.qml +++ b/nymea-app/ui/devicepages/InputTriggerDevicePage.qml @@ -5,14 +5,22 @@ import Nymea 1.0 import "../components" import "../customviews" -GenericDevicePage { +DevicePageBase { id: root GenericTypeLogView { anchors.fill: parent - text: qsTr("This event has appeared %1 times in the last %2 days.") - logsModel: LogsModel { + logsModel: engine.jsonRpcClient.ensureServerVersion("1.10") ? logsModelNg : logsModel + LogsModelNg { + id: logsModelNg + engine: _engine + deviceId: root.device.id + live: true + typeIds: [root.deviceClass.eventTypes.findByName("triggered").id]; + } + LogsModel { + id: logsModel engine: _engine deviceId: root.device.id live: true diff --git a/nymea-app/ui/devicepages/NotificationsDevicePage.qml b/nymea-app/ui/devicepages/NotificationsDevicePage.qml index 5ac06f94..4f7cd7e8 100644 --- a/nymea-app/ui/devicepages/NotificationsDevicePage.qml +++ b/nymea-app/ui/devicepages/NotificationsDevicePage.qml @@ -71,18 +71,33 @@ DevicePageBase { ThinDivider {} + Label { + Layout.fillWidth: true + Layout.margins: app.margins + wrapMode: Text.WordWrap + text: qsTr("Sent notifications:") + } + + GenericTypeLogView { Layout.fillHeight: true Layout.fillWidth: true - text: qsTr("%1 notifications sent to this device in the last %2 days.") - logsModel: LogsModel { + logsModel: engine.jsonRpcClient.ensureServerVersion("1.10") ? logsModelNg : logsModel + LogsModelNg { + id: logsModelNg + deviceId: root.device.id + engine: _engine + typeIds: [root.deviceClass.actionTypes.findByName("notify").id]; + } + + LogsModel { + id: logsModel deviceId: root.device.id live: true engine: _engine Component.onCompleted: update() typeIds: [root.deviceClass.actionTypes.findByName("notify").id]; - } delegate: MeaListItemDelegate { diff --git a/nymea-app/ui/devicepages/SensorDevicePage.qml b/nymea-app/ui/devicepages/SensorDevicePage.qml index 65998a15..e50610dc 100644 --- a/nymea-app/ui/devicepages/SensorDevicePage.qml +++ b/nymea-app/ui/devicepages/SensorDevicePage.qml @@ -8,24 +8,16 @@ import "../customviews" DevicePageBase { id: root - ListView { - anchors { fill: parent } - model: ListModel { - Component.onCompleted: { - var supportedInterfaces = ["temperaturesensor", "humiditysensor", "pressuresensor", "moisturesensor", "lightsensor", "conductivitysensor"] - for (var i = 0; i < supportedInterfaces.length; i++) { - print("checking", root.deviceClass.name, root.deviceClass.interfaces) - if (root.deviceClass.interfaces.indexOf(supportedInterfaces[i]) >= 0) { - append({name: supportedInterfaces[i]}); - } - } + Loader { + anchors.fill: parent + Component.onCompleted: { + var src + if (engine.jsonRpcClient.ensureServerVersion("1.10")) { + src = "SensorDevicePagePost110.qml" + } else { + src = "SensorDevicePagePre110.qml" } - } - delegate: SensorView { - width: parent.width - interfaceName: modelData - device: root.device - deviceClass: root.deviceClass + setSource(Qt.resolvedUrl(src), {device: root.device, deviceClass: root.deviceClass}) } } } diff --git a/nymea-app/ui/devicepages/SensorDevicePagePost110.qml b/nymea-app/ui/devicepages/SensorDevicePagePost110.qml new file mode 100644 index 00000000..bd4330df --- /dev/null +++ b/nymea-app/ui/devicepages/SensorDevicePagePost110.qml @@ -0,0 +1,38 @@ +import QtQuick 2.5 +import QtQuick.Controls 2.1 +import QtQuick.Layouts 1.1 +import Nymea 1.0 +import "../components" +import "../customviews" + +ListView { + anchors { fill: parent } + model: ListModel { + Component.onCompleted: { + var supportedInterfaces = ["temperaturesensor", "humiditysensor", "pressuresensor", "moisturesensor", "lightsensor", "conductivitysensor"] + for (var i = 0; i < supportedInterfaces.length; i++) { + print("checking", root.deviceClass.name, root.deviceClass.interfaces) + if (root.deviceClass.interfaces.indexOf(supportedInterfaces[i]) >= 0) { + append({name: supportedInterfaces[i]}); + } + } + } + } + delegate: GenericTypeGraph { + width: parent.width + device: root.device + stateType: root.deviceClass.stateTypes.findByName(stateTypeName) + color: app.interfaceToColor(modelData) + iconSource: app.interfaceToIcon(modelData) + + implicitHeight: width * .6 + property string stateTypeName: { + switch (modelData) { + case "lightsensor": + return "lightIntensity"; + default: + return modelData.replace("sensor", ""); + } + } + } +} diff --git a/nymea-app/ui/devicepages/SensorDevicePagePre110.qml b/nymea-app/ui/devicepages/SensorDevicePagePre110.qml new file mode 100644 index 00000000..3b15028f --- /dev/null +++ b/nymea-app/ui/devicepages/SensorDevicePagePre110.qml @@ -0,0 +1,31 @@ +import QtQuick 2.5 +import QtQuick.Controls 2.1 +import QtQuick.Layouts 1.1 +import Nymea 1.0 +import "../components" +import "../customviews" + +ListView { + anchors { fill: parent } + + property var device + property var deviceClass + + model: ListModel { + Component.onCompleted: { + var supportedInterfaces = ["temperaturesensor", "humiditysensor", "pressuresensor", "moisturesensor", "lightsensor", "conductivitysensor"] + for (var i = 0; i < supportedInterfaces.length; i++) { + print("checking", root.deviceClass.name, root.deviceClass.interfaces) + if (root.deviceClass.interfaces.indexOf(supportedInterfaces[i]) >= 0) { + append({name: supportedInterfaces[i]}); + } + } + } + } + delegate: SensorView { + width: parent.width + interfaceName: modelData + device: root.device + deviceClass: root.deviceClass + } +} diff --git a/nymea-app/ui/devicepages/SmartMeterDevicePage.qml b/nymea-app/ui/devicepages/SmartMeterDevicePage.qml new file mode 100644 index 00000000..c93a10bb --- /dev/null +++ b/nymea-app/ui/devicepages/SmartMeterDevicePage.qml @@ -0,0 +1,45 @@ +import QtQuick 2.5 +import QtQuick.Controls 2.1 +import QtQuick.Layouts 1.1 +import Nymea 1.0 +import "../components" +import "../customviews" + +DevicePageBase { + id: root + + ListView { + anchors { fill: parent } + model: ListModel { + Component.onCompleted: { + if (root.deviceClass.interfaces.indexOf("extendedsmartmeterproducer") >= 0 + || root.deviceClass.interfaces.indexOf("extendedsmartmeterconsumer") >= 0) { + append( {interface: "extendedsmartmeterproducer", stateTypeName: "currentPower" }) + } + if (root.deviceClass.interfaces.indexOf("smartmeterproducer") >= 0) { + append( {interface: "smartmeterproducer", stateTypeName: "totalEnergyProduced" }) + } + if (root.deviceClass.interfaces.indexOf("smartmeterconsumer") >= 0) { + append( {interface: "smartmeterconsumer", stateTypeName: "totalEnergyConsumed" }) + } + print("shown graphs are", count) + } + } + delegate: ColumnLayout { + width: parent.width + Label { + Layout.fillWidth: true + Layout.leftMargin: app.margins; Layout.topMargin: app.margins; Layout.rightMargin: app.rightMargins; + text: root.deviceClass.stateTypes.findByName(model.stateTypeName).displayName + } + GenericTypeGraph { + Layout.fillWidth: true + device: root.device + stateType: root.deviceClass.stateTypes.findByName(model.stateTypeName) + color: app.interfaceToColor(model.interface) + iconSource: app.interfaceToIcon(model.interface) + roundTo: 5 + } + } + } +} diff --git a/nymea-app/ui/devicepages/StateLogPage.qml b/nymea-app/ui/devicepages/StateLogPage.qml index a5c3e02e..35a7b62f 100644 --- a/nymea-app/ui/devicepages/StateLogPage.qml +++ b/nymea-app/ui/devicepages/StateLogPage.qml @@ -1,5 +1,6 @@ -import QtQuick 2.5 -import QtQuick.Controls 2.1 +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.Material 2.2 import QtQuick.Layouts 1.1 import Nymea 1.0 import "../components" @@ -16,13 +17,15 @@ Page { case "Int": case "Double": return true; + case "Bool": + return engine.jsonRpcClient.ensureServerVersion("1.10") } print("not showing graph for", root.stateType.type) return false; } header: GuhHeader { - text: qsTr("History") + text: qsTr("History for %1").arg(root.stateType.displayName) onBackPressed: pageStack.pop() } @@ -37,17 +40,13 @@ Page { typeIds: [root.stateType.id] } -// LogsModelNg { -// id: logsModelNg -// deviceId: root.device.id -// typeId: root.stateType.id -// startTime: { -// var date = new Date(); -// date.setHours(new Date().getHours() - 24) -// return date; -// } -// endTime: new Date(); -// } + LogsModelNg { + id: logsModelNg + engine: _engine + deviceId: root.device.id + typeIds: [root.stateType.id] + live: true + } ColumnLayout { anchors.fill: parent @@ -75,9 +74,8 @@ Page { id: logView width: swipeView.width height: swipeView.height - text: qsTr("%1, %2 has changed %3 times in the last %4 days").arg(device.name).arg(stateType.displayName) - logsModel: logsModel + logsModel: engine.jsonRpcClient.ensureServerVersion("1.10") ? logsModelNg : logsModel onAddRuleClicked: { var rule = engine.ruleManager.createNewRule(); @@ -94,80 +92,20 @@ Page { } } - ColumnLayout { + Loader { + id: graphLoader width: swipeView.width height: swipeView.height - TabBar { - id: zoomTabBar - Layout.fillWidth: true - TabButton { - text: qsTr("6 h") - property int avg: ValueLogsProxyModel.AverageQuarterHour - property date startTime: { - var date = new Date(); - date.setHours(new Date().getHours() - 6) - date.setMinutes(0) - date.setSeconds(0) - return date; - } - } - TabButton { - text: qsTr("24 h") - property int avg: ValueLogsProxyModel.AverageHourly - property date startTime: { - var date = new Date(); - date.setHours(new Date().getHours() - 24); - date.setMinutes(0) - date.setSeconds(0) - return date; - } - } - TabButton { - text: qsTr("7 d") - property int avg: ValueLogsProxyModel.AverageDayTime - property date startTime: { - var date = new Date(); - date.setDate(new Date().getDate() - 7); - date.setHours(0) - date.setMinutes(0) - date.setSeconds(0) - return date; - } - } - } - - Graph { - Layout.fillWidth: true - Layout.fillHeight: true - mode: settings.graphStyle - color: app.accentColor - - Timer { - id: updateTimer - interval: 10 - repeat: false - onTriggered: { - graphModel.update() - } - } - - model: ValueLogsProxyModel { - id: graphModel - deviceId: root.device.id - typeIds: [stateType.id] - average: zoomTabBar.currentItem.avg - startTime: zoomTabBar.currentItem.startTime - Component.onCompleted: updateTimer.start(); - onAverageChanged: updateTimer.start() - onStartTimeChanged: updateTimer.start(); - engine: _engine - - // Live doesn't work yet with ValueLogsProxyModel - // live: true + Component.onCompleted: { + var source; + if (engine.jsonRpcClient.ensureServerVersion("1.10")) { + source = Qt.resolvedUrl("../customviews/GenericTypeGraph.qml"); + } else { + source = Qt.resolvedUrl("../customviews/GenericTypeGraphPre110.qml"); } + setSource(source, {device: root.device, stateType: root.stateType}) } } - } } } diff --git a/nymea-app/ui/devicepages/WeatherDevicePage.qml b/nymea-app/ui/devicepages/WeatherDevicePage.qml index 6a7c7543..363faf3b 100644 --- a/nymea-app/ui/devicepages/WeatherDevicePage.qml +++ b/nymea-app/ui/devicepages/WeatherDevicePage.qml @@ -8,36 +8,16 @@ import "../customviews" DevicePageBase { id: root - Flickable { + Loader { anchors.fill: parent - clip: true - contentHeight: content.implicitHeight - ColumnLayout { - id: content - width: parent.width - WeatherView { - Layout.fillWidth: true - device: root.device - deviceClass: root.deviceClass - } - SensorView { - Layout.fillWidth: true - device: root.device - deviceClass: root.deviceClass - interfaceName: "temperaturesensor" - } - SensorView { - Layout.fillWidth: true - device: root.device - deviceClass: root.deviceClass - interfaceName: "humiditysensor" - } - SensorView { - Layout.fillWidth: true - device: root.device - deviceClass: root.deviceClass - interfaceName: "pressuresensor" + Component.onCompleted: { + var src + if (engine.jsonRpcClient.ensureServerVersion("1.10")) { + src = "WeatherDevicePagePost110.qml" + } else { + src = "WeatherDevicePagePre110.qml" } + setSource(Qt.resolvedUrl(src), {device: root.device, deviceClass: root.deviceClass}) } } } diff --git a/nymea-app/ui/devicepages/WeatherDevicePagePost110.qml b/nymea-app/ui/devicepages/WeatherDevicePagePost110.qml new file mode 100644 index 00000000..04f08ca3 --- /dev/null +++ b/nymea-app/ui/devicepages/WeatherDevicePagePost110.qml @@ -0,0 +1,43 @@ +import QtQuick 2.5 +import QtQuick.Controls 2.1 +import QtQuick.Layouts 1.1 +import Nymea 1.0 +import "../components" +import "../customviews" + +Flickable { + anchors.fill: parent + clip: true + contentHeight: content.implicitHeight + + property var device + property var deviceClass + + ColumnLayout { + id: content + width: parent.width + WeatherView { + Layout.fillWidth: true + device: root.device + deviceClass: root.deviceClass + } + SensorChart { + Layout.fillWidth: true + device: root.device + deviceClass: root.deviceClass + interfaceName: "temperaturesensor" + } + SensorChart { + Layout.fillWidth: true + device: root.device + deviceClass: root.deviceClass + interfaceName: "humiditysensor" + } + SensorChart { + Layout.fillWidth: true + device: root.device + deviceClass: root.deviceClass + interfaceName: "pressuresensor" + } + } +} diff --git a/nymea-app/ui/devicepages/WeatherDevicePagePre110.qml b/nymea-app/ui/devicepages/WeatherDevicePagePre110.qml new file mode 100644 index 00000000..3feaa8e5 --- /dev/null +++ b/nymea-app/ui/devicepages/WeatherDevicePagePre110.qml @@ -0,0 +1,44 @@ +import QtQuick 2.5 +import QtQuick.Controls 2.1 +import QtQuick.Layouts 1.1 +import Nymea 1.0 +import "../components" +import "../customviews" + + +Flickable { + anchors.fill: parent + clip: true + contentHeight: content.implicitHeight + + property var device + property var deviceClass + + ColumnLayout { + id: content + width: parent.width + WeatherView { + Layout.fillWidth: true + device: root.device + deviceClass: root.deviceClass + } + SensorView { + Layout.fillWidth: true + device: root.device + deviceClass: root.deviceClass + interfaceName: "temperaturesensor" + } + SensorView { + Layout.fillWidth: true + device: root.device + deviceClass: root.deviceClass + interfaceName: "humiditysensor" + } + SensorView { + Layout.fillWidth: true + device: root.device + deviceClass: root.deviceClass + interfaceName: "pressuresensor" + } + } +} diff --git a/nymea-app/ui/images/ev-charger.svg b/nymea-app/ui/images/ev-charger.svg new file mode 100644 index 00000000..6cd918c7 --- /dev/null +++ b/nymea-app/ui/images/ev-charger.svg @@ -0,0 +1,6537 @@ + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/nymea-app/ui/images/radiator.svg b/nymea-app/ui/images/radiator.svg new file mode 100644 index 00000000..9ff0d994 --- /dev/null +++ b/nymea-app/ui/images/radiator.svg @@ -0,0 +1,71 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/nymea-app/ui/images/smartmeter.svg b/nymea-app/ui/images/smartmeter.svg new file mode 100644 index 00000000..4bd777f8 --- /dev/null +++ b/nymea-app/ui/images/smartmeter.svg @@ -0,0 +1,202 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nymea-app/ui/images/zoom-in.svg b/nymea-app/ui/images/zoom-in.svg new file mode 100644 index 00000000..57e89dc4 --- /dev/null +++ b/nymea-app/ui/images/zoom-in.svg @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/nymea-app/ui/images/zoom-out.svg b/nymea-app/ui/images/zoom-out.svg new file mode 100644 index 00000000..38a04c3e --- /dev/null +++ b/nymea-app/ui/images/zoom-out.svg @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/nymea-app/ui/mainviews/DevicesPageDelegate.qml b/nymea-app/ui/mainviews/DevicesPageDelegate.qml index 99af5924..83b9de65 100644 --- a/nymea-app/ui/mainviews/DevicesPageDelegate.qml +++ b/nymea-app/ui/mainviews/DevicesPageDelegate.qml @@ -25,6 +25,9 @@ MainPageTile { case "light": page = "LightsDeviceListPage.qml" break; + case "smartmeter": + page ="SmartMeterDeviceListPage.qml"; + break; default: page = "GenericDeviceListPage.qml" } @@ -65,6 +68,10 @@ MainPageTile { switch (model.name) { case "sensor": case "weather": + case "smartmeterconsumer": + case "smartmeterproducer": + case "extendedsmartmeterconsumer": + case "extendedsmartmeterproducer": return labelComponent; case "light": diff --git a/nymea-app/ui/system/LogViewerPage.qml b/nymea-app/ui/system/LogViewerPage.qml index 8ede8b8b..52d06372 100644 --- a/nymea-app/ui/system/LogViewerPage.qml +++ b/nymea-app/ui/system/LogViewerPage.qml @@ -33,7 +33,6 @@ Page { } endTime: new Date() live: true - Component.onCompleted: update() onCountChanged: { if (root.autoScroll) { listView.positionViewAtEnd() @@ -41,6 +40,12 @@ Page { } } + LogsModelNg { + id: logsModelNg + engine: _engine + live: true + } + BusyIndicator { anchors.centerIn: listView visible: logsModel.busy @@ -48,11 +53,13 @@ Page { ListView { id: listView - model: logsModel + model: engine.jsonRpcClient.ensureServerVersion("1.10") ? logsModelNg : logsModel anchors.fill: parent clip: true headerPositioning: ListView.OverlayHeader + Component.onCompleted: model.update() + onDraggingChanged: { if (dragging) { root.autoScroll = false; @@ -62,8 +69,10 @@ Page { ScrollBar.vertical: ScrollBar {} onContentYChanged: { - if (!logsModel.busy && contentY - originY < 5 * height) { - logsModel.fetchEarlier(1) + if (!engine.jsonRpcClient.ensureServerVersion("1.10")) { + if (!logsModel.busy && contentY - originY < 5 * height) { + logsModel.fetchEarlier(1) + } } } diff --git a/snapcraft.yaml b/snapcraft.yaml index 32ee2c43..99f49300 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -49,6 +49,7 @@ parts: - qtbase5-dev - libavahi-client-dev - libavahi-common-dev + - libqt5charts5-dev - libqt5svg5-dev - libqt5websockets5-dev - qtconnectivity5-dev @@ -60,6 +61,7 @@ parts: - libqt5websockets5 - libqt5bluetooth5 - libgl1-mesa-dri + - qml-module-qtcharts - qml-module-qtquick2 - qml-module-qtquick-controls2 - qml-module-qtquick-layouts