diff --git a/genericthings/integrationplugingenericthings.cpp b/genericthings/integrationplugingenericthings.cpp index 3244bb9e..9aecf771 100644 --- a/genericthings/integrationplugingenericthings.cpp +++ b/genericthings/integrationplugingenericthings.cpp @@ -40,28 +40,10 @@ IntegrationPluginGenericThings::IntegrationPluginGenericThings() } -void IntegrationPluginGenericThings::init() -{ - -} - void IntegrationPluginGenericThings::setupThing(ThingSetupInfo *info) { Thing *thing = info->thing(); - if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) { - if (!m_smartMeterTimer) { - m_smartMeterTimer = hardwareManager()->pluginTimerManager()->registerTimer(10); - } - connect(m_smartMeterTimer, &PluginTimer::timeout, thing, [this, thing] { - double impulsePerKwh = thing->setting(extendedSmartMeterConsumerSettingsImpulsePerKwhParamTypeId).toDouble(); - double power = (m_pulsesPerTimeframe.value(thing)/impulsePerKwh)/(m_smartMeterTimer->interval()/3600.00); // Power = Energy/Time; Energy = Impulses/ImpPerkWh - thing->setStateValue(extendedSmartMeterConsumerCurrentPowerStateTypeId, power*1000); - m_pulsesPerTimeframe.insert(thing, 0); - }); - } - info->finish(Thing::ThingErrorNoError); - Thing *thing = info->thing(); if (thing->thingClassId() == extendedBlindThingClassId) { uint closingTime = thing->setting(extendedBlindSettingsClosingTimeParamTypeId).toUInt(); if (closingTime == 0) { @@ -202,7 +184,19 @@ void IntegrationPluginGenericThings::setupThing(ThingSetupInfo *info) } } }); + } else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) { + if (!m_smartMeterTimer) { + m_smartMeterTimer = hardwareManager()->pluginTimerManager()->registerTimer(10); + } + connect(m_smartMeterTimer, &PluginTimer::timeout, thing, [this, thing] { + + double impulsePerKwh = thing->setting(extendedSmartMeterConsumerSettingsImpulsePerKwhParamTypeId).toDouble(); + double power = (m_pulsesPerTimeframe.value(thing)/impulsePerKwh)/(m_smartMeterTimer->interval()/3600.00); // Power = Energy/Time; Energy = Impulses/ImpPerkWh + thing->setStateValue(extendedSmartMeterConsumerCurrentPowerStateTypeId, power*1000); + m_pulsesPerTimeframe.insert(thing, 0); + }); } + info->finish(Thing::ThingErrorNoError); } void IntegrationPluginGenericThings::executeAction(ThingActionInfo *info) @@ -518,12 +512,7 @@ void IntegrationPluginGenericThings::thingRemoved(Thing *thing) m_extendedBlindTargetPercentage.remove(thing); m_venetianBlindAngleTimer.take(thing)->deleteLater(); m_venetianBlindTargetAngle.remove(thing); - } -} - -void IntegrationPluginGenericThings::thingRemoved(Thing *thing) -{ - if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) { + } else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) { m_pulsesPerTimeframe.remove(thing); } diff --git a/genericthings/integrationplugingenericthings.h b/genericthings/integrationplugingenericthings.h index e8b53857..77fa0aeb 100644 --- a/genericthings/integrationplugingenericthings.h +++ b/genericthings/integrationplugingenericthings.h @@ -32,9 +32,10 @@ #define INTEGRATIONPLUGINGENERICTHINGS_H #include "integrations/integrationplugin.h" -#include #include "plugintimer.h" +#include + class IntegrationPluginGenericThings: public IntegrationPlugin { Q_OBJECT @@ -44,7 +45,6 @@ class IntegrationPluginGenericThings: public IntegrationPlugin public: explicit IntegrationPluginGenericThings(); - void init() override; void setupThing(ThingSetupInfo *info) override; void executeAction(ThingActionInfo *info) override; void thingRemoved(Thing *thing) override;