fixed Denon Heos rediscovery

This commit is contained in:
nymea 2019-05-14 08:55:03 +02:00
parent 91da797dc5
commit 944a126204
5 changed files with 125 additions and 98 deletions

View File

@ -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<QString> serialNumbers;
foreach (Device *device, myDevices()) {
if (device->deviceClassId() == heosDeviceClassId){
serialNumbers.append(device->paramValue(heosDeviceSerialNumberParamTypeId).toString());
}
}
QList<DeviceDescriptor> 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;
}
}

View File

@ -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 <QPair>
#include <QHash>
#include <QObject>
#include <QPointer>
#include <QHostAddress>
#include <QNetworkReply>
#include "plugintimer.h"
#include "denonconnection.h"
#include "heos.h"
#include <QPair>
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 &params) override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
void postSetupDevice(Device * device) override;

View File

@ -1,9 +1,32 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2019 Bernhard Trinnes <bernhard.trinnes@nymea.io> *
* *
* 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 *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef HEOS_H
#define HEOS_H
#include <QObject>
#include <QHostAddress>
#include <QTcpSocket>
#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<int, HeosPlayer*> m_heosPlayers;
void setConnected(const bool &connected);

View File

@ -1,3 +1,25 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2019 Bernhard Trinnes <bernhard.trinnes@nymea.io> *
* *
* 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 *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "heosplayer.h"
HeosPlayer::HeosPlayer(int playerId, QObject *parent) :

View File

@ -1,3 +1,25 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2019 Bernhard Trinnes <bernhard.trinnes@nymea.io> *
* *
* 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 *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#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