Make generic car minimum charging current read only and offer settings for adjustment

master
Simon Stürz 2021-12-10 11:11:40 +01:00
parent 32456e1e20
commit 73c19826c1
2 changed files with 28 additions and 5 deletions

View File

@ -264,8 +264,24 @@ void IntegrationPluginGenericThings::setupThing(ThingSetupInfo *info)
thing->setStateValue(batteryBatteryCriticalStateTypeId, currentBatteryLevel <= value.toInt());
}
});
} else if (thing->thingClassId() == carThingClassId) {
// Set the min charging current state if the settings value changed
connect(thing, &Thing::settingChanged, this, [thing](const ParamTypeId &paramTypeId, const QVariant &value){
if (paramTypeId == carSettingsMinChargingCurrentParamTypeId) {
qCDebug(dcGenericThings()) << "Car minimum charging current settings changed" << value.toUInt() << "A";
thing->setStateValue(carMinChargingCurrentStateTypeId, value);
}
});
// Finish the setup
info->finish(Thing::ThingErrorNoError);
// Set the inital state value
thing->setStateValue(carMinChargingCurrentStateTypeId, thing->setting(carSettingsMinChargingCurrentParamTypeId));
return;
}
// Fall trough, if not already finished and returned...
info->finish(Thing::ThingErrorNoError);
}
@ -899,9 +915,6 @@ void IntegrationPluginGenericThings::executeAction(ThingActionInfo *info)
thing->setStateValue(carBatteryLevelStateTypeId, action.paramValue(carBatteryLevelActionBatteryLevelParamTypeId));
thing->setStateValue(carBatteryCriticalStateTypeId, action.paramValue(carBatteryLevelActionBatteryLevelParamTypeId).toInt() < 10);
info->finish(Thing::ThingErrorNoError);
} else if (action.actionTypeId() == carMinChargingCurrentActionTypeId) {
thing->setStateValue(carMinChargingCurrentStateTypeId, action.paramValue(carMinChargingCurrentActionMinChargingCurrentParamTypeId).toUInt());
info->finish(Thing::ThingErrorNoError);
}
} else {
Q_ASSERT_X(false, "executeAction", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8());

View File

@ -1781,6 +1781,18 @@
"displayName": "Generic electric car",
"createMethods": ["user"],
"interfaces": ["electricvehicle"],
"settingsTypes": [
{
"id": "0c55516d-4285-4d02-8926-1dae03649e18",
"name": "minChargingCurrent",
"displayName": "Minimum charging current",
"type": "uint",
"unit": "Ampere",
"minValue": 6,
"maxValue": 16,
"defaultValue": 6
}
],
"stateTypes": [
{
"id": "363a2a39-61b6-4109-9cd9-aca7367d12c7",
@ -1819,10 +1831,8 @@
"name": "minChargingCurrent",
"displayName": "Minimum charging current",
"displayNameEvent": "Minimum charging current changed",
"displayNameAction": "Set minimum charging current",
"type": "uint",
"unit": "Ampere",
"writable": true,
"minValue": 6,
"maxValue": 16,
"defaultValue": 6