Skip to content

Commit

Permalink
Merge PR #491: Generic things: Add a generic water level sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
nymea-jenkins committed Nov 3, 2021
2 parents e5a05f8 + 67d5f85 commit 7193fc8
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
25 changes: 25 additions & 0 deletions genericthings/integrationplugingenericthings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,19 @@ void IntegrationPluginGenericThings::setupThing(ThingSetupInfo *info)
thermostatCheckPowerOutputState(thing);
}
});
} else if (thing->thingClassId() == waterLevelSensorThingClassId) {
connect(thing, &Thing::settingChanged, thing, [ thing](const ParamTypeId &settingTypeId, const QVariant &value){
if (settingTypeId == waterLevelSensorSettingsCapacityParamTypeId) {
double capacity = value.toDouble();
double input = thing->stateValue(waterLevelSensorInputStateTypeId).toDouble();
double minInputValue = thing->setting(waterLevelSensorSettingsMinInputValueParamTypeId).toDouble();
double maxInputValue = thing->setting(waterLevelSensorSettingsMaxInputValueParamTypeId).toDouble();
double normalizedInput = (input - minInputValue) / (maxInputValue - minInputValue);
double waterLevel = normalizedInput * capacity;
thing->setStateMaxValue(waterLevelSensorWaterLevelStateTypeId, capacity);
thing->setStateValue(waterLevelSensorWaterLevelStateTypeId, waterLevel);
}
});
} else if (thing->thingClassId() == sgReadyThingClassId) {
bool relay1 = thing->stateValue(sgReadyRelay1StateTypeId).toBool();
bool relay2 = thing->stateValue(sgReadyRelay2StateTypeId).toBool();
Expand Down Expand Up @@ -866,6 +879,18 @@ void IntegrationPluginGenericThings::executeAction(ThingActionInfo *info)
info->finish(Thing::ThingErrorNoError);
return;
}
} else if (thing->thingClassId() == waterLevelSensorThingClassId) {
if (action.actionTypeId() == waterLevelSensorInputActionTypeId) {
double capacity = thing->setting(waterLevelSensorSettingsCapacityParamTypeId).toDouble();
double input = action.paramValue(waterLevelSensorInputActionInputParamTypeId).toDouble();
double minInputValue = thing->setting(waterLevelSensorSettingsMinInputValueParamTypeId).toDouble();
double maxInputValue = thing->setting(waterLevelSensorSettingsMaxInputValueParamTypeId).toDouble();
double normalizedInput = (input - minInputValue) / (maxInputValue - minInputValue);
double waterLevel = normalizedInput * capacity;
thing->setStateValue(waterLevelSensorWaterLevelStateTypeId, waterLevel);
info->finish(Thing::ThingErrorNoError);
return;
}
} else if (thing->thingClassId() == presenceSensorThingClassId) {
if (action.actionTypeId() == presenceSensorIsPresentActionTypeId) {
bool isPresent = action.paramValue(presenceSensorIsPresentActionIsPresentParamTypeId).toBool();
Expand Down
58 changes: 58 additions & 0 deletions genericthings/integrationplugingenericthings.json
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,64 @@
}
]
},
{
"id": "f1576df0-fb45-4bf0-89fa-a83c4118c326",
"name": "waterLevelSensor",
"displayName": "Generic water level sensor",
"createMethods": ["user"],
"interfaces": ["waterlevelsensor"],
"settingsTypes": [
{
"id": "5e98e8d2-d849-46c5-b25a-d54f184ea4c7",
"name": "capacity",
"displayName": "Tank capactity",
"type": "double",
"unit": "Liter",
"minValue": 0,
"defaultValue": 100
},
{
"id": "16ea3cf2-46fd-40a3-88bf-21a2bb7cbabe",
"name": "minInputValue",
"displayName": "Minimum input value",
"type": "double",
"defaultValue": 0
},
{
"id": "4e228f9b-8631-4643-8375-3d8d76d12e9c",
"name": "maxInputValue",
"displayName": "Maximum input value",
"type": "double",
"defaultValue": 1
}
],
"stateTypes": [
{
"id": "07563165-e42d-4d0f-ac60-31cdd19170f2",
"name": "waterLevel",
"displayName": "Water level",
"displayNameEvent": "Water level changed",
"type": "double",
"unit": "Liter",
"defaultValue": 0,
"minValue": 0,
"maxValue": 100
},
{
"id": "d344887d-da5d-4742-83bd-608754b2d0aa",
"name": "input",
"displayName": "Input value",
"displayNameEvent": "Input value changed",
"displayNameAction": "Set input value",
"type": "double",
"defaultValue": 0,
"minValue": 0,
"maxValue": 1,
"writable": true,
"ioType": "analogOutput"
}
]
},
{
"id": "339a0c54-4086-404f-8d36-bcf20621b785",
"name": "presenceSensor",
Expand Down

0 comments on commit 7193fc8

Please sign in to comment.