mirror of https://github.com/nymea/nymea.git
add a config option for enabling/disabling the cloud
parent
6aa8ad8a5d
commit
a0371a0133
|
|
@ -185,7 +185,6 @@ void AWSConnector::onPairingsRetrieved(const QVariantList &pairings)
|
|||
|
||||
void AWSConnector::disconnectAWS()
|
||||
{
|
||||
m_reconnect = false;
|
||||
if (isConnected()) {
|
||||
m_client->Disconnect(std::chrono::seconds(2));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,7 +91,6 @@ private:
|
|||
private:
|
||||
std::shared_ptr<awsiotsdk::network::MbedTLSConnection> m_networkConnection;
|
||||
std::shared_ptr<awsiotsdk::MqttClient> m_client;
|
||||
bool m_reconnect = false;
|
||||
QString m_currentEndpoint;
|
||||
QString m_caFile;
|
||||
QString m_clientCertFile;
|
||||
|
|
|
|||
|
|
@ -105,6 +105,9 @@ void CloudManager::setEnabled(bool enabled)
|
|||
if (!m_awsConnector->isConnected() && m_networkManager->state() == NetworkManager::NetworkManagerStateConnectedGlobal) {
|
||||
connect2aws();
|
||||
}
|
||||
} else {
|
||||
m_enabled = false;
|
||||
m_awsConnector->disconnectAWS();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -318,6 +318,24 @@ void GuhConfiguration::setBluetoothServerEnabled(const bool &enabled)
|
|||
emit bluetoothServerEnabled();
|
||||
}
|
||||
|
||||
bool GuhConfiguration::cloudEnabled() const
|
||||
{
|
||||
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||
settings.beginGroup("Cloud");
|
||||
return settings.value("enabled", false).toBool();
|
||||
}
|
||||
|
||||
void GuhConfiguration::setCloudEnabled(bool enabled)
|
||||
{
|
||||
if (cloudEnabled() != enabled) {
|
||||
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||
settings.beginGroup("Cloud");
|
||||
settings.setValue("enabled", enabled);
|
||||
settings.endGroup();
|
||||
emit cloudEnabledChanged(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
QString GuhConfiguration::cloudServerUrl() const
|
||||
{
|
||||
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||
|
|
|
|||
|
|
@ -110,6 +110,9 @@ public:
|
|||
void setBluetoothServerEnabled(const bool &enabled);
|
||||
|
||||
// Cloud
|
||||
bool cloudEnabled() const;
|
||||
void setCloudEnabled(bool enabled);
|
||||
|
||||
QString cloudServerUrl() const;
|
||||
QString cloudCertificateCA() const;
|
||||
QString cloudCertificate() const;
|
||||
|
|
@ -144,6 +147,7 @@ signals:
|
|||
void webSocketServerConfigurationRemoved(const QString &configId);
|
||||
|
||||
void bluetoothServerEnabledChanged();
|
||||
void cloudEnabledChanged(bool enabled);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -451,11 +451,10 @@ void GuhCore::init() {
|
|||
m_cloudManager->setDeviceName(m_configuration->serverName());
|
||||
m_cloudManager->setServerUrl(m_configuration->cloudServerUrl());
|
||||
m_cloudManager->setClientCertificates(m_configuration->cloudCertificateCA(), m_configuration->cloudCertificate(), m_configuration->cloudCertificateKey());
|
||||
if (!m_configuration->cloudServerUrl().isEmpty()) {
|
||||
m_cloudManager->setEnabled(true);
|
||||
}
|
||||
m_cloudManager->setEnabled(m_configuration->cloudEnabled());
|
||||
|
||||
connect(m_configuration, &GuhConfiguration::localeChanged, this, &GuhCore::onLocaleChanged);
|
||||
connect(m_configuration, &GuhConfiguration::cloudEnabledChanged, m_cloudManager, &CloudManager::setEnabled);
|
||||
|
||||
connect(m_deviceManager, &DeviceManager::pluginConfigChanged, this, &GuhCore::pluginConfigChanged);
|
||||
connect(m_deviceManager, &DeviceManager::eventTriggered, this, &GuhCore::gotEvent);
|
||||
|
|
|
|||
|
|
@ -164,6 +164,18 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
|
|||
returns.insert("configurationError", JsonTypes::configurationErrorRef());
|
||||
setReturns("DeleteWebServerConfiguration", returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
setDescription("GetCloudEnabled", "Returns whether the cloud connection is enabled or disabled in the settings.");
|
||||
setParams("GetCloudEnabled", params);
|
||||
returns.insert("enabled", JsonTypes::basicTypeToString(QVariant::Bool));
|
||||
setReturns("GetCloudEnabled", returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
setDescription("SetCloudEnabled", "Sets whether the cloud connection is enabled or disabled in the settings.");
|
||||
params.insert("enabled", JsonTypes::basicTypeToString(QVariant::Bool));
|
||||
setParams("SetCloudEnabled", params);
|
||||
setReturns("SetCloudEnabled", returns);
|
||||
|
||||
// Notifications
|
||||
params.clear(); returns.clear();
|
||||
setDescription("BasicConfigurationChanged", "Emitted whenever the basic configuration of this server changes.");
|
||||
|
|
@ -389,6 +401,21 @@ JsonReply *ConfigurationHandler::DeleteWebSocketServerConfiguration(const QVaria
|
|||
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorNoError));
|
||||
}
|
||||
|
||||
JsonReply *ConfigurationHandler::GetCloudEnabled(const QVariantMap ¶ms) const
|
||||
{
|
||||
Q_UNUSED(params)
|
||||
QVariantMap ret;
|
||||
ret.insert("enabled", GuhCore::instance()->configuration()->cloudEnabled());
|
||||
return createReply(ret);
|
||||
}
|
||||
|
||||
JsonReply *ConfigurationHandler::SetCloudEnabled(const QVariantMap ¶ms) const
|
||||
{
|
||||
bool enabled = params.value("enabled").toBool();
|
||||
GuhCore::instance()->configuration()->setCloudEnabled(enabled);
|
||||
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorNoError));
|
||||
}
|
||||
|
||||
void ConfigurationHandler::onBasicConfigurationChanged()
|
||||
{
|
||||
QVariantMap params;
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ public:
|
|||
Q_INVOKABLE JsonReply *DeleteWebServerConfiguration(const QVariantMap ¶ms) const;
|
||||
Q_INVOKABLE JsonReply *SetWebSocketServerConfiguration(const QVariantMap ¶ms) const;
|
||||
Q_INVOKABLE JsonReply *DeleteWebSocketServerConfiguration(const QVariantMap ¶ms) const;
|
||||
Q_INVOKABLE JsonReply *GetCloudEnabled(const QVariantMap ¶ms) const;
|
||||
Q_INVOKABLE JsonReply *SetCloudEnabled(const QVariantMap ¶ms) const;
|
||||
|
||||
signals:
|
||||
void BasicConfigurationChanged(const QVariantMap ¶ms);
|
||||
|
|
|
|||
Loading…
Reference in New Issue