From e747c2dd976a9478129d6c9f4c4904d1cfc06aaa Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 10 Feb 2021 14:51:05 +0100 Subject: [PATCH] GenericThings: Add a generic light sensor --- .../integrationplugingenericthings.cpp | 15 +++++ .../integrationplugingenericthings.json | 59 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/genericthings/integrationplugingenericthings.cpp b/genericthings/integrationplugingenericthings.cpp index f27d9090..725d20ac 100644 --- a/genericthings/integrationplugingenericthings.cpp +++ b/genericthings/integrationplugingenericthings.cpp @@ -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(); diff --git a/genericthings/integrationplugingenericthings.json b/genericthings/integrationplugingenericthings.json index 7610273c..387f0715 100644 --- a/genericthings/integrationplugingenericthings.json +++ b/genericthings/integrationplugingenericthings.json @@ -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",