added discovery on heos setup
This commit is contained in:
parent
cdff51655f
commit
e24d71905b
@ -84,7 +84,7 @@ void IntegrationPluginDenon::discoverThings(ThingDiscoveryInfo *info)
|
|||||||
QStringList discoveredIds;
|
QStringList discoveredIds;
|
||||||
|
|
||||||
foreach (const ZeroConfServiceEntry &service, m_serviceBrowser->serviceEntries()) {
|
foreach (const ZeroConfServiceEntry &service, m_serviceBrowser->serviceEntries()) {
|
||||||
qCDebug(dcDenon()) << "mDNS service entry:" << service;
|
qCDebug(dcDenon()) << "mDNS service entry:" << service;
|
||||||
if (service.txt().contains("am=AVRX1000")) {
|
if (service.txt().contains("am=AVRX1000")) {
|
||||||
|
|
||||||
QString id = service.name().split("@").first();
|
QString id = service.name().split("@").first();
|
||||||
@ -235,32 +235,59 @@ void IntegrationPluginDenon::setupThing(ThingSetupInfo *info)
|
|||||||
denonConnection->connectDevice();
|
denonConnection->connectDevice();
|
||||||
return;
|
return;
|
||||||
} else if (thing->thingClassId() == heosThingClassId) {
|
} else if (thing->thingClassId() == heosThingClassId) {
|
||||||
qCDebug(dcDenon) << "Setup Denon thing" << thing->paramValue(heosThingIpParamTypeId).toString();
|
|
||||||
|
|
||||||
QHostAddress address(thing->paramValue(heosThingIpParamTypeId).toString());
|
qCDebug(dcDenon) << "Setup Denon thing" << thing->name();
|
||||||
if (address.isNull()) {
|
QString serialnumber = thing->paramValue(heosThingSerialNumberParamTypeId).toString();
|
||||||
qCWarning(dcDenon) << "Could not parse ip address" << thing->paramValue(heosThingIpParamTypeId).toString();
|
if (serialnumber.isEmpty()) {
|
||||||
info->finish(Thing::ThingErrorInvalidParameter, QT_TR_NOOP("The given IP address is not valid."));
|
qCWarning(dcDenon) << "Serial number is empty";
|
||||||
|
info->finish(Thing::ThingErrorInvalidParameter, QT_TR_NOOP("Serial number is not set"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Heos *heos;
|
if (m_heosConnections.contains(thing->id())) {
|
||||||
|
qCDebug(dcDenon()) << "Setup after reconfiguration, cleaning up ...";
|
||||||
|
m_heosConnections.take(thing->id())->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
if (m_unfinishedHeosConnections.contains(thing->id())) {
|
if (m_unfinishedHeosConnections.contains(thing->id())) {
|
||||||
heos = m_unfinishedHeosConnections.take(thing->id());
|
Heos *heos = m_unfinishedHeosConnections.take(thing->id());
|
||||||
m_heosConnections.insert(thing->id(), heos);
|
m_heosConnections.insert(thing->id(), heos);
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
} else {
|
} else {
|
||||||
heos = createHeosConnection(address);
|
|
||||||
m_heosConnections.insert(thing->id(), heos);
|
UpnpDiscoveryReply *reply = hardwareManager()->upnpDiscovery()->discoverDevices();
|
||||||
m_asyncHeosSetups.insert(heos, info);
|
connect(reply, &UpnpDiscoveryReply::finished, reply, &UpnpDiscoveryReply::deleteLater);
|
||||||
// In case the setup is cancelled before we finish it...
|
connect(reply, &UpnpDiscoveryReply::finished, info, [this, reply, info] {
|
||||||
connect(info, &QObject::destroyed, this, [=]() {m_asyncHeosSetups.remove(heos);});
|
if (reply->error() != UpnpDiscoveryReply::UpnpDiscoveryReplyErrorNoError) {
|
||||||
heos->connectDevice();
|
qCWarning(dcDenon()) << "Upnp discovery error" << reply->error();
|
||||||
|
info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("UPnP discovery failed."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (const UpnpDeviceDescriptor &upnpThing, reply->deviceDescriptors()) {
|
||||||
|
if (upnpThing.modelName().contains("HEOS", Qt::CaseSensitivity::CaseInsensitive)) {
|
||||||
|
QString serialNumber = info->thing()->paramValue(heosThingSerialNumberParamTypeId).toString();
|
||||||
|
if (serialNumber == upnpThing.serialNumber()) {
|
||||||
|
ThingId thingId= info->thing()->id();
|
||||||
|
info->thing()->setParamValue(heosThingIpParamTypeId, upnpThing.hostAddress().toString());
|
||||||
|
Heos *heos = createHeosConnection(upnpThing.hostAddress());
|
||||||
|
m_heosConnections.insert(thingId, heos);
|
||||||
|
m_asyncHeosSetups.insert(heos, info);
|
||||||
|
// In case the setup is cancelled before we finish it...
|
||||||
|
connect(info, &ThingSetupInfo::aborted, heos, &Heos::deleteLater);
|
||||||
|
connect(heos, &Heos::destroyed, this, [thingId, heos, this] {
|
||||||
|
m_asyncHeosSetups.remove(heos);
|
||||||
|
m_heosConnections.remove(thingId);
|
||||||
|
});
|
||||||
|
heos->connectDevice();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
} else if (thing->thingClassId() == heosPlayerThingClassId) {
|
} else if (thing->thingClassId() == heosPlayerThingClassId) {
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
info->finish(Thing::ThingErrorThingClassNotFound);
|
info->finish(Thing::ThingErrorThingClassNotFound);
|
||||||
}
|
}
|
||||||
@ -1416,3 +1443,8 @@ Heos *IntegrationPluginDenon::createHeosConnection(const QHostAddress &address)
|
|||||||
connect(heos, &Heos::userChanged, this, &IntegrationPluginDenon::onHeosUserChanged);
|
connect(heos, &Heos::userChanged, this, &IntegrationPluginDenon::onHeosUserChanged);
|
||||||
return heos;
|
return heos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QHostAddress IntegrationPluginDenon::discoverHeos(const QString &serialnumber)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -103,6 +103,7 @@ private:
|
|||||||
QHash<int, HeosPlayer *> m_playerBuffer;
|
QHash<int, HeosPlayer *> m_playerBuffer;
|
||||||
|
|
||||||
Heos *createHeosConnection(const QHostAddress &address);
|
Heos *createHeosConnection(const QHostAddress &address);
|
||||||
|
QHostAddress discoverHeos(const QString &serialnumber);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onPluginTimer();
|
void onPluginTimer();
|
||||||
|
|||||||
@ -324,19 +324,21 @@
|
|||||||
"name": "ip",
|
"name": "ip",
|
||||||
"displayName": "IPv4 address",
|
"displayName": "IPv4 address",
|
||||||
"type" : "QString",
|
"type" : "QString",
|
||||||
"inputType": "IPv4Address"
|
"readOnly": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "f796664d-6cb7-4f29-9d05-771968d82a32",
|
"id": "f796664d-6cb7-4f29-9d05-771968d82a32",
|
||||||
"name": "serialNumber",
|
"name": "serialNumber",
|
||||||
"displayName": "Serial number",
|
"displayName": "Serial number",
|
||||||
"type" : "QString"
|
"type" : "QString",
|
||||||
|
"readOnly": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "ab1a0be8-e3a5-4f95-b9b7-893de1ca4cf7",
|
"id": "ab1a0be8-e3a5-4f95-b9b7-893de1ca4cf7",
|
||||||
"name": "modelName",
|
"name": "modelName",
|
||||||
"displayName": "Model name",
|
"displayName": "Model name",
|
||||||
"type" : "QString"
|
"type" : "QString",
|
||||||
|
"readOnly": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"stateTypes": [
|
"stateTypes": [
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user