add parent/child mock device
This commit is contained in:
parent
34a5596f3e
commit
1f0e13e334
@ -97,16 +97,30 @@ DeviceManager::DeviceSetupStatus DevicePluginMock::setupDevice(Device *device)
|
||||
}
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
} else if (device->deviceClassId() == mockPushButtonDeviceClassId) {
|
||||
qCDebug(dcMockDevice) << "Setup PushButton Mock device" << device->params();
|
||||
qCDebug(dcMockDevice) << "Setup PushButton mock device" << device->params();
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
} else if (device->deviceClassId() == mockDisplayPinDeviceClassId) {
|
||||
qCDebug(dcMockDevice) << "Setup DisplayPin Mock device" << device->params();
|
||||
qCDebug(dcMockDevice) << "Setup DisplayPin mock device" << device->params();
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
} else if (device->deviceClassId() == mockParentDeviceClassId) {
|
||||
qCDebug(dcMockDevice) << "Setup Parent mock device" << device->params();
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
} else if (device->deviceClassId() == mockChildDeviceClassId) {
|
||||
qCDebug(dcMockDevice) << "Setup Child mock device" << device->params();
|
||||
device->setParentId(DeviceId(device->params().paramValue("parent uuid").toString()));
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
|
||||
return DeviceManager::DeviceSetupStatusFailure;
|
||||
}
|
||||
|
||||
void DevicePluginMock::postSetupDevice(Device *device)
|
||||
{
|
||||
if (device->deviceClassId() == mockParentDeviceClassId) {
|
||||
onChildDeviceDiscovered(device->id());
|
||||
}
|
||||
}
|
||||
|
||||
void DevicePluginMock::deviceRemoved(Device *device)
|
||||
{
|
||||
delete m_daemons.take(device);
|
||||
@ -225,6 +239,12 @@ DeviceManager::DeviceError DevicePluginMock::executeAction(Device *device, const
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||
} else if (device->deviceClassId() == mockParentDeviceClassId || device->deviceClassId() == mockChildDeviceClassId) {
|
||||
if (action.actionTypeId() == boolValueActionTypeId) {
|
||||
device->setStateValue(boolValueStateTypeId, action.param("bool value").value().toBool());
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||
}
|
||||
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||
}
|
||||
@ -374,3 +394,15 @@ void DevicePluginMock::onDisplayPinPairingFinished()
|
||||
qCDebug(dcMockDevice) << "Pairing DisplayPin Device finished";
|
||||
emit pairingFinished(m_pairingId, DeviceManager::DeviceSetupStatusSuccess);
|
||||
}
|
||||
|
||||
void DevicePluginMock::onChildDeviceDiscovered(const DeviceId &parentId)
|
||||
{
|
||||
qCDebug(dcMockDevice) << "Child device discovered for parent" << parentId.toString();
|
||||
DeviceDescriptor mockDescriptor(mockChildDeviceClassId, "Child Mock Device (Auto created)");
|
||||
ParamList params;
|
||||
params.append(Param("name", "Child"));
|
||||
params.append(Param("parent uuid", parentId));
|
||||
mockDescriptor.setParams(params);
|
||||
|
||||
emit autoDevicesAppeared(mockChildDeviceClassId, QList<DeviceDescriptor>() << mockDescriptor);
|
||||
}
|
||||
|
||||
@ -43,6 +43,7 @@ public:
|
||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
|
||||
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
||||
void postSetupDevice(Device *device) override;
|
||||
void deviceRemoved(Device *device) override;
|
||||
|
||||
void startMonitoringAutoDevices() override;
|
||||
@ -67,6 +68,7 @@ private slots:
|
||||
void onPushButtonPressed();
|
||||
void onPushButtonPairingFinished();
|
||||
void onDisplayPinPairingFinished();
|
||||
void onChildDeviceDiscovered(const DeviceId &parentId);
|
||||
|
||||
private:
|
||||
QHash<Device*, HttpDaemon*> m_daemons;
|
||||
|
||||
@ -343,6 +343,59 @@
|
||||
"name": "Timout action"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"deviceClassId": "a71fbde9-9a38-4bf8-beab-c8aade2608ba",
|
||||
"idName": "mockParent",
|
||||
"name": "Mock Device (Parent)",
|
||||
"createMethods": ["user"],
|
||||
"paramTypes": [
|
||||
{
|
||||
"name": "name",
|
||||
"type": "QString",
|
||||
"inputType": "TextLine",
|
||||
"defaultValue": "Parent Mock Device"
|
||||
}
|
||||
],
|
||||
"stateTypes": [
|
||||
{
|
||||
"id": "d24ede5f-4064-4898-bb84-cfb533b1fbc0",
|
||||
"idName": "boolValue",
|
||||
"name": "bool value",
|
||||
"type": "bool",
|
||||
"defaultValue": false,
|
||||
"writable": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"deviceClassId": "40893c9f-bc47-40c1-8bf7-b390c7c1b4fc",
|
||||
"idName": "mockChild",
|
||||
"name": "Mock Device (Child)",
|
||||
"createMethods": ["auto"],
|
||||
"paramTypes": [
|
||||
{
|
||||
"name": "name",
|
||||
"type": "QString",
|
||||
"inputType": "TextLine",
|
||||
"defaultValue": "Child Mock Device"
|
||||
},
|
||||
{
|
||||
"name": "parent uuid",
|
||||
"type": "QUuid",
|
||||
"readOnly": true
|
||||
}
|
||||
],
|
||||
"stateTypes": [
|
||||
{
|
||||
"id": "d24ede5f-4064-4898-bb84-cfb533b1fbc0",
|
||||
"idName": "boolValue",
|
||||
"name": "bool value",
|
||||
"type": "bool",
|
||||
"defaultValue": false,
|
||||
"writable": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user