fixed inverter thing setup
This commit is contained in:
parent
1d2bd72cad
commit
4a0541bf18
@ -102,6 +102,7 @@ void IntegrationPluginSma::setupThing(ThingSetupInfo *info)
|
|||||||
connect(sunnyWebBox, &SunnyWebBox::plantOverviewReceived, info, [sunnyWebBox, info, this] {
|
connect(sunnyWebBox, &SunnyWebBox::plantOverviewReceived, info, [sunnyWebBox, info, this] {
|
||||||
qCDebug(dcSma()) << "Received plant overview, finishing setup";
|
qCDebug(dcSma()) << "Received plant overview, finishing setup";
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
connect(sunnyWebBox, &SunnyWebBox::connectedChanged, this, &IntegrationPluginSma::onConnectedChanged);
|
||||||
connect(sunnyWebBox, &SunnyWebBox::plantOverviewReceived, this, &IntegrationPluginSma::onPlantOverviewReceived);
|
connect(sunnyWebBox, &SunnyWebBox::plantOverviewReceived, this, &IntegrationPluginSma::onPlantOverviewReceived);
|
||||||
connect(sunnyWebBox, &SunnyWebBox::devicesReceived, this, &IntegrationPluginSma::onDevicesReceived);
|
connect(sunnyWebBox, &SunnyWebBox::devicesReceived, this, &IntegrationPluginSma::onDevicesReceived);
|
||||||
connect(sunnyWebBox, &SunnyWebBox::processDataReceived, this, &IntegrationPluginSma::onProcessDataReceived);
|
connect(sunnyWebBox, &SunnyWebBox::processDataReceived, this, &IntegrationPluginSma::onProcessDataReceived);
|
||||||
@ -115,16 +116,17 @@ void IntegrationPluginSma::setupThing(ThingSetupInfo *info)
|
|||||||
qCWarning(dcSma()) << "Could not find parentThing for thing " << thing->name();
|
qCWarning(dcSma()) << "Could not find parentThing for thing " << thing->name();
|
||||||
return info->finish(Thing::ThingErrorHardwareNotAvailable, "Please try again");
|
return info->finish(Thing::ThingErrorHardwareNotAvailable, "Please try again");
|
||||||
}
|
}
|
||||||
if (!parentThing->setupComplete()) {
|
if (parentThing->setupComplete()) {
|
||||||
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
} else {
|
||||||
//wait for the parent to finish the setup process
|
//wait for the parent to finish the setup process
|
||||||
connect(parentThing, &Thing::setupStatusChanged, info, [this, info, parentThing] {
|
connect(parentThing, &Thing::setupStatusChanged, info, [this, info, parentThing] {
|
||||||
|
|
||||||
if (parentThing->setupComplete())
|
if (parentThing->setupComplete())
|
||||||
setupChild(info, parentThing);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setupChild(info, parentThing);
|
|
||||||
} else {
|
} else {
|
||||||
Q_ASSERT_X(false, "setupThing", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8());
|
Q_ASSERT_X(false, "setupThing", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8());
|
||||||
}
|
}
|
||||||
@ -140,7 +142,11 @@ void IntegrationPluginSma::postSetupThing(Thing *thing)
|
|||||||
sunnyWebBox->getDevices();
|
sunnyWebBox->getDevices();
|
||||||
thing->setStateValue(sunnyWebBoxConnectedStateTypeId, true);
|
thing->setStateValue(sunnyWebBoxConnectedStateTypeId, true);
|
||||||
} else if (thing->thingClassId() == inverterThingClassId) {
|
} else if (thing->thingClassId() == inverterThingClassId) {
|
||||||
|
SunnyWebBox *sunnyWebBox = m_sunnyWebBoxes.value(myThings().findById(thing->parentId()));
|
||||||
|
if (!sunnyWebBox)
|
||||||
|
return;
|
||||||
|
QString key = thing->paramValue(inverterThingIdParamTypeId).toString();
|
||||||
|
sunnyWebBox->getParameters(QStringList() << key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,6 +194,14 @@ void IntegrationPluginSma::onRefreshTimer()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IntegrationPluginSma::onConnectedChanged(bool connected)
|
||||||
|
{
|
||||||
|
Thing *thing = m_sunnyWebBoxes.key(static_cast<SunnyWebBox *>(sender()));
|
||||||
|
if (!thing)
|
||||||
|
return;
|
||||||
|
thing->setStateValue(sunnyWebBoxConnectedStateTypeId, connected);
|
||||||
|
}
|
||||||
|
|
||||||
void IntegrationPluginSma::onPlantOverviewReceived(const QString &messageId, SunnyWebBox::Overview overview)
|
void IntegrationPluginSma::onPlantOverviewReceived(const QString &messageId, SunnyWebBox::Overview overview)
|
||||||
{
|
{
|
||||||
qCDebug(dcSma()) << "Plant overview received" << overview.status;
|
qCDebug(dcSma()) << "Plant overview received" << overview.status;
|
||||||
@ -200,7 +214,6 @@ void IntegrationPluginSma::onPlantOverviewReceived(const QString &messageId, Sun
|
|||||||
if (!thing)
|
if (!thing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
thing->setStateValue(sunnyWebBoxConnectedStateTypeId, true);
|
|
||||||
thing->setStateValue(sunnyWebBoxCurrentPowerStateTypeId, overview.power);
|
thing->setStateValue(sunnyWebBoxCurrentPowerStateTypeId, overview.power);
|
||||||
thing->setStateValue(sunnyWebBoxDayEnergyStateTypeId, overview.dailyYield);
|
thing->setStateValue(sunnyWebBoxDayEnergyStateTypeId, overview.dailyYield);
|
||||||
thing->setStateValue(sunnyWebBoxTotalEnergyStateTypeId, overview.totalYield);
|
thing->setStateValue(sunnyWebBoxTotalEnergyStateTypeId, overview.totalYield);
|
||||||
@ -226,6 +239,8 @@ void IntegrationPluginSma::onDevicesReceived(const QString &messageId, QList<Sun
|
|||||||
ThingDescriptors descriptors;
|
ThingDescriptors descriptors;
|
||||||
Q_FOREACH(SunnyWebBox::Device device, devices){
|
Q_FOREACH(SunnyWebBox::Device device, devices){
|
||||||
qCDebug(dcSma()) << " - Device received" << device.name << device.key;
|
qCDebug(dcSma()) << " - Device received" << device.name << device.key;
|
||||||
|
if (myThings().findByParams(ParamList() << Param(inverterThingIdParamTypeId, device.key)))
|
||||||
|
continue;
|
||||||
ThingDescriptor descriptor(inverterThingClassId, device.name, device.key ,thing->id());
|
ThingDescriptor descriptor(inverterThingClassId, device.name, device.key ,thing->id());
|
||||||
ParamList params;
|
ParamList params;
|
||||||
params << Param(inverterThingIdParamTypeId, device.key);
|
params << Param(inverterThingIdParamTypeId, device.key);
|
||||||
@ -235,6 +250,18 @@ void IntegrationPluginSma::onDevicesReceived(const QString &messageId, QList<Sun
|
|||||||
emit autoThingsAppeared(descriptors);
|
emit autoThingsAppeared(descriptors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IntegrationPluginSma::onParametersReceived(const QString &messageId, const QString &deviceKey, const QList<SunnyWebBox::Parameter> ¶meters)
|
||||||
|
{
|
||||||
|
Q_UNUSED(messageId);
|
||||||
|
Thing *thing = myThings().findByParams(ParamList() << Param(inverterThingIdParamTypeId, deviceKey));
|
||||||
|
if (!thing)
|
||||||
|
return;
|
||||||
|
qCDebug(dcSma()) << "Parameters received";
|
||||||
|
Q_FOREACH(SunnyWebBox::Parameter parameter, parameters) {
|
||||||
|
qCDebug(dcSma()) << " - " << parameter.name << parameter.value << parameter.unit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void IntegrationPluginSma::onProcessDataReceived(const QString &messageId, const QString &deviceKey, const QHash<QString, QVariant> &channels)
|
void IntegrationPluginSma::onProcessDataReceived(const QString &messageId, const QString &deviceKey, const QHash<QString, QVariant> &channels)
|
||||||
{
|
{
|
||||||
Q_UNUSED(messageId)
|
Q_UNUSED(messageId)
|
||||||
@ -265,12 +292,6 @@ void IntegrationPluginSma::onParameterChannelsReceived(const QString &messageId,
|
|||||||
qCDebug(dcSma()) << "Parameter channels received" << deviceKey << parameterChannels;
|
qCDebug(dcSma()) << "Parameter channels received" << deviceKey << parameterChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegrationPluginSma::setupChild(ThingSetupInfo *info, Thing *parentThing)
|
|
||||||
{
|
|
||||||
Q_UNUSED(info)
|
|
||||||
Q_UNUSED(parentThing)
|
|
||||||
}
|
|
||||||
|
|
||||||
void IntegrationPluginSma::getData(Thing *thing)
|
void IntegrationPluginSma::getData(Thing *thing)
|
||||||
{
|
{
|
||||||
Q_UNUSED(thing)
|
Q_UNUSED(thing)
|
||||||
|
|||||||
@ -59,8 +59,10 @@ public:
|
|||||||
private slots:
|
private slots:
|
||||||
void onRefreshTimer();
|
void onRefreshTimer();
|
||||||
|
|
||||||
|
void onConnectedChanged(bool connected);
|
||||||
void onPlantOverviewReceived(const QString &messageId, SunnyWebBox::Overview overview);
|
void onPlantOverviewReceived(const QString &messageId, SunnyWebBox::Overview overview);
|
||||||
void onDevicesReceived(const QString &messageId, QList<SunnyWebBox::Device> devices);
|
void onDevicesReceived(const QString &messageId, QList<SunnyWebBox::Device> devices);
|
||||||
|
void onParametersReceived(const QString &messageId, const QString &deviceKey, const QList<SunnyWebBox::Parameter> ¶meters);
|
||||||
void onProcessDataReceived(const QString &messageId, const QString &deviceKey, const QHash<QString, QVariant> &channels);
|
void onProcessDataReceived(const QString &messageId, const QString &deviceKey, const QHash<QString, QVariant> &channels);
|
||||||
void onParameterChannelsReceived(const QString &messageId, const QString &deviceKey, QStringList parameterChannels);
|
void onParameterChannelsReceived(const QString &messageId, const QString &deviceKey, QStringList parameterChannels);
|
||||||
|
|
||||||
@ -71,7 +73,6 @@ private:
|
|||||||
QHash<QString, ThingActionInfo *> m_asyncActions;
|
QHash<QString, ThingActionInfo *> m_asyncActions;
|
||||||
SunnyWebBoxCommunication *m_sunnyWebBoxCommunication = nullptr;
|
SunnyWebBoxCommunication *m_sunnyWebBoxCommunication = nullptr;
|
||||||
|
|
||||||
void setupChild(ThingSetupInfo *info, Thing *parentThing);
|
|
||||||
void getData(Thing *thing);
|
void getData(Thing *thing);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -105,7 +105,6 @@
|
|||||||
"name": "id",
|
"name": "id",
|
||||||
"displayName": "Device ID",
|
"displayName": "Device ID",
|
||||||
"type": "QString",
|
"type": "QString",
|
||||||
"inputType": "TextLine",
|
|
||||||
"readOnly": true
|
"readOnly": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user