diff --git a/libnymea-app-core/jsonrpc/jsonrpcclient.cpp b/libnymea-app-core/jsonrpc/jsonrpcclient.cpp index b87817a1..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"); } diff --git a/libnymea-app-core/jsonrpc/jsontypes.cpp b/libnymea-app-core/jsonrpc/jsontypes.cpp index 0ea39be1..b22a6fb2 100644 --- a/libnymea-app-core/jsonrpc/jsontypes.cpp +++ b/libnymea-app-core/jsonrpc/jsontypes.cpp @@ -159,6 +159,8 @@ StateType *JsonTypes::unpackStateType(const QVariantMap &stateTypeMap, QObject * stateType->setDefaultValue(stateTypeMap.value("defaultValue")); stateType->setAllowedValues(stateTypeMap.value("possibleValues").toList()); stateType->setType(stateTypeMap.value("type").toString()); + stateType->setMinValue(stateTypeMap.value("minValue")); + stateType->setMaxValue(stateTypeMap.value("maxValue")); QPair unit = stringToUnit(stateTypeMap.value("unit").toString()); stateType->setUnit(unit.first); diff --git a/libnymea-common/types/actiontype.h b/libnymea-common/types/actiontype.h index bf3cfa34..9db3fc51 100644 --- a/libnymea-common/types/actiontype.h +++ b/libnymea-common/types/actiontype.h @@ -38,7 +38,7 @@ class ActionType : public QObject Q_PROPERTY(ParamTypes *paramTypes READ paramTypes NOTIFY paramTypesChanged) public: - explicit ActionType(QObject *parent = 0); + explicit ActionType(QObject *parent = nullptr); QString id() const; void setId(const QString &id); diff --git a/libnymea-common/types/statetype.cpp b/libnymea-common/types/statetype.cpp index 493c543c..1bbb98fa 100644 --- a/libnymea-common/types/statetype.cpp +++ b/libnymea-common/types/statetype.cpp @@ -122,3 +122,22 @@ void StateType::setUnitString(const QString &unitString) m_unitString = unitString; } +QVariant StateType::minValue() const +{ + return m_minValue; +} + +void StateType::setMinValue(const QVariant &minValue) +{ + m_minValue = minValue; +} + +QVariant StateType::maxValue() const +{ + return m_maxValue; +} + +void StateType::setMaxValue(const QVariant &maxValue) +{ + m_maxValue = maxValue; +} diff --git a/libnymea-common/types/statetype.h b/libnymea-common/types/statetype.h index 5b68cae4..5a1e7114 100644 --- a/libnymea-common/types/statetype.h +++ b/libnymea-common/types/statetype.h @@ -41,6 +41,8 @@ class StateType : public QObject Q_PROPERTY(QVariantList allowedValues READ allowedValues CONSTANT) Q_PROPERTY(Types::Unit unit READ unit CONSTANT) Q_PROPERTY(QString unitString READ unitString CONSTANT) + Q_PROPERTY(QVariant minValue READ minValue CONSTANT) + Q_PROPERTY(QVariant maxValue READ maxValue CONSTANT) public: StateType(QObject *parent = nullptr); @@ -73,6 +75,12 @@ public: QString unitString() const; void setUnitString(const QString &unitString); + QVariant minValue() const; + void setMinValue(const QVariant &minValue); + + QVariant maxValue() const; + void setMaxValue(const QVariant &maxValue); + private: QString m_id; QString m_name; @@ -83,7 +91,8 @@ private: QVariantList m_allowedValues; Types::Unit m_unit; QString m_unitString; - + QVariant m_minValue; + QVariant m_maxValue; }; #endif // STATETYPE_H diff --git a/nymea-app/ui/devicepages/LightDevicePage.qml b/nymea-app/ui/devicepages/LightDevicePage.qml index 62c645be..d31ee1ca 100644 --- a/nymea-app/ui/devicepages/LightDevicePage.qml +++ b/nymea-app/ui/devicepages/LightDevicePage.qml @@ -73,10 +73,10 @@ DevicePageBase { Repeater { model: ListModel { - ListElement { name: "activate"; ct: "153"; bri: 100 } - ListElement { name: "concentrate"; ct: "233"; bri: 100 } - ListElement { name: "reading"; ct: "350"; bri: 100 } - ListElement { name: "relax"; ct: "480" ; bri: 55} + ListElement { name: "activate"; ct: "0"; bri: 100 } + ListElement { name: "concentrate"; ct: "23"; bri: 100 } + ListElement { name: "reading"; ct: "57"; bri: 100 } + ListElement { name: "relax"; ct: "95" ; bri: 55} } delegate: Pane { Layout.fillWidth: true @@ -89,10 +89,14 @@ DevicePageBase { ItemDelegate { anchors.fill: parent onClicked: { + // Translate from % to absolute value in min/max + // % : 100 = abs : (max - min) + print("min,max", root.ctStateType, root.ctStateType.minValue, root.ctStateType.maxValue) + var absoluteCtValue = (model.ct * (root.ctStateType.maxValue - root.ctStateType.minValue) / 100) + root.ctStateType.minValue var params = []; var param1 = {}; param1["paramTypeId"] = root.ctActionType.paramTypes.get(0).id; - param1["value"] = model.ct; + param1["value"] = absoluteCtValue; params.push(param1) engine.deviceManager.executeAction(root.device.id, root.ctActionType.id, params) params = []; @@ -143,8 +147,8 @@ DevicePageBase { anchors.fill: parent ct: root.ctState ? root.ctState.value : 0 visible: root.ctStateType - minCt: root.ctActionType ? root.ctActionType.paramTypes.findByName("colorTemperature").minValue : 0 - maxCt: root.ctActionType ? root.ctActionType.paramTypes.findByName("colorTemperature").maxValue : 0 + minCt: root.ctActionType ? root.ctStateType.minValue : 0 + maxCt: root.ctActionType ? root.ctStateType.maxValue : 0 touchDelegate: Rectangle { diff --git a/nymea-app/ui/mainviews/DevicesPageDelegate.qml b/nymea-app/ui/mainviews/DevicesPageDelegate.qml index 2d2716a0..95f635c1 100644 --- a/nymea-app/ui/mainviews/DevicesPageDelegate.qml +++ b/nymea-app/ui/mainviews/DevicesPageDelegate.qml @@ -271,7 +271,7 @@ MainPageTile { var stateType = deviceClass.stateTypes.findByName("playbackStatus"); var state = device.states.getState(stateType.id) return state.value === "Playing" ? "../images/media-playback-pause.svg" : - state.value === "PAUSED" ? "../images/media-playback-start.svg" : + state.value === "Paused" ? "../images/media-playback-start.svg" : "" case "light": return "../images/system-shutdown.svg"