mirror of https://github.com/nymea/nymea.git
add units to the API
parent
e944c28906
commit
1ec69f8d6f
|
|
@ -414,6 +414,82 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
// set readOnly if given (default false)
|
||||
if (pt.contains("readOnly")) {
|
||||
paramType.setReadOnly(pt.value("readOnly").toBool());
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ ParamType::ParamType(const QString &name, const QVariant::Type type, const QVari
|
|||
m_type(type),
|
||||
m_defaultValue(defaultValue),
|
||||
m_inputType(Types::InputTypeNone),
|
||||
m_unit(Types::UnitNone),
|
||||
m_readOnly(false)
|
||||
{
|
||||
}
|
||||
|
|
@ -114,6 +115,18 @@ void ParamType::setInputType(const Types::InputType &inputType)
|
|||
m_inputType = inputType;
|
||||
}
|
||||
|
||||
/*! Returns the unit of this ParamType. */
|
||||
Types::Unit ParamType::unit() const
|
||||
{
|
||||
return m_unit;
|
||||
}
|
||||
|
||||
/*! Sets the unit of this ParamType to the given \a unit. */
|
||||
void ParamType::setUnit(const Types::Unit &unit)
|
||||
{
|
||||
m_unit = unit;
|
||||
}
|
||||
|
||||
/*! Returns the limits of this ParamType. limits(minValue, maxValue). */
|
||||
QPair<QVariant, QVariant> ParamType::limits() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ public:
|
|||
Types::InputType inputType() const;
|
||||
void setInputType(const Types::InputType &inputType);
|
||||
|
||||
Types::Unit unit() const;
|
||||
void setUnit(const Types::Unit &unit);
|
||||
|
||||
QPair<QVariant, QVariant> limits() const;
|
||||
void setLimits(const QVariant &min, const QVariant &max);
|
||||
|
||||
|
|
@ -65,6 +68,7 @@ private:
|
|||
QVariant m_minValue;
|
||||
QVariant m_maxValue;
|
||||
Types::InputType m_inputType;
|
||||
Types::Unit m_unit;
|
||||
QVariantList m_allowedValues;
|
||||
bool m_readOnly;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -78,12 +78,13 @@ public:
|
|||
};
|
||||
|
||||
enum Unit {
|
||||
UnitNone,
|
||||
UnitSeconds,
|
||||
UnitMinutes,
|
||||
UnitHours,
|
||||
UnitUnixTime,
|
||||
UnitMeterPerSecond,
|
||||
UnitKilometerPerHour,
|
||||
UnitKiloMeterPerHour,
|
||||
UnitDegree,
|
||||
UnitRadiant,
|
||||
UnitDegreeCelsius,
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ QVariantList JsonTypes::s_basicType;
|
|||
QVariantList JsonTypes::s_stateOperator;
|
||||
QVariantList JsonTypes::s_valueOperator;
|
||||
QVariantList JsonTypes::s_inputType;
|
||||
QVariantList JsonTypes::s_unit;
|
||||
QVariantList JsonTypes::s_createMethod;
|
||||
QVariantList JsonTypes::s_setupMethod;
|
||||
QVariantList JsonTypes::s_removePolicy;
|
||||
|
|
@ -77,6 +78,7 @@ void JsonTypes::init()
|
|||
s_stateOperator = enumToStrings(Types::staticMetaObject, "StateOperator");
|
||||
s_valueOperator = enumToStrings(Types::staticMetaObject, "ValueOperator");
|
||||
s_inputType = enumToStrings(Types::staticMetaObject, "InputType");
|
||||
s_unit = enumToStrings(Types::staticMetaObject, "Unit");
|
||||
s_createMethod = enumToStrings(DeviceClass::staticMetaObject, "CreateMethod");
|
||||
s_setupMethod = enumToStrings(DeviceClass::staticMetaObject, "SetupMethod");
|
||||
s_removePolicy = enumToStrings(RuleEngine::staticMetaObject, "RemovePolicy");
|
||||
|
|
@ -95,6 +97,7 @@ void JsonTypes::init()
|
|||
s_paramType.insert("o:maxValue", basicTypeToString(Variant));
|
||||
s_paramType.insert("o:allowedValues", QVariantList() << basicTypeToString(Variant));
|
||||
s_paramType.insert("o:inputType", inputTypeRef());
|
||||
s_paramType.insert("o:unit", unitRef());
|
||||
s_paramType.insert("o:readOnly", basicTypeToString(Bool));
|
||||
|
||||
// Param
|
||||
|
|
@ -251,6 +254,7 @@ QVariantMap JsonTypes::allTypes()
|
|||
allTypes.insert("BasicType", basicType());
|
||||
allTypes.insert("ParamType", paramTypeDescription());
|
||||
allTypes.insert("InputType", inputType());
|
||||
allTypes.insert("Unit", unit());
|
||||
allTypes.insert("CreateMethod", createMethod());
|
||||
allTypes.insert("SetupMethod", setupMethod());
|
||||
allTypes.insert("ValueOperator", valueOperator());
|
||||
|
|
@ -456,6 +460,9 @@ QVariantMap JsonTypes::packParamType(const ParamType ¶mType)
|
|||
if (paramType.inputType() != Types::InputTypeNone) {
|
||||
variantMap.insert("inputType", s_inputType.at(paramType.inputType()));
|
||||
}
|
||||
if (paramType.unit() != Types::UnitNone) {
|
||||
variantMap.insert("unit", s_inputType.at(paramType.unit()));
|
||||
}
|
||||
// only add if this param is NOT writable
|
||||
if (paramType.readOnly()) {
|
||||
variantMap.insert("readOnly", paramType.readOnly());
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ public:
|
|||
DECLARE_TYPE(stateOperator, "StateOperator", Types, StateOperator)
|
||||
DECLARE_TYPE(valueOperator, "ValueOperator", Types, ValueOperator)
|
||||
DECLARE_TYPE(inputType, "InputType", Types, InputType)
|
||||
DECLARE_TYPE(unit, "Unit", Types, Unit)
|
||||
DECLARE_TYPE(createMethod, "CreateMethod", DeviceClass, CreateMethod)
|
||||
DECLARE_TYPE(setupMethod, "SetupMethod", DeviceClass, SetupMethod)
|
||||
DECLARE_TYPE(deviceError, "DeviceError", DeviceManager, DeviceError)
|
||||
|
|
|
|||
Loading…
Reference in New Issue