From 162d719dec6eaf3ccb70bb6f1346915d7f7a481c Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 25 Jun 2021 18:18:01 +0200 Subject: [PATCH] Update plugins to new smartmeter interface --- .../integrationplugingenericthings.cpp | 28 +++++++++---------- .../integrationplugingenericthings.json | 8 +++--- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/genericthings/integrationplugingenericthings.cpp b/genericthings/integrationplugingenericthings.cpp index d467cd2..09ee5d2 100644 --- a/genericthings/integrationplugingenericthings.cpp +++ b/genericthings/integrationplugingenericthings.cpp @@ -181,24 +181,24 @@ void IntegrationPluginGenericThings::setupThing(ThingSetupInfo *info) } } }); - } else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) { + } else if (thing->thingClassId() == smartMeterThingClassId) { QTimer* smartMeterTimer = new QTimer(this); - int timeframe = thing->setting(extendedSmartMeterConsumerSettingsImpulseTimeframeParamTypeId).toInt(); + int timeframe = thing->setting(smartMeterSettingsImpulseTimeframeParamTypeId).toInt(); smartMeterTimer->setInterval(timeframe * 1000); m_smartMeterTimer.insert(thing, smartMeterTimer); smartMeterTimer->start(); connect(thing, &Thing::settingChanged, smartMeterTimer, [smartMeterTimer] (const ParamTypeId ¶mTypeId, const QVariant &value) { - if (paramTypeId == extendedSmartMeterConsumerSettingsImpulseTimeframeParamTypeId) { + if (paramTypeId == smartMeterSettingsImpulseTimeframeParamTypeId) { smartMeterTimer->setInterval(value.toInt() * 1000); } }); connect(smartMeterTimer, &QTimer::timeout, thing, [this, smartMeterTimer, thing] { - double impulsePerKwh = thing->setting(extendedSmartMeterConsumerSettingsImpulsePerKwhParamTypeId).toDouble(); + double impulsePerKwh = thing->setting(smartMeterSettingsImpulsePerKwhParamTypeId).toDouble(); int interval = smartMeterTimer->interval()/1000; double power = (m_pulsesPerTimeframe.value(thing)/impulsePerKwh)/(interval/3600.00); // Power = Energy/Time; Energy = Impulses/ImpPerkWh - thing->setStateValue(extendedSmartMeterConsumerCurrentPowerStateTypeId, power*1000); + thing->setStateValue(smartMeterCurrentPowerStateTypeId, power*1000); m_pulsesPerTimeframe.insert(thing, 0); }); } else if (thing->thingClassId() == extendedStatefulGaragedoorThingClassId) { @@ -589,14 +589,14 @@ void IntegrationPluginGenericThings::executeAction(ThingActionInfo *info) } else { Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8()); } - } else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) { - if (action.actionTypeId() == extendedSmartMeterConsumerImpulseInputActionTypeId) { - bool value = info->action().param(extendedSmartMeterConsumerImpulseInputActionImpulseInputParamTypeId).value().toBool(); - thing->setStateValue(extendedSmartMeterConsumerImpulseInputStateTypeId, value); - int impulsePerKwh = info->thing()->setting(extendedSmartMeterConsumerSettingsImpulsePerKwhParamTypeId).toInt(); + } else if (thing->thingClassId() == smartMeterThingClassId) { + if (action.actionTypeId() == smartMeterImpulseInputActionTypeId) { + bool value = info->action().param(smartMeterImpulseInputActionImpulseInputParamTypeId).value().toBool(); + thing->setStateValue(smartMeterImpulseInputStateTypeId, value); + int impulsePerKwh = info->thing()->setting(smartMeterSettingsImpulsePerKwhParamTypeId).toInt(); if (value) { - double currentEnergy = thing->stateValue(extendedSmartMeterConsumerTotalEnergyConsumedStateTypeId).toDouble(); - thing->setStateValue(extendedSmartMeterConsumerTotalEnergyConsumedStateTypeId ,currentEnergy + (1.00/impulsePerKwh)); + double currentEnergy = thing->stateValue(smartMeterTotalEnergyConsumedStateTypeId).toDouble(); + thing->setStateValue(smartMeterTotalEnergyConsumedStateTypeId ,currentEnergy + (1.00/impulsePerKwh)); m_pulsesPerTimeframe[thing]++; } info->finish(Thing::ThingErrorNoError); @@ -767,9 +767,9 @@ void IntegrationPluginGenericThings::thingRemoved(Thing *thing) m_extendedBlindTargetPercentage.remove(thing); m_venetianBlindAngleTimer.take(thing)->deleteLater(); m_venetianBlindTargetAngle.remove(thing); - } else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) { + } else if (thing->thingClassId() == smartMeterThingClassId) { m_pulsesPerTimeframe.remove(thing); - } else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) { + } else if (thing->thingClassId() == smartMeterThingClassId) { m_smartMeterTimer.take(thing)->deleteLater(); m_pulsesPerTimeframe.remove(thing); } diff --git a/genericthings/integrationplugingenericthings.json b/genericthings/integrationplugingenericthings.json index 9fcd2f3..e3996fa 100644 --- a/genericthings/integrationplugingenericthings.json +++ b/genericthings/integrationplugingenericthings.json @@ -1033,10 +1033,10 @@ }, { "id": "c3123967-f741-4fe1-a0d4-9a3e405d7e52", - "name": "extendedSmartMeterConsumer", + "name": "smartMeter", "displayName": "Impulse based energy meter", "createMethods": ["user"], - "interfaces": ["extendedsmartmeterconsumer"], + "interfaces": ["smartmeterconsumer"], "settingsTypes": [ { "id": "c361732b-68eb-447e-a434-e84031231871", @@ -1062,8 +1062,8 @@ { "id": "5983d714-5f80-42d8-bee2-9228b6382b3b", "name": "currentPower", - "displayName": "Power", - "displayNameEvent": "Power changed", + "displayName": "Current Power usage", + "displayNameEvent": "Current Power usage changed", "type": "double", "defaultValue": 0.00, "unit": "Watt"