Merge PR #448: Update plugins to new smartmeter interface
This commit is contained in:
commit
f608159b0a
@ -181,24 +181,24 @@ void IntegrationPluginGenericThings::setupThing(ThingSetupInfo *info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) {
|
} else if (thing->thingClassId() == smartMeterThingClassId) {
|
||||||
|
|
||||||
QTimer* smartMeterTimer = new QTimer(this);
|
QTimer* smartMeterTimer = new QTimer(this);
|
||||||
int timeframe = thing->setting(extendedSmartMeterConsumerSettingsImpulseTimeframeParamTypeId).toInt();
|
int timeframe = thing->setting(smartMeterSettingsImpulseTimeframeParamTypeId).toInt();
|
||||||
smartMeterTimer->setInterval(timeframe * 1000);
|
smartMeterTimer->setInterval(timeframe * 1000);
|
||||||
m_smartMeterTimer.insert(thing, smartMeterTimer);
|
m_smartMeterTimer.insert(thing, smartMeterTimer);
|
||||||
smartMeterTimer->start();
|
smartMeterTimer->start();
|
||||||
connect(thing, &Thing::settingChanged, smartMeterTimer, [smartMeterTimer] (const ParamTypeId ¶mTypeId, const QVariant &value) {
|
connect(thing, &Thing::settingChanged, smartMeterTimer, [smartMeterTimer] (const ParamTypeId ¶mTypeId, const QVariant &value) {
|
||||||
if (paramTypeId == extendedSmartMeterConsumerSettingsImpulseTimeframeParamTypeId) {
|
if (paramTypeId == smartMeterSettingsImpulseTimeframeParamTypeId) {
|
||||||
smartMeterTimer->setInterval(value.toInt() * 1000);
|
smartMeterTimer->setInterval(value.toInt() * 1000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(smartMeterTimer, &QTimer::timeout, thing, [this, smartMeterTimer, thing] {
|
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;
|
int interval = smartMeterTimer->interval()/1000;
|
||||||
double power = (m_pulsesPerTimeframe.value(thing)/impulsePerKwh)/(interval/3600.00); // Power = Energy/Time; Energy = Impulses/ImpPerkWh
|
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);
|
m_pulsesPerTimeframe.insert(thing, 0);
|
||||||
});
|
});
|
||||||
} else if (thing->thingClassId() == extendedStatefulGaragedoorThingClassId) {
|
} else if (thing->thingClassId() == extendedStatefulGaragedoorThingClassId) {
|
||||||
@ -637,14 +637,14 @@ void IntegrationPluginGenericThings::executeAction(ThingActionInfo *info)
|
|||||||
} else {
|
} else {
|
||||||
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() == smartMeterThingClassId) {
|
||||||
if (action.actionTypeId() == extendedSmartMeterConsumerImpulseInputActionTypeId) {
|
if (action.actionTypeId() == smartMeterImpulseInputActionTypeId) {
|
||||||
bool value = info->action().param(extendedSmartMeterConsumerImpulseInputActionImpulseInputParamTypeId).value().toBool();
|
bool value = info->action().param(smartMeterImpulseInputActionImpulseInputParamTypeId).value().toBool();
|
||||||
thing->setStateValue(extendedSmartMeterConsumerImpulseInputStateTypeId, value);
|
thing->setStateValue(smartMeterImpulseInputStateTypeId, value);
|
||||||
int impulsePerKwh = info->thing()->setting(extendedSmartMeterConsumerSettingsImpulsePerKwhParamTypeId).toInt();
|
int impulsePerKwh = info->thing()->setting(smartMeterSettingsImpulsePerKwhParamTypeId).toInt();
|
||||||
if (value) {
|
if (value) {
|
||||||
double currentEnergy = thing->stateValue(extendedSmartMeterConsumerTotalEnergyConsumedStateTypeId).toDouble();
|
double currentEnergy = thing->stateValue(smartMeterTotalEnergyConsumedStateTypeId).toDouble();
|
||||||
thing->setStateValue(extendedSmartMeterConsumerTotalEnergyConsumedStateTypeId ,currentEnergy + (1.00/impulsePerKwh));
|
thing->setStateValue(smartMeterTotalEnergyConsumedStateTypeId ,currentEnergy + (1.00/impulsePerKwh));
|
||||||
m_pulsesPerTimeframe[thing]++;
|
m_pulsesPerTimeframe[thing]++;
|
||||||
}
|
}
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
@ -829,9 +829,9 @@ void IntegrationPluginGenericThings::thingRemoved(Thing *thing)
|
|||||||
m_extendedBlindTargetPercentage.remove(thing);
|
m_extendedBlindTargetPercentage.remove(thing);
|
||||||
m_venetianBlindAngleTimer.take(thing)->deleteLater();
|
m_venetianBlindAngleTimer.take(thing)->deleteLater();
|
||||||
m_venetianBlindTargetAngle.remove(thing);
|
m_venetianBlindTargetAngle.remove(thing);
|
||||||
} else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) {
|
} else if (thing->thingClassId() == smartMeterThingClassId) {
|
||||||
m_pulsesPerTimeframe.remove(thing);
|
m_pulsesPerTimeframe.remove(thing);
|
||||||
} else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) {
|
} else if (thing->thingClassId() == smartMeterThingClassId) {
|
||||||
m_smartMeterTimer.take(thing)->deleteLater();
|
m_smartMeterTimer.take(thing)->deleteLater();
|
||||||
m_pulsesPerTimeframe.remove(thing);
|
m_pulsesPerTimeframe.remove(thing);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1133,10 +1133,10 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "c3123967-f741-4fe1-a0d4-9a3e405d7e52",
|
"id": "c3123967-f741-4fe1-a0d4-9a3e405d7e52",
|
||||||
"name": "extendedSmartMeterConsumer",
|
"name": "smartMeter",
|
||||||
"displayName": "Impulse based energy meter",
|
"displayName": "Impulse based energy meter",
|
||||||
"createMethods": ["user"],
|
"createMethods": ["user"],
|
||||||
"interfaces": ["extendedsmartmeterconsumer"],
|
"interfaces": ["smartmeterconsumer"],
|
||||||
"settingsTypes": [
|
"settingsTypes": [
|
||||||
{
|
{
|
||||||
"id": "c361732b-68eb-447e-a434-e84031231871",
|
"id": "c361732b-68eb-447e-a434-e84031231871",
|
||||||
@ -1162,8 +1162,8 @@
|
|||||||
{
|
{
|
||||||
"id": "5983d714-5f80-42d8-bee2-9228b6382b3b",
|
"id": "5983d714-5f80-42d8-bee2-9228b6382b3b",
|
||||||
"name": "currentPower",
|
"name": "currentPower",
|
||||||
"displayName": "Power",
|
"displayName": "Current Power usage",
|
||||||
"displayNameEvent": "Power changed",
|
"displayNameEvent": "Current Power usage changed",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"defaultValue": 0.00,
|
"defaultValue": 0.00,
|
||||||
"unit": "Watt"
|
"unit": "Watt"
|
||||||
|
|||||||
Reference in New Issue
Block a user