mirror of https://github.com/nymea/nymea.git
implement setName functionality
parent
c446154b7d
commit
a054f6c9d7
|
|
@ -114,8 +114,8 @@ void AWSConnector::onConnected()
|
|||
}
|
||||
qCDebug(dcAWS()) << "AWS connected. Device already registered in cloud.";
|
||||
|
||||
// OK, we're registerd already, go straight to pairing setup
|
||||
setupPairing();
|
||||
// OK, we're registerd already, go straight to subscription setup
|
||||
setupSubscriptions();
|
||||
}
|
||||
|
||||
void AWSConnector::registerDevice()
|
||||
|
|
@ -146,13 +146,14 @@ void AWSConnector::onDeviceRegistered(bool needsReconnect)
|
|||
return;
|
||||
}
|
||||
|
||||
setupPairing();
|
||||
setupSubscriptions();
|
||||
}
|
||||
|
||||
void AWSConnector::setupPairing()
|
||||
void AWSConnector::setupSubscriptions()
|
||||
{
|
||||
// Subscribe to pairing info topics
|
||||
QStringList subscriptions;
|
||||
subscriptions.append(QString("%1/device/name/response").arg(m_clientId));
|
||||
subscriptions.append(QString("%1/device/users/response").arg(m_clientId));
|
||||
subscriptions.append(QString("%1/pair/response").arg(m_clientId));
|
||||
subscribe(subscriptions);
|
||||
|
|
@ -178,6 +179,10 @@ void AWSConnector::onPairingsRetrieved(const QVariantList &pairings)
|
|||
}
|
||||
subscribe(topics);
|
||||
|
||||
if (!readNameSyncedFlag()) {
|
||||
setName();
|
||||
}
|
||||
|
||||
m_setupInProgress = false;
|
||||
emit connected();
|
||||
}
|
||||
|
|
@ -199,6 +204,17 @@ bool AWSConnector::isConnected() const
|
|||
return m_connectingFuture.isFinished() && m_networkConnection && m_client && m_client->IsConnected();
|
||||
}
|
||||
|
||||
void AWSConnector::setDeviceName(const QString &deviceName)
|
||||
{
|
||||
if (m_clientName != deviceName) {
|
||||
m_clientName = deviceName;
|
||||
storeNameSyncedFlag(false);
|
||||
if (isConnected()) {
|
||||
setName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AWSConnector::pairDevice(const QString &idToken, const QString &userId)
|
||||
{
|
||||
QVariantMap map;
|
||||
|
|
@ -432,3 +448,15 @@ bool AWSConnector::readRegisteredFlag() const
|
|||
QSettings settings(GuhSettings::storagePath() + "/cloudstatus.conf", QSettings::IniFormat);
|
||||
return settings.value("registered", false).toBool();
|
||||
}
|
||||
|
||||
void AWSConnector::storeNameSyncedFlag(bool synced)
|
||||
{
|
||||
QSettings settings(GuhSettings::storagePath() + "/cloudstatus.conf", QSettings::IniFormat);
|
||||
settings.setValue("nameSynced", synced);
|
||||
}
|
||||
|
||||
bool AWSConnector::readNameSyncedFlag()
|
||||
{
|
||||
QSettings settings(GuhSettings::storagePath() + "/cloudstatus.conf", QSettings::IniFormat);
|
||||
return settings.value("nameSynced", false).toBool();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ public:
|
|||
void disconnectAWS();
|
||||
bool isConnected() const;
|
||||
|
||||
void setDeviceName(const QString &deviceName);
|
||||
void pairDevice(const QString &idToken, const QString &userId);
|
||||
|
||||
void sendWebRtcHandshakeMessage(const QString &sessionId, const QVariantMap &map);
|
||||
|
|
@ -58,7 +59,7 @@ private slots:
|
|||
void onConnected();
|
||||
void registerDevice();
|
||||
void onDeviceRegistered(bool needsReconnect);
|
||||
void setupPairing();
|
||||
void setupSubscriptions();
|
||||
void fetchPairings();
|
||||
void onPairingsRetrieved(const QVariantList &pairings);
|
||||
void setName();
|
||||
|
|
@ -89,6 +90,9 @@ private:
|
|||
void storeRegisteredFlag(bool registered);
|
||||
bool readRegisteredFlag() const;
|
||||
|
||||
void storeNameSyncedFlag(bool synced);
|
||||
bool readNameSyncedFlag();
|
||||
|
||||
private:
|
||||
std::shared_ptr<awsiotsdk::network::MbedTLSConnection> m_networkConnection;
|
||||
std::shared_ptr<awsiotsdk::MqttClient> m_client;
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ void CloudManager::setDeviceId(const QUuid &deviceId)
|
|||
void CloudManager::setDeviceName(const QString &name)
|
||||
{
|
||||
m_deviceName = name;
|
||||
m_awsConnector->setDeviceName(name);
|
||||
}
|
||||
|
||||
void CloudManager::setClientCertificates(const QString &caCertificate, const QString &clientCertificate, const QString &clientCertificateKey)
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ void GuhConfiguration::setServerName(const QString &serverName)
|
|||
} else {
|
||||
settings.setValue("name", serverName);
|
||||
settings.endGroup();
|
||||
emit serverNameChanged();
|
||||
emit serverNameChanged(serverName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ private:
|
|||
WebServerConfiguration readWebServerConfig(const QString &id);
|
||||
|
||||
signals:
|
||||
void serverNameChanged();
|
||||
void serverNameChanged(const QString &serverName);
|
||||
void timeZoneChanged();
|
||||
void localeChanged();
|
||||
|
||||
|
|
|
|||
|
|
@ -458,6 +458,7 @@ void GuhCore::init() {
|
|||
|
||||
connect(m_configuration, &GuhConfiguration::localeChanged, this, &GuhCore::onLocaleChanged);
|
||||
connect(m_configuration, &GuhConfiguration::cloudEnabledChanged, m_cloudManager, &CloudManager::setEnabled);
|
||||
connect(m_configuration, &GuhConfiguration::serverNameChanged, m_cloudManager, &CloudManager::setDeviceName);
|
||||
|
||||
connect(m_deviceManager, &DeviceManager::pluginConfigChanged, this, &GuhCore::pluginConfigChanged);
|
||||
connect(m_deviceManager, &DeviceManager::eventTriggered, this, &GuhCore::gotEvent);
|
||||
|
|
|
|||
Loading…
Reference in New Issue