fix min/max statetype values

This commit is contained in:
Michael Zanetti 2018-11-10 16:15:38 +01:00
parent 1b62117779
commit b4a362cb9a
7 changed files with 45 additions and 11 deletions

View File

@ -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");
}

View File

@ -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<Types::Unit, QString> unit = stringToUnit(stateTypeMap.value("unit").toString());
stateType->setUnit(unit.first);

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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 {

View File

@ -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"