Merge PR #429: GenericThings: Add a generic battery thing

pull/1/head
Jenkins nymea 2021-07-01 17:07:10 +02:00
commit bdda68a645
5 changed files with 231 additions and 0 deletions

View File

@ -257,7 +257,15 @@ void IntegrationPluginGenericThings::setupThing(ThingSetupInfo *info)
int operatingMode = sgReadyOperatingMode(relay1, relay2);
thing->setStateValue(sgReadyOperatingModeStateTypeId, operatingMode);
thing->setStateValue(sgReadyOperatingModeDescriptionStateTypeId, sgReadyOperatingModeDescription(operatingMode));
} else if (thing->thingClassId() == batteryThingClassId) {
connect(thing, &Thing::settingChanged, [thing](const ParamTypeId &settingTypeId, const QVariant &value){
if (settingTypeId == batterySettingsCriticalLevelParamTypeId) {
int currentBatteryLevel = thing->stateValue(batteryBatteryLevelStateTypeId).toInt();
thing->setStateValue(batteryBatteryCriticalStateTypeId, currentBatteryLevel <= value.toInt());
}
});
}
info->finish(Thing::ThingErrorNoError);
}
@ -752,6 +760,20 @@ void IntegrationPluginGenericThings::executeAction(ThingActionInfo *info)
info->finish(Thing::ThingErrorNoError);
return;
}
} else if (thing->thingClassId() == batteryThingClassId) {
if (action.actionTypeId() == batteryBatteryLevelControlActionTypeId) {
int value = action.paramValue(batteryBatteryLevelControlActionBatteryLevelControlParamTypeId).toInt();
thing->setStateValue(batteryBatteryLevelStateTypeId, value);
thing->setStateValue(batteryBatteryLevelControlStateTypeId, value);
int criticalValue = thing->setting(batterySettingsCriticalLevelParamTypeId).toInt();
thing->setStateValue(batteryBatteryCriticalStateTypeId, value <= criticalValue);
info->finish(Thing::ThingErrorNoError);
return;
} else if (action.actionTypeId() == batteryChargingActionTypeId) {
thing->setStateValue(batteryChargingStateTypeId, action.paramValue(batteryChargingActionChargingParamTypeId));
info->finish(Thing::ThingErrorNoError);
return;
}
} else {
Q_ASSERT_X(false, "executeAction", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8());
}

View File

@ -33,6 +33,7 @@
#include "integrations/integrationplugin.h"
#include "plugintimer.h"
#include "extern-plugininfo.h"
#include <QTimer>

View File

@ -1301,6 +1301,70 @@
"defaultValue": 0
}
]
},
{
"id": "81418556-cae3-4803-aa0c-9c4b3304a3eb",
"name": "battery",
"displayName": "Generic battery",
"createMethods": ["user"],
"interfaces": ["battery"],
"settingsTypes": [
{
"id": "8d875cb7-3a14-42d1-bf1b-759e5fd95a8f",
"name": "criticalLevel",
"displayName": "Critical battery level",
"type": "int",
"minValue": 0,
"maxValue": 100,
"defaultValue": 10
}
],
"stateTypes": [
{
"id": "d37eed4a-befc-40d4-b435-40a761f99314",
"name": "batteryLevel",
"displayName": "Battery level",
"displayNameEvent": "Battery level changed",
"type": "int",
"unit": "Percentage",
"defaultValue": 0,
"minValue": 0,
"maxValue": 100
},
{
"id": "3336f0c2-158b-4353-b74f-f1bb9c4e8447",
"name": "batteryLevelControl",
"displayName": "Battery level control",
"displayNameEvent": "Battery level control changed",
"displayNameAction": "Set battery level",
"type": "double",
"minValue": 0,
"maxValue": 100,
"defaultValue": 0,
"unit": "Percentage",
"writable": true,
"ioType": "analogOutput"
},
{
"id": "a61c0328-b982-46a5-9cc0-b4fa4d0ab84d",
"name": "charging",
"displayName": "Charging",
"displayNameEvent": "Charging started or stopped",
"displayNameAction": "Set charging",
"type": "bool",
"defaultValue": false,
"writable": true,
"ioType": "digitalOutput"
},
{
"id": "e95dc037-002d-40a2-8c15-cd5489bd354a",
"name": "batteryCritical",
"displayName": "Battery critical",
"displayNameEvent": "Battery entered or left critical state",
"type": "bool",
"defaultValue": false
}
]
}
]
}

View File

@ -1081,6 +1081,78 @@ The name of the StateType ({22c1eac6-9bb5-4cc1-ac0d-e3e1499edd3c}) of ThingClass
<extracomment>The name of the EventType ({7f5fdc2b-7916-4e90-9c24-558162304f71}) of ThingClass doorSensor</extracomment>
<translation>Geöffnet oder geschlossen</translation>
</message>
<message>
<source>Battery critical</source>
<extracomment>The name of the ParamType (ThingClass: battery, EventType: batteryCritical, ID: {e95dc037-002d-40a2-8c15-cd5489bd354a})
----------
The name of the StateType ({e95dc037-002d-40a2-8c15-cd5489bd354a}) of ThingClass battery</extracomment>
<translation>Batterieladung kritisch</translation>
</message>
<message>
<source>Battery level</source>
<extracomment>The name of the ParamType (ThingClass: battery, EventType: batteryLevel, ID: {d37eed4a-befc-40d4-b435-40a761f99314})
----------
The name of the StateType ({d37eed4a-befc-40d4-b435-40a761f99314}) of ThingClass battery</extracomment>
<translation>Batterieladung</translation>
</message>
<message>
<source>Battery level changed</source>
<extracomment>The name of the EventType ({d37eed4a-befc-40d4-b435-40a761f99314}) of ThingClass battery</extracomment>
<translation>Batterieladung geändert</translation>
</message>
<message>
<source>Battery level control</source>
<extracomment>The name of the ParamType (ThingClass: battery, ActionType: batteryLevelControl, ID: {3336f0c2-158b-4353-b74f-f1bb9c4e8447})
----------
The name of the ParamType (ThingClass: battery, EventType: batteryLevelControl, ID: {3336f0c2-158b-4353-b74f-f1bb9c4e8447})
----------
The name of the StateType ({3336f0c2-158b-4353-b74f-f1bb9c4e8447}) of ThingClass battery</extracomment>
<translation>Batterieladungssteuerung</translation>
</message>
<message>
<source>Battery level control changed</source>
<extracomment>The name of the EventType ({3336f0c2-158b-4353-b74f-f1bb9c4e8447}) of ThingClass battery</extracomment>
<translation>Batterieladungssteuerung geändert</translation>
</message>
<message>
<source>Charging</source>
<extracomment>The name of the ParamType (ThingClass: battery, ActionType: charging, ID: {a61c0328-b982-46a5-9cc0-b4fa4d0ab84d})
----------
The name of the ParamType (ThingClass: battery, EventType: charging, ID: {a61c0328-b982-46a5-9cc0-b4fa4d0ab84d})
----------
The name of the StateType ({a61c0328-b982-46a5-9cc0-b4fa4d0ab84d}) of ThingClass battery</extracomment>
<translation>Ladend</translation>
</message>
<message>
<source>Generic battery</source>
<extracomment>The name of the ThingClass ({81418556-cae3-4803-aa0c-9c4b3304a3eb})</extracomment>
<translation>Generische Batterie</translation>
</message>
<message>
<source>Critical battery level</source>
<extracomment>The name of the ParamType (ThingClass: battery, Type: settings, ID: {8d875cb7-3a14-42d1-bf1b-759e5fd95a8f})</extracomment>
<translation>Kritischer Batteriewert</translation>
</message>
<message>
<source>Battery entered or left critical state</source>
<extracomment>The name of the EventType ({e95dc037-002d-40a2-8c15-cd5489bd354a}) of ThingClass battery</extracomment>
<translation>Batterieladung kritisch geändert</translation>
</message>
<message>
<source>Charging started or stopped</source>
<extracomment>The name of the EventType ({a61c0328-b982-46a5-9cc0-b4fa4d0ab84d}) of ThingClass battery</extracomment>
<translation>Laden gestartet oder beendet</translation>
</message>
<message>
<source>Set battery level</source>
<extracomment>The name of the ActionType ({3336f0c2-158b-4353-b74f-f1bb9c4e8447}) of ThingClass battery</extracomment>
<translation>Setze Batterieladung</translation>
</message>
<message>
<source>Set charging</source>
<extracomment>The name of the ActionType ({a61c0328-b982-46a5-9cc0-b4fa4d0ab84d}) of ThingClass battery</extracomment>
<translation>Setze Laden</translation>
</message>
</context>
<context>
<name>IntegrationPluginGenericThings</name>

View File

@ -1081,6 +1081,78 @@ The name of the StateType ({22c1eac6-9bb5-4cc1-ac0d-e3e1499edd3c}) of ThingClass
<extracomment>The name of the EventType ({7f5fdc2b-7916-4e90-9c24-558162304f71}) of ThingClass doorSensor</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Battery critical</source>
<extracomment>The name of the ParamType (ThingClass: battery, EventType: batteryCritical, ID: {e95dc037-002d-40a2-8c15-cd5489bd354a})
----------
The name of the StateType ({e95dc037-002d-40a2-8c15-cd5489bd354a}) of ThingClass battery</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Battery level</source>
<extracomment>The name of the ParamType (ThingClass: battery, EventType: batteryLevel, ID: {d37eed4a-befc-40d4-b435-40a761f99314})
----------
The name of the StateType ({d37eed4a-befc-40d4-b435-40a761f99314}) of ThingClass battery</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Battery level changed</source>
<extracomment>The name of the EventType ({d37eed4a-befc-40d4-b435-40a761f99314}) of ThingClass battery</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Battery level control</source>
<extracomment>The name of the ParamType (ThingClass: battery, ActionType: batteryLevelControl, ID: {3336f0c2-158b-4353-b74f-f1bb9c4e8447})
----------
The name of the ParamType (ThingClass: battery, EventType: batteryLevelControl, ID: {3336f0c2-158b-4353-b74f-f1bb9c4e8447})
----------
The name of the StateType ({3336f0c2-158b-4353-b74f-f1bb9c4e8447}) of ThingClass battery</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Battery level control changed</source>
<extracomment>The name of the EventType ({3336f0c2-158b-4353-b74f-f1bb9c4e8447}) of ThingClass battery</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Charging</source>
<extracomment>The name of the ParamType (ThingClass: battery, ActionType: charging, ID: {a61c0328-b982-46a5-9cc0-b4fa4d0ab84d})
----------
The name of the ParamType (ThingClass: battery, EventType: charging, ID: {a61c0328-b982-46a5-9cc0-b4fa4d0ab84d})
----------
The name of the StateType ({a61c0328-b982-46a5-9cc0-b4fa4d0ab84d}) of ThingClass battery</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Generic battery</source>
<extracomment>The name of the ThingClass ({81418556-cae3-4803-aa0c-9c4b3304a3eb})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Critical battery level</source>
<extracomment>The name of the ParamType (ThingClass: battery, Type: settings, ID: {8d875cb7-3a14-42d1-bf1b-759e5fd95a8f})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Battery entered or left critical state</source>
<extracomment>The name of the EventType ({e95dc037-002d-40a2-8c15-cd5489bd354a}) of ThingClass battery</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Charging started or stopped</source>
<extracomment>The name of the EventType ({a61c0328-b982-46a5-9cc0-b4fa4d0ab84d}) of ThingClass battery</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Set battery level</source>
<extracomment>The name of the ActionType ({3336f0c2-158b-4353-b74f-f1bb9c4e8447}) of ThingClass battery</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Set charging</source>
<extracomment>The name of the ActionType ({a61c0328-b982-46a5-9cc0-b4fa4d0ab84d}) of ThingClass battery</extracomment>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>IntegrationPluginGenericThings</name>