diff --git a/denon/deviceplugindenon.cpp b/denon/deviceplugindenon.cpp index 48907a22..27cf0fa5 100644 --- a/denon/deviceplugindenon.cpp +++ b/denon/deviceplugindenon.cpp @@ -131,7 +131,6 @@ Device::DeviceSetupStatus DevicePluginDenon::setupDevice(Device *device) Heos *heos = new Heos(address, this); connect(heos, &Heos::connectionStatusChanged, this, &DevicePluginDenon::onHeosConnectionChanged); connect(heos, &Heos::playerDiscovered, this, &DevicePluginDenon::onHeosPlayerDiscovered); - connect(heos, &Heos::playStateReceived, this, &DevicePluginDenon::onHeosPlayStateReceived); connect(heos, &Heos::repeatModeReceived, this, &DevicePluginDenon::onHeosRepeatModeReceived); connect(heos, &Heos::shuffleModeReceived, this, &DevicePluginDenon::onHeosShuffleModeReceived); @@ -147,7 +146,6 @@ Device::DeviceSetupStatus DevicePluginDenon::setupDevice(Device *device) if (device->deviceClassId() == heosPlayerDeviceClassId) { return DeviceManager::DeviceSetupStatusSuccess; } - return DeviceManager::DeviceSetupStatusFailure; } @@ -171,9 +169,6 @@ void DevicePluginDenon::deviceRemoved(Device *device) } } - if (device->deviceClassId() == heosPlayerDeviceClassId) { - } - if (myDevices().empty()) { hardwareManager()->pluginTimerManager()->unregisterTimer(m_pluginTimer); } @@ -263,7 +258,6 @@ Device::DeviceError DevicePluginDenon::executeAction(Device *device, const Actio } else if (playbackStatus == "pausing") { heos->setPlayerState(playerId, Heos::HeosPlayerState::Pause); } - return DeviceManager::DeviceErrorNoError; } @@ -318,11 +312,8 @@ Device::DeviceError DevicePluginDenon::executeAction(Device *device, const Actio void DevicePluginDenon::postSetupDevice(Device *device) { - if (device->deviceClassId() == AVRX1000DeviceClassId) { - - } - if (device->deviceClassId() == heosDeviceClassId) { + Heos *heos = m_heos.value(device); heos->getPlayers(); device->setStateValue(heosConnectedStateTypeId, heos->connected()); @@ -342,10 +333,6 @@ void DevicePluginDenon::postSetupDevice(Device *device) } } -void DevicePluginDenon::startMonitoringAutoDevices() -{ - -} void DevicePluginDenon::onPluginTimer() { @@ -462,7 +449,6 @@ void DevicePluginDenon::onAVRDataReceived(const QByteArray &data) } else if (data.contains("FVP")) { cmd = "FVP"; } - qCDebug(dcDenon) << "Update channel:" << cmd; device->setStateValue(AVRX1000ChannelStateTypeId, cmd); } @@ -497,7 +483,6 @@ void DevicePluginDenon::onAVRSocketError() } } - void DevicePluginDenon::onUpnpDiscoveryFinished() { qCDebug(dcDenon()) << "Upnp discovery finished"; @@ -511,32 +496,31 @@ void DevicePluginDenon::onUpnpDiscoveryFinished() qCDebug(dcDenon) << "No UPnP device found."; return; } - QList serialNumbers; - foreach (Device *device, myDevices()) { - if (device->deviceClassId() == heosDeviceClassId){ - serialNumbers.append(device->paramValue(heosDeviceSerialNumberParamTypeId).toString()); - } - } QList deviceDescriptors; foreach (const UpnpDeviceDescriptor &upnpDevice, reply->deviceDescriptors()) { - qCDebug(dcDenon) << "UPnP device found:" << upnpDevice.modelDescription() << upnpDevice.friendlyName() << upnpDevice.hostAddress().toString() << upnpDevice.modelName() << upnpDevice.manufacturer() << upnpDevice.serialNumber() << upnpDevice.deviceType() << upnpDevice.location(); + if (upnpDevice.modelName().contains("HEOS")) { - //check if not already addded QString serialNumber = upnpDevice.serialNumber(); - if ((!serialNumbers.contains(serialNumber)) && (serialNumber !=("0000001"))) { + if (serialNumber != "0000001") { + // child devices have serial number 0000001 + qCDebug(dcDenon) << "UPnP device found:" << upnpDevice.modelDescription() << upnpDevice.friendlyName() << upnpDevice.hostAddress().toString() << upnpDevice.modelName() << upnpDevice.manufacturer() << upnpDevice.serialNumber(); DeviceDescriptor descriptor(heosDeviceClassId, upnpDevice.modelName(), serialNumber); ParamList params; + foreach (Device *existingDevice, myDevices()) { + if (existingDevice->paramValue(heosDeviceSerialNumberParamTypeId).toString() == serialNumber) { + descriptor.setDeviceId(existingDevice->id()); + break; + } + } params.append(Param(heosDeviceModelNameParamTypeId, upnpDevice.modelName())); params.append(Param(heosDeviceIpParamTypeId, upnpDevice.hostAddress().toString())); params.append(Param(heosDeviceSerialNumberParamTypeId, serialNumber)); descriptor.setParams(params); deviceDescriptors.append(descriptor); - serialNumbers.append(serialNumber); } } } - emit devicesDiscovered(heosDeviceClassId, deviceDescriptors); } @@ -576,88 +560,69 @@ void DevicePluginDenon::onHeosPlayerDiscovered(HeosPlayer *heosPlayer) { void DevicePluginDenon::onHeosPlayStateReceived(int playerId, Heos::HeosPlayerState state) { - foreach (Device *device, myDevices()) { - if(device->deviceClassId() == heosPlayerDeviceClassId) { - if (device->paramValue(heosPlayerDevicePlayerIdParamTypeId).toInt() == playerId) { - if (state == Heos::HeosPlayerState::Pause) { - device->setStateValue(heosPlayerPlaybackStatusStateTypeId, "Paused"); - } else if (state == Heos::HeosPlayerState::Play) { - device->setStateValue(heosPlayerPlaybackStatusStateTypeId, "Playing"); - } else if (state == Heos::HeosPlayerState::Stop) { - device->setStateValue(heosPlayerPlaybackStatusStateTypeId, "Stopped"); - } - } + foreach(Device *device, myDevices().filterByParam(heosPlayerDevicePlayerIdParamTypeId, playerId)) { + if (state == Heos::HeosPlayerState::Pause) { + device->setStateValue(heosPlayerPlaybackStatusStateTypeId, "Paused"); + } else if (state == Heos::HeosPlayerState::Play) { + device->setStateValue(heosPlayerPlaybackStatusStateTypeId, "Playing"); + } else if (state == Heos::HeosPlayerState::Stop) { + device->setStateValue(heosPlayerPlaybackStatusStateTypeId, "Stopped"); } + break; } } void DevicePluginDenon::onHeosRepeatModeReceived(int playerId, Heos::HeosRepeatMode repeatMode) { - foreach (Device *device, myDevices()) { - if(device->deviceClassId() == heosPlayerDeviceClassId) { - if (device->paramValue(heosPlayerDevicePlayerIdParamTypeId).toInt() == playerId) { - if (repeatMode == Heos::HeosRepeatMode::All) { - device->setStateValue(heosPlayerRepeatStateTypeId, "All"); - } else if (repeatMode == Heos::HeosRepeatMode::One) { - device->setStateValue(heosPlayerRepeatStateTypeId, "One"); - } else if (repeatMode == Heos::HeosRepeatMode::Off) { - device->setStateValue(heosPlayerRepeatStateTypeId, "None"); - } - } + foreach(Device *device, myDevices().filterByParam(heosPlayerDevicePlayerIdParamTypeId, playerId)) { + if (repeatMode == Heos::HeosRepeatMode::All) { + device->setStateValue(heosPlayerRepeatStateTypeId, "All"); + } else if (repeatMode == Heos::HeosRepeatMode::One) { + device->setStateValue(heosPlayerRepeatStateTypeId, "One"); + } else if (repeatMode == Heos::HeosRepeatMode::Off) { + device->setStateValue(heosPlayerRepeatStateTypeId, "None"); } + break; } } void DevicePluginDenon::onHeosShuffleModeReceived(int playerId, bool shuffle) { - foreach (Device *device, myDevices()) { - if(device->deviceClassId() == heosPlayerDeviceClassId) { - if (device->paramValue(heosPlayerDevicePlayerIdParamTypeId).toInt() == playerId) { - - if (shuffle) { - device->setStateValue(heosPlayerMuteStateTypeId, true); - } else { - device->setStateValue(heosPlayerMuteStateTypeId, false); - } - } + foreach(Device *device, myDevices().filterByParam(heosPlayerDevicePlayerIdParamTypeId, playerId)) { + if (shuffle) { + device->setStateValue(heosPlayerMuteStateTypeId, true); + } else { + device->setStateValue(heosPlayerMuteStateTypeId, false); } + break; } } void DevicePluginDenon::onHeosMuteStatusReceived(int playerId, bool mute) { - foreach (Device *device, myDevices()) { - if(device->deviceClassId() == heosPlayerDeviceClassId) { - if (device->paramValue(heosPlayerDevicePlayerIdParamTypeId).toInt() == playerId) { - device->setStateValue(heosPlayerMuteStateTypeId, mute); - } - } + foreach(Device *device, myDevices().filterByParam(heosPlayerDevicePlayerIdParamTypeId, playerId)) { + device->setStateValue(heosPlayerMuteStateTypeId, mute); + break; } } void DevicePluginDenon::onHeosVolumeStatusReceived(int playerId, int volume) { - foreach (Device *device, myDevices()) { - if(device->deviceClassId() == heosPlayerDeviceClassId) { - if (device->paramValue(heosPlayerDevicePlayerIdParamTypeId).toInt() == playerId) { - device->setStateValue(heosPlayerVolumeStateTypeId, volume); - } - } + foreach(Device *device, myDevices().filterByParam(heosPlayerDevicePlayerIdParamTypeId, playerId)) { + device->setStateValue(heosPlayerVolumeStateTypeId, volume); + break; } } void DevicePluginDenon::onHeosNowPlayingMediaStatusReceived(int playerId, QString source, QString artist, QString album, QString song, QString artwork) { - foreach (Device *device, myDevices()) { - if(device->deviceClassId() == heosPlayerDeviceClassId) { - if (device->paramValue(heosPlayerDevicePlayerIdParamTypeId).toInt() == playerId) { - device->setStateValue(heosPlayerArtistStateTypeId, artist); - device->setStateValue(heosPlayerTitleStateTypeId, song); - device->setStateValue(heosPlayerArtworkStateTypeId, artwork); - device->setStateValue(heosPlayerCollectionStateTypeId, album); - device->setStateValue(heosPlayerSourceStateTypeId, source); - } - } + foreach(Device *device, myDevices().filterByParam(heosPlayerDevicePlayerIdParamTypeId, playerId)) { + device->setStateValue(heosPlayerArtistStateTypeId, artist); + device->setStateValue(heosPlayerTitleStateTypeId, song); + device->setStateValue(heosPlayerArtworkStateTypeId, artwork); + device->setStateValue(heosPlayerCollectionStateTypeId, album); + device->setStateValue(heosPlayerSourceStateTypeId, source); + break; } } diff --git a/denon/deviceplugindenon.h b/denon/deviceplugindenon.h index 6db7b5ef..a71cad8e 100644 --- a/denon/deviceplugindenon.h +++ b/denon/deviceplugindenon.h @@ -24,19 +24,19 @@ #ifndef DEVICEPLUGINDENON_H #define DEVICEPLUGINDENON_H -#include "devices/deviceplugin.h" +#include "devicemanager.h" +#include "plugin/deviceplugin.h" +#include "plugintimer.h" +#include "denonconnection.h" +#include "heos.h" +#include #include #include #include #include #include -#include "plugintimer.h" -#include "denonconnection.h" -#include "heos.h" -#include - class DevicePluginDenon : public DevicePlugin { Q_OBJECT @@ -47,7 +47,6 @@ class DevicePluginDenon : public DevicePlugin public: explicit DevicePluginDenon(); - void startMonitoringAutoDevices() override; DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override; DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; void postSetupDevice(Device * device) override; diff --git a/denon/heos.h b/denon/heos.h index 6ef28651..4cdc1755 100644 --- a/denon/heos.h +++ b/denon/heos.h @@ -1,9 +1,32 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2019 Bernhard Trinnes * + * * + * This file is part of nymea. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; If not, see * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #ifndef HEOS_H #define HEOS_H #include #include #include + #include "heosplayer.h" class Heos : public QObject @@ -22,7 +45,7 @@ public: All = 2 }; - explicit Heos(const QHostAddress &hostAddress, QObject *parent = 0); + explicit Heos(const QHostAddress &hostAddress, QObject *parent = nullptr); ~Heos(); void setAddress(QHostAddress address); @@ -47,10 +70,10 @@ public: void sendHeartbeat(); private: - bool m_connected; - bool m_eventRegistered; + bool m_connected = false; + bool m_eventRegistered = false; QHostAddress m_hostAddress; - QTcpSocket *m_socket; + QTcpSocket *m_socket = nullptr; QHash m_heosPlayers; void setConnected(const bool &connected); diff --git a/denon/heosplayer.cpp b/denon/heosplayer.cpp index e6757d5c..7ac95c89 100644 --- a/denon/heosplayer.cpp +++ b/denon/heosplayer.cpp @@ -1,3 +1,25 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2019 Bernhard Trinnes * + * * + * This file is part of nymea. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; If not, see * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #include "heosplayer.h" HeosPlayer::HeosPlayer(int playerId, QObject *parent) : diff --git a/denon/heosplayer.h b/denon/heosplayer.h index 5fa4795e..aa7a27ef 100644 --- a/denon/heosplayer.h +++ b/denon/heosplayer.h @@ -1,3 +1,25 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2019 Bernhard Trinnes * + * * + * This file is part of nymea. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; If not, see * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #ifndef HEOSPLAYER_H #define HEOSPLAYER_H @@ -7,8 +29,8 @@ class HeosPlayer : public QObject { Q_OBJECT public: - explicit HeosPlayer(int playerId, QObject *parent = 0); - explicit HeosPlayer(int playerId, QString name, QString serialNumber, QObject *parent = 0); + explicit HeosPlayer(int playerId, QObject *parent = nullptr); + explicit HeosPlayer(int playerId, QString name, QString serialNumber, QObject *parent = nullptr); QString name(); void setName(QString name); @@ -33,10 +55,6 @@ private: QString m_playerVersion; QString m_control; - -signals: - -public slots: }; #endif // HEOSPLAYER_H