Generic car: Change capacity setting from a writable state to a setting

This allows to configure it also when there's no generic thing view
available.
pull/4/head
Michael Zanetti 2022-06-20 19:45:32 +02:00
parent f2e2bc4814
commit fd39a2ee53
2 changed files with 18 additions and 8 deletions

View File

@ -46,12 +46,17 @@ void IntegrationPluginGenericCar::setupThing(ThingSetupInfo *info)
// 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) {
if (paramTypeId == carSettingsCapacityParamTypeId) {
thing->setStateValue(carCapacityStateTypeId, value);
} else if (paramTypeId == carSettingsMinChargingCurrentParamTypeId) {
qCDebug(dcGenericCar()) << "Car minimum charging current settings changed" << value.toUInt() << "A";
thing->setStateValue(carMinChargingCurrentStateTypeId, value);
}
});
// Migration from earlier versions (pre 1.3) which had the capacity setting as a writable state.
thing->setSettingValue(carSettingsCapacityParamTypeId, thing->stateValue(carCapacityStateTypeId));
// Finish the setup
info->finish(Thing::ThingErrorNoError);
@ -64,10 +69,7 @@ void IntegrationPluginGenericCar::executeAction(ThingActionInfo *info)
Thing *thing = info->thing();
Action action = info->action();
if (action.actionTypeId() == carCapacityActionTypeId) {
thing->setStateValue(carCapacityStateTypeId, action.paramValue(carCapacityActionCapacityParamTypeId));
info->finish(Thing::ThingErrorNoError);
} else if (action.actionTypeId() == carBatteryLevelActionTypeId) {
if (action.actionTypeId() == carBatteryLevelActionTypeId) {
thing->setStateValue(carBatteryLevelStateTypeId, action.paramValue(carBatteryLevelActionBatteryLevelParamTypeId));
thing->setStateValue(carBatteryCriticalStateTypeId, action.paramValue(carBatteryLevelActionBatteryLevelParamTypeId).toInt() < 10);
info->finish(Thing::ThingErrorNoError);

View File

@ -24,6 +24,16 @@
"minValue": 6,
"maxValue": 16,
"defaultValue": 6
},
{
"id": "57f36386-dd71-4ab0-8d2f-8c74a391f90d",
"name": "capacity",
"displayName": "Capacity",
"type": "uint",
"unit": "KiloWattHour",
"minValue": 5,
"maxValue": 200,
"defaultValue": 50
}
],
"stateTypes": [
@ -32,11 +42,9 @@
"name": "capacity",
"displayName": "Capacity",
"displayNameEvent": "Capacity changed",
"displayNameAction": "Set capacity",
"type": "double",
"unit": "KiloWattHour",
"defaultValue": 50,
"writable": true
"defaultValue": 50
},
{
"id": "d33982d6-6467-4281-b448-68c1b1db088d",