diff --git a/denon/deviceplugindenon.cpp b/denon/deviceplugindenon.cpp index c4063ae0..734d361c 100644 --- a/denon/deviceplugindenon.cpp +++ b/denon/deviceplugindenon.cpp @@ -64,9 +64,41 @@ Device::DeviceError DevicePluginDenon::discoverDevices(const DeviceClassId &devi Q_UNUSED(params) if (deviceClassId == AVRX1000DeviceClassId) { + if (!m_serviceBrowser) { + m_serviceBrowser = hardwareManager()->zeroConfController()->createServiceBrowser(); + connect(m_serviceBrowser, &ZeroConfServiceBrowser::serviceEntryAdded, this, &DevicePluginDenon::onAvahiServiceEntryAdded); + connect(m_serviceBrowser, &ZeroConfServiceBrowser::serviceEntryRemoved, this, &DevicePluginDenon::onAvahiServiceEntryRemoved); + } + QStringList discoveredIds; - UpnpDiscoveryReply *reply = hardwareManager()->upnpDiscovery()->discoverDevices("urn:schemas-upnp-org:device:MediaRenderer:1", "nymea", 7000); - connect(reply, &UpnpDiscoveryReply::finished, this, &DevicePluginDenon::onUpnpDiscoveryFinished); + QList deviceDescriptors; + foreach (const ZeroConfServiceEntry &service, m_serviceBrowser->serviceEntries()) { + if (service.txt().contains("am=AVRX1000")) { + + QString id = service.name().split("@").first(); + QString name = service.name().split("@").last(); + QString address = service.hostAddress().toString(); + qCDebug(dcDenon) << "service discovered" << name << "ID:" << id; + if (discoveredIds.contains(id)) + break; + + discoveredIds.append(id); + DeviceDescriptor deviceDescriptor(AVRX1000DeviceClassId, name, address); + ParamList params; + params.append(Param(AVRX1000DeviceIpParamTypeId, address)); + params.append(Param(AVRX1000DeviceIdParamTypeId, id)); + deviceDescriptor.setParams(params); + foreach (Device *existingDevice, myDevices()) { + if (existingDevice->paramValue(AVRX1000DeviceIdParamTypeId).toString() == id) { + deviceDescriptor.setDeviceId(existingDevice->id()); + break; + } + } + deviceDescriptors.append(deviceDescriptor); + } + } + + emit devicesDiscovered(AVRX1000DeviceClassId, deviceDescriptors); return Device::DeviceErrorAsync; } @@ -500,9 +532,6 @@ void DevicePluginDenon::onUpnpDiscoveryFinished() if (!heosDescriptors.isEmpty()) { emit devicesDiscovered(heosDeviceClassId, heosDescriptors); } - if (!avrDescriptors.isEmpty()) { - emit devicesDiscovered(AVRX1000DeviceClassId, avrDescriptors); - } } void DevicePluginDenon::onHeosConnectionChanged() @@ -608,3 +637,12 @@ void DevicePluginDenon::onHeosNowPlayingMediaStatusReceived(int playerId, QStrin } } +void DevicePluginDenon::onAvahiServiceEntryAdded(const ZeroConfServiceEntry &serviceEntry) +{ + qCDebug(dcDenon()) << "Avahi service entry added:" << serviceEntry; +} + +void DevicePluginDenon::onAvahiServiceEntryRemoved(const ZeroConfServiceEntry &serviceEntry) +{ + qCDebug(dcDenon()) << "Avahi service entry removed:" << serviceEntry; +} diff --git a/denon/deviceplugindenon.h b/denon/deviceplugindenon.h index 42421a14..fbbeb121 100644 --- a/denon/deviceplugindenon.h +++ b/denon/deviceplugindenon.h @@ -24,11 +24,14 @@ #ifndef DEVICEPLUGINDENON_H #define DEVICEPLUGINDENON_H -#include "devices/deviceplugin.h" -#include "plugintimer.h" -#include "avrconnection.h" #include "heos.h" +#include "avrconnection.h" +#include "plugintimer.h" +#include "devices/deviceplugin.h" +#include "network/zeroconf/zeroconfservicebrowser.h" +#include "network/zeroconf/zeroconfserviceentry.h" +#include #include #include #include @@ -54,6 +57,8 @@ public: private: PluginTimer *m_pluginTimer = nullptr; + ZeroConfServiceBrowser *m_serviceBrowser = nullptr; + QHash m_avrConnections; QHash m_heos; @@ -77,6 +82,8 @@ private slots: void onHeosVolumeStatusReceived(int playerId, int volume); void onHeosNowPlayingMediaStatusReceived(int playerId, QString source, QString artist, QString album, QString Song, QString artwork); + void onAvahiServiceEntryAdded(const ZeroConfServiceEntry &serviceEntry); + void onAvahiServiceEntryRemoved(const ZeroConfServiceEntry &serviceEntry); void onAvrConnectionChanged(bool status); void onAvrSocketError(); void onAvrVolumeChanged(int volume); diff --git a/denon/deviceplugindenon.json b/denon/deviceplugindenon.json index 562fe538..cce1b92b 100644 --- a/denon/deviceplugindenon.json +++ b/denon/deviceplugindenon.json @@ -13,14 +13,20 @@ "name": "AVRX1000", "displayName": "AVR X1000", "createMethods": ["discovery"], - "interfaces": ["connectable", "power", "extendedvolumecontroller"], + "interfaces": ["extendedvolumecontroller", "connectable", "power"], "paramTypes": [ { "id": "a54b98b4-b78f-41dd-a257-14425c6cf9ab", "name": "ip", - "displayName": "ip", + "displayName": "Ip", "type" : "QString", "inputType": "IPv4Address" + }, + { + "id": "2e8806cb-f6f3-4e9a-b6ea-0b35f75e61c5", + "name": "id", + "displayName": "Id", + "type" : "QString" } ], "stateTypes": [ @@ -194,7 +200,7 @@ "name": "heosPlayer", "displayName": "Heos player", "createMethods": ["auto"], - "interfaces": ["connectable", "extendedmediacontroller", "extendedvolumecontroller", "mediametadataprovider", "shufflerepeat" ], + "interfaces": ["extendedmediacontroller", "extendedvolumecontroller", "mediametadataprovider", "shufflerepeat", "connectable"], "paramTypes":[ { "id": "89629008-6ad8-4e92-863d-b86e0e012d0b",