fixed power state and added bass setting

master
nymea 2019-07-11 17:44:29 +02:00
parent 5498905a49
commit 9d30ec249f
4 changed files with 140 additions and 15 deletions

View File

@ -61,11 +61,17 @@ Device::DeviceSetupStatus DevicePluginBose::setupDevice(Device *device)
connect(soundTouch, &SoundTouch::nowPlayingReceived, this, &DevicePluginBose::onNowPlayingObjectReceived);
connect(soundTouch, &SoundTouch::volumeReceived, this, &DevicePluginBose::onVolumeObjectReceived);
connect(soundTouch, &SoundTouch::sourcesReceived, this, &DevicePluginBose::onSourcesObjectReceived);
connect(soundTouch, &SoundTouch::bassReceived, this, &DevicePluginBose::onBassObjectReceived);
connect(soundTouch, &SoundTouch::bassCapabilitiesReceived, this, &DevicePluginBose::onBassCapabilitiesObjectReceived);
soundTouch->getInfo();
soundTouch->getNowPlaying();
soundTouch->getVolume();
soundTouch->getSources();
soundTouch->getBass();
soundTouch->getBassCapabilities();
soundTouch->getGroup();
soundTouch->getZone();
m_soundTouch.insert(device, soundTouch);
@ -77,7 +83,7 @@ Device::DeviceSetupStatus DevicePluginBose::setupDevice(Device *device)
void DevicePluginBose::deviceRemoved(Device *device)
{
if (device->deviceClassId() == soundtouchDeviceClassId) {
SoundTouch *soundTouch = m_soundTouch.value(device);
SoundTouch *soundTouch = m_soundTouch.take(device);
soundTouch->deleteLater();
}
@ -100,6 +106,13 @@ Device::DeviceError DevicePluginBose::discoverDevices(const DeviceClassId &devic
QString playerId = avahiEntry.hostName().split(".").first();
DeviceDescriptor descriptor(soundtouchDeviceClassId, avahiEntry.name(), avahiEntry.hostAddress().toString());
ParamList params;
foreach (Device *existingDevice, myDevices().filterByDeviceClassId(soundtouchDeviceClassId)) {
if (existingDevice->paramValue(soundtouchDevicePlayerIdParamTypeId).toString() == playerId) {
descriptor.setDeviceId(existingDevice->id());
break;
}
}
params << Param(soundtouchDeviceIpParamTypeId, avahiEntry.hostAddress().toString());
params << Param(soundtouchDevicePlayerIdParamTypeId, playerId);
descriptor.setParams(params);
@ -177,6 +190,12 @@ Device::DeviceError DevicePluginBose::executeAction(Device *device, const Action
return Device::DeviceErrorNoError;
}
if (action.actionTypeId() == soundtouchBassActionTypeId) {
int bass = action.param(soundtouchBassActionBassParamTypeId).value().toInt();
soundTouch->setBass(bass);
return Device::DeviceErrorNoError;
}
if (action.actionTypeId() == soundtouchPlaybackStatusActionTypeId) {
QString status = action.param(soundtouchPlaybackStatusActionPlaybackStatusParamTypeId).value().toString();
if (status == "Playing") {
@ -200,6 +219,7 @@ void DevicePluginBose::onPluginTimer()
soundTouch->getInfo();
soundTouch->getNowPlaying();
soundTouch->getVolume();
soundTouch->getBass();
}
}
@ -229,6 +249,8 @@ void DevicePluginBose::onNowPlayingObjectReceived(NowPlayingObject nowPlaying)
SoundTouch *soundtouch = static_cast<SoundTouch *>(sender());
Device *device = m_soundTouch.key(soundtouch);
device->setStateValue(soundtouchPowerStateTypeId, !(nowPlaying.source.toUpper() == "STANDBY"));
device->setStateValue(soundtouchSourceStateTypeId, nowPlaying.source);
device->setStateValue(soundtouchTitleStateTypeId, nowPlaying.track);
device->setStateValue(soundtouchArtistStateTypeId, nowPlaying.artist);
device->setStateValue(soundtouchCollectionStateTypeId, nowPlaying.album);
@ -275,3 +297,15 @@ void DevicePluginBose::onSourcesObjectReceived(SourcesObject sources)
qDebug(dcBose()) << "Source:" << sources.deviceId << sourceItem.source << sourceItem.displayName;
}
}
void DevicePluginBose::onBassObjectReceived(BassObject bass)
{
SoundTouch *soundtouch = static_cast<SoundTouch *>(sender());
Device *device = m_soundTouch.key(soundtouch);
device->setStateValue(soundtouchBassStateTypeId, bass.actualBass);
}
void DevicePluginBose::onBassCapabilitiesObjectReceived(BassCapabilitiesObject bassCapabilities)
{
qDebug(dcBose()) << "Bass capabilities (max, min, default):" << bassCapabilities.bassMax << bassCapabilities.bassMin << bassCapabilities.bassDefault;
}

View File

@ -62,6 +62,8 @@ private slots:
void onNowPlayingObjectReceived(NowPlayingObject nowPlaying);
void onVolumeObjectReceived(VolumeObject volume);
void onSourcesObjectReceived(SourcesObject sources);
void onBassObjectReceived(BassObject bass);
void onBassCapabilitiesObjectReceived(BassCapabilitiesObject bassCapabilities);
};
#endif // DEVICEPLUGINBOSE_H

View File

@ -51,7 +51,7 @@
{
"id": "bc98cdb0-4d0e-48ca-afc7-922e49bb7813",
"name": "mute",
"displayName": "mute",
"displayName": "Mute",
"displayNameEvent": "Mute changed",
"displayNameAction": "Set mute",
"type": "bool",
@ -61,8 +61,8 @@
{
"id": "9dfe5d78-4c3f-497c-bab1-bb9fdf7e93a9",
"name": "volume",
"displayName": "volume",
"displayNameEvent": "volume changed",
"displayName": "Volume",
"displayNameEvent": "Volume changed",
"displayNameAction": "Set volume",
"unit": "Percentage",
"type": "int",
@ -74,7 +74,7 @@
{
"id": "2dd512b7-40c2-488e-8d4f-6519edaa6f74",
"name": "playbackStatus",
"displayName": "playback status",
"displayName": "Playback status",
"type": "QString",
"possibleValues": ["Playing", "Paused", "Stopped"],
"defaultValue": "Stopped",
@ -134,50 +134,70 @@
"possibleValues": ["None", "One", "All"],
"defaultValue": "None",
"writable": true
},
{
"id": "f4684de8-ff5f-41f3-a5c3-f5e5754519d2",
"type": "QString",
"name": "source",
"displayName": "Source",
"displayNameEvent": "Source changed",
"defaultValue": "None"
},
{
"id": "91bc53ec-4f3b-438d-8e32-129b7c27aae4",
"name": "bass",
"displayName": "Bass",
"displayNameEvent": "Bass changed",
"displayNameAction": "Set bass",
"type": "int",
"minValue": -9,
"maxValue": 0,
"defaultValue": 0,
"writable": true
}
],
"eventTypes": [
{
"id": "2535a1eb-7643-4874-98f6-b027fdff6311",
"name": "onPlayerPlay",
"displayName": "player play"
"displayName": "Player play"
},
{
"id": "99498b1c-e9c0-480a-9e91-662ee79ba976",
"name": "onPlayerPause",
"displayName": "player pause"
"displayName": "Player pause"
},
{
"id": "a02ce255-3abb-435d-a92e-7f99c952ecb2",
"name": "onPlayerStop",
"displayName": "player stop"
"displayName": "Player stop"
}
],
"actionTypes": [
{
"id": "a180807d-1265-4831-9d86-a421767418dd",
"name": "skipBack",
"displayName": "skip back"
"displayName": "Skip back"
},
{
"id": "ae3cbe03-ee3e-410e-abbd-efabc2402198",
"name": "stop",
"displayName": "stop"
"displayName": "Stop"
},
{
"id": "4d2ee668-a2e3-4795-8b96-0c800b703b46",
"name": "play",
"displayName": "play"
"displayName": "Play"
},
{
"id": "3cf341cb-fe63-40bc-a450-9678d18e91e3",
"name": "pause",
"displayName": "pause"
"displayName": "Pause"
},
{
"id": "85d7126a-b123-4a28-aeb4-d84bcfb4d14f",
"name": "skipNext",
"displayName": "skipNext"
"displayName": "Skip Next"
}
]
}

View File

@ -123,7 +123,7 @@ void SoundTouch::getZone()
url.setScheme("http");
url.setPort(m_port);
url.setPath("/getZone");
qDebug(dcBose) << "Sending request" << url;
//qDebug(dcBose) << "Sending request" << url;
QNetworkReply *reply = m_networkAccessManager->get(QNetworkRequest(url));
connect(reply, &QNetworkReply::finished, this, &SoundTouch::onRestRequestFinished);
}
@ -140,6 +140,18 @@ void SoundTouch::getPresets()
connect(reply, &QNetworkReply::finished, this, &SoundTouch::onRestRequestFinished);
}
void SoundTouch::getBassCapabilities()
{
QUrl url;
url.setHost(m_ipAddress);
url.setScheme("http");
url.setPort(m_port);
url.setPath("/bassCapabilities");
qDebug(dcBose) << "Sending request" << url;
QNetworkReply *reply = m_networkAccessManager->get(QNetworkRequest(url));
connect(reply, &QNetworkReply::finished, this, &SoundTouch::onRestRequestFinished);
}
void SoundTouch::setKey(KEY_VALUE keyValue)
{
QUrl url;
@ -398,7 +410,6 @@ void SoundTouch::onWebsocketDisconnected()
});
}
void SoundTouch::onRestRequestFinished() {
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
@ -627,6 +638,64 @@ void SoundTouch::onRestRequestFinished() {
}
}
emit sourcesReceived(sourcesObject);
} else if (xml.name() == "bass") {
BassObject bassObject;
if(xml.attributes().hasAttribute("deviceID")) {
//qDebug(dcBose) << "Device ID" << xml.attributes().value("deviceID").toString();
bassObject.deviceID = xml.attributes().value("deviceID").toString();
}
while(xml.readNextStartElement()){
if(xml.name() == "targetbass"){
//qDebug(dcBose) << "Target bas" << xml.readElementText();
bassObject.targetBass = xml.readElementText().toInt();
} else if(xml.name() == "actualbass"){
//qDebug(dcBose) << "Actual bass" << xml.readElementText();
bassObject.actualBass = xml.readElementText().toInt();
}else {
xml.skipCurrentElement();
}
}
emit bassReceived(bassObject);
} else if (xml.name() == "bassCapabilities") {
BassCapabilitiesObject bassCapabilities;
emit bassCapabilitiesReceived(bassCapabilities);
} else if (xml.name() == "presets") {
PresetObject preset;
if(xml.attributes().hasAttribute("id")) {
preset.presetId = xml.attributes().value("id").toInt();
}
if(xml.attributes().hasAttribute("createdOn")) {
preset.createdOn= xml.attributes().value("createdOn").toULong();
}
if(xml.attributes().hasAttribute("updatedOn")) {
preset.updatedOn = xml.attributes().value("updatedOn").toULong();
}
while(xml.readNextStartElement()){
if(xml.name() == "ContentItem"){
if(xml.attributes().hasAttribute("source")) {
preset.ContentItem.source = xml.attributes().value("source").toString();
}
if(xml.attributes().hasAttribute("location")) {
preset.ContentItem.location = xml.attributes().value("location").toString();
}
if(xml.attributes().hasAttribute("sourceAccount")) {
preset.ContentItem.sourceAccount = xml.attributes().value("sourceAccount").toString();
}
}else {
xml.skipCurrentElement();
}
}
emit presetsReceived(preset);
} else if (xml.name() == "group") {
GroupObject group;
if(xml.attributes().hasAttribute("deviceID")) {
//qDebug(dcBose) << "Device ID" << xml.attributes().value("deviceID").toString();
group.id = xml.attributes().value("id").toString();
}
emit groupReceived(group);
} else {
xml.skipCurrentElement();
}