diff --git a/genericcar/integrationplugingenericcar.cpp b/genericcar/integrationplugingenericcar.cpp index 61dc5a2..93d919b 100644 --- a/genericcar/integrationplugingenericcar.cpp +++ b/genericcar/integrationplugingenericcar.cpp @@ -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 ¶mTypeId, 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); diff --git a/genericcar/integrationplugingenericcar.json b/genericcar/integrationplugingenericcar.json index 6e9a14d..43ede57 100644 --- a/genericcar/integrationplugingenericcar.json +++ b/genericcar/integrationplugingenericcar.json @@ -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",