From 311fb7bfa493acd19ab9e89727c30533f4f858cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Tue, 3 Dec 2024 16:20:02 +0100 Subject: [PATCH] Introduce interfaces mechanism for ThingClass paramTypes --- libnymea/integrations/pluginmetadata.cpp | 66 +++++++++++++++++-- libnymea/integrations/pluginmetadata.h | 2 +- libnymea/integrations/thingutils.cpp | 40 ++++++++++- libnymea/libnymea.pro | 2 + libnymea/types/interface.cpp | 16 +++-- libnymea/types/interface.h | 7 +- libnymea/types/interfaceactiontype.cpp | 30 +++++++++ libnymea/types/interfaceactiontype.h | 30 +++++++++ libnymea/types/interfaceeventtype.cpp | 30 +++++++++ libnymea/types/interfaceeventtype.h | 30 +++++++++ libnymea/types/interfaceparamtype.cpp | 64 ++++++++++++++++++ libnymea/types/interfaceparamtype.h | 58 ++++++++++++++++ libnymea/types/interfacestatetype.cpp | 30 +++++++++ libnymea/types/interfacestatetype.h | 30 +++++++++ libnymea/types/paramtype.cpp | 34 +++++++++- libnymea/types/paramtype.h | 6 +- .../nymea-plugininfocompiler.pro | 2 + 17 files changed, 461 insertions(+), 16 deletions(-) create mode 100644 libnymea/types/interfaceparamtype.cpp create mode 100644 libnymea/types/interfaceparamtype.h diff --git a/libnymea/integrations/pluginmetadata.cpp b/libnymea/integrations/pluginmetadata.cpp index 2051bc41..3bf5faca 100644 --- a/libnymea/integrations/pluginmetadata.cpp +++ b/libnymea/integrations/pluginmetadata.cpp @@ -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 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 ¶mType = 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(); + 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()) { diff --git a/libnymea/integrations/pluginmetadata.h b/libnymea/integrations/pluginmetadata.h index 0ba68cfc..2c10e59c 100644 --- a/libnymea/integrations/pluginmetadata.h +++ b/libnymea/integrations/pluginmetadata.h @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2024, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. diff --git a/libnymea/integrations/thingutils.cpp b/libnymea/integrations/thingutils.cpp index 832b6c7b..e1a40b02 100644 --- a/libnymea/integrations/thingutils.cpp +++ b/libnymea/integrations/thingutils.cpp @@ -189,9 +189,39 @@ Interface ThingUtils::loadInterface(const QString &name) } } + InterfaceParamTypes paramTypes; InterfaceStateTypes stateTypes; InterfaceActionTypes actionTypes; InterfaceEventTypes eventTypes; + + foreach (const QVariant ¶mVariant, 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(); + 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(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) diff --git a/libnymea/libnymea.pro b/libnymea/libnymea.pro index a8752900..c183dda8 100644 --- a/libnymea/libnymea.pro +++ b/libnymea/libnymea.pro @@ -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 \ diff --git a/libnymea/types/interface.cpp b/libnymea/types/interface.cpp index 83d72e75..72febf8a 100644 --- a/libnymea/types/interface.cpp +++ b/libnymea/types/interface.cpp @@ -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 ¶mTypes, 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; diff --git a/libnymea/types/interface.h b/libnymea/types/interface.h index 8715fdf0..b95b7da7 100644 --- a/libnymea/types/interface.h +++ b/libnymea/types/interface.h @@ -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 ¶mTypes, 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; diff --git a/libnymea/types/interfaceactiontype.cpp b/libnymea/types/interfaceactiontype.cpp index ef66d56e..e793181e 100644 --- a/libnymea/types/interfaceactiontype.cpp +++ b/libnymea/types/interfaceactiontype.cpp @@ -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 . +* +* 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() diff --git a/libnymea/types/interfaceactiontype.h b/libnymea/types/interfaceactiontype.h index 1e650722..792c9890 100644 --- a/libnymea/types/interfaceactiontype.h +++ b/libnymea/types/interfaceactiontype.h @@ -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 . +* +* 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 diff --git a/libnymea/types/interfaceeventtype.cpp b/libnymea/types/interfaceeventtype.cpp index 6b1017d3..97338da3 100644 --- a/libnymea/types/interfaceeventtype.cpp +++ b/libnymea/types/interfaceeventtype.cpp @@ -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 . +* +* 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() diff --git a/libnymea/types/interfaceeventtype.h b/libnymea/types/interfaceeventtype.h index 84eca98f..5dd369c7 100644 --- a/libnymea/types/interfaceeventtype.h +++ b/libnymea/types/interfaceeventtype.h @@ -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 . +* +* 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 diff --git a/libnymea/types/interfaceparamtype.cpp b/libnymea/types/interfaceparamtype.cpp new file mode 100644 index 00000000..b1b6e4fa --- /dev/null +++ b/libnymea/types/interfaceparamtype.cpp @@ -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 . +* +* 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 &other) + : QList(other) +{ + +} + +InterfaceParamType InterfaceParamTypes::findByName(const QString &name) +{ + foreach (const InterfaceParamType &ipt, *this) { + if (ipt.name() == name) { + return ipt; + } + } + return InterfaceParamType(); +} diff --git a/libnymea/types/interfaceparamtype.h b/libnymea/types/interfaceparamtype.h new file mode 100644 index 00000000..f88ac036 --- /dev/null +++ b/libnymea/types/interfaceparamtype.h @@ -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 . +* +* 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 +{ +public: + InterfaceParamTypes() = default; + InterfaceParamTypes(const QList &other); + InterfaceParamType findByName(const QString &name); +}; + + +#endif // INTERFACEPARAMTYPE_H diff --git a/libnymea/types/interfacestatetype.cpp b/libnymea/types/interfacestatetype.cpp index 02c72567..6a6f84aa 100644 --- a/libnymea/types/interfacestatetype.cpp +++ b/libnymea/types/interfacestatetype.cpp @@ -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 . +* +* 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() diff --git a/libnymea/types/interfacestatetype.h b/libnymea/types/interfacestatetype.h index 946ea404..ed0c9e4b 100644 --- a/libnymea/types/interfacestatetype.h +++ b/libnymea/types/interfacestatetype.h @@ -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 . +* +* 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 diff --git a/libnymea/types/paramtype.cpp b/libnymea/types/paramtype.cpp index f78eb6c0..e941a851 100644 --- a/libnymea/types/paramtype.cpp +++ b/libnymea/types/paramtype.cpp @@ -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 &other): QList(other) { } +bool ParamTypes::contains(const ParamTypeId ¶mTypeId) +{ + foreach (const ParamType ¶mType, *this) { + if (paramType.id() == paramTypeId) { + return true; + } + } + return false; +} + +bool ParamTypes::contains(const QString &name) +{ + foreach (const ParamType ¶mType, *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); +} diff --git a/libnymea/types/paramtype.h b/libnymea/types/paramtype.h index 8f8cede2..c3bcacca 100644 --- a/libnymea/types/paramtype.h +++ b/libnymea/types/paramtype.h @@ -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 public: ParamTypes() = default; ParamTypes(const QList &other); + bool contains(const ParamTypeId ¶mTypeId); + 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) Q_DECLARE_METATYPE(ParamTypes) diff --git a/tools/nymea-plugininfocompiler/nymea-plugininfocompiler.pro b/tools/nymea-plugininfocompiler/nymea-plugininfocompiler.pro index e900232b..04bb1830 100644 --- a/tools/nymea-plugininfocompiler/nymea-plugininfocompiler.pro +++ b/tools/nymea-plugininfocompiler/nymea-plugininfocompiler.pro @@ -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 \