Introduce interfaces mechanism for ThingClass paramTypes

This commit is contained in:
Simon Stürz 2024-12-03 16:20:02 +01:00
parent 4fe03a10ea
commit 311fb7bfa4
17 changed files with 461 additions and 16 deletions

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2024, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
@ -202,9 +202,9 @@ void PluginMetadata::parse(const QJsonObject &jsonObject)
QJsonObject thingClassObject = thingClassJson.toObject();
/*! Returns a list of all valid JSON properties a ThingClass JSON definition can have. */
QStringList thingClassProperties = QStringList() << "id" << "name" << "displayName" << "createMethods" << "setupMethod"
<< "interfaces" << "providedInterfaces" << "browsable" << "discoveryParamTypes"
<< "paramTypes" << "settingsTypes" << "stateTypes" << "actionTypes" << "eventTypes" << "browserItemActionTypes"
<< "discoveryType";
<< "interfaces" << "providedInterfaces" << "browsable" << "discoveryParamTypes"
<< "paramTypes" << "settingsTypes" << "stateTypes" << "actionTypes" << "eventTypes" << "browserItemActionTypes"
<< "discoveryType";
QStringList mandatoryThingClassProperties = QStringList() << "id" << "name" << "displayName";
QPair<QStringList, QStringList> verificationResult = verifyFields(thingClassProperties, mandatoryThingClassProperties, thingClassObject);
@ -703,6 +703,64 @@ void PluginMetadata::parse(const QJsonObject &jsonObject)
continue;
}
foreach (const InterfaceParamType &ifaceParamType, iface.paramTypes()) {
if (!thingClass.paramTypes().contains(ifaceParamType.name())) {
if (!ifaceParamType.optional()) {
m_validationErrors.append("Thing class \"" + thingClass.name() + "\" claims to implement interface \"" + value.toString() +
"\" but doesn't implement param \"" + ifaceParamType.name() + "\"");
hasError = true;
}
continue;
}
ParamType &paramType = thingClass.paramTypes()[ifaceParamType.name()];
if (ifaceParamType.type() != paramType.type()) {
m_validationErrors.append("Thing class \"" + thingClass.name() + "\" claims to implement interface \"" + value.toString() +
"\" but param \"" + paramType.name() + "\" has not matching type: \"" +
QVariant::typeToName(paramType.type()) + "\" != \"" + QVariant::typeToName(ifaceParamType.type()) + "\"");
hasError = true;
}
if (ifaceParamType.minValue().isValid() && !ifaceParamType.minValue().isNull()) {
if (ifaceParamType.minValue().toString() == "any") {
if (paramType.minValue().isNull()) {
m_validationErrors.append("Thing class \"" + thingClass.name() + "\" claims to implement interface \"" + value.toString() +
"\" but param \"" + paramType.name() + "\" has no minimum value defined.");
hasError = true;
}
} else if (ifaceParamType.minValue() != paramType.minValue()) {
m_validationErrors.append("Thing class \"" + thingClass.name() + "\" claims to implement interface \"" + value.toString() +
"\" but param \"" + paramType.name() + "\" has not matching minimum value: \"" +
ifaceParamType.minValue().toString() + "\" != \"" + paramType.minValue().toString() + "\"");
hasError = true;
}
}
if (ifaceParamType.maxValue().isValid() && !ifaceParamType.maxValue().isNull()) {
if (ifaceParamType.maxValue().toString() == "any") {
if (paramType.maxValue().isNull()) {
m_validationErrors.append("Thing class \"" + thingClass.name() + "\" claims to implement interface \"" + value.toString() +
"\" but param \"" + paramType.name() + "\" has no maximum value defined.");
hasError = true;
}
} else if (ifaceParamType.maxValue() != paramType.maxValue()) {
m_validationErrors.append("Thing class \"" + thingClass.name() + "\" claims to implement interface \"" + value.toString() +
"\" but param \"" + paramType.name() + "\" has not matching maximum value: \"" +
ifaceParamType.maxValue().toString() + "\" != \"" + paramType.minValue().toString() + "\"");
hasError = true;
}
}
if (!ifaceParamType.allowedValues().isEmpty() && ifaceParamType.allowedValues() != paramType.allowedValues()) {
m_validationErrors.append("Thing class \"" + thingClass.name() + "\" claims to implement interface \"" + value.toString() + "\" but param \"" +
paramType.name() + "\" has not matching allowed values.");
hasError = true;
}
if (ifaceParamType.unit() != Types::UnitNone && ifaceParamType.unit() != paramType.unit()) {
QMetaEnum unitEnum = QMetaEnum::fromType<Types::Unit>();
m_validationErrors.append("Thing class \"" + thingClass.name() + "\" claims to implement interface \"" + value.toString() + "\" but param \"" +
paramType.name() + "\" has not matching unit: \"" + unitEnum.valueToKey(ifaceParamType.unit()) + "\" != \"" + unitEnum.valueToKey(paramType.unit()));
hasError = true;
}
}
foreach (const InterfaceStateType &ifaceStateType, iface.stateTypes()) {
if (!stateTypes.contains(ifaceStateType.name())) {
if (!ifaceStateType.optional()) {

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2024, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -189,9 +189,39 @@ Interface ThingUtils::loadInterface(const QString &name)
}
}
InterfaceParamTypes paramTypes;
InterfaceStateTypes stateTypes;
InterfaceActionTypes actionTypes;
InterfaceEventTypes eventTypes;
foreach (const QVariant &paramVariant, content.value("params").toList()) {
QVariantMap paramMap = paramVariant.toMap();
InterfaceParamType paramType;
paramType.setName(paramMap.value("name").toString());
paramType.setType(QVariant::nameToType(paramMap.value("type").toByteArray()));
paramType.setMinValue(paramMap.value("minValue"));
paramType.setMaxValue(paramMap.value("maxValue"));
paramType.setDefaultValue(paramMap.value("defaultValue"));
paramType.setAllowedValues(paramMap.value("allowedValues").toList());
paramType.setReadOnly(paramMap.value("readOnly").toBool());
//paramType.setOptional(paramMap.value("optional", false).toBool());
if (paramMap.contains("unit")) {
QMetaEnum unitEnum = QMetaEnum::fromType<Types::Unit>();
int enumValue = unitEnum.keyToValue("Unit" + paramMap.value("unit").toByteArray());
if (enumValue == -1) {
qCWarning(dcThingManager) << "Invalid unit" << paramMap.value("unit").toString() << "in interface" << name;
} else {
paramType.setUnit(static_cast<Types::Unit>(enumValue));
}
} else {
paramType.setUnit(Types::UnitNone);
}
paramTypes.append(paramType);
}
foreach (const QVariant &stateVariant, content.value("states").toList()) {
QVariantMap stateMap = stateVariant.toMap();
InterfaceStateType stateType;
@ -279,11 +309,17 @@ Interface ThingUtils::loadInterface(const QString &name)
eventTypes.append(eventType);
}
return Interface(name, iface.actionTypes() << actionTypes, iface.eventTypes() << eventTypes, iface.stateTypes() << stateTypes);
return Interface(name, iface.paramTypes() << paramTypes, iface.actionTypes() << actionTypes, iface.eventTypes() << eventTypes, iface.stateTypes() << stateTypes);
}
Interface ThingUtils::mergeInterfaces(const Interface &iface1, const Interface &iface2)
{
InterfaceParamTypes paramTypes = iface1.paramTypes();
foreach (const InterfaceParamType &pt, iface2.paramTypes()) {
if (paramTypes.findByName(pt.name()).name().isEmpty()) {
paramTypes.append(pt);
}
}
InterfaceEventTypes eventTypes = iface1.eventTypes();
foreach (const InterfaceEventType &et, iface2.eventTypes()) {
if (eventTypes.findByName(et.name()).name().isEmpty()) {
@ -302,7 +338,7 @@ Interface ThingUtils::mergeInterfaces(const Interface &iface1, const Interface &
actionTypes.append(at);
}
}
return Interface(QString(), actionTypes, eventTypes, stateTypes);
return Interface(QString(), paramTypes, actionTypes, eventTypes, stateTypes);
}
QStringList ThingUtils::generateInterfaceParentList(const QString &interface)

View File

@ -72,6 +72,7 @@ HEADERS += \
types/browseraction.h \
types/interfaceactiontype.h \
types/interfaceeventtype.h \
types/interfaceparamtype.h \
types/interfacestatetype.h \
types/mediabrowseritem.h \
types/thingclass.h \
@ -214,6 +215,7 @@ SOURCES += \
types/browseraction.cpp \
types/interfaceactiontype.cpp \
types/interfaceeventtype.cpp \
types/interfaceparamtype.cpp \
types/interfacestatetype.cpp \
types/mediabrowseritem.cpp \
types/action.cpp \

View File

@ -30,11 +30,12 @@
#include "interface.h"
Interface::Interface(const QString &name, const InterfaceActionTypes &actionTypes, const InterfaceEventTypes &eventTypes, const InterfaceStateTypes &stateTypes):
m_name(name),
m_actionTypes(actionTypes),
m_eventTypes(eventTypes),
m_stateTypes(stateTypes)
Interface::Interface(const QString &name, const InterfaceParamTypes &paramTypes, const InterfaceActionTypes &actionTypes, const InterfaceEventTypes &eventTypes, const InterfaceStateTypes &stateTypes):
m_name{name},
m_paramTypes{paramTypes},
m_actionTypes{actionTypes},
m_eventTypes{eventTypes},
m_stateTypes{stateTypes}
{
}
@ -44,6 +45,11 @@ QString Interface::name() const
return m_name;
}
InterfaceParamTypes Interface::paramTypes() const
{
return m_paramTypes;
}
InterfaceActionTypes Interface::actionTypes() const
{
return m_actionTypes;

View File

@ -31,6 +31,7 @@
#ifndef INTERFACE_H
#define INTERFACE_H
#include "interfaceparamtype.h"
#include "interfaceeventtype.h"
#include "interfaceactiontype.h"
#include "interfacestatetype.h"
@ -38,18 +39,20 @@
class Interface{
public:
Interface() = default;
Interface(const QString &name, const InterfaceActionTypes &actionTypes, const InterfaceEventTypes &eventTypes, const InterfaceStateTypes &stateTypes);
Interface(const QString &name, const InterfaceParamTypes &paramTypes, const InterfaceActionTypes &actionTypes, const InterfaceEventTypes &eventTypes, const InterfaceStateTypes &stateTypes);
QString name() const;
InterfaceParamTypes paramTypes() const;
InterfaceActionTypes actionTypes() const;
InterfaceEventTypes eventTypes() const;
InterfaceStateTypes stateTypes() const;
bool isValid() const;
private:
QUuid m_id;
QString m_name;
InterfaceParamTypes m_paramTypes;
InterfaceActionTypes m_actionTypes;
InterfaceEventTypes m_eventTypes;
InterfaceStateTypes m_stateTypes;

View File

@ -1,3 +1,33 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2024, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
* This project including source code and documentation is protected by
* copyright law, and remains the property of nymea GmbH. All rights, including
* reproduction, publication, editing and translation, are reserved. The use of
* this project is subject to the terms of a license agreement to be concluded
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
* under https://nymea.io/license
*
* GNU Lesser General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; version 3. This project is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this project. If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under
* contact@nymea.io or see our FAQ/Licensing Information on
* https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "interfaceactiontype.h"
InterfaceActionType::InterfaceActionType()

View File

@ -1,3 +1,33 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2024, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
* This project including source code and documentation is protected by
* copyright law, and remains the property of nymea GmbH. All rights, including
* reproduction, publication, editing and translation, are reserved. The use of
* this project is subject to the terms of a license agreement to be concluded
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
* under https://nymea.io/license
*
* GNU Lesser General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; version 3. This project is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this project. If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under
* contact@nymea.io or see our FAQ/Licensing Information on
* https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef INTERFACEACTIONTYPE_H
#define INTERFACEACTIONTYPE_H

View File

@ -1,3 +1,33 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2024, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
* This project including source code and documentation is protected by
* copyright law, and remains the property of nymea GmbH. All rights, including
* reproduction, publication, editing and translation, are reserved. The use of
* this project is subject to the terms of a license agreement to be concluded
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
* under https://nymea.io/license
*
* GNU Lesser General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; version 3. This project is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this project. If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under
* contact@nymea.io or see our FAQ/Licensing Information on
* https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "interfaceeventtype.h"
InterfaceEventType::InterfaceEventType()

View File

@ -1,3 +1,33 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2024, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
* This project including source code and documentation is protected by
* copyright law, and remains the property of nymea GmbH. All rights, including
* reproduction, publication, editing and translation, are reserved. The use of
* this project is subject to the terms of a license agreement to be concluded
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
* under https://nymea.io/license
*
* GNU Lesser General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; version 3. This project is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this project. If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under
* contact@nymea.io or see our FAQ/Licensing Information on
* https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef INTERFACEEVENTTYPE_H
#define INTERFACEEVENTTYPE_H

View File

@ -0,0 +1,64 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2024, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
* This project including source code and documentation is protected by
* copyright law, and remains the property of nymea GmbH. All rights, including
* reproduction, publication, editing and translation, are reserved. The use of
* this project is subject to the terms of a license agreement to be concluded
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
* under https://nymea.io/license
*
* GNU Lesser General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; version 3. This project is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this project. If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under
* contact@nymea.io or see our FAQ/Licensing Information on
* https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "interfaceparamtype.h"
InterfaceParamType::InterfaceParamType()
{
}
bool InterfaceParamType::optional() const
{
return m_optional;
}
void InterfaceParamType::setOptional(bool optional)
{
m_optional = optional;
}
InterfaceParamTypes::InterfaceParamTypes(const QList<InterfaceParamType> &other)
: QList<InterfaceParamType>(other)
{
}
InterfaceParamType InterfaceParamTypes::findByName(const QString &name)
{
foreach (const InterfaceParamType &ipt, *this) {
if (ipt.name() == name) {
return ipt;
}
}
return InterfaceParamType();
}

View File

@ -0,0 +1,58 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2024, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
* This project including source code and documentation is protected by
* copyright law, and remains the property of nymea GmbH. All rights, including
* reproduction, publication, editing and translation, are reserved. The use of
* this project is subject to the terms of a license agreement to be concluded
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
* under https://nymea.io/license
*
* GNU Lesser General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; version 3. This project is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this project. If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under
* contact@nymea.io or see our FAQ/Licensing Information on
* https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef INTERFACEPARAMTYPE_H
#define INTERFACEPARAMTYPE_H
#include "paramtype.h"
class InterfaceParamType : public ParamType
{
public:
InterfaceParamType();
bool optional() const;
void setOptional(bool optional);
private:
bool m_optional = false;
};
class InterfaceParamTypes: public QList<InterfaceParamType>
{
public:
InterfaceParamTypes() = default;
InterfaceParamTypes(const QList<InterfaceParamType> &other);
InterfaceParamType findByName(const QString &name);
};
#endif // INTERFACEPARAMTYPE_H

View File

@ -1,3 +1,33 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2024, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
* This project including source code and documentation is protected by
* copyright law, and remains the property of nymea GmbH. All rights, including
* reproduction, publication, editing and translation, are reserved. The use of
* this project is subject to the terms of a license agreement to be concluded
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
* under https://nymea.io/license
*
* GNU Lesser General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; version 3. This project is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this project. If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under
* contact@nymea.io or see our FAQ/Licensing Information on
* https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "interfacestatetype.h"
InterfaceStateType::InterfaceStateType()

View File

@ -1,3 +1,33 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2024, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
* This project including source code and documentation is protected by
* copyright law, and remains the property of nymea GmbH. All rights, including
* reproduction, publication, editing and translation, are reserved. The use of
* this project is subject to the terms of a license agreement to be concluded
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
* under https://nymea.io/license
*
* GNU Lesser General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; version 3. This project is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this project. If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under
* contact@nymea.io or see our FAQ/Licensing Information on
* https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef INTERFACESTATETYPE_H
#define INTERFACESTATETYPE_H

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2024, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
@ -264,6 +264,26 @@ ParamTypes::ParamTypes(const QList<ParamType> &other): QList<ParamType>(other)
{
}
bool ParamTypes::contains(const ParamTypeId &paramTypeId)
{
foreach (const ParamType &paramType, *this) {
if (paramType.id() == paramTypeId) {
return true;
}
}
return false;
}
bool ParamTypes::contains(const QString &name)
{
foreach (const ParamType &paramType, *this) {
if (paramType.name() == name) {
return true;
}
}
return false;
}
QVariant ParamTypes::get(int index) const
{
return QVariant::fromValue(at(index));
@ -293,3 +313,15 @@ ParamType ParamTypes::findById(const ParamTypeId &id) const
}
return ParamType();
}
ParamType &ParamTypes::operator[](const QString &name)
{
int index = -1;
for (int i = 0; i < count(); i++) {
if (at(i).name() == name) {
index = i;
break;
}
}
return QList::operator[](index);
}

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2024, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
@ -122,10 +122,14 @@ class ParamTypes: public QList<ParamType>
public:
ParamTypes() = default;
ParamTypes(const QList<ParamType> &other);
bool contains(const ParamTypeId &paramTypeId);
bool contains(const QString &name);
Q_INVOKABLE QVariant get(int index) const;
Q_INVOKABLE void put(const QVariant &variant);
ParamType findByName(const QString &name) const;
ParamType findById(const ParamTypeId &id) const;
ParamType &operator[](const QString &name);
};
Q_DECLARE_METATYPE(QList<ParamType>)
Q_DECLARE_METATYPE(ParamTypes)

View File

@ -24,6 +24,7 @@ SOURCES += \
$$top_srcdir/libnymea/types/eventtype.cpp \
$$top_srcdir/libnymea/types/actiontype.cpp \
$$top_srcdir/libnymea/types/interface.cpp \
$$top_srcdir/libnymea/types/interfaceparamtype.cpp \
$$top_srcdir/libnymea/types/interfacestatetype.cpp \
$$top_srcdir/libnymea/types/interfaceeventtype.cpp \
$$top_srcdir/libnymea/types/interfaceactiontype.cpp \
@ -42,6 +43,7 @@ HEADERS += \
$$top_srcdir/libnymea/types/eventtype.h \
$$top_srcdir/libnymea/types/actiontype.h \
$$top_srcdir/libnymea/types/interface.h \
$$top_srcdir/libnymea/types/interfaceparamtype.h \
$$top_srcdir/libnymea/types/interfacestatetype.h \
$$top_srcdir/libnymea/types/interfaceeventtype.h \
$$top_srcdir/libnymea/types/interfaceactiontype.h \