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.
This commit is contained in:
parent
f2e2bc4814
commit
fd39a2ee53
@ -46,12 +46,17 @@ void IntegrationPluginGenericCar::setupThing(ThingSetupInfo *info)
|
|||||||
|
|
||||||
// Set the min charging current state if the settings value changed
|
// Set the min charging current state if the settings value changed
|
||||||
connect(thing, &Thing::settingChanged, this, [thing](const ParamTypeId ¶mTypeId, const QVariant &value){
|
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";
|
qCDebug(dcGenericCar()) << "Car minimum charging current settings changed" << value.toUInt() << "A";
|
||||||
thing->setStateValue(carMinChargingCurrentStateTypeId, value);
|
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
|
// Finish the setup
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
|
||||||
@ -64,10 +69,7 @@ void IntegrationPluginGenericCar::executeAction(ThingActionInfo *info)
|
|||||||
Thing *thing = info->thing();
|
Thing *thing = info->thing();
|
||||||
Action action = info->action();
|
Action action = info->action();
|
||||||
|
|
||||||
if (action.actionTypeId() == carCapacityActionTypeId) {
|
if (action.actionTypeId() == carBatteryLevelActionTypeId) {
|
||||||
thing->setStateValue(carCapacityStateTypeId, action.paramValue(carCapacityActionCapacityParamTypeId));
|
|
||||||
info->finish(Thing::ThingErrorNoError);
|
|
||||||
} else if (action.actionTypeId() == carBatteryLevelActionTypeId) {
|
|
||||||
thing->setStateValue(carBatteryLevelStateTypeId, action.paramValue(carBatteryLevelActionBatteryLevelParamTypeId));
|
thing->setStateValue(carBatteryLevelStateTypeId, action.paramValue(carBatteryLevelActionBatteryLevelParamTypeId));
|
||||||
thing->setStateValue(carBatteryCriticalStateTypeId, action.paramValue(carBatteryLevelActionBatteryLevelParamTypeId).toInt() < 10);
|
thing->setStateValue(carBatteryCriticalStateTypeId, action.paramValue(carBatteryLevelActionBatteryLevelParamTypeId).toInt() < 10);
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
|||||||
@ -24,6 +24,16 @@
|
|||||||
"minValue": 6,
|
"minValue": 6,
|
||||||
"maxValue": 16,
|
"maxValue": 16,
|
||||||
"defaultValue": 6
|
"defaultValue": 6
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "57f36386-dd71-4ab0-8d2f-8c74a391f90d",
|
||||||
|
"name": "capacity",
|
||||||
|
"displayName": "Capacity",
|
||||||
|
"type": "uint",
|
||||||
|
"unit": "KiloWattHour",
|
||||||
|
"minValue": 5,
|
||||||
|
"maxValue": 200,
|
||||||
|
"defaultValue": 50
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"stateTypes": [
|
"stateTypes": [
|
||||||
@ -32,11 +42,9 @@
|
|||||||
"name": "capacity",
|
"name": "capacity",
|
||||||
"displayName": "Capacity",
|
"displayName": "Capacity",
|
||||||
"displayNameEvent": "Capacity changed",
|
"displayNameEvent": "Capacity changed",
|
||||||
"displayNameAction": "Set capacity",
|
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"unit": "KiloWattHour",
|
"unit": "KiloWattHour",
|
||||||
"defaultValue": 50,
|
"defaultValue": 50
|
||||||
"writable": true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "d33982d6-6467-4281-b448-68c1b1db088d",
|
"id": "d33982d6-6467-4281-b448-68c1b1db088d",
|
||||||
|
|||||||
Reference in New Issue
Block a user