diff --git a/sma/integrationpluginsma.cpp b/sma/integrationpluginsma.cpp index 1968c28a..6dfa1835 100644 --- a/sma/integrationpluginsma.cpp +++ b/sma/integrationpluginsma.cpp @@ -75,8 +75,8 @@ void IntegrationPluginSma::discoverThings(ThingDiscoveryInfo *info) } ParamList params; - params << Param(sunnyWebBoxThingMacAddressParamTypeId, networkDeviceInfo.macAddress()); params << Param(sunnyWebBoxThingHostParamTypeId, networkDeviceInfo.address().toString()); + params << Param(sunnyWebBoxThingMacAddressParamTypeId, networkDeviceInfo.macAddress()); descriptor.setParams(params); descriptors.append(descriptor); } @@ -89,25 +89,29 @@ void IntegrationPluginSma::discoverThings(ThingDiscoveryInfo *info) void IntegrationPluginSma::setupThing(ThingSetupInfo *info) { Thing *thing = info->thing(); - qCDebug(dcSma()) << "Setup thing" << thing->name(); + qCDebug(dcSma()) << "Setup thing" << thing << thing->params(); if (thing->thingClassId() == sunnyWebBoxThingClassId) { - //check if a Sunny WebBox is already added with this IPv4Address - foreach(SunnyWebBox *sunnyWebBox, m_sunnyWebBoxes.values()) { - if(sunnyWebBox->hostAddress().toString() == thing->paramValue(sunnyWebBoxThingHostParamTypeId).toString()){ - //this logger at this IPv4 address is already added - qCWarning(dcSma()) << "thing at " << thing->paramValue(sunnyWebBoxThingHostParamTypeId).toString() << " already added!"; + // Check if a Sunny WebBox is already added with this mac address + foreach (SunnyWebBox *sunnyWebBox, m_sunnyWebBoxes.values()) { + if (sunnyWebBox->macAddress() == thing->paramValue(sunnyWebBoxThingMacAddressParamTypeId).toString()){ + qCWarning(dcSma()) << "Thing with mac address" << thing->paramValue(sunnyWebBoxThingMacAddressParamTypeId).toString() << " already added!"; info->finish(Thing::ThingErrorThingInUse); return; } } + if (m_sunnyWebBoxes.contains(thing)) { qCDebug(dcSma()) << "Setup after reconfiguration, cleaning up..."; m_sunnyWebBoxes.take(thing)->deleteLater(); } + SunnyWebBox *sunnyWebBox = new SunnyWebBox(hardwareManager()->networkManager(), QHostAddress(thing->paramValue(sunnyWebBoxThingHostParamTypeId).toString()), this); + sunnyWebBox->setMacAddress(thing->paramValue(sunnyWebBoxThingMacAddressParamTypeId).toString()); + connect(info, &ThingSetupInfo::aborted, sunnyWebBox, &SunnyWebBox::deleteLater); connect(sunnyWebBox, &SunnyWebBox::destroyed, this, [thing, this] { m_sunnyWebBoxes.remove(thing);}); + QString requestId = sunnyWebBox->getPlantOverview(); connect(sunnyWebBox, &SunnyWebBox::plantOverviewReceived, info, [=] (const QString &messageId, SunnyWebBox::Overview overview) { qCDebug(dcSma()) << "Received plant overview" << messageId << "Finish setup"; diff --git a/sma/sunnywebbox.cpp b/sma/sunnywebbox.cpp index 94490875..f2b2c56a 100644 --- a/sma/sunnywebbox.cpp +++ b/sma/sunnywebbox.cpp @@ -121,15 +121,25 @@ QString SunnyWebBox::setParameters(const QString &deviceKey, const QHash &channels); //Sets parameter values + QHostAddress hostAddress() const; void setHostAddress(const QHostAddress &address); - QHostAddress hostAddress(); + + QString macAddress() const; + void setMacAddress(const QString &macAddress); private: bool m_connected = false; QHostAddress m_hostAddresss; + QString m_macAddress; NetworkAccessManager *m_networkManager = nullptr; QString sendMessage(const QHostAddress &address, const QString &procedure);