added avr auto rediscovery
This commit is contained in:
parent
31a77dab03
commit
44d4029a32
@ -85,11 +85,23 @@ QHostAddress AvrConnection::hostAddress() const
|
|||||||
return m_hostAddress;
|
return m_hostAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AvrConnection::setHostAddress(const QHostAddress &hostAddress)
|
||||||
|
{
|
||||||
|
m_hostAddress = hostAddress;
|
||||||
|
connectDevice();
|
||||||
|
}
|
||||||
|
|
||||||
int AvrConnection::port() const
|
int AvrConnection::port() const
|
||||||
{
|
{
|
||||||
return m_port;
|
return m_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AvrConnection::setPort(int port)
|
||||||
|
{
|
||||||
|
m_port = port;
|
||||||
|
connectDevice();
|
||||||
|
}
|
||||||
|
|
||||||
bool AvrConnection::connected()
|
bool AvrConnection::connected()
|
||||||
{
|
{
|
||||||
return m_socket->isOpen();
|
return m_socket->isOpen();
|
||||||
@ -391,15 +403,15 @@ void AvrConnection::readData()
|
|||||||
emit playBackModeChanged(PlayBackMode::PlayBackModeStopped);
|
emit playBackModeChanged(PlayBackMode::PlayBackModeStopped);
|
||||||
}
|
}
|
||||||
} else if (data.left(4).contains("NSE1")) {
|
} 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;
|
qCDebug(dcDenon()) << "Song" << song;
|
||||||
emit songChanged(song);
|
emit songChanged(song);
|
||||||
} else if (data.left(4).contains("NSE2")) {
|
} 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;
|
qCDebug(dcDenon()) << "Artist" << artist;
|
||||||
emit artistChanged(artist);
|
emit artistChanged(artist);
|
||||||
} else if (data.left(4).contains("NSE4")) {
|
} 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;
|
qCDebug(dcDenon()) << "Album" << album;
|
||||||
emit albumChanged(album);
|
emit albumChanged(album);
|
||||||
} else if (data.contains("PSTONE CTRL ON")) {
|
} else if (data.contains("PSTONE CTRL ON")) {
|
||||||
|
|||||||
@ -60,7 +60,9 @@ public:
|
|||||||
void disconnectDevice();
|
void disconnectDevice();
|
||||||
|
|
||||||
QHostAddress hostAddress() const;
|
QHostAddress hostAddress() const;
|
||||||
|
void setHostAddress(const QHostAddress &hostAddress);
|
||||||
int port() const;
|
int port() const;
|
||||||
|
void setPort(int port);
|
||||||
bool connected();
|
bool connected();
|
||||||
|
|
||||||
QUuid getChannel();
|
QUuid getChannel();
|
||||||
|
|||||||
@ -53,26 +53,38 @@ void IntegrationPluginDenon::init()
|
|||||||
{
|
{
|
||||||
m_notificationUrl = QUrl(configValue(denonPluginNotificationUrlParamTypeId).toString());
|
m_notificationUrl = QUrl(configValue(denonPluginNotificationUrlParamTypeId).toString());
|
||||||
connect(this, &IntegrationPluginDenon::configValueChanged, this, &IntegrationPluginDenon::onPluginConfigurationChanged);
|
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)
|
void IntegrationPluginDenon::discoverThings(ThingDiscoveryInfo *info)
|
||||||
{
|
{
|
||||||
if (info->thingClassId() == AVRX1000ThingClassId) {
|
if (info->thingClassId() == AVRX1000ThingClassId) {
|
||||||
|
|
||||||
if (!m_serviceBrowser) {
|
|
||||||
m_serviceBrowser = hardwareManager()->zeroConfController()->createServiceBrowser();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hardwareManager()->zeroConfController()->available()) {
|
if (!hardwareManager()->zeroConfController()->available()) {
|
||||||
qCDebug(dcDenon()) << "Error discovering Denon things. Available:" << hardwareManager()->zeroConfController()->available();
|
qCDebug(dcDenon()) << "Error discovering Denon things. Available:" << hardwareManager()->zeroConfController()->available();
|
||||||
info->finish(Thing::ThingErrorHardwareNotAvailable, "Thing discovery not possible");
|
info->finish(Thing::ThingErrorHardwareNotAvailable, "Thing discovery not possible");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTimer::singleShot(2000, info, [this, info](){
|
|
||||||
QStringList discoveredIds;
|
QStringList discoveredIds;
|
||||||
|
|
||||||
foreach (const ZeroConfServiceEntry &service, m_serviceBrowser->serviceEntries()) {
|
foreach (const ZeroConfServiceEntry &service, m_serviceBrowser->serviceEntries()) {
|
||||||
|
qCDebug(dcDenon()) << "mDNS service entry:" << service;
|
||||||
if (service.txt().contains("am=AVRX1000")) {
|
if (service.txt().contains("am=AVRX1000")) {
|
||||||
|
|
||||||
QString id = service.name().split("@").first();
|
QString id = service.name().split("@").first();
|
||||||
@ -87,7 +99,7 @@ void IntegrationPluginDenon::discoverThings(ThingDiscoveryInfo *info)
|
|||||||
params.append(Param(AVRX1000ThingIpParamTypeId, address));
|
params.append(Param(AVRX1000ThingIpParamTypeId, address));
|
||||||
params.append(Param(AVRX1000ThingIdParamTypeId, id));
|
params.append(Param(AVRX1000ThingIdParamTypeId, id));
|
||||||
thingDescriptor.setParams(params);
|
thingDescriptor.setParams(params);
|
||||||
foreach (Thing *existingThing, myThings()) {
|
foreach (Thing *existingThing, myThings().filterByThingClassId(AVRX1000ThingClassId)) {
|
||||||
if (existingThing->paramValue(AVRX1000ThingIdParamTypeId).toString() == id) {
|
if (existingThing->paramValue(AVRX1000ThingIdParamTypeId).toString() == id) {
|
||||||
thingDescriptor.setThingId(existingThing->id());
|
thingDescriptor.setThingId(existingThing->id());
|
||||||
break;
|
break;
|
||||||
@ -97,8 +109,7 @@ void IntegrationPluginDenon::discoverThings(ThingDiscoveryInfo *info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
});
|
|
||||||
return;
|
|
||||||
} else if (info->thingClassId() == heosThingClassId) {
|
} else if (info->thingClassId() == heosThingClassId) {
|
||||||
/*
|
/*
|
||||||
* The HEOS products can be discovered using the UPnP SSDP protocol. Through discovery,
|
* 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 (thing->thingClassId() == AVRX1000ThingClassId) {
|
||||||
if (m_avrConnections.contains(thing->id())) {
|
if (m_avrConnections.contains(thing->id())) {
|
||||||
AvrConnection *denonConnection = m_avrConnections.take(thing->id());
|
AvrConnection *avrConnection = m_avrConnections.take(thing->id());
|
||||||
denonConnection->disconnectDevice();
|
avrConnection->disconnectDevice();
|
||||||
denonConnection->deleteLater();
|
avrConnection->deleteLater();
|
||||||
}
|
}
|
||||||
} else if (thing->thingClassId() == heosThingClassId) {
|
} else if (thing->thingClassId() == heosThingClassId) {
|
||||||
if (m_heosConnections.contains(thing->id())) {
|
if (m_heosConnections.contains(thing->id())) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user