Introduce interfaces mechanism for ThingClass paramTypes
This commit is contained in:
parent
4fe03a10ea
commit
311fb7bfa4
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2024, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
@ -202,9 +202,9 @@ void PluginMetadata::parse(const QJsonObject &jsonObject)
|
|||||||
QJsonObject thingClassObject = thingClassJson.toObject();
|
QJsonObject thingClassObject = thingClassJson.toObject();
|
||||||
/*! Returns a list of all valid JSON properties a ThingClass JSON definition can have. */
|
/*! Returns a list of all valid JSON properties a ThingClass JSON definition can have. */
|
||||||
QStringList thingClassProperties = QStringList() << "id" << "name" << "displayName" << "createMethods" << "setupMethod"
|
QStringList thingClassProperties = QStringList() << "id" << "name" << "displayName" << "createMethods" << "setupMethod"
|
||||||
<< "interfaces" << "providedInterfaces" << "browsable" << "discoveryParamTypes"
|
<< "interfaces" << "providedInterfaces" << "browsable" << "discoveryParamTypes"
|
||||||
<< "paramTypes" << "settingsTypes" << "stateTypes" << "actionTypes" << "eventTypes" << "browserItemActionTypes"
|
<< "paramTypes" << "settingsTypes" << "stateTypes" << "actionTypes" << "eventTypes" << "browserItemActionTypes"
|
||||||
<< "discoveryType";
|
<< "discoveryType";
|
||||||
QStringList mandatoryThingClassProperties = QStringList() << "id" << "name" << "displayName";
|
QStringList mandatoryThingClassProperties = QStringList() << "id" << "name" << "displayName";
|
||||||
|
|
||||||
QPair<QStringList, QStringList> verificationResult = verifyFields(thingClassProperties, mandatoryThingClassProperties, thingClassObject);
|
QPair<QStringList, QStringList> verificationResult = verifyFields(thingClassProperties, mandatoryThingClassProperties, thingClassObject);
|
||||||
@ -703,6 +703,64 @@ void PluginMetadata::parse(const QJsonObject &jsonObject)
|
|||||||
continue;
|
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<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()) {
|
foreach (const InterfaceStateType &ifaceStateType, iface.stateTypes()) {
|
||||||
if (!stateTypes.contains(ifaceStateType.name())) {
|
if (!stateTypes.contains(ifaceStateType.name())) {
|
||||||
if (!ifaceStateType.optional()) {
|
if (!ifaceStateType.optional()) {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2024, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
|
|||||||
@ -189,9 +189,39 @@ Interface ThingUtils::loadInterface(const QString &name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InterfaceParamTypes paramTypes;
|
||||||
InterfaceStateTypes stateTypes;
|
InterfaceStateTypes stateTypes;
|
||||||
InterfaceActionTypes actionTypes;
|
InterfaceActionTypes actionTypes;
|
||||||
InterfaceEventTypes eventTypes;
|
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<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()) {
|
foreach (const QVariant &stateVariant, content.value("states").toList()) {
|
||||||
QVariantMap stateMap = stateVariant.toMap();
|
QVariantMap stateMap = stateVariant.toMap();
|
||||||
InterfaceStateType stateType;
|
InterfaceStateType stateType;
|
||||||
@ -279,11 +309,17 @@ Interface ThingUtils::loadInterface(const QString &name)
|
|||||||
eventTypes.append(eventType);
|
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)
|
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();
|
InterfaceEventTypes eventTypes = iface1.eventTypes();
|
||||||
foreach (const InterfaceEventType &et, iface2.eventTypes()) {
|
foreach (const InterfaceEventType &et, iface2.eventTypes()) {
|
||||||
if (eventTypes.findByName(et.name()).name().isEmpty()) {
|
if (eventTypes.findByName(et.name()).name().isEmpty()) {
|
||||||
@ -302,7 +338,7 @@ Interface ThingUtils::mergeInterfaces(const Interface &iface1, const Interface &
|
|||||||
actionTypes.append(at);
|
actionTypes.append(at);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Interface(QString(), actionTypes, eventTypes, stateTypes);
|
return Interface(QString(), paramTypes, actionTypes, eventTypes, stateTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ThingUtils::generateInterfaceParentList(const QString &interface)
|
QStringList ThingUtils::generateInterfaceParentList(const QString &interface)
|
||||||
|
|||||||
@ -72,6 +72,7 @@ HEADERS += \
|
|||||||
types/browseraction.h \
|
types/browseraction.h \
|
||||||
types/interfaceactiontype.h \
|
types/interfaceactiontype.h \
|
||||||
types/interfaceeventtype.h \
|
types/interfaceeventtype.h \
|
||||||
|
types/interfaceparamtype.h \
|
||||||
types/interfacestatetype.h \
|
types/interfacestatetype.h \
|
||||||
types/mediabrowseritem.h \
|
types/mediabrowseritem.h \
|
||||||
types/thingclass.h \
|
types/thingclass.h \
|
||||||
@ -214,6 +215,7 @@ SOURCES += \
|
|||||||
types/browseraction.cpp \
|
types/browseraction.cpp \
|
||||||
types/interfaceactiontype.cpp \
|
types/interfaceactiontype.cpp \
|
||||||
types/interfaceeventtype.cpp \
|
types/interfaceeventtype.cpp \
|
||||||
|
types/interfaceparamtype.cpp \
|
||||||
types/interfacestatetype.cpp \
|
types/interfacestatetype.cpp \
|
||||||
types/mediabrowseritem.cpp \
|
types/mediabrowseritem.cpp \
|
||||||
types/action.cpp \
|
types/action.cpp \
|
||||||
|
|||||||
@ -30,11 +30,12 @@
|
|||||||
|
|
||||||
#include "interface.h"
|
#include "interface.h"
|
||||||
|
|
||||||
Interface::Interface(const QString &name, const InterfaceActionTypes &actionTypes, const InterfaceEventTypes &eventTypes, const InterfaceStateTypes &stateTypes):
|
Interface::Interface(const QString &name, const InterfaceParamTypes ¶mTypes, const InterfaceActionTypes &actionTypes, const InterfaceEventTypes &eventTypes, const InterfaceStateTypes &stateTypes):
|
||||||
m_name(name),
|
m_name{name},
|
||||||
m_actionTypes(actionTypes),
|
m_paramTypes{paramTypes},
|
||||||
m_eventTypes(eventTypes),
|
m_actionTypes{actionTypes},
|
||||||
m_stateTypes(stateTypes)
|
m_eventTypes{eventTypes},
|
||||||
|
m_stateTypes{stateTypes}
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -44,6 +45,11 @@ QString Interface::name() const
|
|||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InterfaceParamTypes Interface::paramTypes() const
|
||||||
|
{
|
||||||
|
return m_paramTypes;
|
||||||
|
}
|
||||||
|
|
||||||
InterfaceActionTypes Interface::actionTypes() const
|
InterfaceActionTypes Interface::actionTypes() const
|
||||||
{
|
{
|
||||||
return m_actionTypes;
|
return m_actionTypes;
|
||||||
|
|||||||
@ -31,6 +31,7 @@
|
|||||||
#ifndef INTERFACE_H
|
#ifndef INTERFACE_H
|
||||||
#define INTERFACE_H
|
#define INTERFACE_H
|
||||||
|
|
||||||
|
#include "interfaceparamtype.h"
|
||||||
#include "interfaceeventtype.h"
|
#include "interfaceeventtype.h"
|
||||||
#include "interfaceactiontype.h"
|
#include "interfaceactiontype.h"
|
||||||
#include "interfacestatetype.h"
|
#include "interfacestatetype.h"
|
||||||
@ -38,18 +39,20 @@
|
|||||||
class Interface{
|
class Interface{
|
||||||
public:
|
public:
|
||||||
Interface() = default;
|
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;
|
QString name() const;
|
||||||
|
|
||||||
|
InterfaceParamTypes paramTypes() const;
|
||||||
InterfaceActionTypes actionTypes() const;
|
InterfaceActionTypes actionTypes() const;
|
||||||
InterfaceEventTypes eventTypes() const;
|
InterfaceEventTypes eventTypes() const;
|
||||||
InterfaceStateTypes stateTypes() const;
|
InterfaceStateTypes stateTypes() const;
|
||||||
|
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid m_id;
|
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
InterfaceParamTypes m_paramTypes;
|
||||||
InterfaceActionTypes m_actionTypes;
|
InterfaceActionTypes m_actionTypes;
|
||||||
InterfaceEventTypes m_eventTypes;
|
InterfaceEventTypes m_eventTypes;
|
||||||
InterfaceStateTypes m_stateTypes;
|
InterfaceStateTypes m_stateTypes;
|
||||||
|
|||||||
@ -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"
|
#include "interfaceactiontype.h"
|
||||||
|
|
||||||
InterfaceActionType::InterfaceActionType()
|
InterfaceActionType::InterfaceActionType()
|
||||||
|
|||||||
@ -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
|
#ifndef INTERFACEACTIONTYPE_H
|
||||||
#define INTERFACEACTIONTYPE_H
|
#define 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 <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"
|
#include "interfaceeventtype.h"
|
||||||
|
|
||||||
InterfaceEventType::InterfaceEventType()
|
InterfaceEventType::InterfaceEventType()
|
||||||
|
|||||||
@ -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
|
#ifndef INTERFACEEVENTTYPE_H
|
||||||
#define INTERFACEEVENTTYPE_H
|
#define INTERFACEEVENTTYPE_H
|
||||||
|
|
||||||
|
|||||||
64
libnymea/types/interfaceparamtype.cpp
Normal file
64
libnymea/types/interfaceparamtype.cpp
Normal 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();
|
||||||
|
}
|
||||||
58
libnymea/types/interfaceparamtype.h
Normal file
58
libnymea/types/interfaceparamtype.h
Normal 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
|
||||||
@ -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"
|
#include "interfacestatetype.h"
|
||||||
|
|
||||||
InterfaceStateType::InterfaceStateType()
|
InterfaceStateType::InterfaceStateType()
|
||||||
|
|||||||
@ -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
|
#ifndef INTERFACESTATETYPE_H
|
||||||
#define INTERFACESTATETYPE_H
|
#define INTERFACESTATETYPE_H
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2024, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
@ -264,6 +264,26 @@ ParamTypes::ParamTypes(const QList<ParamType> &other): QList<ParamType>(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
|
QVariant ParamTypes::get(int index) const
|
||||||
{
|
{
|
||||||
return QVariant::fromValue(at(index));
|
return QVariant::fromValue(at(index));
|
||||||
@ -293,3 +313,15 @@ ParamType ParamTypes::findById(const ParamTypeId &id) const
|
|||||||
}
|
}
|
||||||
return ParamType();
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2024, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
@ -122,10 +122,14 @@ class ParamTypes: public QList<ParamType>
|
|||||||
public:
|
public:
|
||||||
ParamTypes() = default;
|
ParamTypes() = default;
|
||||||
ParamTypes(const QList<ParamType> &other);
|
ParamTypes(const QList<ParamType> &other);
|
||||||
|
bool contains(const ParamTypeId ¶mTypeId);
|
||||||
|
bool contains(const QString &name);
|
||||||
Q_INVOKABLE QVariant get(int index) const;
|
Q_INVOKABLE QVariant get(int index) const;
|
||||||
Q_INVOKABLE void put(const QVariant &variant);
|
Q_INVOKABLE void put(const QVariant &variant);
|
||||||
ParamType findByName(const QString &name) const;
|
ParamType findByName(const QString &name) const;
|
||||||
ParamType findById(const ParamTypeId &id) const;
|
ParamType findById(const ParamTypeId &id) const;
|
||||||
|
ParamType &operator[](const QString &name);
|
||||||
|
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(QList<ParamType>)
|
Q_DECLARE_METATYPE(QList<ParamType>)
|
||||||
Q_DECLARE_METATYPE(ParamTypes)
|
Q_DECLARE_METATYPE(ParamTypes)
|
||||||
|
|||||||
@ -24,6 +24,7 @@ SOURCES += \
|
|||||||
$$top_srcdir/libnymea/types/eventtype.cpp \
|
$$top_srcdir/libnymea/types/eventtype.cpp \
|
||||||
$$top_srcdir/libnymea/types/actiontype.cpp \
|
$$top_srcdir/libnymea/types/actiontype.cpp \
|
||||||
$$top_srcdir/libnymea/types/interface.cpp \
|
$$top_srcdir/libnymea/types/interface.cpp \
|
||||||
|
$$top_srcdir/libnymea/types/interfaceparamtype.cpp \
|
||||||
$$top_srcdir/libnymea/types/interfacestatetype.cpp \
|
$$top_srcdir/libnymea/types/interfacestatetype.cpp \
|
||||||
$$top_srcdir/libnymea/types/interfaceeventtype.cpp \
|
$$top_srcdir/libnymea/types/interfaceeventtype.cpp \
|
||||||
$$top_srcdir/libnymea/types/interfaceactiontype.cpp \
|
$$top_srcdir/libnymea/types/interfaceactiontype.cpp \
|
||||||
@ -42,6 +43,7 @@ HEADERS += \
|
|||||||
$$top_srcdir/libnymea/types/eventtype.h \
|
$$top_srcdir/libnymea/types/eventtype.h \
|
||||||
$$top_srcdir/libnymea/types/actiontype.h \
|
$$top_srcdir/libnymea/types/actiontype.h \
|
||||||
$$top_srcdir/libnymea/types/interface.h \
|
$$top_srcdir/libnymea/types/interface.h \
|
||||||
|
$$top_srcdir/libnymea/types/interfaceparamtype.h \
|
||||||
$$top_srcdir/libnymea/types/interfacestatetype.h \
|
$$top_srcdir/libnymea/types/interfacestatetype.h \
|
||||||
$$top_srcdir/libnymea/types/interfaceeventtype.h \
|
$$top_srcdir/libnymea/types/interfaceeventtype.h \
|
||||||
$$top_srcdir/libnymea/types/interfaceactiontype.h \
|
$$top_srcdir/libnymea/types/interfaceactiontype.h \
|
||||||
|
|||||||
Reference in New Issue
Block a user