changed remarks from reviewer

This commit is contained in:
bernhard.trinnes 2020-07-29 14:49:41 +02:00 committed by Michael Zanetti
parent aefb6e0dfe
commit 69f2cdf406
5 changed files with 81 additions and 50 deletions

View File

@ -185,13 +185,20 @@ void IntegrationPluginGenericThings::setupThing(ThingSetupInfo *info)
} }
}); });
} else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) { } else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) {
if (!m_smartMeterTimer) {
m_smartMeterTimer = hardwareManager()->pluginTimerManager()->registerTimer(10);
}
connect(m_smartMeterTimer, &PluginTimer::timeout, thing, [this, thing] {
QTimer* smartMeterTimer = new QTimer(this);
int timeframe = thing->setting(extendedSmartMeterConsumerSettingsImpulseTimeframeParamTypeId).toInt();
smartMeterTimer->setInterval(timeframe * 1000);
m_smartMeterTimer.insert(thing, smartMeterTimer);
connect(thing, &Thing::settingChanged, smartMeterTimer, [smartMeterTimer] (const ParamTypeId &paramTypeId, const QVariant &value) {
if (paramTypeId == extendedSmartMeterConsumerSettingsImpulseTimeframeParamTypeId) {
smartMeterTimer->setInterval(value.toInt() * 1000);
}
});
connect(smartMeterTimer, &QTimer::timeout, thing, [this, smartMeterTimer, thing] {
double impulsePerKwh = thing->setting(extendedSmartMeterConsumerSettingsImpulsePerKwhParamTypeId).toDouble(); double impulsePerKwh = thing->setting(extendedSmartMeterConsumerSettingsImpulsePerKwhParamTypeId).toDouble();
double power = (m_pulsesPerTimeframe.value(thing)/impulsePerKwh)/(m_smartMeterTimer->interval()/3600.00); // Power = Energy/Time; Energy = Impulses/ImpPerkWh double power = (m_pulsesPerTimeframe.value(thing)/impulsePerKwh)/(smartMeterTimer->interval()/3600.00); // Power = Energy/Time; Energy = Impulses/ImpPerkWh
thing->setStateValue(extendedSmartMeterConsumerCurrentPowerStateTypeId, power*1000); thing->setStateValue(extendedSmartMeterConsumerCurrentPowerStateTypeId, power*1000);
m_pulsesPerTimeframe.insert(thing, 0); m_pulsesPerTimeframe.insert(thing, 0);
}); });
@ -483,14 +490,14 @@ void IntegrationPluginGenericThings::executeAction(ThingActionInfo *info)
Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8()); Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8());
} }
} else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) { } else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) {
if (action.actionTypeId() == extendedSmartMeterConsumerS0InputActionTypeId) { if (action.actionTypeId() == extendedSmartMeterConsumerImpulseInputActionTypeId) {
bool value = info->action().param(extendedSmartMeterConsumerS0InputActionS0InputParamTypeId).value().toBool(); bool value = info->action().param(extendedSmartMeterConsumerImpulseInputActionImpulseInputParamTypeId).value().toBool();
thing->setStateValue(extendedSmartMeterConsumerS0InputStateTypeId, value); thing->setStateValue(extendedSmartMeterConsumerImpulseInputStateTypeId, value);
int impulsePerKwh = info->thing()->setting(extendedSmartMeterConsumerSettingsImpulsePerKwhParamTypeId).toInt(); int impulsePerKwh = info->thing()->setting(extendedSmartMeterConsumerSettingsImpulsePerKwhParamTypeId).toInt();
if (value) { if (value) {
double currentEnergy = thing->stateValue(extendedSmartMeterConsumerTotalEnergyConsumedStateTypeId).toDouble(); double currentEnergy = thing->stateValue(extendedSmartMeterConsumerTotalEnergyConsumedStateTypeId).toDouble();
thing->setStateValue(extendedSmartMeterConsumerTotalEnergyConsumedStateTypeId ,currentEnergy + (1.00/impulsePerKwh)); thing->setStateValue(extendedSmartMeterConsumerTotalEnergyConsumedStateTypeId ,currentEnergy + (1.00/impulsePerKwh));
m_pulsesPerTimeframe.insert(thing, m_pulsesPerTimeframe.value(thing)+1); m_pulsesPerTimeframe[thing]++;
} }
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
@ -514,11 +521,9 @@ void IntegrationPluginGenericThings::thingRemoved(Thing *thing)
m_venetianBlindTargetAngle.remove(thing); m_venetianBlindTargetAngle.remove(thing);
} else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) { } else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) {
m_pulsesPerTimeframe.remove(thing); m_pulsesPerTimeframe.remove(thing);
} } else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) {
m_smartMeterTimer.take(thing)->deleteLater();
if (myThings().isEmpty()) { m_pulsesPerTimeframe.remove(thing);
hardwareManager()->pluginTimerManager()->unregisterTimer(m_smartMeterTimer);
m_smartMeterTimer = nullptr;
} }
} }

View File

@ -50,13 +50,13 @@ public:
void thingRemoved(Thing *thing) override; void thingRemoved(Thing *thing) override;
private: private:
PluginTimer *m_smartMeterTimer = nullptr;
QHash<Thing *, int> m_pulsesPerTimeframe; QHash<Thing *, int> m_pulsesPerTimeframe;
double mapDoubleValue(double value, double fromMin, double fromMax, double toMin, double toMax); double mapDoubleValue(double value, double fromMin, double fromMax, double toMin, double toMax);
QHash<Thing *, QTimer *> m_extendedBlindPercentageTimer; QHash<Thing *, QTimer *> m_extendedBlindPercentageTimer;
QHash<Thing *, QTimer *> m_venetianBlindAngleTimer; QHash<Thing *, QTimer *> m_venetianBlindAngleTimer;
QHash<Thing *, QTimer *> m_smartMeterTimer;
QHash<Thing *, uint> m_extendedBlindTargetPercentage; QHash<Thing *, uint> m_extendedBlindTargetPercentage;
QHash<Thing *, int> m_venetianBlindTargetAngle; QHash<Thing *, int> m_venetianBlindTargetAngle;

View File

@ -697,7 +697,7 @@
{ {
"id": "c3123967-f741-4fe1-a0d4-9a3e405d7e52", "id": "c3123967-f741-4fe1-a0d4-9a3e405d7e52",
"name": "extendedSmartMeterConsumer", "name": "extendedSmartMeterConsumer",
"displayName": "Extended smart meter consumer", "displayName": "Impulse based energy meter",
"createMethods": ["user"], "createMethods": ["user"],
"interfaces": ["extendedsmartmeterconsumer"], "interfaces": ["extendedsmartmeterconsumer"],
"settingsTypes": [ "settingsTypes": [
@ -709,6 +709,16 @@
"minValue": 1, "minValue": 1,
"maxValue": 1000000, "maxValue": 1000000,
"defaultValue": 1000 "defaultValue": 1000
},
{
"id": "73c9acc3-8f76-40d7-a79b-a1f08bb308d4",
"name": "impulseTimeframe",
"displayName": "Timeframe for power calculation",
"type": "int",
"unit": "Seconds",
"minValue": 1,
"maxValue": 600,
"defaultValue": 10
} }
], ],
"stateTypes": [ "stateTypes": [
@ -732,10 +742,10 @@
}, },
{ {
"id": "9cd7e5ca-f8f8-48d5-9785-911ae75158c3", "id": "9cd7e5ca-f8f8-48d5-9785-911ae75158c3",
"name": "s0Input", "name": "impulseInput",
"displayName": "S0 input", "displayName": "Impulse input",
"displayNameEvent": "S0 impulse", "displayNameEvent": "Impulse input changed",
"displayNameAction": "S0 impulse", "displayNameAction": "Set impulse input",
"type": "bool", "type": "bool",
"defaultValue": false, "defaultValue": false,
"writable": true, "writable": true,

View File

@ -567,31 +567,39 @@ The name of the StateType ({5821edb7-e6cb-4e5a-9d0b-3375126d3367}) of ThingClass
<extracomment>The name of the EventType ({5821edb7-e6cb-4e5a-9d0b-3375126d3367}) of ThingClass extendedSmartMeterConsumer</extracomment> <extracomment>The name of the EventType ({5821edb7-e6cb-4e5a-9d0b-3375126d3367}) of ThingClass extendedSmartMeterConsumer</extracomment>
<translation>Energie geändert</translation> <translation>Energie geändert</translation>
</message> </message>
<message>
<source>Extended smart meter consumer</source>
<extracomment>The name of the ThingClass ({c3123967-f741-4fe1-a0d4-9a3e405d7e52})</extracomment>
<translation>Erweiterter Smart-Meter Verbraucher</translation>
</message>
<message> <message>
<source>Impulse/kWh</source> <source>Impulse/kWh</source>
<extracomment>The name of the ParamType (ThingClass: extendedSmartMeterConsumer, Type: settings, ID: {c361732b-68eb-447e-a434-e84031231871})</extracomment> <extracomment>The name of the ParamType (ThingClass: extendedSmartMeterConsumer, Type: settings, ID: {c361732b-68eb-447e-a434-e84031231871})</extracomment>
<translation>Impulse/kWh</translation> <translation>Impulse/kWh</translation>
</message> </message>
<message> <message>
<source>S0 impulse</source> <source>Impulse input</source>
<extracomment>The name of the ActionType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer <extracomment>The name of the ParamType (ThingClass: extendedSmartMeterConsumer, ActionType: impulseInput, ID: {9cd7e5ca-f8f8-48d5-9785-911ae75158c3})
---------- ----------
The name of the EventType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer</extracomment> The name of the ParamType (ThingClass: extendedSmartMeterConsumer, EventType: impulseInput, ID: {9cd7e5ca-f8f8-48d5-9785-911ae75158c3})
<translation>S0 Impulse</translation>
</message>
<message>
<source>S0 input</source>
<extracomment>The name of the ParamType (ThingClass: extendedSmartMeterConsumer, ActionType: s0Input, ID: {9cd7e5ca-f8f8-48d5-9785-911ae75158c3})
----------
The name of the ParamType (ThingClass: extendedSmartMeterConsumer, EventType: s0Input, ID: {9cd7e5ca-f8f8-48d5-9785-911ae75158c3})
---------- ----------
The name of the StateType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer</extracomment> The name of the StateType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer</extracomment>
<translation>S0 Input</translation> <translation>Impulseingang</translation>
</message>
<message>
<source>Impulse input changed</source>
<extracomment>The name of the EventType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer</extracomment>
<translation>Impulseingang geändert</translation>
</message>
<message>
<source>Set impulse input</source>
<extracomment>The name of the ActionType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer</extracomment>
<translation>Setze Impulseingang</translation>
</message>
<message>
<source>Timeframe for power calculation</source>
<extracomment>The name of the ParamType (ThingClass: extendedSmartMeterConsumer, Type: settings, ID: {73c9acc3-8f76-40d7-a79b-a1f08bb308d4})</extracomment>
<translation>Zeitfenster für Leistungsberechnung</translation>
</message>
<message>
<source>Impulse based energy meter</source>
<extracomment>The name of the ThingClass ({c3123967-f741-4fe1-a0d4-9a3e405d7e52})</extracomment>
<translation>Impulsbasierter Energiezähler</translation>
</message> </message>
</context> </context>
<context> <context>

View File

@ -567,30 +567,38 @@ The name of the StateType ({5821edb7-e6cb-4e5a-9d0b-3375126d3367}) of ThingClass
<extracomment>The name of the EventType ({5821edb7-e6cb-4e5a-9d0b-3375126d3367}) of ThingClass extendedSmartMeterConsumer</extracomment> <extracomment>The name of the EventType ({5821edb7-e6cb-4e5a-9d0b-3375126d3367}) of ThingClass extendedSmartMeterConsumer</extracomment>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Extended smart meter consumer</source>
<extracomment>The name of the ThingClass ({c3123967-f741-4fe1-a0d4-9a3e405d7e52})</extracomment>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Impulse/kWh</source> <source>Impulse/kWh</source>
<extracomment>The name of the ParamType (ThingClass: extendedSmartMeterConsumer, Type: settings, ID: {c361732b-68eb-447e-a434-e84031231871})</extracomment> <extracomment>The name of the ParamType (ThingClass: extendedSmartMeterConsumer, Type: settings, ID: {c361732b-68eb-447e-a434-e84031231871})</extracomment>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>S0 impulse</source> <source>Impulse input</source>
<extracomment>The name of the ActionType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer <extracomment>The name of the ParamType (ThingClass: extendedSmartMeterConsumer, ActionType: impulseInput, ID: {9cd7e5ca-f8f8-48d5-9785-911ae75158c3})
---------- ----------
The name of the EventType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer</extracomment> The name of the ParamType (ThingClass: extendedSmartMeterConsumer, EventType: impulseInput, ID: {9cd7e5ca-f8f8-48d5-9785-911ae75158c3})
----------
The name of the StateType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer</extracomment>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>S0 input</source> <source>Impulse input changed</source>
<extracomment>The name of the ParamType (ThingClass: extendedSmartMeterConsumer, ActionType: s0Input, ID: {9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) <extracomment>The name of the EventType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer</extracomment>
---------- <translation type="unfinished"></translation>
The name of the ParamType (ThingClass: extendedSmartMeterConsumer, EventType: s0Input, ID: {9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) </message>
---------- <message>
The name of the StateType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer</extracomment> <source>Set impulse input</source>
<extracomment>The name of the ActionType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Timeframe for power calculation</source>
<extracomment>The name of the ParamType (ThingClass: extendedSmartMeterConsumer, Type: settings, ID: {73c9acc3-8f76-40d7-a79b-a1f08bb308d4})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Impulse based energy meter</source>
<extracomment>The name of the ThingClass ({c3123967-f741-4fe1-a0d4-9a3e405d7e52})</extracomment>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>