nymeadiscovery doesn't use the Engine any more
This commit is contained in:
parent
e529cc87f0
commit
7ef39cb2d7
@ -1,5 +1,4 @@
|
|||||||
#include "nymeadiscovery.h"
|
#include "nymeadiscovery.h"
|
||||||
#include "engine.h"
|
|
||||||
#include "upnpdiscovery.h"
|
#include "upnpdiscovery.h"
|
||||||
#include "zeroconfdiscovery.h"
|
#include "zeroconfdiscovery.h"
|
||||||
#include "bluetoothservicediscovery.h"
|
#include "bluetoothservicediscovery.h"
|
||||||
@ -21,12 +20,11 @@ NymeaDiscovery::NymeaDiscovery(QObject *parent) : QObject(parent)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_cloudPollTimer.setInterval(5000);
|
m_cloudPollTimer.setInterval(5000);
|
||||||
connect(&m_cloudPollTimer, &QTimer::timeout, this, [](){
|
connect(&m_cloudPollTimer, &QTimer::timeout, this, [this](){
|
||||||
if (Engine::instance()->awsClient()->isLoggedIn()) {
|
if (m_awsClient && m_awsClient->isLoggedIn()) {
|
||||||
Engine::instance()->awsClient()->fetchDevices();
|
m_awsClient->fetchDevices();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(Engine::instance()->awsClient(), &AWSClient::devicesFetched, this, &NymeaDiscovery::syncCloudDevices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NymeaDiscovery::discovering() const
|
bool NymeaDiscovery::discovering() const
|
||||||
@ -62,9 +60,9 @@ void NymeaDiscovery::setDiscovering(bool discovering)
|
|||||||
// start polling cloud
|
// start polling cloud
|
||||||
m_cloudPollTimer.start();
|
m_cloudPollTimer.start();
|
||||||
// If we're logged in, poll right away
|
// If we're logged in, poll right away
|
||||||
if (Engine::instance()->awsClient()->isLoggedIn()) {
|
if (m_awsClient && m_awsClient->isLoggedIn()) {
|
||||||
syncCloudDevices();
|
syncCloudDevices();
|
||||||
Engine::instance()->awsClient()->fetchDevices();
|
m_awsClient->fetchDevices();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!m_zeroConf->available()) {
|
if (!m_zeroConf->available()) {
|
||||||
@ -86,10 +84,28 @@ DiscoveryModel *NymeaDiscovery::discoveryModel() const
|
|||||||
return m_discoveryModel;
|
return m_discoveryModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AWSClient *NymeaDiscovery::awsClient() const
|
||||||
|
{
|
||||||
|
return m_awsClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NymeaDiscovery::setAwsClient(AWSClient *awsClient)
|
||||||
|
{
|
||||||
|
if (m_awsClient != awsClient) {
|
||||||
|
m_awsClient = awsClient;
|
||||||
|
emit awsClientChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_awsClient) {
|
||||||
|
connect(m_awsClient, &AWSClient::devicesFetched, this, &NymeaDiscovery::syncCloudDevices);
|
||||||
|
syncCloudDevices();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NymeaDiscovery::syncCloudDevices()
|
void NymeaDiscovery::syncCloudDevices()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < Engine::instance()->awsClient()->awsDevices()->rowCount(); i++) {
|
for (int i = 0; i < m_awsClient->awsDevices()->rowCount(); i++) {
|
||||||
AWSDevice *d = Engine::instance()->awsClient()->awsDevices()->get(i);
|
AWSDevice *d = m_awsClient->awsDevices()->get(i);
|
||||||
DiscoveryDevice *device = m_discoveryModel->find(d->id());
|
DiscoveryDevice *device = m_discoveryModel->find(d->id());
|
||||||
if (!device) {
|
if (!device) {
|
||||||
device = new DiscoveryDevice();
|
device = new DiscoveryDevice();
|
||||||
@ -115,7 +131,7 @@ void NymeaDiscovery::syncCloudDevices()
|
|||||||
DiscoveryDevice *device = m_discoveryModel->get(i);
|
DiscoveryDevice *device = m_discoveryModel->get(i);
|
||||||
for (int j = 0; j < device->connections()->rowCount(); j++) {
|
for (int j = 0; j < device->connections()->rowCount(); j++) {
|
||||||
if (device->connections()->get(j)->bearerType() == Connection::BearerTypeCloud) {
|
if (device->connections()->get(j)->bearerType() == Connection::BearerTypeCloud) {
|
||||||
if (Engine::instance()->awsClient()->awsDevices()->getDevice(device->uuid().toString()) == nullptr) {
|
if (m_awsClient->awsDevices()->getDevice(device->uuid().toString()) == nullptr) {
|
||||||
device->connections()->removeConnection(j);
|
device->connections()->removeConnection(j);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,8 @@ class NymeaDiscovery : public QObject
|
|||||||
Q_PROPERTY(bool discovering READ discovering WRITE setDiscovering NOTIFY discoveringChanged)
|
Q_PROPERTY(bool discovering READ discovering WRITE setDiscovering NOTIFY discoveringChanged)
|
||||||
Q_PROPERTY(DiscoveryModel *discoveryModel READ discoveryModel CONSTANT)
|
Q_PROPERTY(DiscoveryModel *discoveryModel READ discoveryModel CONSTANT)
|
||||||
|
|
||||||
|
Q_PROPERTY(AWSClient* awsClient READ awsClient WRITE setAwsClient NOTIFY awsClientChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NymeaDiscovery(QObject *parent = nullptr);
|
explicit NymeaDiscovery(QObject *parent = nullptr);
|
||||||
|
|
||||||
@ -26,8 +28,12 @@ public:
|
|||||||
|
|
||||||
DiscoveryModel *discoveryModel() const;
|
DiscoveryModel *discoveryModel() const;
|
||||||
|
|
||||||
|
AWSClient* awsClient() const;
|
||||||
|
void setAwsClient(AWSClient *awsClient);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void discoveringChanged();
|
void discoveringChanged();
|
||||||
|
void awsClientChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void syncCloudDevices();
|
void syncCloudDevices();
|
||||||
@ -39,6 +45,7 @@ private:
|
|||||||
UpnpDiscovery *m_upnp = nullptr;
|
UpnpDiscovery *m_upnp = nullptr;
|
||||||
ZeroconfDiscovery *m_zeroConf = nullptr;
|
ZeroconfDiscovery *m_zeroConf = nullptr;
|
||||||
BluetoothServiceDiscovery *m_bluetooth = nullptr;
|
BluetoothServiceDiscovery *m_bluetooth = nullptr;
|
||||||
|
AWSClient *m_awsClient = nullptr;
|
||||||
|
|
||||||
QTimer m_cloudPollTimer;
|
QTimer m_cloudPollTimer;
|
||||||
|
|
||||||
|
|||||||
@ -37,6 +37,7 @@ Page {
|
|||||||
NymeaDiscovery {
|
NymeaDiscovery {
|
||||||
id: discovery
|
id: discovery
|
||||||
objectName: "discovery"
|
objectName: "discovery"
|
||||||
|
awsClient: Engine.awsClient
|
||||||
discovering: pageStack.currentItem.objectName === "discoveryPage"
|
discovering: pageStack.currentItem.objectName === "discoveryPage"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user