Update Bose plugin

master
Michael Zanetti 2019-09-17 18:53:57 +02:00
parent 58476b4592
commit 668a07f63d
2 changed files with 58 additions and 39 deletions

View File

@ -42,18 +42,14 @@ void DevicePluginBose::init()
{ {
} }
Device::DeviceSetupStatus DevicePluginBose::setupDevice(Device *device) void DevicePluginBose::setupDevice(DeviceSetupInfo *info)
{ {
if (!m_pluginTimer) {
m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(2);
connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginBose::onPluginTimer);
}
if (device->deviceClassId() == soundtouchDeviceClassId) { if (info->device()->deviceClassId() == soundtouchDeviceClassId) {
connect(device, &Device::nameChanged, this, &DevicePluginBose::onDeviceNameChanged); connect(info->device(), &Device::nameChanged, this, &DevicePluginBose::onDeviceNameChanged);
QString ipAddress = device->paramValue(soundtouchDeviceIpParamTypeId).toString(); QString ipAddress = info->device()->paramValue(soundtouchDeviceIpParamTypeId).toString();
SoundTouch *soundTouch = new SoundTouch(hardwareManager()->networkManager(), ipAddress, this); SoundTouch *soundTouch = new SoundTouch(hardwareManager()->networkManager(), ipAddress, this);
connect(soundTouch, &SoundTouch::connectionChanged, this, &DevicePluginBose::onConnectionChanged); connect(soundTouch, &SoundTouch::connectionChanged, this, &DevicePluginBose::onConnectionChanged);
@ -73,11 +69,22 @@ Device::DeviceSetupStatus DevicePluginBose::setupDevice(Device *device)
soundTouch->getBassCapabilities(); soundTouch->getBassCapabilities();
soundTouch->getZone(); soundTouch->getZone();
m_soundTouch.insert(device, soundTouch); m_soundTouch.insert(info->device(), soundTouch);
return Device::DeviceSetupStatusSuccess; info->finish(Device::DeviceErrorNoError);
return;
}
info->finish(Device::DeviceErrorDeviceClassNotFound);
}
void DevicePluginBose::postSetupDevice(Device *device)
{
Q_UNUSED(device)
if (!m_pluginTimer) {
m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(2);
connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginBose::onPluginTimer);
} }
return Device::DeviceSetupStatusFailure;
} }
void DevicePluginBose::deviceRemoved(Device *device) void DevicePluginBose::deviceRemoved(Device *device)
@ -92,14 +99,11 @@ void DevicePluginBose::deviceRemoved(Device *device)
} }
} }
Device::DeviceError DevicePluginBose::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) void DevicePluginBose::discoverDevices(DeviceDiscoveryInfo *info)
{ {
Q_UNUSED(params)
Q_UNUSED(deviceClassId)
ZeroConfServiceBrowser *serviceBrowser = hardwareManager()->zeroConfController()->createServiceBrowser("_soundtouch._tcp"); ZeroConfServiceBrowser *serviceBrowser = hardwareManager()->zeroConfController()->createServiceBrowser("_soundtouch._tcp");
QTimer::singleShot(5000, this, [this, serviceBrowser](){
QList<DeviceDescriptor> descriptors; QTimer::singleShot(5000, info, [this, serviceBrowser, info](){
foreach (const ZeroConfServiceEntry avahiEntry, serviceBrowser->serviceEntries()) { foreach (const ZeroConfServiceEntry avahiEntry, serviceBrowser->serviceEntries()) {
qCDebug(dcBose) << "Zeroconf entry:" << avahiEntry; qCDebug(dcBose) << "Zeroconf entry:" << avahiEntry;
@ -116,48 +120,56 @@ Device::DeviceError DevicePluginBose::discoverDevices(const DeviceClassId &devic
params << Param(soundtouchDeviceIpParamTypeId, avahiEntry.hostAddress().toString()); params << Param(soundtouchDeviceIpParamTypeId, avahiEntry.hostAddress().toString());
params << Param(soundtouchDevicePlayerIdParamTypeId, playerId); params << Param(soundtouchDevicePlayerIdParamTypeId, playerId);
descriptor.setParams(params); descriptor.setParams(params);
descriptors << descriptor; info->addDeviceDescriptor(descriptor);
} }
emit devicesDiscovered(soundtouchDeviceClassId, descriptors);
serviceBrowser->deleteLater(); serviceBrowser->deleteLater();
info->finish(Device::DeviceErrorNoError);
}); });
return Device::DeviceErrorAsync;
} }
Device::DeviceError DevicePluginBose::executeAction(Device *device, const Action &action) void DevicePluginBose::executeAction(DeviceActionInfo *info)
{ {
Device *device = info->device();
Action action = info->action();
if (device->deviceClassId() == soundtouchDeviceClassId) { if (device->deviceClassId() == soundtouchDeviceClassId) {
SoundTouch *soundTouch = m_soundTouch.value(device); SoundTouch *soundTouch = m_soundTouch.value(device);
if (action.actionTypeId() == soundtouchPowerActionTypeId) { if (action.actionTypeId() == soundtouchPowerActionTypeId) {
//bool power = action.param(soundtouchPowerActionPowerParamTypeId).value().toBool(); //bool power = action.param(soundtouchPowerActionPowerParamTypeId).value().toBool();
soundTouch->setKey(KEY_VALUE::KEY_VALUE_POWER); //only toggling possible soundTouch->setKey(KEY_VALUE::KEY_VALUE_POWER); //only toggling possible
return Device::DeviceErrorNoError; info->finish(Device::DeviceErrorNoError);
return;
} }
if (action.actionTypeId() == soundtouchMuteActionTypeId) { if (action.actionTypeId() == soundtouchMuteActionTypeId) {
soundTouch->setKey(KEY_VALUE::KEY_VALUE_MUTE); soundTouch->setKey(KEY_VALUE::KEY_VALUE_MUTE);
return Device::DeviceErrorNoError; info->finish(Device::DeviceErrorNoError);
return;
} }
if (action.actionTypeId() == soundtouchPlayActionTypeId) { if (action.actionTypeId() == soundtouchPlayActionTypeId) {
soundTouch->setKey(KEY_VALUE::KEY_VALUE_PLAY); soundTouch->setKey(KEY_VALUE::KEY_VALUE_PLAY);
return Device::DeviceErrorNoError; info->finish(Device::DeviceErrorNoError);
return;
} }
if (action.actionTypeId() == soundtouchPauseActionTypeId) { if (action.actionTypeId() == soundtouchPauseActionTypeId) {
soundTouch->setKey(KEY_VALUE::KEY_VALUE_PAUSE); soundTouch->setKey(KEY_VALUE::KEY_VALUE_PAUSE);
return Device::DeviceErrorNoError; info->finish(Device::DeviceErrorNoError);
return;
} }
if (action.actionTypeId() == soundtouchStopActionTypeId) { if (action.actionTypeId() == soundtouchStopActionTypeId) {
soundTouch->setKey(KEY_VALUE::KEY_VALUE_STOP); soundTouch->setKey(KEY_VALUE::KEY_VALUE_STOP);
return Device::DeviceErrorNoError; info->finish(Device::DeviceErrorNoError);
return;
} }
if (action.actionTypeId() == soundtouchSkipNextActionTypeId) { if (action.actionTypeId() == soundtouchSkipNextActionTypeId) {
soundTouch->setKey(KEY_VALUE::KEY_VALUE_NEXT_TRACK); soundTouch->setKey(KEY_VALUE::KEY_VALUE_NEXT_TRACK);
return Device::DeviceErrorNoError; info->finish(Device::DeviceErrorNoError);
return;
} }
if (action.actionTypeId() == soundtouchSkipBackActionTypeId) { if (action.actionTypeId() == soundtouchSkipBackActionTypeId) {
soundTouch->setKey(KEY_VALUE::KEY_VALUE_PREV_TRACK); soundTouch->setKey(KEY_VALUE::KEY_VALUE_PREV_TRACK);
return Device::DeviceErrorNoError; info->finish(Device::DeviceErrorNoError);
return;
} }
if (action.actionTypeId() == soundtouchShuffleActionTypeId) { if (action.actionTypeId() == soundtouchShuffleActionTypeId) {
@ -168,7 +180,8 @@ Device::DeviceError DevicePluginBose::executeAction(Device *device, const Action
} else { } else {
soundTouch->setKey(KEY_VALUE::KEY_VALUE_SHUFFLE_OFF); soundTouch->setKey(KEY_VALUE::KEY_VALUE_SHUFFLE_OFF);
} }
return Device::DeviceErrorNoError; info->finish(Device::DeviceErrorNoError);
return;
} }
if (action.actionTypeId() == soundtouchRepeatActionTypeId) { if (action.actionTypeId() == soundtouchRepeatActionTypeId) {
@ -181,19 +194,22 @@ Device::DeviceError DevicePluginBose::executeAction(Device *device, const Action
} else if (repeat == "All") { } else if (repeat == "All") {
soundTouch->setKey(KEY_VALUE::KEY_VALUE_REPEAT_ALL); soundTouch->setKey(KEY_VALUE::KEY_VALUE_REPEAT_ALL);
} }
return Device::DeviceErrorNoError; info->finish(Device::DeviceErrorNoError);
return;
} }
if (action.actionTypeId() == soundtouchVolumeActionTypeId) { if (action.actionTypeId() == soundtouchVolumeActionTypeId) {
int volume = action.param(soundtouchVolumeActionVolumeParamTypeId).value().toInt(); int volume = action.param(soundtouchVolumeActionVolumeParamTypeId).value().toInt();
soundTouch->setVolume(volume); soundTouch->setVolume(volume);
return Device::DeviceErrorNoError; info->finish(Device::DeviceErrorNoError);
return;
} }
if (action.actionTypeId() == soundtouchBassActionTypeId) { if (action.actionTypeId() == soundtouchBassActionTypeId) {
int bass = action.param(soundtouchBassActionBassParamTypeId).value().toInt(); int bass = action.param(soundtouchBassActionBassParamTypeId).value().toInt();
soundTouch->setBass(bass); soundTouch->setBass(bass);
return Device::DeviceErrorNoError; info->finish(Device::DeviceErrorNoError);
return;
} }
if (action.actionTypeId() == soundtouchPlaybackStatusActionTypeId) { if (action.actionTypeId() == soundtouchPlaybackStatusActionTypeId) {
@ -205,12 +221,14 @@ Device::DeviceError DevicePluginBose::executeAction(Device *device, const Action
} else if (status == "Stopped") { } else if (status == "Stopped") {
soundTouch->setKey(KEY_VALUE::KEY_VALUE_STOP); soundTouch->setKey(KEY_VALUE::KEY_VALUE_STOP);
} }
return Device::DeviceErrorNoError; info->finish(Device::DeviceErrorNoError);
return;
} }
return Device::DeviceErrorActionTypeNotFound; info->finish(Device::DeviceErrorActionTypeNotFound);
return;
} }
return Device::DeviceErrorDeviceClassNotFound; info->finish(Device::DeviceErrorDeviceClassNotFound);
} }
void DevicePluginBose::onPluginTimer() void DevicePluginBose::onPluginTimer()

View File

@ -42,10 +42,11 @@ public:
~DevicePluginBose() override; ~DevicePluginBose() override;
void init() override; void init() override;
Device::DeviceSetupStatus setupDevice(Device *device) override; void discoverDevices(DeviceDiscoveryInfo *info) override;
void setupDevice(DeviceSetupInfo *info) override;
void postSetupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; void executeAction(DeviceActionInfo *info) override;
Device::DeviceError executeAction(Device *device, const Action &action) override;
private: private:
PluginTimer *m_pluginTimer = nullptr; PluginTimer *m_pluginTimer = nullptr;