update plugin json files

add unit to states
This commit is contained in:
Simon Stürz 2015-06-09 16:13:10 +02:00 committed by Michael Zanetti
parent 1ec69f8d6f
commit 2ab185d215
10 changed files with 169 additions and 89 deletions

View File

@ -237,6 +237,7 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
StateType stateType(st.value("id").toString());
stateType.setName(st.value("name").toString());
stateType.setType(t);
stateType.setUnit(unitStringToUnit(st.value("unit").toString()));
stateType.setDefaultValue(st.value("defaultValue").toVariant());
stateTypes.append(stateType);
@ -248,6 +249,7 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
ParamType paramType(st.value("name").toString(), t, st.value("defaultValue").toVariant());
// states don't have allowed values
// states don't have input types
paramType.setUnit(unitStringToUnit(st.value("unit").toString()));
paramType.setLimits(st.value("minValue").toVariant(), st.value("maxValue").toVariant());
actionType.setParamTypes(QList<ParamType>() << paramType);
actionTypes.append(actionType);
@ -416,78 +418,7 @@ QList<ParamType> DevicePlugin::parseParamTypes(const QJsonArray &array) const
// set the unit if there is any
if (pt.contains("unit")) {
QString unitString = pt.value("unit").toString();
if (unitString == "Seconds") {
paramType.setUnit(Types::UnitSeconds);
} else if (unitString == "Minutes") {
paramType.setUnit(Types::UnitMinutes);
} else if (unitString == "Hours") {
paramType.setUnit(Types::UnitHours);
} else if (unitString == "UnixTime") {
paramType.setUnit(Types::UnitUnixTime);
} else if (unitString == "MeterPerSecond") {
paramType.setUnit(Types::UnitMeterPerSecond);
} else if (unitString == "KiloMeterPerHour") {
paramType.setUnit(Types::UnitKiloMeterPerHour);
} else if (unitString == "Degree") {
paramType.setUnit(Types::UnitDegree);
} else if (unitString == "Radiant") {
paramType.setUnit(Types::UnitRadiant);
} else if (unitString == "DegreeCelsius") {
paramType.setUnit(Types::UnitDegreeCelsius);
} else if (unitString == "DegreeKelvin") {
paramType.setUnit(Types::UnitDegreeKelvin);
} else if (unitString == "MilliBar") {
paramType.setUnit(Types::UnitMilliBar);
} else if (unitString == "Bar") {
paramType.setUnit(Types::UnitBar);
} else if (unitString == "Pascal") {
paramType.setUnit(Types::UnitPascal);
} else if (unitString == "HectoPascal") {
paramType.setUnit(Types::UnitHectoPascal);
} else if (unitString == "Atmosphere") {
paramType.setUnit(Types::UnitAtmosphere);
} else if (unitString == "Lumen") {
paramType.setUnit(Types::UnitLumen);
} else if (unitString == "Lux") {
paramType.setUnit(Types::UnitLux);
} else if (unitString == "Candela") {
paramType.setUnit(Types::UnitCandela);
} else if (unitString == "MilliMeter") {
paramType.setUnit(Types::UnitMilliMeter);
} else if (unitString == "CentiMeter") {
paramType.setUnit(Types::UnitCentiMeter);
} else if (unitString == "Meter") {
paramType.setUnit(Types::UnitMeter);
} else if (unitString == "KiloMeter") {
paramType.setUnit(Types::UnitKiloMeter);
} else if (unitString == "Gram") {
paramType.setUnit(Types::UnitGram);
} else if (unitString == "KiloGram") {
paramType.setUnit(Types::UnitKiloGram);
} else if (unitString == "Dezibel") {
paramType.setUnit(Types::UnitDezibel);
} else if (unitString == "KiloByte") {
paramType.setUnit(Types::UnitKiloByte);
} else if (unitString == "MegaByte") {
paramType.setUnit(Types::UnitMegaByte);
} else if (unitString == "GigaByte") {
paramType.setUnit(Types::UnitGigaByte);
} else if (unitString == "TeraByte") {
paramType.setUnit(Types::UnitTeraByte);
} else if (unitString == "MilliWatt") {
paramType.setUnit(Types::UnitMilliWatt);
} else if (unitString == "Watt") {
paramType.setUnit(Types::UnitWatt);
} else if (unitString == "KiloWatt") {
paramType.setUnit(Types::UnitKiloWatt);
} else if (unitString == "KiloWattHour") {
paramType.setUnit(Types::UnitKiloWattHour);
} else if (unitString == "Euro") {
paramType.setUnit(Types::UnitEuro);
} else if (unitString == "Dollar") {
paramType.setUnit(Types::UnitDollar);
}
paramType.setUnit(unitStringToUnit(pt.value("unit").toString()));
}
// set readOnly if given (default false)
@ -711,3 +642,85 @@ QStringList DevicePlugin::verifyFields(const QStringList &fields, const QJsonObj
}
return ret;
}
Types::Unit DevicePlugin::unitStringToUnit(const QString &unitString) const
{
if (unitString == QString()) {
return Types::UnitNone;
} else if (unitString == "Seconds") {
return Types::UnitSeconds;
} else if (unitString == "Minutes") {
return Types::UnitMinutes;
} else if (unitString == "Hours") {
return Types::UnitHours;
} else if (unitString == "UnixTime") {
return Types::UnitUnixTime;
} else if (unitString == "MeterPerSecond") {
return Types::UnitMeterPerSecond;
} else if (unitString == "KiloMeterPerHour") {
return Types::UnitKiloMeterPerHour;
} else if (unitString == "Degree") {
return Types::UnitDegree;
} else if (unitString == "Radiant") {
return Types::UnitRadiant;
} else if (unitString == "DegreeCelsius") {
return Types::UnitDegreeCelsius;
} else if (unitString == "DegreeKelvin") {
return Types::UnitDegreeKelvin;
} else if (unitString == "MilliBar") {
return Types::UnitMilliBar;
} else if (unitString == "Bar") {
return Types::UnitBar;
} else if (unitString == "Pascal") {
return Types::UnitPascal;
} else if (unitString == "HectoPascal") {
return Types::UnitHectoPascal;
} else if (unitString == "Atmosphere") {
return Types::UnitAtmosphere;
} else if (unitString == "Lumen") {
return Types::UnitLumen;
} else if (unitString == "Lux") {
return Types::UnitLux;
} else if (unitString == "Candela") {
return Types::UnitCandela;
} else if (unitString == "MilliMeter") {
return Types::UnitMilliMeter;
} else if (unitString == "CentiMeter") {
return Types::UnitCentiMeter;
} else if (unitString == "Meter") {
return Types::UnitMeter;
} else if (unitString == "KiloMeter") {
return Types::UnitKiloMeter;
} else if (unitString == "Gram") {
return Types::UnitGram;
} else if (unitString == "KiloGram") {
return Types::UnitKiloGram;
} else if (unitString == "Dezibel") {
return Types::UnitDezibel;
} else if (unitString == "KiloByte") {
return Types::UnitKiloByte;
} else if (unitString == "MegaByte") {
return Types::UnitMegaByte;
} else if (unitString == "GigaByte") {
return Types::UnitGigaByte;
} else if (unitString == "TeraByte") {
return Types::UnitTeraByte;
} else if (unitString == "MilliWatt") {
return Types::UnitMilliWatt;
} else if (unitString == "Watt") {
return Types::UnitWatt;
} else if (unitString == "KiloWatt") {
return Types::UnitKiloWatt;
} else if (unitString == "KiloWattHour") {
return Types::UnitKiloWattHour;
} else if (unitString == "Percentage") {
return Types::UnitPercentage;
} else if (unitString == "Euro") {
return Types::UnitEuro;
} else if (unitString == "Dollar") {
return Types::UnitDollar;
} else {
qWarning() << "Could not parse unit:" << unitString << "in plugin" << this->pluginName();
}
return Types::UnitNone;
}

View File

@ -112,6 +112,8 @@ private:
QStringList verifyFields(const QStringList &fields, const QJsonObject &value) const;
Types::Unit unitStringToUnit(const QString &unitString) const;
DeviceManager *m_deviceManager;
ParamList m_config;

View File

@ -35,8 +35,10 @@
* When creating a \l{DevicePlugin} generate a new uuid for each StateType you define and
* hardcode it into the plugin. */
StateType::StateType(const StateTypeId &id):
m_id(id)
m_id(id),
m_unit(Types::UnitNone)
{
}
/*! Returns the id of the StateType. */
@ -80,3 +82,15 @@ void StateType::setDefaultValue(const QVariant &defaultValue)
{
m_defaultValue = defaultValue;
}
/*! Returns the unit of this StateType. */
Types::Unit StateType::unit() const
{
return m_unit;
}
/*! Sets the unit of this StateType to the given \a unit. */
void StateType::setUnit(const Types::Unit &unit)
{
m_unit = unit;
}

View File

@ -42,11 +42,15 @@ public:
QVariant defaultValue() const;
void setDefaultValue(const QVariant &defaultValue);
Types::Unit unit() const;
void setUnit(const Types::Unit &unit);
private:
StateTypeId m_id;
QString m_name;
QVariant::Type m_type;
QVariant m_defaultValue;
Types::Unit m_unit;
};
#endif // STATETYPE_H

View File

@ -32,6 +32,7 @@
"idName": "minute",
"name": "minute",
"type": "uint",
"unit": "Minutes",
"defaultValue": "0"
},
{
@ -39,6 +40,7 @@
"idName": "hour",
"name": "hour",
"type": "uint",
"unit": "Hours",
"defaultValue": "0"
},
{

View File

@ -114,6 +114,7 @@
"idName": "comfortTemp",
"name": "comfort temperature",
"type": "double",
"unit": "DegreeCelsius",
"defaultValue": 0
},
{
@ -121,6 +122,7 @@
"idName": "ecoTemp",
"name": "eco temperature",
"type": "double",
"unit": "DegreeCelsius",
"defaultValue": 0
},
{
@ -128,6 +130,7 @@
"idName": "maxSetpointTemp",
"name": "max setpoint",
"type": "double",
"unit": "DegreeCelsius",
"defaultValue": 0
},
{
@ -135,6 +138,7 @@
"idName": "minSetpointTemp",
"name": "min setpoint",
"type": "double",
"unit": "DegreeCelsius",
"defaultValue": 0
},
{
@ -204,6 +208,7 @@
"idName": "desiredTemperature",
"name": "desired temperature",
"type": "double",
"unit": "DegreeCelsius",
"defaultValue": 0,
"writable": true
@ -212,6 +217,7 @@
"id": "852e7708-db1d-42d1-96e4-19c13598262c",
"idName": "currentTemperature",
"name": "current temp",
"unit": "DegreeCelsius",
"type": "double",
"defaultValue": 0
}
@ -270,6 +276,7 @@
"id": "850380ee-a787-43e7-adb8-768a21a6e64d",
"idName": "comfortTemp",
"name": "comfort temperature",
"unit": "DegreeCelsius",
"type": "double",
"defaultValue": 0
},
@ -277,6 +284,7 @@
"id": "24dfd20d-bc8d-48e4-8162-b20ae0465c41",
"idName": "comfortTemp",
"name": "eco temperature",
"unit": "DegreeCelsius",
"type": "double",
"defaultValue": 0
},
@ -284,19 +292,21 @@
"id": "a8536ddf-a6e4-41c2-89c1-e7102608f5f6",
"idName": "maxSetpointTemp",
"name": "max setpoint",
"unit": "DegreeCelsius",
"type": "double",
"defaultValue": 0
},
{
"id": "ceb0ad05-37ad-4b79-a4d9-540c34a7e3e4",
"idName": "maxSetpointTemp",
"idName": "minSetpointTemp",
"name": "min setpoint",
"unit": "DegreeCelsius",
"type": "double",
"defaultValue": 0
},
{
"id": "9880247b-cf9a-453c-b0c3-d910eba8a253",
"idName": "maxSetpointTemp",
"idName": "errorOccurred",
"name": "error occured",
"type": "bool",
"defaultValue": false
@ -360,6 +370,7 @@
"id": "579aa8c6-8814-491b-9e7c-b98108c323d1",
"idName": "desiredTemperature",
"name": "desired temperature",
"unit": "DegreeCelsius",
"type": "double",
"defaultValue": 0,
"writable": true
@ -368,6 +379,7 @@
"id": "576da571-9a65-478f-96bf-19256c8b9ece",
"idName": "offsetTemp",
"name": "offset temperature",
"unit": "DegreeCelsius",
"type": "double",
"defaultValue": 0
},
@ -375,6 +387,7 @@
"id": "81c6c74a-b0cd-4daa-9eb9-f1cd68f328af",
"idName": "windowOpenDuration",
"name": "window open duration",
"unit": "Minutes",
"type": "int",
"defaultValue": 0
},
@ -389,6 +402,7 @@
"id": "e75c1398-9ad7-466c-b3b9-b03bbb686a30",
"idName": "boostDuration",
"name": "boost duration",
"unit": "Seconds",
"type": "int",
"defaultValue": 0
},
@ -416,14 +430,16 @@
{
"id": "ffaff87b-b741-4db8-9875-3380af4f1885",
"idName": "valveOffset",
"name": "valve offset %",
"name": "valve offset",
"unit": "Percentage",
"type": "int",
"defaultValue": 0
},
{
"id": "72956000-0203-4c32-a6b6-3bb7e46c03ca",
"idName": "valvePosition",
"name": "valve position %",
"name": "valve position",
"unit": "Percentage",
"type": "int",
"defaultValue": 0
}

View File

@ -46,63 +46,72 @@
{
"id": "36b2f09b-7d77-4fbc-a68f-23d735dda0b1",
"idName": "updateTime",
"name": "last update [unixtime]",
"name": "last update",
"unit": "UnixTime",
"type": "uint",
"defaultValue": 0
},
{
"id": "6013402f-b5b1-46b3-8490-f0c20d62fe61",
"idName": "temperature",
"name": "temperature [Celsius]",
"name": "temperature",
"unit": "DegreeCelsius",
"type": "double",
"defaultValue": 0
},
{
"id": "14ec2781-cb04-4bbf-b097-7d01ef982630",
"idName": "temperatureMin",
"name": "temperature minimum [Celsius]",
"name": "temperature minimum",
"unit": "DegreeCelsius",
"type": "double",
"defaultValue": 0
},
{
"id": "fefe5563-452f-4833-b5cf-49c3cc67c772",
"idName": "temperatureMax",
"name": "temperature maximum [Celsius]",
"name": "temperature maximum",
"unit": "DegreeCelsius",
"type": "double",
"defaultValue": 0
},
{
"id": "6f32ec73-3240-4630-ada9-1c10b8e98123",
"idName": "humidity",
"name": "humidity [%]",
"name": "humidity",
"unit": "Percentage",
"type": "int",
"defaultValue": 0
},
{
"id": "4a42eea9-00eb-440b-915e-dbe42180f83b",
"idName": "pressure",
"name": "pressure [hPa]",
"name": "pressure",
"unit": "HectoPascal",
"type": "double",
"defaultValue": 0
},
{
"id": "2bf63430-e9e2-4fbf-88e6-6f1b4770f287",
"idName": "windSpeed",
"name": "wind speed [m/s]",
"name": "wind speed",
"unit": "MeterPerSecond",
"type": "double",
"defaultValue": 0
},
{
"id": "589e2ea5-65b2-4afd-9b72-e3708a589a12",
"idName": "windDirection",
"name": "wind direction [degree]",
"name": "wind direction",
"unit": "Degree",
"type": "int",
"defaultValue": 0
},
{
"id": "798553bc-45c7-42eb-9105-430bddb5d9b7",
"idName": "cloudiness",
"name": "cloudiness [%]",
"name": "cloudiness",
"unit": "Percentage",
"type": "int",
"defaultValue": 0
},
@ -115,14 +124,16 @@
{
"id": "af155e94-9492-44e1-8608-7d0ee8b5d50d",
"idName": "sunset",
"name": "sunset [unixtime]",
"name": "sunset",
"unit": "UnixTime",
"type": "uint",
"defaultValue": 0
},
{
"id": "a1dddc3d-549f-4f20-b78b-be850548f286",
"idName": "sunrise",
"name": "sunrise [unixtime]",
"name": "sunrise",
"unit": "UnixTime",
"type": "int",
"defaultValue": 0
}

View File

@ -68,6 +68,7 @@
"type": "int",
"minValue": 0,
"maxValue": 100,
"unit": "Percentage",
"defaultValue": 0,
"writable": true
}

View File

@ -60,6 +60,7 @@
"idName": "value",
"name": "value",
"type": "int",
"unit": "Percentage",
"minValue": 0,
"maxValue": 100,
"defaultValue": 0,
@ -97,18 +98,21 @@
"id": "ccc656b0-7b66-473d-875e-b0b9a47d300c",
"idName": "temperature",
"name": "temperature",
"unit": "DegreeCelsius",
"type": "double"
},
{
"id": "94df310d-32eb-40f7-b80e-32781b3f8a3e",
"idName": "humidity",
"name": "humidity",
"unit": "Percentage",
"type": "int"
},
{
"id": "9f1212c9-0523-4a00-991e-b652c79b04ed",
"idName": "lightIntensity",
"name": "light intensity",
"unit": "Lumen",
"type": "int"
},
{
@ -124,6 +128,7 @@
"idName": "brightness",
"name": "brightness",
"type": "int",
"unit": "Percentage",
"minValue": 0,
"maxValue": 100,
"defaultValue": 0,

View File

@ -125,6 +125,7 @@ void JsonTypes::init()
s_stateType.insert("name", basicTypeToString(String));
s_stateType.insert("type", basicTypeRef());
s_stateType.insert("defaultValue", basicTypeToString(Variant));
s_stateType.insert("o:unit", unitRef());
// State
s_state.insert("stateTypeId", basicTypeToString(Uuid));
@ -390,6 +391,11 @@ QVariantMap JsonTypes::packStateType(const StateType &stateType)
variantMap.insert("name", stateType.name());
variantMap.insert("type", QVariant::typeToName(stateType.type()));
variantMap.insert("defaultValue", stateType.defaultValue());
if(stateType.unit() != Types::UnitNone) {
variantMap.insert("unit", s_unit.at(stateType.unit()));
}
return variantMap;
}
@ -461,7 +467,7 @@ QVariantMap JsonTypes::packParamType(const ParamType &paramType)
variantMap.insert("inputType", s_inputType.at(paramType.inputType()));
}
if (paramType.unit() != Types::UnitNone) {
variantMap.insert("unit", s_inputType.at(paramType.unit()));
variantMap.insert("unit", s_unit.at(paramType.unit()));
}
// only add if this param is NOT writable
if (paramType.readOnly()) {
@ -1031,6 +1037,12 @@ QPair<bool, QString> JsonTypes::validateVariant(const QVariant &templateVariant,
qDebug() << QString("value %1 not allowed in %2").arg(variant.toString()).arg(inputTypeRef());
return result;
}
} else if (refName == unitRef()) {
QPair<bool, QString> result = validateEnum(s_unit, variant);
if (!result.first) {
qDebug() << QString("value %1 not allowed in %2").arg(variant.toString()).arg(unitRef());
return result;
}
} else {
Q_ASSERT_X(false, "JsonTypes", QString("Unhandled ref: %1").arg(refName).toLatin1().data());
return report(false, QString("Unhandled ref %1. Server implementation incomplete.").arg(refName));