GenericThings: Add a generic light sensor

pull/1/head
Michael Zanetti 2021-02-10 14:51:05 +01:00
parent e69df4eec0
commit 120da1f37f
2 changed files with 74 additions and 0 deletions

View File

@ -574,6 +574,21 @@ void IntegrationPluginGenericThings::executeAction(ThingActionInfo *info)
} else {
Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8());
}
} else if (thing->thingClassId() == lightSensorThingClassId) {
if (action.actionTypeId() == lightSensorInputActionTypeId) {
double value = info->action().param(lightSensorInputActionInputParamTypeId).value().toDouble();
thing->setStateValue(lightSensorInputStateTypeId, value);
double min = info->thing()->setting(lightSensorSettingsMinLuxParamTypeId).toDouble();
double max = info->thing()->setting(lightSensorSettingsMaxLuxParamTypeId).toDouble();
double newValue = mapDoubleValue(value, 0, 100, min, max);
double roundingFactor = qPow(10, info->thing()->setting(lightSensorSettingsAccuracyParamTypeId).toInt());
newValue = qRound(newValue * roundingFactor) / roundingFactor;
thing->setStateValue(lightSensorLightIntensityStateTypeId, newValue);
info->finish(Thing::ThingErrorNoError);
return;
} else {
Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8());
}
} else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) {
if (action.actionTypeId() == extendedSmartMeterConsumerImpulseInputActionTypeId) {
bool value = info->action().param(extendedSmartMeterConsumerImpulseInputActionImpulseInputParamTypeId).value().toBool();

View File

@ -971,6 +971,65 @@
}
]
},
{
"id": "d4d873fd-f0fc-433f-b615-91c1506a1890",
"name": "lightSensor",
"displayName": "Generic light sensor",
"createMethods": ["user"],
"interfaces": ["lightsensor"],
"settingsTypes": [
{
"id": "6dea7384-b079-443b-8cc2-1479138fa212",
"name": "minLux",
"displayName": "Minimum Lux",
"type": "double",
"defaultValue": 0,
"unit": "Lux"
},
{
"id": "7fe74404-d7f0-41af-a8d4-dd1bda27f752",
"name": "maxLux",
"displayName": "Maximum Lux",
"type": "double",
"defaultValue": 120000,
"unit": "Lux"
},
{
"id": "f800988f-1ad5-4ffb-9aa8-70ef17614966",
"name": "accuracy",
"displayName": "Accuracy (decimal places)",
"type": "uint",
"minValue": 0,
"maxValue": 5,
"defaultValue": 1
}
],
"stateTypes": [
{
"id": "fe12ef32-9f2f-41cd-acb7-6b8e4acffa3b",
"name": "lightIntensity",
"displayName": "Light intensity",
"displayNameEvent": "Light intensity changed",
"type": "double",
"unit": "Lux",
"defaultValue": 0
},
{
"id": "520e5d27-7d15-4d79-94cf-5d01f5a09ea8",
"name": "input",
"displayName": "Input value",
"displayNameEvent": "Input value changed",
"displayNameAction": "Set input value",
"type": "double",
"defaultValue": 0,
"minValue": 0,
"maxValue": 100,
"unit": "Percentage",
"writable": true,
"ioType": "analogOutput"
}
]
},
{
"id": "c3123967-f741-4fe1-a0d4-9a3e405d7e52",
"name": "extendedSmartMeterConsumer",