implement fingerprint interface in simulation plugin
This commit is contained in:
parent
a83b9479cb
commit
e20d5c7eb0
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
DevicePluginSimulation::DevicePluginSimulation()
|
DevicePluginSimulation::DevicePluginSimulation()
|
||||||
{
|
{
|
||||||
@ -55,10 +56,14 @@ DeviceManager::DeviceSetupStatus DevicePluginSimulation::setupDevice(Device *dev
|
|||||||
qCDebug(dcSimulation()) << "Set up device" << device->name();
|
qCDebug(dcSimulation()) << "Set up device" << device->name();
|
||||||
if (device->deviceClassId() == garageGateDeviceClassId ||
|
if (device->deviceClassId() == garageGateDeviceClassId ||
|
||||||
device->deviceClassId() == extendedAwningDeviceClassId ||
|
device->deviceClassId() == extendedAwningDeviceClassId ||
|
||||||
device->deviceClassId() == rollerShutterDeviceClassId) {
|
device->deviceClassId() == rollerShutterDeviceClassId ||
|
||||||
|
device->deviceClassId() == fingerPrintSensorDeviceClassId) {
|
||||||
m_simulationTimers.insert(device, new QTimer(device));
|
m_simulationTimers.insert(device, new QTimer(device));
|
||||||
connect(m_simulationTimers[device], &QTimer::timeout, this, &DevicePluginSimulation::simulationTimerTimeout);
|
connect(m_simulationTimers[device], &QTimer::timeout, this, &DevicePluginSimulation::simulationTimerTimeout);
|
||||||
}
|
}
|
||||||
|
if (device->deviceClassId() == fingerPrintSensorDeviceClassId && device->stateValue(fingerPrintSensorUsersStateTypeId).toStringList().count() > 0) {
|
||||||
|
m_simulationTimers.value(device)->start(10000);
|
||||||
|
}
|
||||||
return DeviceManager::DeviceSetupStatusSuccess;
|
return DeviceManager::DeviceSetupStatusSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,6 +357,53 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (device->deviceClassId() == fingerPrintSensorDeviceClassId) {
|
||||||
|
if (action.actionTypeId() == fingerPrintSensorAddUserActionTypeId) {
|
||||||
|
QStringList users = device->stateValue(fingerPrintSensorUsersStateTypeId).toStringList();
|
||||||
|
QString username = action.param(fingerPrintSensorUserIdParamTypeId).value().toString();
|
||||||
|
QString finger = action.param(fingerPrintSensorFingerParamTypeId).value().toString();
|
||||||
|
QSettings settings;
|
||||||
|
settings.beginGroup(device->id().toString());
|
||||||
|
QStringList usedFingers = settings.value(username).toStringList();
|
||||||
|
if (users.contains(username) && usedFingers.contains(finger)) {
|
||||||
|
return DeviceManager::DeviceErrorDuplicateUuid;
|
||||||
|
}
|
||||||
|
QTimer::singleShot(5000, this, [this, action, device, username, finger]() {
|
||||||
|
if (username.toLower().trimmed() == "john") {
|
||||||
|
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorHardwareFailure);
|
||||||
|
} else {
|
||||||
|
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorNoError);
|
||||||
|
QStringList users = device->stateValue(fingerPrintSensorUsersStateTypeId).toStringList();
|
||||||
|
if (!users.contains(username)) {
|
||||||
|
users.append(username);
|
||||||
|
device->setStateValue(fingerPrintSensorUsersStateTypeId, users);
|
||||||
|
m_simulationTimers.value(device)->start(10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSettings settings;
|
||||||
|
settings.beginGroup(device->id().toString());
|
||||||
|
QStringList usedFingers = settings.value(username).toStringList();
|
||||||
|
usedFingers.append(finger);
|
||||||
|
settings.setValue(username, usedFingers);
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return DeviceManager::DeviceErrorAsync;
|
||||||
|
}
|
||||||
|
if (action.actionTypeId() == fingerPrintSensorRemoveUserActionTypeId) {
|
||||||
|
QStringList users = device->stateValue(fingerPrintSensorUsersStateTypeId).toStringList();
|
||||||
|
QString username = action.params().first().value().toString();
|
||||||
|
if (!users.contains(username)) {
|
||||||
|
return DeviceManager::DeviceErrorInvalidParameter;
|
||||||
|
}
|
||||||
|
users.removeAll(username);
|
||||||
|
device->setStateValue(fingerPrintSensorUsersStateTypeId, users);
|
||||||
|
if (users.count() == 0) {
|
||||||
|
m_simulationTimers.value(device)->stop();
|
||||||
|
}
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
}
|
||||||
|
}
|
||||||
qCWarning(dcSimulation()) << "Unhandled device class" << device->deviceClassId() << "for device" << device->name();
|
qCWarning(dcSimulation()) << "Unhandled device class" << device->deviceClassId() << "for device" << device->name();
|
||||||
|
|
||||||
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||||
@ -460,5 +512,23 @@ void DevicePluginSimulation::simulationTimerTimeout()
|
|||||||
t->stop();
|
t->stop();
|
||||||
device->setStateValue(rollerShutterMovingStateTypeId, false);
|
device->setStateValue(rollerShutterMovingStateTypeId, false);
|
||||||
}
|
}
|
||||||
|
} else if (device->deviceClassId() == fingerPrintSensorDeviceClassId) {
|
||||||
|
EventTypeId evt = qrand() % 2 == 0 ? fingerPrintSensorAccessGrantedEventTypeId : fingerPrintSensorAccessDeniedEventTypeId;
|
||||||
|
ParamList params;
|
||||||
|
if (evt == fingerPrintSensorAccessGrantedEventTypeId) {
|
||||||
|
QStringList users = device->stateValue(fingerPrintSensorUsersStateTypeId).toStringList();
|
||||||
|
QString user = users.at(qrand() % users.count());
|
||||||
|
QSettings settings;
|
||||||
|
settings.beginGroup(device->id().toString());
|
||||||
|
QStringList fingers = settings.value(user).toStringList();
|
||||||
|
params.append(Param(fingerPrintSensorUserIdParamTypeId, user));
|
||||||
|
QString finger = fingers.at(qrand() % fingers.count());
|
||||||
|
params.append(Param(fingerPrintSensorFingerParamTypeId, finger));
|
||||||
|
qCDebug(dcSimulation()) << "Emitting fingerprint accepted for user" << user << "and finger" << finger;
|
||||||
|
} else {
|
||||||
|
qCDebug(dcSimulation()) << "Emitting fingerprint denied";
|
||||||
|
}
|
||||||
|
Event event(evt, device->id(), params);
|
||||||
|
emitEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -549,7 +549,7 @@
|
|||||||
"name": "fingerPrintSensor",
|
"name": "fingerPrintSensor",
|
||||||
"displayName": "Finger Print Sensor",
|
"displayName": "Finger Print Sensor",
|
||||||
"createMethods": ["user"],
|
"createMethods": ["user"],
|
||||||
"interfaces": ["connectable"],
|
"interfaces": ["fingerprintreader", "connectable"],
|
||||||
"deviceIcon": "Network",
|
"deviceIcon": "Network",
|
||||||
"basicTags": [
|
"basicTags": [
|
||||||
"Device",
|
"Device",
|
||||||
@ -564,13 +564,93 @@
|
|||||||
"displayNameEvent": "Connected changed",
|
"displayNameEvent": "Connected changed",
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"defaultValue": true
|
"defaultValue": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "02482093-3b82-4918-a3ce-2a2f4831aae0",
|
||||||
|
"name": "users",
|
||||||
|
"displayName": "users",
|
||||||
|
"displayNameEvent": "Users",
|
||||||
|
"type": "QStringList",
|
||||||
|
"defaultValue": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actionTypes": [
|
||||||
|
{
|
||||||
|
"id": "c3805253-a09b-4657-b86c-97936f390672",
|
||||||
|
"name": "addUser",
|
||||||
|
"displayName": "Add user",
|
||||||
|
"paramTypes": [
|
||||||
|
{
|
||||||
|
"id": "d9e0c68f-8b61-4f5a-9909-b27a4ac562a3",
|
||||||
|
"displayName": "User ID",
|
||||||
|
"name": "userId",
|
||||||
|
"type": "QString"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2a97de6c-5ffb-4ca8-b4c7-41ad6790668d",
|
||||||
|
"displayName": "Finger",
|
||||||
|
"name": "finger",
|
||||||
|
"type": "QString",
|
||||||
|
"allowedValues": [
|
||||||
|
"ThumbLeft",
|
||||||
|
"IndexFingerLeft",
|
||||||
|
"MiddleFingerLeft",
|
||||||
|
"RingFingerLeft",
|
||||||
|
"PinkyLeft",
|
||||||
|
"ThumbRight",
|
||||||
|
"IndexFingerRight",
|
||||||
|
"MiddleFingerRight",
|
||||||
|
"RingFingerRight",
|
||||||
|
"PinkyRight"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "28bf4cd1-bb1c-442b-8ba3-ed019f34abbd",
|
||||||
|
"name": "removeUser",
|
||||||
|
"displayName": "Remove user",
|
||||||
|
"paramTypes": [
|
||||||
|
{
|
||||||
|
"id": "ca2ffce8-ee71-47ff-8247-f17fca14fd87",
|
||||||
|
"displayName": "User ID",
|
||||||
|
"name": "userId",
|
||||||
|
"type": "QString"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"eventTypes": [
|
"eventTypes": [
|
||||||
{
|
{
|
||||||
"id": "1d2dde79-7121-4f8c-b7c1-904ced66a79e",
|
"id": "1d2dde79-7121-4f8c-b7c1-904ced66a79e",
|
||||||
"name": "accessGranted",
|
"name": "accessGranted",
|
||||||
"displayName": "Access granted"
|
"displayName": "Access granted",
|
||||||
|
"paramTypes": [
|
||||||
|
{
|
||||||
|
"id": "84addd61-15e9-4e98-aa80-6b0bf5d82a15",
|
||||||
|
"name": "userId",
|
||||||
|
"displayName": "User ID",
|
||||||
|
"type": "QString"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "3611bfc0-be3c-4ddb-8184-b64fc38c7256",
|
||||||
|
"displayName": "Finger",
|
||||||
|
"name": "finger",
|
||||||
|
"type": "QString",
|
||||||
|
"allowedValues": [
|
||||||
|
"ThumbLeft",
|
||||||
|
"IndexFingerLeft",
|
||||||
|
"MiddleFingerLeft",
|
||||||
|
"RingFingerLeft",
|
||||||
|
"PinkyLeft",
|
||||||
|
"ThumbRight",
|
||||||
|
"IndexFingerRight",
|
||||||
|
"MiddleFingerRight",
|
||||||
|
"RingFingerRight",
|
||||||
|
"PinkyRight"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "992b7742-af0c-447c-bd94-9ec70b872268",
|
"id": "992b7742-af0c-447c-bd94-9ec70b872268",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user