implement awning interface in simulation plugin
This commit is contained in:
parent
2b7f7f59ce
commit
bea46cb954
@ -53,7 +53,9 @@ void DevicePluginSimulation::init()
|
|||||||
DeviceManager::DeviceSetupStatus DevicePluginSimulation::setupDevice(Device *device)
|
DeviceManager::DeviceSetupStatus DevicePluginSimulation::setupDevice(Device *device)
|
||||||
{
|
{
|
||||||
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() == rollerShutterDeviceClassId) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -293,14 +295,59 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
|
|||||||
if (device->deviceClassId() == rollerShutterDeviceClassId) {
|
if (device->deviceClassId() == rollerShutterDeviceClassId) {
|
||||||
if (action.actionTypeId() == rollerShutterOpenActionTypeId) {
|
if (action.actionTypeId() == rollerShutterOpenActionTypeId) {
|
||||||
qCDebug(dcSimulation()) << "Opening roller shutter";
|
qCDebug(dcSimulation()) << "Opening roller shutter";
|
||||||
|
m_simulationTimers.value(device)->setProperty("targetValue", 0);
|
||||||
|
m_simulationTimers.value(device)->start(500);
|
||||||
|
device->setStateValue(rollerShutterMovingStateTypeId, true);
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
}
|
}
|
||||||
if (action.actionTypeId() == rollerShutterCloseActionTypeId) {
|
if (action.actionTypeId() == rollerShutterCloseActionTypeId) {
|
||||||
qCDebug(dcSimulation()) << "Closing roller shutter";
|
qCDebug(dcSimulation()) << "Closing roller shutter";
|
||||||
|
m_simulationTimers.value(device)->setProperty("targetValue", 100);
|
||||||
|
m_simulationTimers.value(device)->start(500);
|
||||||
|
device->setStateValue(rollerShutterMovingStateTypeId, true);
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
}
|
}
|
||||||
if (action.actionTypeId() == rollerShutterStopActionTypeId) {
|
if (action.actionTypeId() == rollerShutterStopActionTypeId) {
|
||||||
qCDebug(dcSimulation()) << "Stopping roller shutter";
|
qCDebug(dcSimulation()) << "Stopping roller shutter";
|
||||||
|
m_simulationTimers.value(device)->stop();
|
||||||
|
device->setStateValue(rollerShutterMovingStateTypeId, false);
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
}
|
||||||
|
if (action.actionTypeId() == rollerShutterPercentageActionTypeId) {
|
||||||
|
qCDebug(dcSimulation()) << "Setting awning to" << action.param(rollerShutterPercentageActionParamTypeId);
|
||||||
|
m_simulationTimers.value(device)->setProperty("targetValue", action.param(rollerShutterPercentageActionParamTypeId).value());
|
||||||
|
m_simulationTimers.value(device)->start(500);
|
||||||
|
device->setStateValue(rollerShutterMovingStateTypeId, true);
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (device->deviceClassId() == extendedAwningDeviceClassId) {
|
||||||
|
if (action.actionTypeId() == extendedAwningOpenActionTypeId) {
|
||||||
|
qCDebug(dcSimulation()) << "Opening awning";
|
||||||
|
m_simulationTimers.value(device)->setProperty("targetValue", 100);
|
||||||
|
m_simulationTimers.value(device)->start(500);
|
||||||
|
device->setStateValue(extendedAwningMovingStateTypeId, true);
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
}
|
||||||
|
if (action.actionTypeId() == extendedAwningCloseActionTypeId) {
|
||||||
|
qCDebug(dcSimulation()) << "Closing awning";
|
||||||
|
m_simulationTimers.value(device)->setProperty("targetValue", 0);
|
||||||
|
m_simulationTimers.value(device)->start(500);
|
||||||
|
device->setStateValue(extendedAwningMovingStateTypeId, true);
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
}
|
||||||
|
if (action.actionTypeId() == extendedAwningStopActionTypeId) {
|
||||||
|
qCDebug(dcSimulation()) << "Stopping awning";
|
||||||
|
m_simulationTimers.value(device)->stop();
|
||||||
|
device->setStateValue(extendedAwningMovingStateTypeId, false);
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
}
|
||||||
|
if (action.actionTypeId() == extendedAwningPercentageActionTypeId) {
|
||||||
|
qCDebug(dcSimulation()) << "Setting awning to" << action.param(extendedAwningPercentageActionParamTypeId);
|
||||||
|
m_simulationTimers.value(device)->setProperty("targetValue", action.param(extendedAwningPercentageActionParamTypeId).value());
|
||||||
|
m_simulationTimers.value(device)->start(500);
|
||||||
|
device->setStateValue(extendedAwningMovingStateTypeId, true);
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -395,5 +442,23 @@ void DevicePluginSimulation::simulationTimerTimeout()
|
|||||||
device->setStateValue(garageGateIntermediatePositionStateTypeId, false);
|
device->setStateValue(garageGateIntermediatePositionStateTypeId, false);
|
||||||
device->setStateValue(garageGateStateStateTypeId, "closed");
|
device->setStateValue(garageGateStateStateTypeId, "closed");
|
||||||
}
|
}
|
||||||
|
} else if (device->deviceClassId() == extendedAwningDeviceClassId) {
|
||||||
|
int currentValue = device->stateValue(extendedAwningPercentageStateTypeId).toInt();
|
||||||
|
int targetValue = t->property("targetValue").toInt();
|
||||||
|
int newValue = targetValue > currentValue ? qMin(targetValue, currentValue + 5) : qMax(targetValue, currentValue - 5);
|
||||||
|
device->setStateValue(extendedAwningPercentageStateTypeId, newValue);
|
||||||
|
if (newValue == targetValue) {
|
||||||
|
t->stop();
|
||||||
|
device->setStateValue(extendedAwningMovingStateTypeId, false);
|
||||||
|
}
|
||||||
|
} else if (device->deviceClassId() == rollerShutterDeviceClassId) {
|
||||||
|
int currentValue = device->stateValue(rollerShutterPercentageStateTypeId).toInt();
|
||||||
|
int targetValue = t->property("targetValue").toInt();
|
||||||
|
int newValue = targetValue > currentValue ? qMin(targetValue, currentValue + 5) : qMax(targetValue, currentValue - 5);
|
||||||
|
device->setStateValue(rollerShutterPercentageStateTypeId, newValue);
|
||||||
|
if (newValue == targetValue) {
|
||||||
|
t->stop();
|
||||||
|
device->setStateValue(rollerShutterMovingStateTypeId, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -312,23 +312,127 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "1d7aaa1d-fc50-4d7b-9657-1449322e40d8",
|
||||||
|
"name": "extendedBlind",
|
||||||
|
"displayName": "Extended blind",
|
||||||
|
"createMethods": ["user"],
|
||||||
|
"interfaces": ["extendedblind"],
|
||||||
|
"paramTypes": [ ],
|
||||||
|
"stateTypes": [
|
||||||
|
{
|
||||||
|
"id": "18fc257c-6b7b-472c-b52a-acd4ba405bf2",
|
||||||
|
"name": "percentage",
|
||||||
|
"displayName": "percentage",
|
||||||
|
"type": "int",
|
||||||
|
"unit": "Percentage",
|
||||||
|
"displayNameEvent": "percentage changed",
|
||||||
|
"defaultValue": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "83559182-f3db-4a4a-8c70-d5fb3ceb57de",
|
||||||
|
"name": "moving",
|
||||||
|
"type": "bool",
|
||||||
|
"defaultValue": false,
|
||||||
|
"displayName": "mooving",
|
||||||
|
"displayNameEvent": "moving changed"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actionTypes": [
|
||||||
|
{
|
||||||
|
"id": "b4379ab7-5fc2-45b6-8214-5855b040ee1a",
|
||||||
|
"name": "open",
|
||||||
|
"displayName": "Open"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "fd63d8bf-ffde-4343-bbdc-1645c94017dc",
|
||||||
|
"name": "stop",
|
||||||
|
"displayName": "stop"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "316c17e6-01a8-45c4-921d-7773b2d441a4",
|
||||||
|
"name": "close",
|
||||||
|
"displayName": "close"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "d302630b-f331-4bb0-88e4-4078f16aba7f",
|
||||||
|
"name": "extendedAwning",
|
||||||
|
"displayName": "Extended awning",
|
||||||
|
"createMethods": ["user"],
|
||||||
|
"interfaces": ["extendedawning"],
|
||||||
|
"paramTypes": [ ],
|
||||||
|
"stateTypes": [
|
||||||
|
{
|
||||||
|
"id": "e4c92da3-da3e-40ea-907f-a93283426789",
|
||||||
|
"name": "percentage",
|
||||||
|
"type": "int",
|
||||||
|
"unit": "Percentage",
|
||||||
|
"writable": true,
|
||||||
|
"displayName": "percentage",
|
||||||
|
"displayNameEvent": "percentage changed",
|
||||||
|
"displayNameAction": "set percentage",
|
||||||
|
"minValue": 0,
|
||||||
|
"maxValue": 100,
|
||||||
|
"defaultValue": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "b2a888b3-c526-410f-bafc-9d6dc459dbf8",
|
||||||
|
"name": "moving",
|
||||||
|
"type": "bool",
|
||||||
|
"defaultValue": false,
|
||||||
|
"displayName": "mooving",
|
||||||
|
"displayNameEvent": "moving changed"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actionTypes": [
|
||||||
|
{
|
||||||
|
"id": "508c8f1b-aa1d-43d8-badb-0c9d219025b3",
|
||||||
|
"name": "open",
|
||||||
|
"displayName": "Open"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "41fdeba2-8d2f-46ce-8f2d-b8c31bdf90ff",
|
||||||
|
"name": "stop",
|
||||||
|
"displayName": "stop"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "79ec0271-5361-4f0f-a458-bf22e570c9ac",
|
||||||
|
"name": "close",
|
||||||
|
"displayName": "close"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "1039b7ee-5351-400b-a477-5b8fc1447138",
|
"id": "1039b7ee-5351-400b-a477-5b8fc1447138",
|
||||||
"name": "rollerShutter",
|
"name": "rollerShutter",
|
||||||
"displayName": "Roller Shutter",
|
"displayName": "Roller Shutter",
|
||||||
"createMethods": ["user"],
|
"createMethods": ["user"],
|
||||||
"deviceIcon": "RollerShutter",
|
"deviceIcon": "RollerShutter",
|
||||||
"interfaces": ["shutter"],
|
"interfaces": ["extendedshutter"],
|
||||||
"paramTypes": [ ],
|
"paramTypes": [ ],
|
||||||
"stateTypes": [
|
"stateTypes": [
|
||||||
{
|
{
|
||||||
"id": "1386029d-f3a6-4b47-978a-ac1a581aac0f",
|
"id": "1386029d-f3a6-4b47-978a-ac1a581aac0f",
|
||||||
"name": "shutterStatus",
|
"name": "percentage",
|
||||||
"displayName": "Status",
|
|
||||||
"type": "int",
|
"type": "int",
|
||||||
"unit": "Percentage",
|
"unit": "Percentage",
|
||||||
"displayNameEvent": "Shutter status changed",
|
"writable": true,
|
||||||
|
"displayName": "percentage",
|
||||||
|
"displayNameEvent": "percentage changed",
|
||||||
|
"displayNameAction": "set percentage",
|
||||||
|
"minValue": 0,
|
||||||
|
"maxValue": 100,
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "fd94b07d-4631-450d-9f99-9e9221cc3602",
|
||||||
|
"name": "moving",
|
||||||
|
"type": "bool",
|
||||||
|
"defaultValue": false,
|
||||||
|
"displayName": "mooving",
|
||||||
|
"displayNameEvent": "moving changed"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"actionTypes": [
|
"actionTypes": [
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user