diff --git a/libnymea-app/thingmanager.cpp b/libnymea-app/thingmanager.cpp index 3fff48c8..a63d33b3 100644 --- a/libnymea-app/thingmanager.cpp +++ b/libnymea-app/thingmanager.cpp @@ -832,6 +832,7 @@ ParamType *ThingManager::unpackParamType(const QVariantMap ¶mTypeMap, QObjec paramType->setDefaultValue(paramTypeMap.value("defaultValue")); paramType->setMinValue(paramTypeMap.value("minValue")); paramType->setMaxValue(paramTypeMap.value("maxValue")); + paramType->setStepSize(paramTypeMap.value("stepSize").toDouble()); paramType->setAllowedValues(paramTypeMap.value("allowedValues").toList()); paramType->setInputType(stringToInputType(paramTypeMap.value("inputType").toString())); paramType->setReadOnly(paramTypeMap.value("readOnly").toBool()); @@ -858,6 +859,7 @@ StateType *ThingManager::unpackStateType(const QVariantMap &stateTypeMap, QObjec stateType->setType(stateTypeMap.value("type").toString()); stateType->setMinValue(stateTypeMap.value("minValue")); stateType->setMaxValue(stateTypeMap.value("maxValue")); + stateType->setStepSize(stateTypeMap.value("stepSize").toDouble()); stateType->setUnit(stringToUnit(stateTypeMap.value("unit").toString())); QMetaEnum metaEnum = QMetaEnum::fromType(); diff --git a/libnymea-app/types/paramtype.cpp b/libnymea-app/types/paramtype.cpp index 787d903e..b1a68c99 100644 --- a/libnymea-app/types/paramtype.cpp +++ b/libnymea-app/types/paramtype.cpp @@ -24,20 +24,19 @@ #include "paramtype.h" -ParamType::ParamType(QObject *parent) : - QObject(parent) +ParamType::ParamType(QObject *parent) + : QObject(parent) { m_readOnly = false; } -ParamType::ParamType(const QString &name, const QVariant::Type type, const QVariant &defaultValue, QObject *parent) : - QObject(parent), - m_name(name), - m_type(QVariant::typeToName(type)), - m_defaultValue(defaultValue), - m_readOnly(false) -{ -} +ParamType::ParamType(const QString &name, const QVariant::Type type, const QVariant &defaultValue, QObject *parent) + : QObject(parent) + , m_name(name) + , m_type(QVariant::typeToName(type)) + , m_defaultValue(defaultValue) + , m_readOnly(false) +{} QUuid ParamType::id() const { @@ -119,6 +118,16 @@ void ParamType::setMaxValue(const QVariant &maxValue) m_maxValue = maxValue; } +double ParamType::stepSize() const +{ + return m_stepSize; +} + +void ParamType::setStepSize(double stepSize) +{ + m_stepSize = stepSize; +} + Types::InputType ParamType::inputType() const { return m_inputType; diff --git a/libnymea-app/types/paramtype.h b/libnymea-app/types/paramtype.h index 1fee5f40..c4df20c6 100644 --- a/libnymea-app/types/paramtype.h +++ b/libnymea-app/types/paramtype.h @@ -25,10 +25,10 @@ #ifndef PARAMTYPE_H #define PARAMTYPE_H -#include -#include #include +#include #include +#include #include "types.h" @@ -43,6 +43,7 @@ class ParamType : public QObject Q_PROPERTY(QVariant defaultValue READ defaultValue CONSTANT) Q_PROPERTY(QVariant minValue READ minValue CONSTANT) Q_PROPERTY(QVariant maxValue READ maxValue CONSTANT) + Q_PROPERTY(double stepSize READ stepSize CONSTANT) Q_PROPERTY(Types::InputType inputType READ inputType CONSTANT) Q_PROPERTY(Types::Unit unit READ unit CONSTANT) Q_PROPERTY(QVariantList allowedValues READ allowedValues CONSTANT) @@ -76,6 +77,9 @@ public: QVariant maxValue() const; void setMaxValue(const QVariant &maxValue); + double stepSize() const; + void setStepSize(double stepSize); + Types::InputType inputType() const; void setInputType(const Types::InputType &inputType); @@ -97,6 +101,7 @@ private: QVariant m_defaultValue; QVariant m_minValue; QVariant m_maxValue; + double m_stepSize = 0; Types::InputType m_inputType; Types::Unit m_unit; QVariantList m_allowedValues; diff --git a/libnymea-app/types/statetype.cpp b/libnymea-app/types/statetype.cpp index 338c2c4b..5375acc9 100644 --- a/libnymea-app/types/statetype.cpp +++ b/libnymea-app/types/statetype.cpp @@ -24,10 +24,9 @@ #include "statetype.h" -StateType::StateType(QObject *parent) : - QObject(parent) -{ -} +StateType::StateType(QObject *parent) + : QObject(parent) +{} QUuid StateType::id() const { @@ -147,6 +146,16 @@ void StateType::setMaxValue(const QVariant &maxValue) m_maxValue = maxValue; } +double StateType::stepSize() const +{ + return m_stepSize; +} + +void StateType::setStepSize(double stepSize) +{ + m_stepSize = stepSize; +} + Types::IOType StateType::ioType() const { return m_ioType; diff --git a/libnymea-app/types/statetype.h b/libnymea-app/types/statetype.h index 54fcc8fe..a97ef768 100644 --- a/libnymea-app/types/statetype.h +++ b/libnymea-app/types/statetype.h @@ -25,9 +25,9 @@ #ifndef STATETYPE_H #define STATETYPE_H -#include #include #include +#include #include "types.h" @@ -47,6 +47,7 @@ class StateType : public QObject Q_PROPERTY(Types::IOType ioType READ ioType CONSTANT) Q_PROPERTY(QVariant minValue READ minValue CONSTANT) Q_PROPERTY(QVariant maxValue READ maxValue CONSTANT) + Q_PROPERTY(double stepSize READ stepSize CONSTANT) public: StateType(QObject *parent = nullptr); @@ -87,6 +88,9 @@ public: QVariant maxValue() const; void setMaxValue(const QVariant &maxValue); + double stepSize() const; + void setStepSize(double stepSize); + private: QUuid m_id; QString m_name; @@ -100,6 +104,7 @@ private: Types::IOType m_ioType = Types::IOTypeNone; QVariant m_minValue; QVariant m_maxValue; + double m_stepSize = 0; }; #endif // STATETYPE_H diff --git a/nymea-app/ui/components/MediaPlayer.qml b/nymea-app/ui/components/MediaPlayer.qml index dab53d0e..bf7d7810 100644 --- a/nymea-app/ui/components/MediaPlayer.qml +++ b/nymea-app/ui/components/MediaPlayer.qml @@ -73,8 +73,8 @@ Item { Connections { target: engine.thingManager - onExecuteActionReply: { - if (commandId == d.pendingCallId) { + onExecuteActionReply: (commandId, thingError, displayMessage) => { + if (commandId === d.pendingCallId) { if (thingError !== Thing.ThingErrorNoError) { var errorDialog = Qt.createComponent(Qt.resolvedUrl("../components/ErrorDialog.qml")); var dialogParams = {} diff --git a/nymea-app/ui/components/StateDial.qml b/nymea-app/ui/components/StateDial.qml index 3f69ca3a..2225ee1e 100644 --- a/nymea-app/ui/components/StateDial.qml +++ b/nymea-app/ui/components/StateDial.qml @@ -38,7 +38,8 @@ Item { property color color: Style.accentColor property bool on: true - property int precision: 1 + property real precision: 1 + property real linePrecision: 1 readonly property State progressState: thing ? thing.states.getState(stateType.id) : null readonly property State powerState: thing ? thing.stateByName("power") : null @@ -46,8 +47,10 @@ Item { property int startAngle: 135 property int maxAngle: 270 readonly property int steps: canvas.roundToPrecision(root.progressState.maxValue - root.progressState.minValue) / root.precision + 1 + readonly property int lineSteps: canvas.roundToPrecision(root.progressState.maxValue - root.progressState.minValue, root.linePrecision) / root.linePrecision + 1 readonly property double stepSize: (root.progressState.maxValue - root.progressState.minValue) / steps readonly property double anglePerStep: maxAngle / steps + readonly property double lineAnglePerStep: maxAngle / lineSteps ActionQueue { @@ -81,8 +84,9 @@ Item { Behavior on effectColor { ColorAnimation { duration: Style.animationDuration } } onEffectColorChanged: requestPaint() - function roundToPrecision(value) { - var tmp = Math.round(value / root.precision) * root.precision; + function roundToPrecision(value, precision) { + var effectivePrecision = precision === undefined ? root.precision : precision; + var tmp = Math.round(value / effectivePrecision) * effectivePrecision; return tmp; } @@ -94,19 +98,20 @@ Item { // Step lines var currentValue = actionQueue.pendingValue || root.progressState.value - var currentStep; + var currentStepValue; if (root.progressState) { - currentStep = roundToPrecision(currentValue - root.progressState.minValue) / root.precision + currentStepValue = roundToPrecision(currentValue - root.progressState.minValue, root.linePrecision) } -// print("* current step", currentStep, root.steps, currentValue) +// print("* current step", currentStepValue, root.lineSteps, currentValue) - for(var step = 0; step < steps; step += root.precision) { - var angle = step * anglePerStep + startAngle; + for (var step = 0; step < lineSteps; step += 1) { + var stepValue = step * root.linePrecision + var angle = step * lineAnglePerStep + startAngle; var innerRadius = canvas.width * 0.4 var outerRadius = canvas.width * 0.5 - if (step <= currentStep) { + if (stepValue <= currentStepValue) { ctx.strokeStyle = canvas.effectColor innerRadius = canvas.width * 0.38 ctx.lineWidth = 4; diff --git a/nymea-app/ui/components/ThingInfoPane.qml b/nymea-app/ui/components/ThingInfoPane.qml index 74710499..094a674c 100644 --- a/nymea-app/ui/components/ThingInfoPane.qml +++ b/nymea-app/ui/components/ThingInfoPane.qml @@ -106,7 +106,7 @@ InfoPaneBase { } Connections { target: engine.thingManager - onExecuteActionReply: { + onExecuteActionReply: (commandId, thingError, displayMessage) => { if (commandId === childLockIcon.pendingAction) { childLockIcon.pendingAction = -1 } diff --git a/nymea-app/ui/devicepages/EvChargerThingPage.qml b/nymea-app/ui/devicepages/EvChargerThingPage.qml index 88795c24..a6a7f5b0 100644 --- a/nymea-app/ui/devicepages/EvChargerThingPage.qml +++ b/nymea-app/ui/devicepages/EvChargerThingPage.qml @@ -27,8 +27,8 @@ import QtQuick.Controls import QtQuick.Layouts import Nymea -import "../components" -import "../utils" +import "qrc:/ui/components" +import "qrc:/ui/utils" ThingPageBase { id: root @@ -36,6 +36,7 @@ ThingPageBase { readonly property State powerState: thing.stateByName("power") readonly property State maxChargingCurrentState: thing.stateByName("maxChargingCurrent") readonly property StateType maxChargingCurrentStateType: thing.thingClass.stateTypes.findByName("maxChargingCurrent") + readonly property real precision: maxChargingCurrentStateType.stepSize !== 0 ? maxChargingCurrentStateType.stepSize : 0.1 readonly property State currentPowerState: thing.stateByName("currentPower") readonly property State pluggedInState: thing.stateByName("pluggedIn") @@ -94,6 +95,7 @@ ThingPageBase { thing: root.thing stateName: "maxChargingCurrent" color: app.interfaceToColor("evcharger") + precision: root.precision on: (actionQueue.pendingValue || powerState.value) === true } } diff --git a/nymea-app/ui/devicepages/FingerprintReaderDevicePage.qml b/nymea-app/ui/devicepages/FingerprintReaderDevicePage.qml index fa689cd5..608d9b7c 100644 --- a/nymea-app/ui/devicepages/FingerprintReaderDevicePage.qml +++ b/nymea-app/ui/devicepages/FingerprintReaderDevicePage.qml @@ -184,7 +184,7 @@ ThingPageBase { Connections { target: engine.thingManager - onExecuteActionReply: { + onExecuteActionReply: (commandId, thingError, displayMessage) => { addUserPage.error = thingError !== Thing.ThingErrorNoError var masks =[] masks.push({x: 0, y: 0, width: 1, height: 1}); diff --git a/nymea-app/ui/devicepages/GenericThingPage.qml b/nymea-app/ui/devicepages/GenericThingPage.qml index a2a01106..f18a23ad 100644 --- a/nymea-app/ui/devicepages/GenericThingPage.qml +++ b/nymea-app/ui/devicepages/GenericThingPage.qml @@ -359,7 +359,7 @@ ThingPageBase { } Connections { target: engine.thingManager - onExecuteActionReply: { + onExecuteActionReply: (commandId, thingError, displayMessage) => { if (stateDelegate.pendingActionId === commandId) { stateDelegate.pendingActionId = -1 if (stateDelegate.valueCacheDirty) { @@ -384,7 +384,7 @@ ThingPageBase { Connections { target: engine.thingManager - onExecuteActionReply: { + onExecuteActionReply: (commandId, thingError, displayMessage) => { if (commandId === actionDelegate.pendingActionId) { pendingTimer.start(); actionDelegate.lastSuccess = thingError === Thing.ThingErrorNoError diff --git a/nymea-app/ui/devicepages/NotificationsThingPage.qml b/nymea-app/ui/devicepages/NotificationsThingPage.qml index c948c648..cb787842 100644 --- a/nymea-app/ui/devicepages/NotificationsThingPage.qml +++ b/nymea-app/ui/devicepages/NotificationsThingPage.qml @@ -40,8 +40,8 @@ ThingPageBase { Connections { target: engine.thingManager - onExecuteActionReply: { - if (commandId == d.pendingAction) { + onExecuteActionReply: (commandId, thingError, displayMessage) => { + if (commandId === d.pendingAction) { d.pendingAction = -1 } } diff --git a/nymea-app/ui/experiences/heating/Main.qml b/nymea-app/ui/experiences/heating/Main.qml index 3e985d28..3893e5d5 100644 --- a/nymea-app/ui/experiences/heating/Main.qml +++ b/nymea-app/ui/experiences/heating/Main.qml @@ -113,7 +113,7 @@ Item { Connections { target: engine.thingManager - onExecuteActionReply: { + onExecuteActionReply: (commandId, thingError, displayMessage) => { print("executeActionReply:", commandId) if (commandId === d.pendingCallId) { d.pendingCallId = -1; diff --git a/nymea-app/ui/utils/ActionQueue.qml b/nymea-app/ui/utils/ActionQueue.qml index 7a4d0d22..c2eaba85 100644 --- a/nymea-app/ui/utils/ActionQueue.qml +++ b/nymea-app/ui/utils/ActionQueue.qml @@ -68,8 +68,8 @@ Item { Connections { target: root.thing - onExecuteActionReply: { - if (d.pendingCommand == commandId) { + onExecuteActionReply: (commandId, thingError, displayMessage) => { + if (d.pendingCommand === commandId) { // print("command finished") d.pendingCommand = -1; if (d.queuedValue != null) {