Add simulated venetian blinds
parent
acdb74df1e
commit
99fc6c2ad4
|
|
@ -68,6 +68,7 @@ void IntegrationPluginSimulation::setupThing(ThingSetupInfo *info)
|
|||
if (thing->thingClassId() == garageGateThingClassId ||
|
||||
thing->thingClassId() == extendedAwningThingClassId ||
|
||||
thing->thingClassId() == extendedBlindThingClassId ||
|
||||
thing->thingClassId() == venetianBlindThingClassId ||
|
||||
thing->thingClassId() == rollerShutterThingClassId ||
|
||||
thing->thingClassId() == fingerPrintSensorThingClassId ||
|
||||
thing->thingClassId() == barcodeScannerThingClassId ||
|
||||
|
|
@ -536,6 +537,45 @@ void IntegrationPluginSimulation::executeAction(ThingActionInfo *info)
|
|||
}
|
||||
}
|
||||
|
||||
if (thing->thingClassId() == venetianBlindThingClassId) {
|
||||
if (action.actionTypeId() == venetianBlindOpenActionTypeId) {
|
||||
qCDebug(dcSimulation()) << "Opening venetian blind";
|
||||
m_simulationTimers.value(thing)->setProperty("targetPosition", 0);
|
||||
m_simulationTimers.value(thing)->start(500);
|
||||
thing->setStateValue(venetianBlindMovingStateTypeId, true);
|
||||
return info->finish(Thing::ThingErrorNoError);
|
||||
}
|
||||
if (action.actionTypeId() == venetianBlindCloseActionTypeId) {
|
||||
qCDebug(dcSimulation()) << "Closing venetian blind";
|
||||
m_simulationTimers.value(thing)->setProperty("targetPosition", 100);
|
||||
m_simulationTimers.value(thing)->start(500);
|
||||
thing->setStateValue(venetianBlindMovingStateTypeId, true);
|
||||
return info->finish(Thing::ThingErrorNoError);
|
||||
}
|
||||
if (action.actionTypeId() == venetianBlindStopActionTypeId) {
|
||||
qCDebug(dcSimulation()) << "Stopping venetian blind";
|
||||
m_simulationTimers.value(thing)->stop();
|
||||
m_simulationTimers.value(thing)->setProperty("targetPosition", thing->stateValue(venetianBlindPercentageStateTypeId).toInt());
|
||||
m_simulationTimers.value(thing)->setProperty("targetAngle", thing->stateValue(venetianBlindAngleStateTypeId).toInt());
|
||||
thing->setStateValue(venetianBlindMovingStateTypeId, false);
|
||||
return info->finish(Thing::ThingErrorNoError);
|
||||
}
|
||||
if (action.actionTypeId() == venetianBlindPercentageActionTypeId) {
|
||||
qCDebug(dcSimulation()) << "Setting venetian blind position to" << action.param(venetianBlindPercentageActionPercentageParamTypeId);
|
||||
m_simulationTimers.value(thing)->setProperty("targetPosition", action.param(venetianBlindPercentageActionPercentageParamTypeId).value());
|
||||
m_simulationTimers.value(thing)->start(500);
|
||||
thing->setStateValue(venetianBlindMovingStateTypeId, true);
|
||||
return info->finish(Thing::ThingErrorNoError);
|
||||
}
|
||||
if (action.actionTypeId() == venetianBlindAngleActionTypeId) {
|
||||
qCDebug(dcSimulation()) << "Setting venetian blind angle to" << action.param(venetianBlindAngleActionAngleParamTypeId);
|
||||
m_simulationTimers.value(thing)->setProperty("targetAngle", action.param(venetianBlindAngleActionAngleParamTypeId).value());
|
||||
m_simulationTimers.value(thing)->start(500);
|
||||
thing->setStateValue(venetianBlindMovingStateTypeId, true);
|
||||
return info->finish(Thing::ThingErrorNoError);
|
||||
}
|
||||
}
|
||||
|
||||
qCWarning(dcSimulation()) << "Unhandled thing class" << thing->thingClassId() << "for" << thing->name();
|
||||
}
|
||||
|
||||
|
|
@ -730,6 +770,23 @@ void IntegrationPluginSimulation::simulationTimerTimeout()
|
|||
t->stop();
|
||||
thing->setStateValue(extendedBlindMovingStateTypeId, false);
|
||||
}
|
||||
} else if (thing->thingClassId() == venetianBlindThingClassId) {
|
||||
int targetPosition = t->property("targetPosition").toInt();
|
||||
int targetAngle = t->property("targetAngle").toInt();
|
||||
|
||||
int currentPosition = thing->stateValue(venetianBlindPercentageStateTypeId).toInt();
|
||||
int currentAngle = thing->stateValue(venetianBlindAngleStateTypeId).toInt();
|
||||
|
||||
int newPosition = targetPosition > currentPosition ? qMin(targetPosition, currentPosition + 5) : qMax(targetPosition, currentPosition - 5);
|
||||
thing->setStateValue(venetianBlindPercentageStateTypeId, newPosition);
|
||||
|
||||
int newAngle = targetAngle > currentAngle ? qMin(targetAngle, currentAngle + 5) : qMax(targetAngle, currentAngle - 5);
|
||||
thing->setStateValue(venetianBlindAngleStateTypeId, newAngle);
|
||||
|
||||
if (newPosition == targetPosition && newAngle == targetAngle) {
|
||||
t->stop();
|
||||
thing->setStateValue(venetianBlindMovingStateTypeId, false);
|
||||
}
|
||||
} else if (thing->thingClassId() == rollerShutterThingClassId) {
|
||||
int currentValue = thing->stateValue(rollerShutterPercentageStateTypeId).toInt();
|
||||
int targetValue = t->property("targetValue").toInt();
|
||||
|
|
|
|||
|
|
@ -415,6 +415,65 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "38757fee-ac55-403e-be53-bad5b97364c1",
|
||||
"name": "venetianBlind",
|
||||
"displayName": "Venetian blind",
|
||||
"createMethods": ["user"],
|
||||
"interfaces": ["venetianblind"],
|
||||
"paramTypes": [ ],
|
||||
"stateTypes": [
|
||||
{
|
||||
"id": "16453cde-15c9-4133-a4fd-7da76735778c",
|
||||
"name": "percentage",
|
||||
"displayName": "percentage",
|
||||
"type": "int",
|
||||
"unit": "Percentage",
|
||||
"displayNameEvent": "percentage changed",
|
||||
"writable": true,
|
||||
"displayNameAction": "set percentage",
|
||||
"defaultValue": 0
|
||||
},
|
||||
{
|
||||
"id": "9dedaf04-3570-403e-b083-ec59dd08981a",
|
||||
"name": "moving",
|
||||
"type": "bool",
|
||||
"defaultValue": false,
|
||||
"displayName": "moving",
|
||||
"displayNameEvent": "moving changed"
|
||||
},
|
||||
{
|
||||
"id": "fe3c802d-253f-4594-b64c-14a8870d9828",
|
||||
"name": "angle",
|
||||
"type": "int",
|
||||
"displayName": "Angle",
|
||||
"displayNameEvent": "Angle changed",
|
||||
"displayNameAction": "Set angle",
|
||||
"minValue": -90,
|
||||
"maxValue": 90,
|
||||
"defaultValue": 0,
|
||||
"unit": "Degree",
|
||||
"writable": true
|
||||
}
|
||||
],
|
||||
"actionTypes": [
|
||||
{
|
||||
"id": "4347b46b-4048-4f3a-b45d-71d99c15c30d",
|
||||
"name": "open",
|
||||
"displayName": "Open"
|
||||
},
|
||||
{
|
||||
"id": "06be8ad4-24e5-4c03-9502-cda165a01bc4",
|
||||
"name": "stop",
|
||||
"displayName": "stop"
|
||||
},
|
||||
{
|
||||
"id": "61cadeae-810e-43f5-a6b5-e85fcaefde9c",
|
||||
"name": "close",
|
||||
"displayName": "close"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "d302630b-f331-4bb0-88e4-4078f16aba7f",
|
||||
"name": "extendedAwning",
|
||||
|
|
@ -463,6 +522,30 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "5f4e3fc9-afb1-45d0-86a2-8713d5894aee",
|
||||
"name": "simpleShutter",
|
||||
"displayName": "Simple roller shutter",
|
||||
"createMethods": ["user"],
|
||||
"interfaces": ["shutter"],
|
||||
"actionTypes": [
|
||||
{
|
||||
"id": "20259935-c39b-42d3-888b-ffdb98800a8d",
|
||||
"name": "open",
|
||||
"displayName": "Open"
|
||||
},
|
||||
{
|
||||
"id": "b1f9b62a-1987-4d2b-af88-e64710cbf626",
|
||||
"name": "close",
|
||||
"displayName": "Close"
|
||||
},
|
||||
{
|
||||
"id": "7c310908-75ee-47b2-b2c1-90b85eed4694",
|
||||
"name": "stop",
|
||||
"displayName": "Stop"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "1039b7ee-5351-400b-a477-5b8fc1447138",
|
||||
"name": "rollerShutter",
|
||||
|
|
|
|||
Loading…
Reference in New Issue