From 4a0b3979d86a679697f25cb24d5c6e22d945eec8 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 2 May 2021 16:48:49 +0200 Subject: [PATCH] GenericThings: Add a generic battery thing --- .../integrationplugingenericthings.cpp | 22 ++++++ .../integrationplugingenericthings.h | 1 + .../integrationplugingenericthings.json | 64 +++++++++++++++++ ...b3188696-2585-4806-bf98-30ab576ce5c8-de.ts | 72 +++++++++++++++++++ ...88696-2585-4806-bf98-30ab576ce5c8-en_US.ts | 72 +++++++++++++++++++ 5 files changed, 231 insertions(+) diff --git a/genericthings/integrationplugingenericthings.cpp b/genericthings/integrationplugingenericthings.cpp index d467cd2..bd6cbc5 100644 --- a/genericthings/integrationplugingenericthings.cpp +++ b/genericthings/integrationplugingenericthings.cpp @@ -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()); } diff --git a/genericthings/integrationplugingenericthings.h b/genericthings/integrationplugingenericthings.h index 8f531d5..0bd383d 100644 --- a/genericthings/integrationplugingenericthings.h +++ b/genericthings/integrationplugingenericthings.h @@ -33,6 +33,7 @@ #include "integrations/integrationplugin.h" #include "plugintimer.h" +#include "extern-plugininfo.h" #include diff --git a/genericthings/integrationplugingenericthings.json b/genericthings/integrationplugingenericthings.json index 9fcd2f3..6313642 100644 --- a/genericthings/integrationplugingenericthings.json +++ b/genericthings/integrationplugingenericthings.json @@ -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 + } + ] } ] } diff --git a/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-de.ts b/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-de.ts index a3333d1..daa6d62 100644 --- a/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-de.ts +++ b/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-de.ts @@ -1081,6 +1081,78 @@ The name of the StateType ({22c1eac6-9bb5-4cc1-ac0d-e3e1499edd3c}) of ThingClass The name of the EventType ({7f5fdc2b-7916-4e90-9c24-558162304f71}) of ThingClass doorSensor Geöffnet oder geschlossen + + Battery critical + 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 + Batterieladung kritisch + + + Battery level + 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 + Batterieladung + + + Battery level changed + The name of the EventType ({d37eed4a-befc-40d4-b435-40a761f99314}) of ThingClass battery + Batterieladung geändert + + + Battery level control + 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 + Batterieladungssteuerung + + + Battery level control changed + The name of the EventType ({3336f0c2-158b-4353-b74f-f1bb9c4e8447}) of ThingClass battery + Batterieladungssteuerung geändert + + + Charging + 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 + Ladend + + + Generic battery + The name of the ThingClass ({81418556-cae3-4803-aa0c-9c4b3304a3eb}) + Generische Batterie + + + Critical battery level + The name of the ParamType (ThingClass: battery, Type: settings, ID: {8d875cb7-3a14-42d1-bf1b-759e5fd95a8f}) + Kritischer Batteriewert + + + Battery entered or left critical state + The name of the EventType ({e95dc037-002d-40a2-8c15-cd5489bd354a}) of ThingClass battery + Batterieladung kritisch geändert + + + Charging started or stopped + The name of the EventType ({a61c0328-b982-46a5-9cc0-b4fa4d0ab84d}) of ThingClass battery + Laden gestartet oder beendet + + + Set battery level + The name of the ActionType ({3336f0c2-158b-4353-b74f-f1bb9c4e8447}) of ThingClass battery + Setze Batterieladung + + + Set charging + The name of the ActionType ({a61c0328-b982-46a5-9cc0-b4fa4d0ab84d}) of ThingClass battery + Setze Laden + IntegrationPluginGenericThings diff --git a/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-en_US.ts b/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-en_US.ts index 54bf1a2..ea50a69 100644 --- a/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-en_US.ts +++ b/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-en_US.ts @@ -1081,6 +1081,78 @@ The name of the StateType ({22c1eac6-9bb5-4cc1-ac0d-e3e1499edd3c}) of ThingClass The name of the EventType ({7f5fdc2b-7916-4e90-9c24-558162304f71}) of ThingClass doorSensor + + Battery critical + 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 + + + + Battery level + 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 + + + + Battery level changed + The name of the EventType ({d37eed4a-befc-40d4-b435-40a761f99314}) of ThingClass battery + + + + Battery level control + 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 + + + + Battery level control changed + The name of the EventType ({3336f0c2-158b-4353-b74f-f1bb9c4e8447}) of ThingClass battery + + + + Charging + 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 + + + + Generic battery + The name of the ThingClass ({81418556-cae3-4803-aa0c-9c4b3304a3eb}) + + + + Critical battery level + The name of the ParamType (ThingClass: battery, Type: settings, ID: {8d875cb7-3a14-42d1-bf1b-759e5fd95a8f}) + + + + Battery entered or left critical state + The name of the EventType ({e95dc037-002d-40a2-8c15-cd5489bd354a}) of ThingClass battery + + + + Charging started or stopped + The name of the EventType ({a61c0328-b982-46a5-9cc0-b4fa4d0ab84d}) of ThingClass battery + + + + Set battery level + The name of the ActionType ({3336f0c2-158b-4353-b74f-f1bb9c4e8447}) of ThingClass battery + + + + Set charging + The name of the ActionType ({a61c0328-b982-46a5-9cc0-b4fa4d0ab84d}) of ThingClass battery + + IntegrationPluginGenericThings