diff --git a/libnymea-app/connection/discovery/upnpdiscovery.cpp b/libnymea-app/connection/discovery/upnpdiscovery.cpp
index 35c9a636..1de798ca 100644
--- a/libnymea-app/connection/discovery/upnpdiscovery.cpp
+++ b/libnymea-app/connection/discovery/upnpdiscovery.cpp
@@ -140,7 +140,7 @@ void UpnpDiscovery::readData()
data.resize(socket->pendingDatagramSize());
socket->readDatagram(data.data(), data.size(), &hostAddress, &port);
- qDebug() << "Received UPnP datagram:" << data;
+// qDebug() << "Received UPnP datagram:" << data;
// if the data contains the HTTP OK header...
if (data.contains("HTTP/1.1 200 OK")) {
diff --git a/libnymea-app/models/logsmodel.cpp b/libnymea-app/models/logsmodel.cpp
index 89d53d23..b4baa62a 100644
--- a/libnymea-app/models/logsmodel.cpp
+++ b/libnymea-app/models/logsmodel.cpp
@@ -322,7 +322,7 @@ void LogsModel::fetchMore(const QModelIndex &parent)
params.insert("limit", m_blockSize);
params.insert("offset", m_list.count());
- qDebug() << "Fetching logs from" << m_startTime.toString() << "to" << m_endTime.toString() << "with offset" << m_list.count() << "and limit" << m_blockSize;
+// qDebug() << "Fetching logs from" << m_startTime.toString() << "to" << m_endTime.toString() << "with offset" << m_list.count() << "and limit" << m_blockSize;
m_engine->jsonRpcClient()->sendCommand("Logging.GetLogEntries", params, this, "logsReply");
// qDebug() << "GetLogEntries called";
diff --git a/libnymea-app/models/logsmodelng.cpp b/libnymea-app/models/logsmodelng.cpp
index d9585380..bb1a4995 100644
--- a/libnymea-app/models/logsmodelng.cpp
+++ b/libnymea-app/models/logsmodelng.cpp
@@ -418,7 +418,7 @@ void LogsModelNg::fetchMore(const QModelIndex &parent)
params.insert("limit", m_blockSize);
params.insert("offset", m_list.count());
- qDebug() << "Fetching logs:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson());
+// qDebug() << "Fetching logs:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson());
m_engine->jsonRpcClient()->sendCommand("Logging.GetLogEntries", params, this, "logsReply");
// qDebug() << "GetLogEntries called";
diff --git a/libnymea-app/models/xyseriesadapter.cpp b/libnymea-app/models/xyseriesadapter.cpp
index 325df9d5..3727e472 100644
--- a/libnymea-app/models/xyseriesadapter.cpp
+++ b/libnymea-app/models/xyseriesadapter.cpp
@@ -46,12 +46,34 @@ void XYSeriesAdapter::setBaseSeries(QtCharts::QXYSeries *series)
connect(m_baseSeries, &QtCharts::QXYSeries::pointAdded, this, [=](int index){
if (m_series->count() > index) {
- m_series->replace(index, m_series->at(index).x(), calculateSampleValue(index));
+ qreal value = calculateSampleValue(index);
+ m_series->replace(index, m_series->at(index).x(), value);
+ if (value < m_minValue) {
+ m_minValue = value;
+ qDebug() << "New min:" << m_minValue;
+ emit minValueChanged();
+ }
+ if (value > m_maxValue) {
+ m_maxValue = value;
+ qDebug() << "New max:" << m_maxValue;
+ emit maxValueChanged();
+ }
}
});
connect(m_baseSeries, &QtCharts::QXYSeries::pointReplaced, this, [=](int index){
if (m_series->count() > index) {
- m_series->replace(index, m_series->at(index).x(), calculateSampleValue(index));
+ qreal value = calculateSampleValue(index);
+ m_series->replace(index, m_series->at(index).x(), value);
+ if (value < m_minValue) {
+ m_minValue = value;
+ qDebug() << "New min:" << m_minValue;
+ emit minValueChanged();
+ }
+ if (value > m_maxValue) {
+ m_maxValue = value;
+ qDebug() << "New max:" << m_maxValue;
+ emit maxValueChanged();
+ }
}
});
}
@@ -155,10 +177,12 @@ void XYSeriesAdapter::logEntryAdded(LogEntry *entry)
if (value < m_minValue) {
m_minValue = value;
+// qDebug() << "New min:" << m_minValue;
emit minValueChanged();
}
if (value > m_maxValue) {
m_maxValue = value;
+// qDebug() << "New max:" << m_maxValue;
emit maxValueChanged();
}
}
diff --git a/libnymea-app/types/interfaces.cpp b/libnymea-app/types/interfaces.cpp
index 8ddd2fa8..83e95886 100644
--- a/libnymea-app/types/interfaces.cpp
+++ b/libnymea-app/types/interfaces.cpp
@@ -297,6 +297,8 @@ Interfaces::Interfaces(QObject *parent) : QAbstractListModel(parent)
addInterface("wirelessconnectable", tr("Wireless devices"), {"connectable"});
addStateType("wirelessconnectable", "signalStrength", QVariant::UInt, false, tr("Signal strength"), tr("Signal strength changed"));
+ addInterface("watersensor", tr("Water sensors"), {"sensor"});
+ addStateType("watersensor", "watterDetected", QVariant::Double, false, tr("Water detected"), tr("Water detected changed"));
}
int Interfaces::rowCount(const QModelIndex &parent) const
diff --git a/nymea-app/images.qrc b/nymea-app/images.qrc
index 9ee9ca9c..792e16ed 100644
--- a/nymea-app/images.qrc
+++ b/nymea-app/images.qrc
@@ -253,5 +253,6 @@
ui/images/media/ambeo.svg
ui/images/thermostat/cooling.svg
ui/images/thermostat/heating.svg
+ ui/images/sensors/water.svg
diff --git a/nymea-app/ui/Nymea.qml b/nymea-app/ui/Nymea.qml
index 11982c8e..41494ca3 100644
--- a/nymea-app/ui/Nymea.qml
+++ b/nymea-app/ui/Nymea.qml
@@ -291,6 +291,8 @@ ApplicationWindow {
return Qt.resolvedUrl("images/sensors/closable.svg")
case "windspeedsensor":
return Qt.resolvedUrl("images/sensors/windspeed.svg")
+ case "watersensor":
+ return Qt.resolvedUrl("images/sensors/water.svg")
case "media":
case "mediacontroller":
case "mediaplayer":
@@ -390,6 +392,31 @@ ApplicationWindow {
id: styleBase
}
+ function stateColor(stateName) {
+ // Try to load color map from style
+ if (Style.stateColors[stateName]) {
+ return Style.stateColors[stateName];
+ }
+
+ if (styleBase.stateColors[stateName]) {
+ return styleBase.stateColors[stateName];
+ }
+ console.warn("stateColor(): Color not set for state", stateName)
+ return "grey";
+ }
+
+ function stateIcon(stateName) {
+ var iconMap = {
+ "currentPower": "energy.svg",
+ "totalEnergyConsumed": "smartmeter.svg",
+ "totalEnergyProduced": "smartmeter.svg",
+ }
+ if (!iconMap[stateName]) {
+ console.warn("stateIcon(): Icon not set for state", stateName)
+ }
+ return Qt.resolvedUrl("images/" + iconMap[stateName]);
+ }
+
function interfaceToColor(name) {
// Try to load color map from style
if (Style.interfaceColors[name]) {
diff --git a/nymea-app/ui/StyleBase.qml b/nymea-app/ui/StyleBase.qml
index 30acdd64..ef40cfb4 100644
--- a/nymea-app/ui/StyleBase.qml
+++ b/nymea-app/ui/StyleBase.qml
@@ -36,12 +36,19 @@ Item {
"closablesensor": "green",
"smartmeterproducer": "lightgreen",
"extendedsmartmeterproducer": "lightgreen",
- "smartmeterconsumer": "orange",
- "extendedsmartmeterconsumer": "orange",
+ "smartmeterconsumer": "deepskyblue",
+ "extendedsmartmeterconsumer": "deepskyblue",
"heating" : "gainsboro",
"thermostat": "dodgerblue",
"irrigation": "lightblue",
"windspeedsensor": "blue",
- "ventilation": "lightblue"
+ "ventilation": "lightblue",
+ "watersensor": "aqua"
+ }
+
+ property var stateColors: {
+ "totalEnergyConsumed": "orange",
+ "totalEnergyProduced": "lightgreen",
+ "currentPower": "deepskyblue",
}
}
diff --git a/nymea-app/ui/components/SmartMeterChart.qml b/nymea-app/ui/components/SmartMeterChart.qml
index 1d14fee1..49b46b74 100644
--- a/nymea-app/ui/components/SmartMeterChart.qml
+++ b/nymea-app/ui/components/SmartMeterChart.qml
@@ -37,7 +37,8 @@ import Nymea 1.0
ChartView {
id: chart
- backgroundColor: Style.backgroundColor
+ backgroundColor: Style.tileBackgroundColor
+ backgroundRoundness: Style.tileRadius
theme: ChartView.ChartThemeLight
legend.labelColor: Style.foregroundColor
legend.font.pixelSize: app.smallFont
diff --git a/nymea-app/ui/customviews/GenericTypeGraph.qml b/nymea-app/ui/customviews/GenericTypeGraph.qml
index 2a729252..0d6240e4 100644
--- a/nymea-app/ui/customviews/GenericTypeGraph.qml
+++ b/nymea-app/ui/customviews/GenericTypeGraph.qml
@@ -44,13 +44,15 @@ Item {
property Device device: null
property StateType stateType: null
property int roundTo: 2
+ property color color: Style.accentColor
+ property string iconSource: ""
+ property alias title: titleLabel.text
+
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: Style.accentColor
- property string iconSource: ""
LogsModelNg {
id: logsModelNg
@@ -91,7 +93,7 @@ Item {
animationOptions: ChartView.SeriesAnimations
RowLayout {
- anchors { left: parent.left; top: parent.top; right: parent.right; topMargin: app.margins / 2; leftMargin: app.margins; rightMargin: app.margins }
+ anchors { left: parent.left; top: parent.top; right: parent.right; topMargin: app.margins / 2; leftMargin: app.margins * 1.5; rightMargin: app.margins }
ColorIcon {
Layout.preferredHeight: app.iconSize
@@ -101,6 +103,7 @@ Item {
color: root.color
}
Label {
+ id: titleLabel
Layout.fillWidth: true
text: root.stateType.type.toLowerCase() === "bool"
? root.stateType.displayName
diff --git a/nymea-app/ui/delegates/InterfaceTile.qml b/nymea-app/ui/delegates/InterfaceTile.qml
index ee04f920..fbf478fe 100644
--- a/nymea-app/ui/delegates/InterfaceTile.qml
+++ b/nymea-app/ui/delegates/InterfaceTile.qml
@@ -627,6 +627,7 @@ MainPageTile {
ListElement { ifaceName: "presencesensor"; stateName: "isPresent" }
ListElement { ifaceName: "closablesensor"; stateName: "closed" }
ListElement { ifaceName: "lightsensor"; stateName: "lightIntensity" }
+ ListElement { ifaceName: "watersensor"; stateName: "waterDetected" }
ListElement { ifaceName: "co2sensor"; stateName: "co2" }
ListElement { ifaceName: "conductivity"; stateName: "conductivity" }
ListElement { ifaceName: "noisesensor"; stateName: "noise" }
@@ -717,6 +718,5 @@ MainPageTile {
}
}
}
-
}
}
diff --git a/nymea-app/ui/devicelistpages/SensorsDeviceListPage.qml b/nymea-app/ui/devicelistpages/SensorsDeviceListPage.qml
index 6be739f9..f6443a81 100644
--- a/nymea-app/ui/devicelistpages/SensorsDeviceListPage.qml
+++ b/nymea-app/ui/devicelistpages/SensorsDeviceListPage.qml
@@ -85,6 +85,7 @@ DeviceListPageBase {
ListElement { interfaceName: "closablesensor"; stateName: "closed" }
ListElement { interfaceName: "heating"; stateName: "power" }
ListElement { interfaceName: "thermostat"; stateName: "targetTemperature" }
+ ListElement { interfaceName: "watersensor"; stateName: "waterDetected" }
}
delegate: RowLayout {
@@ -124,10 +125,12 @@ DeviceListPageBase {
switch (model.interfaceName) {
case "closablesensor":
return sensorValueDelegate.stateValue && sensorValueDelegate.stateValue.value === true ? qsTr("Closed") : qsTr("Open");
- case "preencesensor":
+ case "presencesensor":
return sensorValueDelegate.stateValue && sensorValueDelegate.stateValue.value === true ? qsTr("Presence") : qsTr("Vacant");
case "daylightsensor":
return sensorValueDelegate.stateValue && sensorValueDelegate.stateValue.value === true ? qsTr("Daytime") : qsTr("Nighttime");
+ case "watersensor":
+ return sensorValueDelegate.stateValue && sensorValueDelegate.stateValue.value === true ? qsTr("Wet") : qsTr("Dry");
case "heating":
return sensorValueDelegate.stateValue && sensorValueDelegate.stateValue.value === true ? qsTr("On") : qsTr("Off");
default:
@@ -144,7 +147,7 @@ DeviceListPageBase {
}
Led {
id: led
- visible: sensorValueDelegate.stateType && sensorValueDelegate.stateType.type.toLowerCase() === "bool" && ["presencesensor", "daylightsensor", "heating", "closablesensor"].indexOf(model.interfaceName) < 0
+ visible: sensorValueDelegate.stateType && sensorValueDelegate.stateType.type.toLowerCase() === "bool" && ["presencesensor", "daylightsensor", "heating", "closablesensor", "watersensor"].indexOf(model.interfaceName) < 0
state: visible && sensorValueDelegate.stateValue.value === true ? "on" : "off"
}
Item {
diff --git a/nymea-app/ui/devicelistpages/SmartMeterDeviceListPage.qml b/nymea-app/ui/devicelistpages/SmartMeterDeviceListPage.qml
index df5688af..cf0dcef3 100644
--- a/nymea-app/ui/devicelistpages/SmartMeterDeviceListPage.qml
+++ b/nymea-app/ui/devicelistpages/SmartMeterDeviceListPage.qml
@@ -103,8 +103,8 @@ DeviceListPageBase {
Layout.preferredHeight: app.iconSize
Layout.preferredWidth: height
Layout.alignment: Qt.AlignVCenter
- color: app.interfaceToColor(model.interfaceName)
- name: app.interfaceToIcon(model.interfaceName)
+ color: app.stateColor(model.stateName)
+ name: app.stateIcon(model.stateName)
}
Label {
diff --git a/nymea-app/ui/devicepages/SensorDevicePage.qml b/nymea-app/ui/devicepages/SensorDevicePage.qml
index 224379a8..46998c90 100644
--- a/nymea-app/ui/devicepages/SensorDevicePage.qml
+++ b/nymea-app/ui/devicepages/SensorDevicePage.qml
@@ -41,18 +41,22 @@ DevicePageBase {
Flickable {
id: listView
anchors { fill: parent }
+ topMargin: app.margins / 2
interactive: contentHeight > height
contentHeight: contentGrid.implicitHeight
GridLayout {
id: contentGrid
- width: parent.width
+ width: parent.width - app.margins
+ anchors.horizontalCenter: parent.horizontalCenter
columns: Math.ceil(width / 600)
+ rowSpacing: 0
+ columnSpacing: 0
Repeater {
model: ListModel {
Component.onCompleted: {
- var supportedInterfaces = ["temperaturesensor", "humiditysensor", "pressuresensor", "moisturesensor", "lightsensor", "conductivitysensor", "noisesensor", "co2sensor", "presencesensor", "daylightsensor", "closablesensor"]
+ var supportedInterfaces = ["temperaturesensor", "humiditysensor", "pressuresensor", "moisturesensor", "lightsensor", "conductivitysensor", "noisesensor", "co2sensor", "presencesensor", "daylightsensor", "closablesensor", "watersensor"]
for (var i = 0; i < supportedInterfaces.length; i++) {
if (root.deviceClass.interfaces.indexOf(supportedInterfaces[i]) >= 0) {
append({name: supportedInterfaces[i]});
@@ -67,6 +71,7 @@ DevicePageBase {
Layout.preferredHeight: item.implicitHeight
property StateType stateType: root.deviceClass.stateTypes.findByName(interfaceStateMap[modelData])
+ property State state: root.thing.stateByName(interfaceStateMap[modelData])
property string interfaceName: modelData
// sourceComponent: stateType && stateType.type.toLowerCase() === "bool" ? boolComponent : graphComponent
@@ -83,7 +88,8 @@ DevicePageBase {
"co2sensor": "co2",
"presencesensor": "isPresent",
"daylightsensor": "daylight",
- "closablesensor": "closed"
+ "closablesensor": "closed",
+ "watersensor": "waterDetected"
}
}
@@ -96,12 +102,32 @@ DevicePageBase {
id: graphComponent
GenericTypeGraph {
+ id: graph
device: root.device
color: app.interfaceToColor(interfaceName)
iconSource: app.interfaceToIcon(interfaceName)
implicitHeight: width * .6
property string interfaceName: parent.interfaceName
stateType: parent.stateType
+ property State state: parent.state
+
+ Binding {
+ target: graph
+ property: "title"
+ when: ["presencesensor", "daylightsensor", "closablesensor", "watersensor"].indexOf(graph.interfaceName) >= 0
+ value: {
+ switch (graph.interfaceName) {
+ case "presencesensor":
+ return graph.state.value === true ? qsTr("Presence") : qsTr("Vacant")
+ case "daylightsensor":
+ return graph.state.value === true ? qsTr("Daytimet") : qsTr("Nighttime")
+ case "closablesensor":
+ return graph.state.value === true ? qsTr("Closed") : qsTr("Open")
+ case "watersensor":
+ return graph.state.value === true ? qsTr("Wet") : qsTr("Dry")
+ }
+ }
+ }
}
}
diff --git a/nymea-app/ui/devicepages/SmartMeterDevicePage.qml b/nymea-app/ui/devicepages/SmartMeterDevicePage.qml
index 08924e43..73f76fb3 100644
--- a/nymea-app/ui/devicepages/SmartMeterDevicePage.qml
+++ b/nymea-app/ui/devicepages/SmartMeterDevicePage.qml
@@ -45,6 +45,7 @@ DevicePageBase {
Flickable {
anchors.fill: parent
+ topMargin: app.margins / 2
contentHeight: contentGrid.height
interactive: contentHeight > height
@@ -56,13 +57,17 @@ DevicePageBase {
BigTile {
Layout.preferredWidth: contentGrid.width / contentGrid.columns
- showHeader: false
+ showHeader: true
+ header: Label {
+ text: qsTr("Total energy consumption")
+ }
+
contentItem: RowLayout {
ColorIcon {
Layout.preferredHeight: app.iconSize
Layout.preferredWidth: app.iconSize
- name: app.interfaceToIcon("smartmeterconsumer")
- color: app.interfaceToColor("smartmeterconsumer")
+ name: app.stateIcon("totalEnergyConsumed")
+ color: app.stateColor("totalEnergyConsumed")
}
Label {
@@ -73,14 +78,16 @@ DevicePageBase {
ColorIcon {
Layout.preferredHeight: app.iconSize
Layout.preferredWidth: app.iconSize
- name: app.interfaceToIcon("smartmeterproducer")
- color: app.interfaceToColor("smartmeterproducer")
+ name: app.stateIcon("totalEnergyProduced")
+ color: app.stateColor("totalEnergyProduced")
+ visible: root.totalEnergyProducedState !== null
}
Label {
Layout.fillWidth: true
text: root.totalEnergyProducedState.value.toFixed(2) + " " + root.totalEnergyProducedStateType.unitString
font.pixelSize: app.largeFont
+ visible: root.totalEnergyProducedState !== null
}
}
}
@@ -89,8 +96,8 @@ DevicePageBase {
Layout.preferredWidth: contentGrid.width / contentGrid.columns
device: root.device
stateType: root.deviceClass.stateTypes.findByName("currentPower")
- color: app.interfaceToColor("smartmeterconsumer")
- iconSource: app.interfaceToIcon("smartmeterconsumer")
+ color: app.stateColor("currentPower")
+ iconSource: app.stateIcon("currentPower")
roundTo: 5
}
}
diff --git a/nymea-app/ui/images/sensors/water.svg b/nymea-app/ui/images/sensors/water.svg
new file mode 100644
index 00000000..fee3e80a
--- /dev/null
+++ b/nymea-app/ui/images/sensors/water.svg
@@ -0,0 +1,177 @@
+
+
diff --git a/nymea-app/ui/mainviews/EnergyView.qml b/nymea-app/ui/mainviews/EnergyView.qml
index f6d34874..168d40a7 100644
--- a/nymea-app/ui/mainviews/EnergyView.qml
+++ b/nymea-app/ui/mainviews/EnergyView.qml
@@ -79,7 +79,8 @@ MainViewBase {
legend.alignment: Qt.AlignBottom
legend.font.pixelSize: app.smallFont
legend.visible: false
- backgroundColor: Style.backgroundColor
+ backgroundColor: Style.tileBackgroundColor
+ backgroundRoundness: Style.tileRadius
titleColor: Style.foregroundColor
title: qsTr("Power usage history")
@@ -150,7 +151,7 @@ MainViewBase {
}
Component.onCompleted: {
- print("creating series")
+ print("creating series", consumer.thing.name, index)
seriesAdapter.ensureSamples(xAxis.min, xAxis.max)
var areaSeries = chartView.createSeries(ChartView.SeriesTypeArea, consumer.thing.name, xAxis, yAxis)
areaSeries.upperSeries = upperSeries;
@@ -179,8 +180,8 @@ MainViewBase {
ValueAxis {
id: yAxis
readonly property XYSeriesAdapter adapter: consumersRepeater.itemAt(consumersRepeater.count - 1).adapter;
- max: Math.ceil(adapter.maxValue + Math.abs(adapter.maxValue * .05))
- min: Math.floor(adapter.minValue - Math.abs(adapter.minValue * .05))
+ max: Math.ceil(Math.max(adapter.maxValue * 0.95, adapter.maxValue * 1.05))
+ min: Math.floor(Math.min(adapter.minValue * 0.95, adapter.minValue * 1.05))
// This seems to crash occationally
// onMinChanged: applyNiceNumbers();
// onMaxChanged: applyNiceNumbers();
@@ -354,6 +355,8 @@ MainViewBase {
SmartMeterChart {
Layout.fillWidth: true
Layout.preferredHeight: width * .7
+ backgroundColor: Style.tileBackgroundColor
+ backgroundRoundness: Style.tileRadius
meters: producers
title: qsTr("Total produced energy")
visible: producers.count > 0