From a43e18c74ea87b58eaf1d3c184d1b4f375db7d3c Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 3 Mar 2020 19:12:12 +0100 Subject: [PATCH] Fix LogViewer and Weather view unit conversion --- libnymea-common/types/types.cpp | 1 + nymea-app/ui/customviews/WeatherView.qml | 31 +++++++++++----------- nymea-app/ui/devicepages/DeviceLogPage.qml | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/libnymea-common/types/types.cpp b/libnymea-common/types/types.cpp index c5d8b432..006eb5e5 100644 --- a/libnymea-common/types/types.cpp +++ b/libnymea-common/types/types.cpp @@ -248,5 +248,6 @@ QVariant Types::toUiValue(const QVariant &value, Types::Unit unit) const return value; } } + qDebug() << "**********" << value; return value; } diff --git a/nymea-app/ui/customviews/WeatherView.qml b/nymea-app/ui/customviews/WeatherView.qml index 092dcd9e..e234b89a 100644 --- a/nymea-app/ui/customviews/WeatherView.qml +++ b/nymea-app/ui/customviews/WeatherView.qml @@ -32,31 +32,32 @@ import QtQuick 2.5 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.1 import "../components" +import Nymea 1.0 CustomViewBase { id: root height: grid.implicitHeight + app.margins * 2 - readonly property var weatherConditionStateType: deviceClass.stateTypes ? deviceClass.stateTypes.findByName("weatherCondition") : null - readonly property var weatherConditionState: weatherConditionStateType && device.states ? device.states.getState(weatherConditionStateType.id) : null + readonly property StateType weatherConditionStateType: deviceClass.stateTypes ? deviceClass.stateTypes.findByName("weatherCondition") : null + readonly property State weatherConditionState: weatherConditionStateType && device.states ? device.states.getState(weatherConditionStateType.id) : null - readonly property var weatherDescriptionStateType: deviceClass.stateTypes ? deviceClass.stateTypes.findByName("weatherDescription") : null - readonly property var weatherDescriptionState: weatherDescriptionStateType && device.states ? device.states.getState(weatherDescriptionStateType.id) : null + readonly property StateType weatherDescriptionStateType: deviceClass.stateTypes ? deviceClass.stateTypes.findByName("weatherDescription") : null + readonly property State weatherDescriptionState: weatherDescriptionStateType && device.states ? device.states.getState(weatherDescriptionStateType.id) : null - readonly property var temperatureStateType: deviceClass.stateTypes ? deviceClass.stateTypes.findByName("temperature") : null - readonly property var temperatureState: temperatureStateType && device.states ? device.states.getState(temperatureStateType.id) : null + readonly property StateType temperatureStateType: deviceClass.stateTypes ? deviceClass.stateTypes.findByName("temperature") : null + readonly property State temperatureState: temperatureStateType && device.states ? device.states.getState(temperatureStateType.id) : null - readonly property var humidityStateType: deviceClass.stateTypes ? deviceClass.stateTypes.findByName("humidity") : null - readonly property var humidityState: humidityStateType && device.states ? device.states.getState(humidityStateType.id) : null + readonly property StateType humidityStateType: deviceClass.stateTypes ? deviceClass.stateTypes.findByName("humidity") : null + readonly property State humidityState: humidityStateType && device.states ? device.states.getState(humidityStateType.id) : null - readonly property var pressureStateType: deviceClass.stateTypes ? deviceClass.stateTypes.findByName("pressure") : null - readonly property var pressureState: pressureStateType && device.states ? device.states.getState(pressureStateType.id) : null + readonly property StateType pressureStateType: deviceClass.stateTypes ? deviceClass.stateTypes.findByName("pressure") : null + readonly property State pressureState: pressureStateType && device.states ? device.states.getState(pressureStateType.id) : null - readonly property var windDirectionStateType: deviceClass.stateTypes ? deviceClass.stateTypes.findByName("windDirection") : null - readonly property var windDirectionState: windDirectionStateType && device.states ? device.states.getState(windDirectionStateType.id) : null + readonly property StateType windDirectionStateType: deviceClass.stateTypes ? deviceClass.stateTypes.findByName("windDirection") : null + readonly property State windDirectionState: windDirectionStateType && device.states ? device.states.getState(windDirectionStateType.id) : null - readonly property var windSpeedStateType: deviceClass.stateTypes ? deviceClass.stateTypes.findByName("windSpeed") : null - readonly property var windSpeedState: windSpeedStateType && device.states ? device.states.getState(windSpeedStateType.id) : null + readonly property StateType windSpeedStateType: deviceClass.stateTypes ? deviceClass.stateTypes.findByName("windSpeed") : null + readonly property State windSpeedState: windSpeedStateType && device.states ? device.states.getState(windSpeedStateType.id) : null ColumnLayout { id: grid @@ -80,7 +81,7 @@ CustomViewBase { color: app.interfaceToColor("temperaturesensor") } Label { - text: (temperatureState ? Math.round(temperatureState.value * 10) / 10 : "N/A") + " °" + text: (temperatureState ? Math.round(Types.toUiValue(temperatureState.value, temperatureStateType.unit) * 10) / 10 : "N/A") + " °" Layout.fillWidth: true font.pixelSize: app.largeFont horizontalAlignment: Text.AlignHCenter diff --git a/nymea-app/ui/devicepages/DeviceLogPage.qml b/nymea-app/ui/devicepages/DeviceLogPage.qml index c039d2a5..b8b59a90 100644 --- a/nymea-app/ui/devicepages/DeviceLogPage.qml +++ b/nymea-app/ui/devicepages/DeviceLogPage.qml @@ -259,7 +259,7 @@ Page { return labelComponent } - Binding { target: valueLoader.item; property: "value"; value: Types.toUiValue(model.value, entryDelegate.stateType.unit) } + Binding { target: valueLoader.item; property: "value"; value: entryDelegate.stateType ? Types.toUiValue(model.value, entryDelegate.stateType.unit) : model.value } Binding { target: entryDelegate.stateType && valueLoader.item.hasOwnProperty("unitString") ? valueLoader.item : null; property: "unitString"