Update duplicated sma setup check
This commit is contained in:
parent
ae77bcef7c
commit
4ee7015117
@ -75,8 +75,8 @@ void IntegrationPluginSma::discoverThings(ThingDiscoveryInfo *info)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ParamList params;
|
ParamList params;
|
||||||
params << Param(sunnyWebBoxThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
|
|
||||||
params << Param(sunnyWebBoxThingHostParamTypeId, networkDeviceInfo.address().toString());
|
params << Param(sunnyWebBoxThingHostParamTypeId, networkDeviceInfo.address().toString());
|
||||||
|
params << Param(sunnyWebBoxThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
|
||||||
descriptor.setParams(params);
|
descriptor.setParams(params);
|
||||||
descriptors.append(descriptor);
|
descriptors.append(descriptor);
|
||||||
}
|
}
|
||||||
@ -89,25 +89,29 @@ void IntegrationPluginSma::discoverThings(ThingDiscoveryInfo *info)
|
|||||||
void IntegrationPluginSma::setupThing(ThingSetupInfo *info)
|
void IntegrationPluginSma::setupThing(ThingSetupInfo *info)
|
||||||
{
|
{
|
||||||
Thing *thing = info->thing();
|
Thing *thing = info->thing();
|
||||||
qCDebug(dcSma()) << "Setup thing" << thing->name();
|
qCDebug(dcSma()) << "Setup thing" << thing << thing->params();
|
||||||
|
|
||||||
if (thing->thingClassId() == sunnyWebBoxThingClassId) {
|
if (thing->thingClassId() == sunnyWebBoxThingClassId) {
|
||||||
//check if a Sunny WebBox is already added with this IPv4Address
|
// Check if a Sunny WebBox is already added with this mac address
|
||||||
foreach(SunnyWebBox *sunnyWebBox, m_sunnyWebBoxes.values()) {
|
foreach (SunnyWebBox *sunnyWebBox, m_sunnyWebBoxes.values()) {
|
||||||
if(sunnyWebBox->hostAddress().toString() == thing->paramValue(sunnyWebBoxThingHostParamTypeId).toString()){
|
if (sunnyWebBox->macAddress() == thing->paramValue(sunnyWebBoxThingMacAddressParamTypeId).toString()){
|
||||||
//this logger at this IPv4 address is already added
|
qCWarning(dcSma()) << "Thing with mac address" << thing->paramValue(sunnyWebBoxThingMacAddressParamTypeId).toString() << " already added!";
|
||||||
qCWarning(dcSma()) << "thing at " << thing->paramValue(sunnyWebBoxThingHostParamTypeId).toString() << " already added!";
|
|
||||||
info->finish(Thing::ThingErrorThingInUse);
|
info->finish(Thing::ThingErrorThingInUse);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_sunnyWebBoxes.contains(thing)) {
|
if (m_sunnyWebBoxes.contains(thing)) {
|
||||||
qCDebug(dcSma()) << "Setup after reconfiguration, cleaning up...";
|
qCDebug(dcSma()) << "Setup after reconfiguration, cleaning up...";
|
||||||
m_sunnyWebBoxes.take(thing)->deleteLater();
|
m_sunnyWebBoxes.take(thing)->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
SunnyWebBox *sunnyWebBox = new SunnyWebBox(hardwareManager()->networkManager(), QHostAddress(thing->paramValue(sunnyWebBoxThingHostParamTypeId).toString()), this);
|
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(info, &ThingSetupInfo::aborted, sunnyWebBox, &SunnyWebBox::deleteLater);
|
||||||
connect(sunnyWebBox, &SunnyWebBox::destroyed, this, [thing, this] { m_sunnyWebBoxes.remove(thing);});
|
connect(sunnyWebBox, &SunnyWebBox::destroyed, this, [thing, this] { m_sunnyWebBoxes.remove(thing);});
|
||||||
|
|
||||||
QString requestId = sunnyWebBox->getPlantOverview();
|
QString requestId = sunnyWebBox->getPlantOverview();
|
||||||
connect(sunnyWebBox, &SunnyWebBox::plantOverviewReceived, info, [=] (const QString &messageId, SunnyWebBox::Overview overview) {
|
connect(sunnyWebBox, &SunnyWebBox::plantOverviewReceived, info, [=] (const QString &messageId, SunnyWebBox::Overview overview) {
|
||||||
qCDebug(dcSma()) << "Received plant overview" << messageId << "Finish setup";
|
qCDebug(dcSma()) << "Received plant overview" << messageId << "Finish setup";
|
||||||
|
|||||||
@ -121,15 +121,25 @@ QString SunnyWebBox::setParameters(const QString &deviceKey, const QHash<QString
|
|||||||
return sendMessage(m_hostAddresss, "SetParameter", paramsObj);
|
return sendMessage(m_hostAddresss, "SetParameter", paramsObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QHostAddress SunnyWebBox::hostAddress() const
|
||||||
|
{
|
||||||
|
return m_hostAddresss;
|
||||||
|
}
|
||||||
|
|
||||||
void SunnyWebBox::setHostAddress(const QHostAddress &address)
|
void SunnyWebBox::setHostAddress(const QHostAddress &address)
|
||||||
{
|
{
|
||||||
qCDebug(dcSma()) << "SunnyWebBox: Setting host address to" << address.toString();
|
qCDebug(dcSma()) << "SunnyWebBox: Setting host address to" << address.toString();
|
||||||
m_hostAddresss = address;
|
m_hostAddresss = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
QHostAddress SunnyWebBox::hostAddress()
|
QString SunnyWebBox::macAddress() const
|
||||||
{
|
{
|
||||||
return m_hostAddresss;
|
return m_macAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SunnyWebBox::setMacAddress(const QString &macAddress)
|
||||||
|
{
|
||||||
|
m_macAddress = macAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SunnyWebBox::parseMessage(const QString &messageId, const QString &messageType, const QVariantMap &result)
|
void SunnyWebBox::parseMessage(const QString &messageId, const QString &messageType, const QVariantMap &result)
|
||||||
|
|||||||
@ -84,12 +84,16 @@ public:
|
|||||||
QString getParameters(const QStringList &deviceKeys); //Returns the parameter values of up to 5 devices
|
QString getParameters(const QStringList &deviceKeys); //Returns the parameter values of up to 5 devices
|
||||||
QString setParameters(const QString &deviceKeys, const QHash<QString, QVariant> &channels); //Sets parameter values
|
QString setParameters(const QString &deviceKeys, const QHash<QString, QVariant> &channels); //Sets parameter values
|
||||||
|
|
||||||
|
QHostAddress hostAddress() const;
|
||||||
void setHostAddress(const QHostAddress &address);
|
void setHostAddress(const QHostAddress &address);
|
||||||
QHostAddress hostAddress();
|
|
||||||
|
QString macAddress() const;
|
||||||
|
void setMacAddress(const QString &macAddress);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_connected = false;
|
bool m_connected = false;
|
||||||
QHostAddress m_hostAddresss;
|
QHostAddress m_hostAddresss;
|
||||||
|
QString m_macAddress;
|
||||||
NetworkAccessManager *m_networkManager = nullptr;
|
NetworkAccessManager *m_networkManager = nullptr;
|
||||||
|
|
||||||
QString sendMessage(const QHostAddress &address, const QString &procedure);
|
QString sendMessage(const QHostAddress &address, const QString &procedure);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user