mirror of https://github.com/nymea/nymea.git
Merge PR #242: Support units in interfaces
commit
29c2a2b7b2
|
|
@ -26,6 +26,7 @@
|
|||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QJsonParseError>
|
||||
#include <QMetaEnum>
|
||||
|
||||
DeviceUtils::DeviceUtils()
|
||||
{
|
||||
|
|
@ -191,6 +192,15 @@ Interface DeviceUtils::loadInterface(const QString &name)
|
|||
stateType.setPossibleValues(stateVariant.toMap().value("allowedValues").toList());
|
||||
stateType.setMinValue(stateVariant.toMap().value("minValue"));
|
||||
stateType.setMaxValue(stateVariant.toMap().value("maxValue"));
|
||||
if (stateVariant.toMap().contains("unit")) {
|
||||
QMetaEnum unitEnum = QMetaEnum::fromType<Types::Unit>();
|
||||
int enumValue = unitEnum.keyToValue("Unit" + stateVariant.toMap().value("unit").toByteArray());
|
||||
if (enumValue == -1) {
|
||||
qCWarning(dcDeviceManager) << "Invalid unit" << stateVariant.toMap().value("unit").toString() << "in interface" << name;
|
||||
} else {
|
||||
stateType.setUnit(static_cast<Types::Unit>(unitEnum.keyToValue("Unit" + stateVariant.toMap().value("unit").toByteArray())));
|
||||
}
|
||||
}
|
||||
stateTypes.append(stateType);
|
||||
|
||||
EventType stateChangeEventType;
|
||||
|
|
|
|||
|
|
@ -594,6 +594,12 @@ void PluginMetadata::parse(const QJsonObject &jsonObject)
|
|||
hasError = true;
|
||||
continue;
|
||||
}
|
||||
if (ifaceStateType.unit() != Types::UnitNone && ifaceStateType.unit() != stateType.unit()) {
|
||||
QMetaEnum unitEnum = QMetaEnum::fromType<Types::Unit>();
|
||||
m_validationErrors.append("Device class \"" + deviceClass.name() + "\" claims to implement interface \"" + value.toString() + "\" but state \"" + stateType.name() + "\" has not matching unit: \"" + unitEnum.valueToKey(ifaceStateType.unit()) + "\" != \"" + unitEnum.valueToKey(stateType.unit()));
|
||||
hasError = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (const ActionType &ifaceActionType, iface.actionTypes()) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
{
|
||||
"name": "conductivity",
|
||||
"type": "double",
|
||||
"unit": "UnitMicroSiemensPerCentimeter"
|
||||
"unit": "MicroSiemensPerCentimeter"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
"states": [
|
||||
{
|
||||
"name": "currentPower",
|
||||
"type": "double"
|
||||
"type": "double",
|
||||
"unit": "Watt"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
"states": [
|
||||
{
|
||||
"name": "totalEnergyConsumed",
|
||||
"type": "double"
|
||||
"type": "double",
|
||||
"unit": "KiloWattHour"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue