Add network device mock thing

This commit is contained in:
Simon Stürz 2025-01-08 16:36:38 +01:00
parent 46ccc8a46b
commit 1c6fbc8d1e
5 changed files with 107 additions and 2 deletions

View File

@ -232,5 +232,10 @@ extern StateTypeId virtualIoTemperatureSensorMockInputStateTypeId;
extern StateTypeId virtualIoTemperatureSensorMockTemperatureStateTypeId;
extern ActionTypeId virtualIoTemperatureSensorMockInputActionTypeId;
extern ParamTypeId virtualIoTemperatureSensorMockInputActionInputParamTypeId;
extern ThingClassId networkDeviceMockThingClassId;
extern ParamTypeId networkDeviceMockThingMacAddressParamTypeId;
extern ParamTypeId networkDeviceMockThingHostNameParamTypeId;
extern ParamTypeId networkDeviceMockThingAddressParamTypeId;
extern ParamTypeId networkDeviceMockDiscoveryResultTypeParamTypeId;
#endif // EXTERNPLUGININFO_H

View File

@ -126,6 +126,27 @@ void IntegrationPluginMock::discoverThings(ThingDiscoveryInfo *info)
return;
}
if (info->thingClassId() == networkDeviceMockThingClassId) {
qCDebug(dcMock()) << "starting network device mock discovery:" << info->params();
QTimer::singleShot(1000, info, [info](){
QString resultType = info->params().paramValue(networkDeviceMockDiscoveryResultTypeParamTypeId).toString();
ParamList params;
if (resultType == "MAC address") {
params.append(Param(networkDeviceMockThingMacAddressParamTypeId, "00:11:22:33:44:55"));
} else if (resultType == "Host name") {
params.append(Param(networkDeviceMockThingHostNameParamTypeId, "hostname.localhost"));
} else if (resultType == "IP address") {
params.append(Param(networkDeviceMockThingAddressParamTypeId, "127.0.0.1"));
}
ThingDescriptor descriptor(networkDeviceMockThingClassId, "Mocked Thing (networkdevice)", QString());
descriptor.setParams(params);
info->addThingDescriptor(descriptor);
info->finish(Thing::ThingErrorNoError);
});
return;
}
qCWarning(dcMock()) << "Cannot discover for ThingClassId" << info->thingClassId();
info->finish(Thing::ThingErrorThingNotFound);
}
@ -273,6 +294,12 @@ void IntegrationPluginMock::setupThing(ThingSetupInfo *info)
return;
}
if (info->thing()->thingClassId() == networkDeviceMockThingClassId) {
qCDebug(dcMock()) << "Network device mock setup complete";
info->finish(Thing::ThingErrorNoError);
return;
}
qCWarning(dcMock()) << "Unhandled thing class" << info->thing()->thingClass();
info->finish(Thing::ThingErrorThingClassNotFound);
}

View File

@ -1198,6 +1198,59 @@
"defaultValue": -20
}
]
},
{
"id": "cd8fad43-174b-4ca4-a225-c07e4dbba10a",
"name": "networkDeviceMock",
"displayName": "Mocked Thing (network device)",
"interfaces": ["networkdevice"],
"createMethods": ["discovery", "user"],
"setupMethod": "justAdd",
"discoveryParamTypes": [
{
"id": "762d9bc3-c07e-42e7-8dab-62c980998677",
"name": "resultType",
"displayName": "Result type",
"type": "QString",
"defaultValue": "MAC address",
"allowedValues": [
"MAC address",
"Host name",
"IP address"
]
}
],
"paramTypes": [
{
"id": "5c2462ca-883e-4fe1-91f2-7190f9363247",
"name": "macAddress",
"displayName": "MAC address",
"type": "QString",
"defaultValue":"",
"inputType": "MacAddress",
"defaultValue": "",
"readOnly": true
},
{
"id": "ae867d45-c743-4185-87d3-1a027c985f11",
"name": "hostName",
"displayName": "Host name",
"type": "QString",
"inputType": "TextLine",
"defaultValue": ""
},
{
"id": "619fb102-0ebd-497e-9960-615c5d347db9",
"name": "address",
"displayName": "IP address",
"type": "QString",
"inputType": "IPv4Address",
"defaultValue": ""
}
],
"stateTypes": [ ],
"actionTypes": [ ],
"eventTypes": [ ]
}
]
}

View File

@ -236,6 +236,11 @@ StateTypeId virtualIoTemperatureSensorMockInputStateTypeId = StateTypeId("{fd341
StateTypeId virtualIoTemperatureSensorMockTemperatureStateTypeId = StateTypeId("{db9cc518-1012-47e2-8212-6e616fed07a6}");
ActionTypeId virtualIoTemperatureSensorMockInputActionTypeId = ActionTypeId("{fd341f72-6d9a-4812-9f66-47197c48a935}");
ParamTypeId virtualIoTemperatureSensorMockInputActionInputParamTypeId = ParamTypeId("{fd341f72-6d9a-4812-9f66-47197c48a935}");
ThingClassId networkDeviceMockThingClassId = ThingClassId("{cd8fad43-174b-4ca4-a225-c07e4dbba10a}");
ParamTypeId networkDeviceMockThingMacAddressParamTypeId = ParamTypeId("{5c2462ca-883e-4fe1-91f2-7190f9363247}");
ParamTypeId networkDeviceMockThingHostNameParamTypeId = ParamTypeId("{ae867d45-c743-4185-87d3-1a027c985f11}");
ParamTypeId networkDeviceMockThingAddressParamTypeId = ParamTypeId("{619fb102-0ebd-497e-9960-615c5d347db9}");
ParamTypeId networkDeviceMockDiscoveryResultTypeParamTypeId = ParamTypeId("{762d9bc3-c07e-42e7-8dab-62c980998677}");
const QString translations[] {
//: The name of the Browser Item ActionType ({00b8f0a8-99ca-4aa4-833d-59eb8d4d6de3}) of ThingClass mock
@ -361,6 +366,12 @@ const QString translations[] {
//: The name of the ThingClass ({f8917e12-c9cb-4ea1-a06e-1ce6db2194f3})
QT_TRANSLATE_NOOP("mock", "Generic Temperature Sensor (Mock)"),
//: The name of the ParamType (ThingClass: networkDeviceMock, Type: thing, ID: {ae867d45-c743-4185-87d3-1a027c985f11})
QT_TRANSLATE_NOOP("mock", "Host name"),
//: The name of the ParamType (ThingClass: networkDeviceMock, Type: thing, ID: {619fb102-0ebd-497e-9960-615c5d347db9})
QT_TRANSLATE_NOOP("mock", "IP address"),
//: The name of the ParamType (ThingClass: inputTypeMock, Type: thing, ID: {9e5f86a0-4bb3-4892-bff8-3fc4032af6e2})
QT_TRANSLATE_NOOP("mock", "IPv4 address"),
@ -388,6 +399,9 @@ const QString translations[] {
//: The name of the StateType ({23df3dce-bd10-4eb3-b5e3-221168440cd4}) of ThingClass inputTypeMock
QT_TRANSLATE_NOOP("mock", "Localized list"),
//: The name of the ParamType (ThingClass: networkDeviceMock, Type: thing, ID: {5c2462ca-883e-4fe1-91f2-7190f9363247})
QT_TRANSLATE_NOOP("mock", "MAC address"),
//: The name of the ParamType (ThingClass: inputTypeMock, Type: thing, ID: {e93db587-7919-48f3-8c88-1651de63c765})
QT_TRANSLATE_NOOP("mock", "Mac address"),
@ -481,6 +495,9 @@ const QString translations[] {
//: The name of the ThingClass ({6fe07a77-9c07-4736-81e2-d504314bbcb9})
QT_TRANSLATE_NOOP("mock", "Mocked Thing (User & Password)"),
//: The name of the ThingClass ({cd8fad43-174b-4ca4-a225-c07e4dbba10a})
QT_TRANSLATE_NOOP("mock", "Mocked Thing (network device)"),
//: The name of the plugin mock ({727a4a9a-c187-446f-aadf-f1b2220607d1})
QT_TRANSLATE_NOOP("mock", "Mocked things"),
@ -508,6 +525,9 @@ const QString translations[] {
//: The name of the ParamType (ThingClass: mock, Type: discovery, ID: {d222adb4-2f9c-4c3f-8655-76400d0fb6ce})
QT_TRANSLATE_NOOP("mock", "Result count"),
//: The name of the ParamType (ThingClass: networkDeviceMock, Type: discovery, ID: {762d9bc3-c07e-42e7-8dab-62c980998677})
QT_TRANSLATE_NOOP("mock", "Result type"),
//: The name of the ParamType (ThingClass: inputTypeMock, Type: thing, ID: {22add8c9-ee4f-43ad-8931-58e999313ac3})
QT_TRANSLATE_NOOP("mock", "Search text"),

View File

@ -298,8 +298,8 @@ void TestIntegrations::getThingClasses_data()
QTest::addColumn<QList<ThingClassId>>("thingClassIds");
QTest::addColumn<int>("resultCount");
QTest::newRow("vendor nymea") << nymeaVendorId << QList<ThingClassId>() << 16;
QTest::newRow("no filter") << VendorId() << QList<ThingClassId>() << 16;
QTest::newRow("vendor nymea") << nymeaVendorId << QList<ThingClassId>() << 17;
QTest::newRow("no filter") << VendorId() << QList<ThingClassId>() << 17;
QTest::newRow("invalid vendor") << VendorId("93e7d361-8025-4354-b17e-b68406c800bc") << QList<ThingClassId>() << 0;
QTest::newRow("mockThingClassId") << VendorId() << (QList<ThingClassId>() << mockThingClassId) << 1;
QTest::newRow("invalid thingClassId") << VendorId() << (QList<ThingClassId>() << ThingClassId("6c78ec28-09b6-476d-ac27-1d6966a45c57")) << 0;