diff --git a/denon/deviceplugindenon.cpp b/denon/deviceplugindenon.cpp index 91cfcf90..48907a22 100644 --- a/denon/deviceplugindenon.cpp +++ b/denon/deviceplugindenon.cpp @@ -60,8 +60,25 @@ DeviceManager::DeviceError DevicePluginDenon::discoverDevices(const DeviceClassI Q_UNUSED(params) if (deviceClassId == AVRX1000DeviceClassId) { - QtAvahiServiceBrowser *avahiBrowser = hardwareManager()->avahiBrowser(); - connect(avahiBrowser, &QtAvahiServiceBrowser::serviceEntryAdded, this, &DevicePluginDenon::onAvahiEntryAdded); + + QList deviceDescriptors; + foreach (const AvahiServiceEntry &service, hardwareManager()->avahiBrowser()->serviceEntries()) { + if (service.name().contains("AVR-X1000")) { + DeviceDescriptor deviceDescriptor(AVRX1000DeviceClassId, service.hostName().remove(".local"), service.hostAddress().toString()); + ParamList params; + qCDebug(dcDenon) << "Avahi discovered device: " << service.name() << service.hostName() << service.serviceType(); + params.append(Param(AVRX1000DeviceIpParamTypeId, service.hostAddress().toString())); + deviceDescriptor.setParams(params); + foreach (Device *existingDevice, myDevices()) { + if (existingDevice->paramValue(AVRX1000DeviceIpParamTypeId).toString() == service.hostAddress().toString()) { + deviceDescriptor.setDeviceId(existingDevice->id()); + break; + } + } + deviceDescriptors.append(deviceDescriptor); + } + } + emit devicesDiscovered(AVRX1000DeviceClassId, deviceDescriptors); return DeviceManager::DeviceErrorAsync; } @@ -173,7 +190,7 @@ Device::DeviceError DevicePluginDenon::executeAction(Device *device, const Actio qCDebug(dcDenon) << "set power action" << action.id(); qCDebug(dcDenon) << "power: " << action.param(AVRX1000PowerActionPowerParamTypeId).value().Bool; - if (action.param(AVRX1000PowerActionPowerParamTypeId).value().toBool() == true){ + if (action.param(AVRX1000PowerActionPowerParamTypeId).value().toBool() == true) { QByteArray cmd = "PWON\r"; qCDebug(dcDenon) << "Execute power: " << action.id() << cmd; denonConnection->sendData(cmd); @@ -192,8 +209,7 @@ Device::DeviceError DevicePluginDenon::executeAction(Device *device, const Actio qCDebug(dcDenon) << "Execute volume" << action.id() << cmd; denonConnection->sendData(cmd); - - return Device::DeviceErrorNoError; + return DeviceManager::DeviceErrorNoError; } else if (action.actionTypeId() == AVRX1000ChannelActionTypeId) { @@ -203,22 +219,20 @@ Device::DeviceError DevicePluginDenon::executeAction(Device *device, const Actio qCDebug(dcDenon) << "Change to channel:" << cmd; denonConnection->sendData(cmd); - return DeviceManager::DeviceErrorNoError; + } else if (action.actionTypeId() == AVRX1000IncreaseVolumeActionTypeId) { QByteArray cmd = "MVUP\r"; qCDebug(dcDenon) << "Execute volume increase" << action.id() << cmd; denonConnection->sendData(cmd); - return DeviceManager::DeviceErrorNoError; + } else if (action.actionTypeId() == AVRX1000DecreaseVolumeActionTypeId) { QByteArray cmd = "MVDOWN\r"; qCDebug(dcDenon) << "Execute volume decrease" << action.id() << cmd; denonConnection->sendData(cmd); return DeviceManager::DeviceErrorNoError; } - - return DeviceManager::DeviceErrorActionTypeNotFound; } @@ -297,7 +311,6 @@ Device::DeviceError DevicePluginDenon::executeAction(Device *device, const Actio heos->playNext(playerId); return DeviceManager::DeviceErrorNoError; } - return DeviceManager::DeviceErrorActionTypeNotFound; } return Device::DeviceErrorDeviceClassNotFound; @@ -358,7 +371,6 @@ void DevicePluginDenon::onPluginTimer() heos->registerForChangeEvents(true); } - if (device->deviceClassId() == heosPlayerDeviceClassId) { Device *heosDevice = myDevices().findById(device->parentId()); Heos *heos = m_heos.value(heosDevice); @@ -408,7 +420,7 @@ void DevicePluginDenon::onAVRDataReceived(const QByteArray &data) } if (data.contains("SI")) { - QString cmd = NULL; + QString cmd; if (data.contains("TUNER")) { cmd = "TUNER"; } else if (data.contains("DVD")) { @@ -528,10 +540,6 @@ void DevicePluginDenon::onUpnpDiscoveryFinished() emit devicesDiscovered(heosDeviceClassId, deviceDescriptors); } -void DevicePluginDenon::onAvahiEntryAdded() { - qCDebug(dcDenon) << "Avahi entry added"; -} - void DevicePluginDenon::onHeosConnectionChanged() { Heos *heos = static_cast(sender()); diff --git a/denon/deviceplugindenon.h b/denon/deviceplugindenon.h index a986ddf1..6db7b5ef 100644 --- a/denon/deviceplugindenon.h +++ b/denon/deviceplugindenon.h @@ -73,7 +73,6 @@ private slots: void onAVRSocketError(); void onUpnpDiscoveryFinished(); - void onAvahiEntryAdded(); void onHeosConnectionChanged(); void onHeosPlayerDiscovered(HeosPlayer *heosPlayer); diff --git a/denon/deviceplugindenon.json b/denon/deviceplugindenon.json index 6739d302..f6d6d0a8 100644 --- a/denon/deviceplugindenon.json +++ b/denon/deviceplugindenon.json @@ -12,8 +12,7 @@ "id": "1cd3d67e-aba0-450e-9e2a-483a1527aba6", "name": "AVRX1000", "displayName": "AVR X1000", - "createMethods": ["user"], - "deviceIcon": "Hifi", + "createMethods": ["discovery"], "interfaces": ["connectable", "power", "extendedvolumecontroller"], "paramTypes": [ {