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,52 +53,63 @@ 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()) {
|
||||||
if (service.txt().contains("am=AVRX1000")) {
|
qCDebug(dcDenon()) << "mDNS service entry:" << service;
|
||||||
|
if (service.txt().contains("am=AVRX1000")) {
|
||||||
|
|
||||||
QString id = service.name().split("@").first();
|
QString id = service.name().split("@").first();
|
||||||
QString name = service.name().split("@").last();
|
QString name = service.name().split("@").last();
|
||||||
QString address = service.hostAddress().toString();
|
QString address = service.hostAddress().toString();
|
||||||
qCDebug(dcDenon) << "service discovered" << name << "ID:" << id;
|
qCDebug(dcDenon) << "service discovered" << name << "ID:" << id;
|
||||||
if (discoveredIds.contains(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;
|
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);
|
}
|
||||||
});
|
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())) {
|
||||||
@ -763,11 +774,11 @@ void IntegrationPluginDenon::onAvrCommandExecuted(const QUuid &commandId, bool s
|
|||||||
if(info->action().actionTypeId() == AVRX1000PlayActionTypeId) {
|
if(info->action().actionTypeId() == AVRX1000PlayActionTypeId) {
|
||||||
info->thing()->setStateValue(AVRX1000PlaybackStatusStateTypeId, "Playing");
|
info->thing()->setStateValue(AVRX1000PlaybackStatusStateTypeId, "Playing");
|
||||||
} else if(info->action().actionTypeId() == AVRX1000PauseActionTypeId) {
|
} else if(info->action().actionTypeId() == AVRX1000PauseActionTypeId) {
|
||||||
info->thing()->setStateValue(AVRX1000PlaybackStatusStateTypeId, "Paused");
|
info->thing()->setStateValue(AVRX1000PlaybackStatusStateTypeId, "Paused");
|
||||||
} else if(info->action().actionTypeId() == AVRX1000StopActionTypeId) {
|
} else if(info->action().actionTypeId() == AVRX1000StopActionTypeId) {
|
||||||
info->thing()->setStateValue(AVRX1000PlaybackStatusStateTypeId, "Stopped");
|
info->thing()->setStateValue(AVRX1000PlaybackStatusStateTypeId, "Stopped");
|
||||||
} else if(info->action().actionTypeId() == AVRX1000PlaybackStatusActionTypeId) {
|
} 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);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
|
||||||
|
|||||||
@ -91,28 +91,28 @@
|
|||||||
"writable": true
|
"writable": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"displayName": "Bass",
|
"displayName": "Bass",
|
||||||
"id": "2c92b22e-d5b2-4991-a523-64222bffc9e7",
|
"id": "2c92b22e-d5b2-4991-a523-64222bffc9e7",
|
||||||
"name": "bass",
|
"name": "bass",
|
||||||
"displayNameEvent": "Bass changed",
|
"displayNameEvent": "Bass changed",
|
||||||
"displayNameAction": "Set bass",
|
"displayNameAction": "Set bass",
|
||||||
"type": "int",
|
"type": "int",
|
||||||
"defaultValue": 0,
|
"defaultValue": 0,
|
||||||
"minValue": -50,
|
"minValue": -50,
|
||||||
"maxValue": 49,
|
"maxValue": 49,
|
||||||
"writable": true
|
"writable": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"displayName": "Treble",
|
"displayName": "Treble",
|
||||||
"id": "38a3be02-6ed4-4a84-903e-eb923b933989",
|
"id": "38a3be02-6ed4-4a84-903e-eb923b933989",
|
||||||
"name": "treble",
|
"name": "treble",
|
||||||
"displayNameEvent": "Treble changed",
|
"displayNameEvent": "Treble changed",
|
||||||
"displayNameAction": "Set treble",
|
"displayNameAction": "Set treble",
|
||||||
"type": "int",
|
"type": "int",
|
||||||
"defaultValue": 0,
|
"defaultValue": 0,
|
||||||
"minValue": -50,
|
"minValue": -50,
|
||||||
"maxValue": 49,
|
"maxValue": 49,
|
||||||
"writable": true
|
"writable": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"displayName": "Channel",
|
"displayName": "Channel",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user