bose: Add Qt6 support

This commit is contained in:
Simon Stürz 2025-08-07 15:45:07 +02:00
parent e0328bbd4b
commit 7d782078b4
5 changed files with 139 additions and 142 deletions

View File

@ -1,10 +1,6 @@
include(../plugins.pri) include(../plugins.pri)
QT += \ QT *= network websockets
network \
websockets \
TARGET = $$qtLibraryTarget(nymea_integrationpluginbose)
SOURCES += \ SOURCES += \
integrationpluginbose.cpp \ integrationpluginbose.cpp \

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2020, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -29,11 +29,12 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "integrationpluginbose.h" #include "integrationpluginbose.h"
#include "integrations/thing.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "platform/platformzeroconfcontroller.h"
#include "network/zeroconf/zeroconfserviceentry.h" #include <integrations/thing.h>
#include "types/mediabrowseritem.h" #include <platform/platformzeroconfcontroller.h>
#include <network/zeroconf/zeroconfserviceentry.h>
#include <types/mediabrowseritem.h>
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QNetworkReply> #include <QNetworkReply>
@ -545,7 +546,7 @@ void IntegrationPluginBose::onSourcesObjectReceived(QUuid requestId, SourcesObje
if (m_asyncBrowseResults.contains(requestId)) { if (m_asyncBrowseResults.contains(requestId)) {
BrowseResult *result = m_asyncBrowseResults.value(requestId); BrowseResult *result = m_asyncBrowseResults.value(requestId);
foreach (SourceItemObject sourceItem, sources.sourceItems) { foreach (SourceItemObject sourceItem, sources.sourceItems) {
qDebug(dcBose()) << "Source:" << sourceItem.source; qCDebug(dcBose()) << "Source:" << sourceItem.source;
if (sourceItem.source == "BLUETOOTH") { if (sourceItem.source == "BLUETOOTH") {
MediaBrowserItem item(sourceItem.source, sourceItem.source, false, true); MediaBrowserItem item(sourceItem.source, sourceItem.source, false, true);
item.setDescription(sourceItem.sourceAccount); item.setDescription(sourceItem.sourceAccount);
@ -591,15 +592,15 @@ void IntegrationPluginBose::onBassObjectReceived(QUuid requestId, BassObject bas
void IntegrationPluginBose::onBassCapabilitiesObjectReceived(QUuid requestId, BassCapabilitiesObject bassCapabilities) void IntegrationPluginBose::onBassCapabilitiesObjectReceived(QUuid requestId, BassCapabilitiesObject bassCapabilities)
{ {
Q_UNUSED(requestId); Q_UNUSED(requestId);
qDebug(dcBose()) << "Bass capabilities (max, min, default):" << bassCapabilities.bassMax << bassCapabilities.bassMin << bassCapabilities.bassDefault; qCDebug(dcBose()) << "Bass capabilities (max, min, default):" << bassCapabilities.bassMax << bassCapabilities.bassMin << bassCapabilities.bassDefault;
} }
void IntegrationPluginBose::onGroupObjectReceived(QUuid requestId, GroupObject group) void IntegrationPluginBose::onGroupObjectReceived(QUuid requestId, GroupObject group)
{ {
Q_UNUSED(requestId); Q_UNUSED(requestId);
qDebug(dcBose()) << "Group" << group.name << group.status; qCDebug(dcBose()) << "Group" << group.name << group.status;
foreach (RolesObject role, group.roles) { foreach (RolesObject role, group.roles) {
qDebug(dcBose()) << "-> member:" << role.groupRole.deviceID; qCDebug(dcBose()) << "-> member:" << role.groupRole.deviceID;
} }
} }
@ -607,7 +608,7 @@ void IntegrationPluginBose::onZoneObjectReceived(QUuid requestId, ZoneObject zon
{ {
Q_UNUSED(requestId); Q_UNUSED(requestId);
foreach (MemberObject member, zone.members) { foreach (MemberObject member, zone.members) {
qDebug(dcBose()) << "-> member:" << member.deviceID; qCDebug(dcBose()) << "-> member:" << member.deviceID;
} }
} }

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2020, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -31,9 +31,10 @@
#ifndef INTEGRATIONPLUGINBOSE_H #ifndef INTEGRATIONPLUGINBOSE_H
#define INTEGRATIONPLUGINBOSE_H #define INTEGRATIONPLUGINBOSE_H
#include "integrations/integrationplugin.h" #include <integrations/integrationplugin.h>
#include "network/zeroconf/zeroconfservicebrowser.h" #include <network/zeroconf/zeroconfservicebrowser.h>
#include "plugintimer.h" #include <plugintimer.h>
#include "soundtouch.h" #include "soundtouch.h"
#include "soundtouchtypes.h" #include "soundtouchtypes.h"

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2020, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -29,9 +29,9 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "soundtouch.h" #include "soundtouch.h"
#include "hardwaremanager.h"
#include "integrations/thing.h" #include <hardwaremanager.h>
#include "network/networkaccessmanager.h" #include <integrations/thing.h>
SoundTouch::SoundTouch(NetworkAccessManager *networkAccessManager, QString ipAddress, QObject *parent) : SoundTouch::SoundTouch(NetworkAccessManager *networkAccessManager, QString ipAddress, QObject *parent) :
QObject(parent), QObject(parent),
@ -47,7 +47,7 @@ SoundTouch::SoundTouch(NetworkAccessManager *networkAccessManager, QString ipAdd
//url.setHost(m_ipAddress); //url.setHost(m_ipAddress);
//url.setScheme("ws"); //url.setScheme("ws");
//url.setPort(8080); //url.setPort(8080);
//qDebug(dcBose) << "Connecting websocket to" << url; //qCDebug(dcBose()) << "Connecting websocket to" << url;
//TODO missing websocket subprotocol "gabbo" //TODO missing websocket subprotocol "gabbo"
//QWebsockets doesn't support subprotocols //QWebsockets doesn't support subprotocols
//m_websocket->open(url); //m_websocket->open(url);
@ -249,9 +249,10 @@ QUuid SoundTouch::setKey(KEY_VALUE keyValue, bool pressed)
xml.writeCharacters("PRESET_6"); xml.writeCharacters("PRESET_6");
break; break;
default: default:
qWarning(dcBose) << "key not yet implemented"; qCWarning(dcBose()) << "key not yet implemented";
return "0"; return QUuid();
} }
xml.writeEndElement(); //key xml.writeEndElement(); //key
xml.writeEndDocument(); xml.writeEndDocument();
QNetworkRequest request(url); QNetworkRequest request(url);
@ -444,7 +445,7 @@ QUuid SoundTouch::setBass(int volume)
return requestId; return requestId;
} }
QUuid SoundTouch::setName(QString name) QUuid SoundTouch::setName(const QString &name)
{ {
QUuid requestId = QUuid::createUuid(); QUuid requestId = QUuid::createUuid();
QUrl url; QUrl url;
@ -454,7 +455,7 @@ QUuid SoundTouch::setName(QString name)
url.setPath("/name"); url.setPath("/name");
QByteArray content = ("<?xml version=\"1.0\" ?>"); QByteArray content = ("<?xml version=\"1.0\" ?>");
content.append("<name>"); content.append("<name>");
content.append(name); content.append(name.toUtf8());
content.append("</name>"); content.append("</name>");
QNetworkRequest request(url); QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/xml"); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/xml");
@ -498,13 +499,13 @@ QUuid SoundTouch::setSpeaker(PlayInfoObject playInfo)
void SoundTouch::onWebsocketConnected() void SoundTouch::onWebsocketConnected()
{ {
qDebug(dcBose) << "Bose websocket connected"; qCDebug(dcBose()) << "Bose websocket connected";
emit connectionChanged(true); emit connectionChanged(true);
} }
void SoundTouch::onWebsocketDisconnected() void SoundTouch::onWebsocketDisconnected()
{ {
qDebug(dcBose) << "Bose websocket disconnected"; qCDebug(dcBose()) << "Bose websocket disconnected";
emit connectionChanged(false); emit connectionChanged(false);
QTimer::singleShot(5000, this, [this](){ QTimer::singleShot(5000, this, [this](){
QUrl url; QUrl url;
@ -517,7 +518,7 @@ void SoundTouch::onWebsocketDisconnected()
void SoundTouch::onWebsocketMessageReceived(QString message) void SoundTouch::onWebsocketMessageReceived(QString message)
{ {
qDebug(dcBose) << "Websocket message received:" << message; qCDebug(dcBose()) << "Websocket message received:" << message;
//TODO as soon as QWebSocket supports sub-protocols //TODO as soon as QWebSocket supports sub-protocols
} }
@ -529,7 +530,7 @@ QUuid SoundTouch::sendGetRequest(QString path)
url.setScheme("http"); url.setScheme("http");
url.setPort(m_port); url.setPort(m_port);
url.setPath(path); url.setPath(path);
//qDebug(dcBose) << "Sending request" << url; //qCDebug(dcBose()) << "Sending request" << url;
QNetworkRequest request = QNetworkRequest(url); QNetworkRequest request = QNetworkRequest(url);
QNetworkReply *reply = m_networkAccessManager->get(request); QNetworkReply *reply = m_networkAccessManager->get(request);
@ -563,7 +564,7 @@ QUuid SoundTouch::sendGetRequest(QString path)
return requestId; return requestId;
} }
void SoundTouch::emitRequestStatus(QUuid requestId, QNetworkReply *reply) void SoundTouch::emitRequestStatus(const QUuid &requestId, QNetworkReply *reply)
{ {
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
// Check HTTP status code // Check HTTP status code
@ -584,17 +585,17 @@ void SoundTouch::emitRequestStatus(QUuid requestId, QNetworkReply *reply)
xml.addData(data); xml.addData(data);
if (xml.readNextStartElement()) { if (xml.readNextStartElement()) {
if (xml.name() == "status") { if (xml.name() == QString("status")) {
//QString status = xml.readElementText(); //QString status = xml.readElementText();
emit requestExecuted(requestId, true); emit requestExecuted(requestId, true);
} else if (xml.name() == "errors") { } else if (xml.name() == QString("errors")) {
emit requestExecuted(requestId, false); emit requestExecuted(requestId, false);
QString deviceId; QString deviceId;
if(xml.attributes().hasAttribute("deviceID")) { if(xml.attributes().hasAttribute("deviceID")) {
deviceId = xml.attributes().value("deviceID").toString(); deviceId = xml.attributes().value("deviceID").toString();
} }
while(xml.readNextStartElement()){ while(xml.readNextStartElement()){
if(xml.name() == "error"){ if(xml.name() == QString("error")){
ErrorObject error; ErrorObject error;
error.deviceId = deviceId; error.deviceId = deviceId;
error.error = xml.readElementText(); error.error = xml.readElementText();
@ -614,36 +615,36 @@ void SoundTouch::emitRequestStatus(QUuid requestId, QNetworkReply *reply)
} }
} }
void SoundTouch::parseData(QUuid requestId, const QByteArray &data) void SoundTouch::parseData(const QUuid &requestId, const QByteArray &data)
{ {
QXmlStreamReader xml; QXmlStreamReader xml;
xml.addData(data); xml.addData(data);
if (xml.readNextStartElement()) { if (xml.readNextStartElement()) {
if (xml.name() == "info") { if (xml.name() == QString("info")) {
InfoObject info; InfoObject info;
if(xml.attributes().hasAttribute("deviceID")) { if(xml.attributes().hasAttribute("deviceID")) {
//qDebug(dcBose) << "Device ID" << xml.attributes().value("deviceID").toString(); //qCDebug(dcBose()) << "Device ID" << xml.attributes().value("deviceID").toString();
info.deviceID = xml.attributes().value("deviceID").toString(); info.deviceID = xml.attributes().value("deviceID").toString();
} }
while(xml.readNextStartElement()){ while(xml.readNextStartElement()){
if(xml.name() == "name"){ if(xml.name() == QString("name")){
//qDebug(dcBose) << "name" << xml.readElementText(); //qCDebug(dcBose()) << "name" << xml.readElementText();
info.name = xml.readElementText(); info.name = xml.readElementText();
} else if(xml.name() == "type"){ } else if(xml.name() == QString("type")){
//qDebug(dcBose) << "type" << xml.readElementText(); //qCDebug(dcBose()) << "type" << xml.readElementText();
info.type = xml.readElementText(); info.type = xml.readElementText();
} else if(xml.name() == "components"){ } else if(xml.name() == QString("components")){
//qDebug(dcBose) << "components element"; //qCDebug(dcBose()) << "components element";
while(xml.readNextStartElement()){ while(xml.readNextStartElement()){
if(xml.name() == "component"){ if(xml.name() == QString("component")){
ComponentObject component; ComponentObject component;
while(xml.readNextStartElement()){ while(xml.readNextStartElement()){
if(xml.name() == "softwareVersion"){ if(xml.name() == QString("softwareVersion")){
//qDebug(dcBose) << "Software version" << xml.readElementText(); //qCDebug(dcBose()) << "Software version" << xml.readElementText();
component.softwareVersion = xml.readElementText(); component.softwareVersion = xml.readElementText();
} else if(xml.name() == "serialNumber") { } else if(xml.name() == QString("serialNumber")) {
//qDebug(dcBose) << "Serialnumber" << xml.readElementText(); //qCDebug(dcBose()) << "Serialnumber" << xml.readElementText();
component.serialNumber = xml.readElementText(); component.serialNumber = xml.readElementText();
} else { } else {
xml.skipCurrentElement(); xml.skipCurrentElement();
@ -654,11 +655,11 @@ void SoundTouch::parseData(QUuid requestId, const QByteArray &data)
xml.skipCurrentElement(); xml.skipCurrentElement();
} }
} }
} else if(xml.name() == "networkInfo"){ } else if(xml.name() == QString("networkInfo")){
while (xml.readNextStartElement()) { while (xml.readNextStartElement()) {
if (xml.name() == "macAddress") { if (xml.name() == QString("macAddress")) {
info.networkInfo.macAddress = xml.readElementText(); info.networkInfo.macAddress = xml.readElementText();
} else if(xml.name() == "ipAddress") { } else if(xml.name() == QString("ipAddress")) {
info.networkInfo.ipAddress = xml.readElementText(); info.networkInfo.ipAddress = xml.readElementText();
} else { } else {
xml.skipCurrentElement(); xml.skipCurrentElement();
@ -669,45 +670,45 @@ void SoundTouch::parseData(QUuid requestId, const QByteArray &data)
} }
} }
emit infoReceived(requestId, info); emit infoReceived(requestId, info);
} else if (xml.name() == "nowPlaying") { } else if (xml.name() == QString("nowPlaying")) {
NowPlayingObject nowPlaying; NowPlayingObject nowPlaying;
if(xml.attributes().hasAttribute("deviceID")) { if(xml.attributes().hasAttribute("deviceID")) {
//qDebug(dcBose) << "Device ID" << xml.attributes().value("deviceID").toString(); //qCDebug(dcBose()) << "Device ID" << xml.attributes().value("deviceID").toString();
nowPlaying.deviceID = xml.attributes().value("deviceID").toString(); nowPlaying.deviceID = xml.attributes().value("deviceID").toString();
} }
if(xml.attributes().hasAttribute("source")) { if(xml.attributes().hasAttribute("source")) {
//qDebug(dcBose) << "Source" << xml.attributes().value("source").toString(); //qCDebug(dcBose()) << "Source" << xml.attributes().value("source").toString();
nowPlaying.source = xml.attributes().value("source").toString(); nowPlaying.source = xml.attributes().value("source").toString();
} }
if(xml.attributes().hasAttribute("sourceAccount")) { if(xml.attributes().hasAttribute("sourceAccount")) {
//qDebug(dcBose) << "Source Account" << xml.attributes().value("sourceAccount").toString(); //qCDebug(dcBose()) << "Source Account" << xml.attributes().value("sourceAccount").toString();
nowPlaying.sourceAccount = xml.attributes().value("sourceAccount").toString(); nowPlaying.sourceAccount = xml.attributes().value("sourceAccount").toString();
} }
while(xml.readNextStartElement()){ while(xml.readNextStartElement()){
if (xml.name() == "track") { if (xml.name() == QString("track")) {
//qDebug(dcBose) << "track" << xml.readElementText(); //qCDebug(dcBose()) << "track" << xml.readElementText();
nowPlaying.track = xml.readElementText(); nowPlaying.track = xml.readElementText();
} else if(xml.name() == "artist") { } else if(xml.name() == QString("artist")) {
//qDebug(dcBose) << "artist" << xml.readElementText(); //qCDebug(dcBose()) << "artist" << xml.readElementText();
nowPlaying.artist = xml.readElementText(); nowPlaying.artist = xml.readElementText();
} else if(xml.name() == "album") { } else if(xml.name() == QString("album")) {
//qDebug(dcBose) << "album" << xml.readElementText(); //qCDebug(dcBose()) << "album" << xml.readElementText();
nowPlaying.album = xml.readElementText(); nowPlaying.album = xml.readElementText();
} else if(xml.name() == "genre") { } else if(xml.name() == QString("genre")) {
//qDebug(dcBose) << "genre" << xml.readElementText(); //qCDebug(dcBose()) << "genre" << xml.readElementText();
nowPlaying.genre = xml.readElementText(); nowPlaying.genre = xml.readElementText();
} else if(xml.name() == "rating") { } else if(xml.name() == QString("rating")) {
//qDebug(dcBose) << "rating" << xml.readElementText(); //qCDebug(dcBose()) << "rating" << xml.readElementText();
nowPlaying.rating = xml.readElementText(); nowPlaying.rating = xml.readElementText();
} else if(xml.name() == "stationName") { } else if(xml.name() == QString("stationName")) {
//qDebug(dcBose) << "Station name" << xml.readElementText(); //qCDebug(dcBose()) << "Station name" << xml.readElementText();
nowPlaying.stationName = xml.readElementText(); nowPlaying.stationName = xml.readElementText();
} else if(xml.name() == "art") { } else if(xml.name() == QString("art")) {
ArtObject art; ArtObject art;
if(xml.attributes().hasAttribute("artImageStatus")) { if(xml.attributes().hasAttribute("artImageStatus")) {
QString artStatus = xml.attributes().value("artImageStatus").toString().toUpper(); QString artStatus = xml.attributes().value("artImageStatus").toString().toUpper();
//ART_STATUS: INVALID, SHOW_DEFAULT_IMAGE, DOWNLOADING, IMAGE_PRESENT //ART_STATUS: INVALID, SHOW_DEFAULT_IMAGE, DOWNLOADING, IMAGE_PRESENT
//qDebug(dcBose) << "Art Image status" << artStatus; //qCDebug(dcBose()) << "Art Image status" << artStatus;
if (artStatus == "INVALID") { if (artStatus == "INVALID") {
art.artStatus = ART_STATUS_INVALID; art.artStatus = ART_STATUS_INVALID;
} else if (artStatus == "SHOW_DEFAULT_IMAGE") { } else if (artStatus == "SHOW_DEFAULT_IMAGE") {
@ -719,9 +720,9 @@ void SoundTouch::parseData(QUuid requestId, const QByteArray &data)
} }
} }
nowPlaying.art.url = xml.readElementText(); nowPlaying.art.url = xml.readElementText();
}else if(xml.name() == "playStatus") { }else if(xml.name() == QString("playStatus")) {
QString playStatus = xml.readElementText(); QString playStatus = xml.readElementText();
//qDebug(dcBose) << "Play Status" << playStatus; //qCDebug(dcBose()) << "Play Status" << playStatus;
//Modes: PLAY_STATE, PAUSE_STATE, STOP_STATE, BUFFERING_STATE //Modes: PLAY_STATE, PAUSE_STATE, STOP_STATE, BUFFERING_STATE
if (playStatus == "PLAY_STATE") { if (playStatus == "PLAY_STATE") {
nowPlaying.playStatus = PLAY_STATUS_PLAY_STATE; nowPlaying.playStatus = PLAY_STATUS_PLAY_STATE;
@ -732,17 +733,17 @@ void SoundTouch::parseData(QUuid requestId, const QByteArray &data)
} else if (playStatus == "BUFFERING_STATE") { } else if (playStatus == "BUFFERING_STATE") {
nowPlaying.playStatus = PLAY_STATUS_BUFFERING_STATE; nowPlaying.playStatus = PLAY_STATUS_BUFFERING_STATE;
} }
} else if(xml.name() == "shuffleSetting") { } else if(xml.name() == QString("shuffleSetting")) {
QString shuffle = xml.readElementText().toUpper(); QString shuffle = xml.readElementText().toUpper();
//qDebug(dcBose) << "Shuffle Setting" << shuffle; //qCDebug(dcBose()) << "Shuffle Setting" << shuffle;
if (shuffle == "SHUFFLE_ON") { if (shuffle == "SHUFFLE_ON") {
nowPlaying.shuffleSetting = SHUFFLE_STATUS_SHUFFLE_ON; nowPlaying.shuffleSetting = SHUFFLE_STATUS_SHUFFLE_ON;
} else { } else {
nowPlaying.shuffleSetting = SHUFFLE_STATUS_SHUFFLE_OFF; nowPlaying.shuffleSetting = SHUFFLE_STATUS_SHUFFLE_OFF;
} }
}else if(xml.name() == "repeatSetting") { }else if(xml.name() == QString("repeatSetting")) {
QString repeat = xml.readElementText().toUpper(); QString repeat = xml.readElementText().toUpper();
//qDebug(dcBose) << "Repeat Setting" << repeat; //qCDebug(dcBose()) << "Repeat Setting" << repeat;
//Modes: REPEAT_OFF, REPEAT_ALL, REPEAT_ONE //Modes: REPEAT_OFF, REPEAT_ALL, REPEAT_ONE
if (repeat == "REPEAT_OFF") { if (repeat == "REPEAT_OFF") {
nowPlaying.repeatSettings = REPEAT_STATUS_REPEAT_OFF; nowPlaying.repeatSettings = REPEAT_STATUS_REPEAT_OFF;
@ -751,9 +752,9 @@ void SoundTouch::parseData(QUuid requestId, const QByteArray &data)
} else if (repeat == "REPEAT_ALL") { } else if (repeat == "REPEAT_ALL") {
nowPlaying.repeatSettings = REPEAT_STATUS_REPEAT_ALL; nowPlaying.repeatSettings = REPEAT_STATUS_REPEAT_ALL;
} }
} else if(xml.name() == "streamType") { } else if(xml.name() == QString("streamType")) {
QString streamType = xml.readElementText().toUpper(); QString streamType = xml.readElementText().toUpper();
//qDebug(dcBose) << "Stream Type" << streamType; //qCDebug(dcBose()) << "Stream Type" << streamType;
//Types: TRACK_ONDEMAND, RADIO_STREAMING, RADIO_TRACKS, NO_TRANSPORT_CONTROLS //Types: TRACK_ONDEMAND, RADIO_STREAMING, RADIO_TRACKS, NO_TRANSPORT_CONTROLS
if (streamType == "RADIO_TRACKS") { if (streamType == "RADIO_TRACKS") {
nowPlaying.streamType = STREAM_STATUS_RADIO_TRACKS; nowPlaying.streamType = STREAM_STATUS_RADIO_TRACKS;
@ -764,54 +765,54 @@ void SoundTouch::parseData(QUuid requestId, const QByteArray &data)
} else if (streamType == "NO_TRANSPORT_CONTROLS") { } else if (streamType == "NO_TRANSPORT_CONTROLS") {
nowPlaying.streamType = STREAM_STATUS_NO_TRANSPORT_CONTROLS; nowPlaying.streamType = STREAM_STATUS_NO_TRANSPORT_CONTROLS;
}; };
} else if(xml.name() == "stationLocation") { } else if(xml.name() == QString("stationLocation")) {
nowPlaying.stationLocation = xml.readElementText(); nowPlaying.stationLocation = xml.readElementText();
} else { } else {
xml.skipCurrentElement(); xml.skipCurrentElement();
} }
} }
emit nowPlayingReceived(requestId, nowPlaying); emit nowPlayingReceived(requestId, nowPlaying);
} else if (xml.name() == "volume") { } else if (xml.name() == QString("volume")) {
VolumeObject volumeObject; VolumeObject volumeObject;
if(xml.attributes().hasAttribute("deviceID")) { if(xml.attributes().hasAttribute("deviceID")) {
//qDebug(dcBose) << "Device ID" << xml.attributes().value("deviceID").toString(); //qCDebug(dcBose()) << "Device ID" << xml.attributes().value("deviceID").toString();
volumeObject.deviceID = xml.attributes().value("deviceID").toString(); volumeObject.deviceID = xml.attributes().value("deviceID").toString();
} }
while(xml.readNextStartElement()){ while(xml.readNextStartElement()){
if(xml.name() == "targetvolume"){ if(xml.name() == QString("targetvolume")){
//qDebug(dcBose) << "Target volume" << xml.readElementText(); //qCDebug(dcBose()) << "Target volume" << xml.readElementText();
volumeObject.targetVolume = xml.readElementText().toInt(); volumeObject.targetVolume = xml.readElementText().toInt();
}else if(xml.name() == "actualvolume"){ }else if(xml.name() == QString("actualvolume")){
//qDebug(dcBose) << "Actual volume" << xml.readElementText(); //qCDebug(dcBose()) << "Actual volume" << xml.readElementText();
volumeObject.actualVolume = xml.readElementText().toInt(); volumeObject.actualVolume = xml.readElementText().toInt();
}else if(xml.name() == "muteenabled"){ }else if(xml.name() == QString("muteenabled")){
//qDebug(dcBose) << "Mute enabled" << xml.readElementText(); //qCDebug(dcBose()) << "Mute enabled" << xml.readElementText();
volumeObject.muteEnabled = ( xml.readElementText().toUpper() == "TRUE" ); //TODO convert from "false" to bool volumeObject.muteEnabled = ( xml.readElementText().toUpper() == "TRUE" ); //TODO convert from "false" to bool
}else { }else {
xml.skipCurrentElement(); xml.skipCurrentElement();
} }
} }
emit volumeReceived(requestId, volumeObject); emit volumeReceived(requestId, volumeObject);
} else if (xml.name() == "sources") { } else if (xml.name() == QString("sources")) {
SourcesObject sourcesObject; SourcesObject sourcesObject;
if(xml.attributes().hasAttribute("deviceID")) { if(xml.attributes().hasAttribute("deviceID")) {
//qDebug(dcBose) << "Device ID" << xml.attributes().value("deviceID").toString(); //qCDebug(dcBose()) << "Device ID" << xml.attributes().value("deviceID").toString();
sourcesObject.deviceId = xml.attributes().value("deviceID").toString(); sourcesObject.deviceId = xml.attributes().value("deviceID").toString();
} }
while(xml.readNextStartElement()){ while(xml.readNextStartElement()){
if(xml.name() == "sourceItem"){ if(xml.name() == QString("sourceItem")){
SourceItemObject sourceItem; SourceItemObject sourceItem;
if(xml.attributes().hasAttribute("source")) { if(xml.attributes().hasAttribute("source")) {
//qDebug(dcBose) << "Source" << xml.attributes().value("source").toString(); //qCDebug(dcBose()) << "Source" << xml.attributes().value("source").toString();
sourceItem.source = xml.attributes().value("source").toString(); sourceItem.source = xml.attributes().value("source").toString();
} }
if(xml.attributes().hasAttribute("sourceAccount")) { if(xml.attributes().hasAttribute("sourceAccount")) {
//qDebug(dcBose) << "Source Account" << xml.attributes().value("sourceAccount").toString(); //qCDebug(dcBose()) << "Source Account" << xml.attributes().value("sourceAccount").toString();
sourceItem.sourceAccount = xml.attributes().value("sourceAccount").toString(); sourceItem.sourceAccount = xml.attributes().value("sourceAccount").toString();
} }
if(xml.attributes().hasAttribute("status")) { if(xml.attributes().hasAttribute("status")) {
QString status = xml.attributes().value("status").toString().toUpper(); //UNAVAILABLE, READY QString status = xml.attributes().value("status").toString().toUpper(); //UNAVAILABLE, READY
//qDebug(dcBose) << "status" << status; //qCDebug(dcBose()) << "status" << status;
if (status == "READY") { if (status == "READY") {
sourceItem.status = SOURCE_STATUS_READY; sourceItem.status = SOURCE_STATUS_READY;
} else { } else {
@ -819,7 +820,7 @@ void SoundTouch::parseData(QUuid requestId, const QByteArray &data)
} }
} }
if(xml.attributes().hasAttribute("isLocal")) { if(xml.attributes().hasAttribute("isLocal")) {
//qDebug(dcBose) << "is Local" << xml.attributes().value("isLocal").toString(); //qCDebug(dcBose()) << "is Local" << xml.attributes().value("isLocal").toString();
sourceItem.isLocal = ( xml.attributes().value("isLocal").toString().toUpper() == "TRUE" ); sourceItem.isLocal = ( xml.attributes().value("isLocal").toString().toUpper() == "TRUE" );
} }
if(xml.attributes().hasAttribute("multiroomallowed")) { if(xml.attributes().hasAttribute("multiroomallowed")) {
@ -833,52 +834,52 @@ void SoundTouch::parseData(QUuid requestId, const QByteArray &data)
} }
} }
emit sourcesReceived(requestId, sourcesObject); emit sourcesReceived(requestId, sourcesObject);
} else if (xml.name() == "bass") { } else if (xml.name() == QString("bass")) {
BassObject bassObject; BassObject bassObject;
if(xml.attributes().hasAttribute("deviceID")) { if(xml.attributes().hasAttribute("deviceID")) {
//qDebug(dcBose) << "Device ID" << xml.attributes().value("deviceID").toString(); //qCDebug(dcBose()) << "Device ID" << xml.attributes().value("deviceID").toString();
bassObject.deviceID = xml.attributes().value("deviceID").toString(); bassObject.deviceID = xml.attributes().value("deviceID").toString();
} }
while(xml.readNextStartElement()){ while(xml.readNextStartElement()){
if(xml.name() == "targetbass"){ if(xml.name() == QString("targetbass")){
//qDebug(dcBose) << "Target bas" << xml.readElementText(); //qCDebug(dcBose()) << "Target bas" << xml.readElementText();
bassObject.targetBass = xml.readElementText().toInt(); bassObject.targetBass = xml.readElementText().toInt();
} else if(xml.name() == "actualbass"){ } else if(xml.name() == QString("actualbass")){
//qDebug(dcBose) << "Actual bass" << xml.readElementText(); //qCDebug(dcBose()) << "Actual bass" << xml.readElementText();
bassObject.actualBass = xml.readElementText().toInt(); bassObject.actualBass = xml.readElementText().toInt();
} else { } else {
xml.skipCurrentElement(); xml.skipCurrentElement();
} }
} }
emit bassReceived(requestId, bassObject); emit bassReceived(requestId, bassObject);
} else if (xml.name() == "bassCapabilities") { } else if (xml.name() == QString("bassCapabilities")) {
BassCapabilitiesObject bassCapabilities; BassCapabilitiesObject bassCapabilities;
if(xml.attributes().hasAttribute("deviceID")) { if(xml.attributes().hasAttribute("deviceID")) {
bassCapabilities.deviceID = xml.attributes().value("deviceID").toString(); bassCapabilities.deviceID = xml.attributes().value("deviceID").toString();
} }
while(xml.readNextStartElement()){ while(xml.readNextStartElement()){
if(xml.name() == "bassAvailable"){ if(xml.name() == QString("bassAvailable")){
//qDebug(dcBose) << "BassAvailable" << xml.readElementText(); //qCDebug(dcBose()) << "BassAvailable" << xml.readElementText();
bassCapabilities.bassAvailable = ( xml.readElementText().toUpper() == "TRUE" ); bassCapabilities.bassAvailable = ( xml.readElementText().toUpper() == "TRUE" );
} else if(xml.name() == "bassMin"){ } else if(xml.name() == QString("bassMin")){
//qDebug(dcBose) << "bass Min" << xml.readElementText(); //qCDebug(dcBose()) << "bass Min" << xml.readElementText();
bassCapabilities.bassMin = xml.readElementText().toInt(); bassCapabilities.bassMin = xml.readElementText().toInt();
} else if(xml.name() == "bassMax"){ } else if(xml.name() == QString("bassMax")){
//qDebug(dcBose) << "bass Max" << xml.readElementText(); //qCDebug(dcBose()) << "bass Max" << xml.readElementText();
bassCapabilities.bassMax = xml.readElementText().toInt(); bassCapabilities.bassMax = xml.readElementText().toInt();
} else if(xml.name() == "bassDefault"){ } else if(xml.name() == QString("bassDefault")){
//qDebug(dcBose) << "bass default" << xml.readElementText(); //qCDebug(dcBose()) << "bass default" << xml.readElementText();
bassCapabilities.bassDefault = xml.readElementText().toInt(); bassCapabilities.bassDefault = xml.readElementText().toInt();
}else { }else {
xml.skipCurrentElement(); xml.skipCurrentElement();
} }
} }
emit bassCapabilitiesReceived(requestId, bassCapabilities); emit bassCapabilitiesReceived(requestId, bassCapabilities);
} else if (xml.name() == "presets") { } else if (xml.name() == QString("presets")) {
QList<PresetObject> presets; QList<PresetObject> presets;
qDebug(dcBose) << "Presets"; qCDebug(dcBose()) << "Presets";
while(xml.readNextStartElement()){ while(xml.readNextStartElement()){
if(xml.name() == "preset"){ if(xml.name() == QString("preset")){
PresetObject preset; PresetObject preset;
if(xml.attributes().hasAttribute("id")) { if(xml.attributes().hasAttribute("id")) {
preset.presetId = xml.attributes().value("id").toInt(); preset.presetId = xml.attributes().value("id").toInt();
@ -889,10 +890,10 @@ void SoundTouch::parseData(QUuid requestId, const QByteArray &data)
if(xml.attributes().hasAttribute("updatedOn")) { if(xml.attributes().hasAttribute("updatedOn")) {
preset.updatedOn = xml.attributes().value("updatedOn").toULong(); preset.updatedOn = xml.attributes().value("updatedOn").toULong();
} }
qDebug(dcBose) << "Preset" << preset.presetId; qCDebug(dcBose()) << "Preset" << preset.presetId;
while(xml.readNextStartElement()){ while(xml.readNextStartElement()){
if (xml.name() == "ContentItem") { if (xml.name() == QString("ContentItem")) {
if(xml.attributes().hasAttribute("source")) { if(xml.attributes().hasAttribute("source")) {
preset.ContentItem.source = xml.attributes().value("source").toString(); preset.ContentItem.source = xml.attributes().value("source").toString();
} }
@ -904,9 +905,9 @@ void SoundTouch::parseData(QUuid requestId, const QByteArray &data)
} }
while(xml.readNextStartElement()){ while(xml.readNextStartElement()){
if (xml.name() == "itemName") { if (xml.name() == QString("itemName")) {
preset.ContentItem.itemName = xml.readElementText(); preset.ContentItem.itemName = xml.readElementText();
} else if (xml.name() == "containerArt"){ } else if (xml.name() == QString("containerArt")){
preset.ContentItem.containerArt = xml.readElementText(); preset.ContentItem.containerArt = xml.readElementText();
} else { } else {
qCWarning(dcBose()) << "Presets: unhandled XML element" << xml.name(); qCWarning(dcBose()) << "Presets: unhandled XML element" << xml.name();
@ -927,35 +928,35 @@ void SoundTouch::parseData(QUuid requestId, const QByteArray &data)
} }
emit presetsReceived(requestId, presets); emit presetsReceived(requestId, presets);
} else if (xml.name() == "group") { } else if (xml.name() == QString("group")) {
GroupObject group; GroupObject group;
if(xml.attributes().hasAttribute("deviceID")) { if(xml.attributes().hasAttribute("deviceID")) {
group.id = xml.attributes().value("id").toString(); group.id = xml.attributes().value("id").toString();
} }
while(xml.readNextStartElement()){ while(xml.readNextStartElement()){
if(xml.name() == "name") { if(xml.name() == QString("name")) {
group.name = xml.readElementText(); group.name = xml.readElementText();
} else if(xml.name() == "masterDeviceId") { } else if(xml.name() == QString("masterDeviceId")) {
group.masterDeviceId = xml.readElementText(); group.masterDeviceId = xml.readElementText();
} else if(xml.name() == "roles") { } else if(xml.name() == QString("roles")) {
//group.roles = xml.readElementText().toInt(); //group.roles = xml.readElementText().toInt();
} else if(xml.name() == "status"){ } else if(xml.name() == QString("status")){
QString groupStatus = xml.readElementText(); QString groupStatus = xml.readElementText();
//qDebug(dcBose) << "Group role" << groupStatus; //qCDebug(dcBose()) << "Group role" << groupStatus;
//group.status = xml.readElementText(); //group.status = xml.readElementText();
}else { }else {
xml.skipCurrentElement(); xml.skipCurrentElement();
} }
} }
emit groupReceived(requestId, group); emit groupReceived(requestId, group);
} else if (xml.name() == "zone") { } else if (xml.name() == QString("zone")) {
ZoneObject zone; ZoneObject zone;
if(xml.attributes().hasAttribute("master")) { if(xml.attributes().hasAttribute("master")) {
zone.deviceID = xml.attributes().value("master").toString(); zone.deviceID = xml.attributes().value("master").toString();
} }
while(xml.readNextStartElement()){ while(xml.readNextStartElement()){
MemberObject member; MemberObject member;
if(xml.name() == "member") { if(xml.name() == QString("member")) {
if(xml.attributes().hasAttribute("ipaddress")) { if(xml.attributes().hasAttribute("ipaddress")) {
member.ipAddress = xml.attributes().value("ipaddress").toString(); member.ipAddress = xml.attributes().value("ipaddress").toString();
} }

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2020, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -39,9 +39,7 @@
#include "extern-plugininfo.h" #include "extern-plugininfo.h"
#include "soundtouchtypes.h" #include "soundtouchtypes.h"
#include "hardwaremanager.h" #include <network/networkaccessmanager.h>
#include "network/networkaccessmanager.h"
class SoundTouch : public QObject class SoundTouch : public QObject
{ {
@ -67,7 +65,7 @@ public:
QUuid addZoneSlave(ZoneObject zone); //Add one or more slave product(s) to a multiroom zone. QUuid addZoneSlave(ZoneObject zone); //Add one or more slave product(s) to a multiroom zone.
QUuid removeZoneSlave(ZoneObject zone); //Remove one or more slave product(s) from a multiroom zone. QUuid removeZoneSlave(ZoneObject zone); //Remove one or more slave product(s) from a multiroom zone.
QUuid setBass(int volume); //Set the bass level of a product, if supported.*/ QUuid setBass(int volume); //Set the bass level of a product, if supported.*/
QUuid setName(QString name); //Set the products user-facing name. QUuid setName(const QString &name); //Set the products user-facing name.
QUuid setSpeaker(PlayInfoObject playInfo); //initiate playback of a specified network-accessible audio file on a Bose SoundTouch product. QUuid setSpeaker(PlayInfoObject playInfo); //initiate playback of a specified network-accessible audio file on a Bose SoundTouch product.
private: private:
@ -82,23 +80,23 @@ private:
QString m_ipAddress; QString m_ipAddress;
int m_port = 8090; int m_port = 8090;
QWebSocket *m_websocket = nullptr; QWebSocket *m_websocket = nullptr;
void emitRequestStatus(QUuid requestId, QNetworkReply *reply); //returns the status, -1 in case of error void emitRequestStatus(const QUuid &requestId, QNetworkReply *reply); //returns the status, -1 in case of error
void parseData(QUuid requestId, const QByteArray &data); void parseData(const QUuid &requestId, const QByteArray &data);
signals: signals:
void connectionChanged(bool connected); void connectionChanged(bool connected);
void infoReceived(QUuid requestId, InfoObject info); void infoReceived(const QUuid &requestId, InfoObject info);
void nowPlayingReceived(QUuid requestId, NowPlayingObject nowPlaying); void nowPlayingReceived(const QUuid &requestId, NowPlayingObject nowPlaying);
void volumeReceived(QUuid requestId, VolumeObject volume); void volumeReceived(const QUuid &requestId, VolumeObject volume);
void sourcesReceived(QUuid requestId, SourcesObject sources); void sourcesReceived(const QUuid &requestId, SourcesObject sources);
void zoneReceived(QUuid requestId, ZoneObject); void zoneReceived(const QUuid &requestId, ZoneObject);
void bassCapabilitiesReceived(QUuid requestId, BassCapabilitiesObject bassCapabilities); void bassCapabilitiesReceived(const QUuid &requestId, BassCapabilitiesObject bassCapabilities);
void bassReceived(QUuid requestId, BassObject bass); void bassReceived(const QUuid &requestId, BassObject bass);
void presetsReceived(QUuid requestId, QList<PresetObject> presets); void presetsReceived(const QUuid &requestId, QList<PresetObject> presets);
void groupReceived(QUuid requestId, GroupObject group); void groupReceived(const QUuid &requestId, GroupObject group);
void requestExecuted(QUuid requestId, bool success); void requestExecuted(const QUuid &requestId, bool success);
void errorReceived(ErrorObject error); void errorReceived(ErrorObject error);
private slots: private slots: