denon AVR added discovery on setup and disconnect

This commit is contained in:
Boernsman 2021-02-05 15:10:25 +01:00
parent e24d71905b
commit 1bbdedcaf6
3 changed files with 27 additions and 15 deletions

View File

@ -96,7 +96,6 @@ void IntegrationPluginDenon::discoverThings(ThingDiscoveryInfo *info)
discoveredIds.append(id); discoveredIds.append(id);
ThingDescriptor thingDescriptor(AVRX1000ThingClassId, name, address); ThingDescriptor thingDescriptor(AVRX1000ThingClassId, name, address);
ParamList params; ParamList params;
params.append(Param(AVRX1000ThingIpParamTypeId, address));
params.append(Param(AVRX1000ThingIdParamTypeId, id)); params.append(Param(AVRX1000ThingIdParamTypeId, id));
thingDescriptor.setParams(params); thingDescriptor.setParams(params);
foreach (Thing *existingThing, myThings().filterByThingClassId(AVRX1000ThingClassId)) { foreach (Thing *existingThing, myThings().filterByThingClassId(AVRX1000ThingClassId)) {
@ -196,12 +195,17 @@ void IntegrationPluginDenon::setupThing(ThingSetupInfo *info)
Thing *thing = info->thing(); Thing *thing = info->thing();
if (thing->thingClassId() == AVRX1000ThingClassId) { if (thing->thingClassId() == AVRX1000ThingClassId) {
qCDebug(dcDenon) << "Setup Denon thing" << thing->paramValue(AVRX1000ThingIpParamTypeId).toString();
QHostAddress address(thing->paramValue(AVRX1000ThingIpParamTypeId).toString());
if (m_avrConnections.contains(thing->id())) {
qCDebug(dcDenon()) << "Setup after reconfiguration, cleaning up ...";
m_avrConnections.take(thing->id())->deleteLater();
}
QString id = thing->paramValue(AVRX1000ThingIdParamTypeId).toString();
QHostAddress address = findAvrById(id);
if (address.isNull()) { if (address.isNull()) {
qCWarning(dcDenon) << "Could not parse ip address" << thing->paramValue(AVRX1000ThingIpParamTypeId).toString(); info->finish(Thing::ThingErrorHardwareNotAvailable);
info->finish(Thing::ThingErrorInvalidParameter, QT_TR_NOOP("The given IP address is not valid."));
return; return;
} }
@ -617,6 +621,14 @@ void IntegrationPluginDenon::onAvrConnectionChanged(bool status)
if (thing->thingClassId() == AVRX1000ThingClassId) { if (thing->thingClassId() == AVRX1000ThingClassId) {
thing->setStateValue(AVRX1000ConnectedStateTypeId, denonConnection->connected()); thing->setStateValue(AVRX1000ConnectedStateTypeId, denonConnection->connected());
if (!status) {
QString id = thing->paramValue(AVRX1000ThingIdParamTypeId).toString();
QHostAddress address = findAvrById(id);
if (!address.isNull()){
denonConnection->setHostAddress(address);
}
}
} }
} }
@ -1444,7 +1456,14 @@ Heos *IntegrationPluginDenon::createHeosConnection(const QHostAddress &address)
return heos; return heos;
} }
QHostAddress IntegrationPluginDenon::discoverHeos(const QString &serialnumber) QHostAddress IntegrationPluginDenon::findAvrById(const QString &id)
{ {
foreach (const ZeroConfServiceEntry &service, m_serviceBrowser->serviceEntries()) {
if (service.txt().contains("am=AVRX1000")) {
if (service.name().split("@").first() == id) {
return service.hostAddress();
}
}
}
return QHostAddress();
} }

View File

@ -103,7 +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); QHostAddress findAvrById(const QString &id);
private slots: private slots:
void onPluginTimer(); void onPluginTimer();

View File

@ -24,13 +24,6 @@
"createMethods": ["discovery"], "createMethods": ["discovery"],
"interfaces": ["mediaplayer", "mediacontroller", "volumecontroller", "mediametadataprovider", "connectable", "power"], "interfaces": ["mediaplayer", "mediacontroller", "volumecontroller", "mediametadataprovider", "connectable", "power"],
"paramTypes": [ "paramTypes": [
{
"id": "cb6eeeb0-3d75-43b6-8177-b5ac19648557",
"name": "ip",
"displayName": "IPv4 address",
"type" : "QString",
"inputType": "IPv4Address"
},
{ {
"id": "2e8806cb-f6f3-4e9a-b6ea-0b35f75e61c5", "id": "2e8806cb-f6f3-4e9a-b6ea-0b35f75e61c5",
"name": "id", "name": "id",