added avr auto rediscovery
This commit is contained in:
parent
31a77dab03
commit
44d4029a32
@ -85,11 +85,23 @@ QHostAddress AvrConnection::hostAddress() const
|
||||
return m_hostAddress;
|
||||
}
|
||||
|
||||
void AvrConnection::setHostAddress(const QHostAddress &hostAddress)
|
||||
{
|
||||
m_hostAddress = hostAddress;
|
||||
connectDevice();
|
||||
}
|
||||
|
||||
int AvrConnection::port() const
|
||||
{
|
||||
return m_port;
|
||||
}
|
||||
|
||||
void AvrConnection::setPort(int port)
|
||||
{
|
||||
m_port = port;
|
||||
connectDevice();
|
||||
}
|
||||
|
||||
bool AvrConnection::connected()
|
||||
{
|
||||
return m_socket->isOpen();
|
||||
@ -391,15 +403,15 @@ void AvrConnection::readData()
|
||||
emit playBackModeChanged(PlayBackMode::PlayBackModeStopped);
|
||||
}
|
||||
} else if (data.left(4).contains("NSE1")) {
|
||||
QString song = QString(data).remove(0, 4).trimmed();
|
||||
QString song = QString(data).remove(0, 5).trimmed();
|
||||
qCDebug(dcDenon()) << "Song" << song;
|
||||
emit songChanged(song);
|
||||
} else if (data.left(4).contains("NSE2")) {
|
||||
QString artist = QString(data).remove(0, 4).trimmed();
|
||||
QString artist = QString(data).remove(0, 5).trimmed();
|
||||
qCDebug(dcDenon()) << "Artist" << artist;
|
||||
emit artistChanged(artist);
|
||||
} else if (data.left(4).contains("NSE4")) {
|
||||
QString album = QString(data).remove(0, 4).trimmed();
|
||||
QString album = QString(data).remove(0, 5).trimmed();
|
||||
qCDebug(dcDenon()) << "Album" << album;
|
||||
emit albumChanged(album);
|
||||
} else if (data.contains("PSTONE CTRL ON")) {
|
||||
|
||||
@ -60,7 +60,9 @@ public:
|
||||
void disconnectDevice();
|
||||
|
||||
QHostAddress hostAddress() const;
|
||||
void setHostAddress(const QHostAddress &hostAddress);
|
||||
int port() const;
|
||||
void setPort(int port);
|
||||
bool connected();
|
||||
|
||||
QUuid getChannel();
|
||||
|
||||
@ -53,52 +53,63 @@ void IntegrationPluginDenon::init()
|
||||
{
|
||||
m_notificationUrl = QUrl(configValue(denonPluginNotificationUrlParamTypeId).toString());
|
||||
connect(this, &IntegrationPluginDenon::configValueChanged, this, &IntegrationPluginDenon::onPluginConfigurationChanged);
|
||||
|
||||
m_serviceBrowser = hardwareManager()->zeroConfController()->createServiceBrowser();
|
||||
connect(m_serviceBrowser, &ZeroConfServiceBrowser::serviceEntryAdded, this, [=](const ZeroConfServiceEntry &entry){
|
||||
foreach (Thing *thing, myThings().filterByThingClassId(AVRX1000ThingClassId)) {
|
||||
|
||||
if (entry.txt().contains("am=AVRX1000")) {
|
||||
QString thingId = thing->paramValue(AVRX1000ThingIdParamTypeId).toString();
|
||||
QString id = entry.name().split("@").first();
|
||||
QHostAddress address = entry.hostAddress();
|
||||
if (thingId == id) {
|
||||
AvrConnection *avrConnection = m_avrConnections.value(thing->id());
|
||||
avrConnection->setHostAddress(address);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void IntegrationPluginDenon::discoverThings(ThingDiscoveryInfo *info)
|
||||
{
|
||||
if (info->thingClassId() == AVRX1000ThingClassId) {
|
||||
|
||||
if (!m_serviceBrowser) {
|
||||
m_serviceBrowser = hardwareManager()->zeroConfController()->createServiceBrowser();
|
||||
}
|
||||
|
||||
if (!hardwareManager()->zeroConfController()->available()) {
|
||||
qCDebug(dcDenon()) << "Error discovering Denon things. Available:" << hardwareManager()->zeroConfController()->available();
|
||||
info->finish(Thing::ThingErrorHardwareNotAvailable, "Thing discovery not possible");
|
||||
return;
|
||||
}
|
||||
|
||||
QTimer::singleShot(2000, info, [this, info](){
|
||||
QStringList discoveredIds;
|
||||
QStringList discoveredIds;
|
||||
|
||||
foreach (const ZeroConfServiceEntry &service, m_serviceBrowser->serviceEntries()) {
|
||||
if (service.txt().contains("am=AVRX1000")) {
|
||||
foreach (const ZeroConfServiceEntry &service, m_serviceBrowser->serviceEntries()) {
|
||||
qCDebug(dcDenon()) << "mDNS service entry:" << service;
|
||||
if (service.txt().contains("am=AVRX1000")) {
|
||||
|
||||
QString id = service.name().split("@").first();
|
||||
QString name = service.name().split("@").last();
|
||||
QString address = service.hostAddress().toString();
|
||||
qCDebug(dcDenon) << "service discovered" << name << "ID:" << id;
|
||||
if (discoveredIds.contains(id))
|
||||
QString id = service.name().split("@").first();
|
||||
QString name = service.name().split("@").last();
|
||||
QString address = service.hostAddress().toString();
|
||||
qCDebug(dcDenon) << "service discovered" << name << "ID:" << id;
|
||||
if (discoveredIds.contains(id))
|
||||
break;
|
||||
discoveredIds.append(id);
|
||||
ThingDescriptor thingDescriptor(AVRX1000ThingClassId, name, address);
|
||||
ParamList params;
|
||||
params.append(Param(AVRX1000ThingIpParamTypeId, address));
|
||||
params.append(Param(AVRX1000ThingIdParamTypeId, id));
|
||||
thingDescriptor.setParams(params);
|
||||
foreach (Thing *existingThing, myThings().filterByThingClassId(AVRX1000ThingClassId)) {
|
||||
if (existingThing->paramValue(AVRX1000ThingIdParamTypeId).toString() == id) {
|
||||
thingDescriptor.setThingId(existingThing->id());
|
||||
break;
|
||||
discoveredIds.append(id);
|
||||
ThingDescriptor thingDescriptor(AVRX1000ThingClassId, name, address);
|
||||
ParamList params;
|
||||
params.append(Param(AVRX1000ThingIpParamTypeId, address));
|
||||
params.append(Param(AVRX1000ThingIdParamTypeId, id));
|
||||
thingDescriptor.setParams(params);
|
||||
foreach (Thing *existingThing, myThings()) {
|
||||
if (existingThing->paramValue(AVRX1000ThingIdParamTypeId).toString() == id) {
|
||||
thingDescriptor.setThingId(existingThing->id());
|
||||
break;
|
||||
}
|
||||
}
|
||||
info->addThingDescriptor(thingDescriptor);
|
||||
}
|
||||
info->addThingDescriptor(thingDescriptor);
|
||||
}
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
});
|
||||
return;
|
||||
}
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
|
||||
} else if (info->thingClassId() == heosThingClassId) {
|
||||
/*
|
||||
* The HEOS products can be discovered using the UPnP SSDP protocol. Through discovery,
|
||||
@ -261,9 +272,9 @@ void IntegrationPluginDenon::thingRemoved(Thing *thing)
|
||||
|
||||
if (thing->thingClassId() == AVRX1000ThingClassId) {
|
||||
if (m_avrConnections.contains(thing->id())) {
|
||||
AvrConnection *denonConnection = m_avrConnections.take(thing->id());
|
||||
denonConnection->disconnectDevice();
|
||||
denonConnection->deleteLater();
|
||||
AvrConnection *avrConnection = m_avrConnections.take(thing->id());
|
||||
avrConnection->disconnectDevice();
|
||||
avrConnection->deleteLater();
|
||||
}
|
||||
} else if (thing->thingClassId() == heosThingClassId) {
|
||||
if (m_heosConnections.contains(thing->id())) {
|
||||
@ -763,11 +774,11 @@ void IntegrationPluginDenon::onAvrCommandExecuted(const QUuid &commandId, bool s
|
||||
if(info->action().actionTypeId() == AVRX1000PlayActionTypeId) {
|
||||
info->thing()->setStateValue(AVRX1000PlaybackStatusStateTypeId, "Playing");
|
||||
} else if(info->action().actionTypeId() == AVRX1000PauseActionTypeId) {
|
||||
info->thing()->setStateValue(AVRX1000PlaybackStatusStateTypeId, "Paused");
|
||||
info->thing()->setStateValue(AVRX1000PlaybackStatusStateTypeId, "Paused");
|
||||
} else if(info->action().actionTypeId() == AVRX1000StopActionTypeId) {
|
||||
info->thing()->setStateValue(AVRX1000PlaybackStatusStateTypeId, "Stopped");
|
||||
info->thing()->setStateValue(AVRX1000PlaybackStatusStateTypeId, "Stopped");
|
||||
} else if(info->action().actionTypeId() == AVRX1000PlaybackStatusActionTypeId) {
|
||||
info->thing()->setStateValue(AVRX1000PlaybackStatusStateTypeId, info->action().param(AVRX1000PlaybackStatusActionPlaybackStatusParamTypeId).value());
|
||||
info->thing()->setStateValue(AVRX1000PlaybackStatusStateTypeId, info->action().param(AVRX1000PlaybackStatusActionPlaybackStatusParamTypeId).value());
|
||||
}
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
|
||||
|
||||
@ -91,28 +91,28 @@
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"displayName": "Bass",
|
||||
"id": "2c92b22e-d5b2-4991-a523-64222bffc9e7",
|
||||
"name": "bass",
|
||||
"displayNameEvent": "Bass changed",
|
||||
"displayNameAction": "Set bass",
|
||||
"type": "int",
|
||||
"defaultValue": 0,
|
||||
"minValue": -50,
|
||||
"maxValue": 49,
|
||||
"writable": true
|
||||
"displayName": "Bass",
|
||||
"id": "2c92b22e-d5b2-4991-a523-64222bffc9e7",
|
||||
"name": "bass",
|
||||
"displayNameEvent": "Bass changed",
|
||||
"displayNameAction": "Set bass",
|
||||
"type": "int",
|
||||
"defaultValue": 0,
|
||||
"minValue": -50,
|
||||
"maxValue": 49,
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"displayName": "Treble",
|
||||
"id": "38a3be02-6ed4-4a84-903e-eb923b933989",
|
||||
"name": "treble",
|
||||
"displayNameEvent": "Treble changed",
|
||||
"displayNameAction": "Set treble",
|
||||
"type": "int",
|
||||
"defaultValue": 0,
|
||||
"minValue": -50,
|
||||
"maxValue": 49,
|
||||
"writable": true
|
||||
"displayName": "Treble",
|
||||
"id": "38a3be02-6ed4-4a84-903e-eb923b933989",
|
||||
"name": "treble",
|
||||
"displayNameEvent": "Treble changed",
|
||||
"displayNameAction": "Set treble",
|
||||
"type": "int",
|
||||
"defaultValue": 0,
|
||||
"minValue": -50,
|
||||
"maxValue": 49,
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"displayName": "Channel",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user