Generic things: Add a generic water level sensor
This commit is contained in:
parent
7f6ceb4171
commit
67d5f85c93
@ -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();
|
||||
@ -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();
|
||||
|
||||
@ -1682,6 +1682,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",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user