some cleanup
This commit is contained in:
parent
a2272f9699
commit
ec08e6c7d5
@ -226,10 +226,10 @@ void AWSClient::login(const QString &username, const QString &password, int atte
|
||||
m_idToken = authenticationResult.value("IdToken").toByteArray();
|
||||
m_refreshToken = authenticationResult.value("RefreshToken").toByteArray();
|
||||
|
||||
qDebug() << "AWS ID token" << m_idToken;
|
||||
// qDebug() << "AWS ID token" << m_idToken;
|
||||
QList<QByteArray> jwtParts = m_idToken.split('.');
|
||||
if (jwtParts.count() != 3) {
|
||||
qWarning() << "JWT token doesn't have 3 parts";
|
||||
qWarning() << "Error: JWT token doesn't have 3 parts. Cannot retrieve AWS Cognito ID.";
|
||||
return;
|
||||
}
|
||||
// qDebug() << "decoded header:" << QByteArray::fromBase64(jwtParts.at(0));
|
||||
@ -237,7 +237,7 @@ void AWSClient::login(const QString &username, const QString &password, int atte
|
||||
QJsonDocument tokenPayloadJsonDoc = QJsonDocument::fromJson(QByteArray::fromBase64(jwtParts.at(1)));
|
||||
m_userId = tokenPayloadJsonDoc.toVariant().toMap().value("cognito:username").toByteArray();
|
||||
|
||||
qDebug() << "Getting cognito ID";
|
||||
// qDebug() << "Getting cognito ID";
|
||||
getId();
|
||||
});
|
||||
}
|
||||
@ -597,7 +597,7 @@ void AWSClient::getId()
|
||||
}
|
||||
m_identityId = jsonDoc.toVariant().toMap().value("IdentityId").toByteArray();
|
||||
|
||||
qDebug() << "Received cognito identity id" << m_identityId;// << qUtf8Printable(data);
|
||||
// qDebug() << "Received cognito identity id" << m_identityId;// << qUtf8Printable(data);
|
||||
getCredentialsForIdentity(m_identityId);
|
||||
|
||||
});
|
||||
|
||||
@ -393,7 +393,7 @@ bool NymeaConnection::storePem(const QUrl &host, const QByteArray &pem)
|
||||
bool NymeaConnection::loadPem(const QUrl &host, QByteArray &pem)
|
||||
{
|
||||
QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/sslcerts/");
|
||||
qDebug() << "Loading certificates from:" << dir.absoluteFilePath(host.host() + ".pem");
|
||||
// qDebug() << "Loading certificates from:" << dir.absoluteFilePath(host.host() + ".pem");
|
||||
QFile certFile(dir.absoluteFilePath(host.host() + ".pem"));
|
||||
if (!certFile.open(QFile::ReadOnly)) {
|
||||
return false;
|
||||
|
||||
@ -84,12 +84,11 @@ void NymeaHosts::removeHost(NymeaHost *host)
|
||||
emit countChanged();
|
||||
}
|
||||
|
||||
NymeaHost *NymeaHosts::createHost(const QString &name, const QUrl &url)
|
||||
NymeaHost *NymeaHosts::createHost(const QString &name, const QUrl &url, Connection::BearerType bearerType)
|
||||
{
|
||||
NymeaHost *host = new NymeaHost(this);
|
||||
host->setUuid(QUuid::createUuid());
|
||||
host->setName(name);
|
||||
Connection *connection = new Connection(url, Connection::BearerTypeAll, false, url.toString(), host);
|
||||
Connection *connection = new Connection(url, bearerType, false, url.toString(), host);
|
||||
host->connections()->addConnection(connection);
|
||||
addHost(host);
|
||||
return host;
|
||||
@ -195,6 +194,11 @@ void NymeaHostsFilterModel::setShowUnreachableBearers(bool showUnreachableBearer
|
||||
}
|
||||
}
|
||||
|
||||
NymeaHost *NymeaHostsFilterModel::get(int index) const
|
||||
{
|
||||
return m_nymeaDiscovery->nymeaHosts()->get(mapToSource(this->index(index, 0)).row());
|
||||
}
|
||||
|
||||
bool NymeaHostsFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||
{
|
||||
Q_UNUSED(sourceParent)
|
||||
|
||||
@ -25,8 +25,8 @@
|
||||
#include <QList>
|
||||
#include <QBluetoothAddress>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include "nymeahost.h"
|
||||
|
||||
class NymeaHost;
|
||||
class NymeaDiscovery;
|
||||
class NymeaConnection;
|
||||
|
||||
@ -49,7 +49,7 @@ public:
|
||||
|
||||
void addHost(NymeaHost *host);
|
||||
void removeHost(NymeaHost *host);
|
||||
Q_INVOKABLE NymeaHost* createHost(const QString &name, const QUrl &url);
|
||||
Q_INVOKABLE NymeaHost* createHost(const QString &name, const QUrl &url, Connection::BearerType bearerType);
|
||||
|
||||
Q_INVOKABLE NymeaHost *get(int index) const;
|
||||
Q_INVOKABLE NymeaHost *find(const QUuid &uuid);
|
||||
@ -89,6 +89,8 @@ public:
|
||||
bool showUnreachableBearers() const;
|
||||
void setShowUnreachableBearers(bool showUnreachableBearers);
|
||||
|
||||
Q_INVOKABLE NymeaHost* get(int index) const;
|
||||
|
||||
signals:
|
||||
void countChanged();
|
||||
void discoveryChanged();
|
||||
|
||||
@ -363,6 +363,7 @@ void JsonRpcClient::dataReceived(const QByteArray &data)
|
||||
if (!protoVersionString.contains('.')) {
|
||||
protoVersionString.prepend("0.");
|
||||
}
|
||||
|
||||
m_jsonRpcVersion = QVersionNumber::fromString(protoVersionString);
|
||||
|
||||
qDebug() << "Handshake reply:" << "Protocol version:" << protoVersionString << "InitRequired:" << m_initialSetupRequired << "AuthRequired:" << m_authenticationRequired << "PushButtonAvailable:" << m_pushButtonAuthAvailable;;
|
||||
@ -377,6 +378,11 @@ void JsonRpcClient::dataReceived(const QByteArray &data)
|
||||
|
||||
emit handshakeReceived();
|
||||
|
||||
if (m_connection->currentHost()->uuid().isNull()) {
|
||||
qDebug() << "Updating Server UUID in connection:" << m_connection->currentHost()->uuid().toString() << "->" << m_serverUuid;
|
||||
m_connection->currentHost()->setUuid(m_serverUuid);
|
||||
}
|
||||
|
||||
if (m_initialSetupRequired) {
|
||||
emit initialSetupRequiredChanged();
|
||||
return;
|
||||
|
||||
@ -102,14 +102,13 @@ Item {
|
||||
print("Last connected host was", tabSettings.lastConnectedHost)
|
||||
var cachedHost = discovery.nymeaHosts.find(tabSettings.lastConnectedHost);
|
||||
if (cachedHost) {
|
||||
engine.connection.currentHost = cachedHost
|
||||
} else {
|
||||
print("Warning: There is a last connected host but UUID is unknown to discovery...")
|
||||
engine.connection.connect(cachedHost)
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
PlatformHelper.hideSplashScreen();
|
||||
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"), StackView.Immediate)
|
||||
print("Warning: There is a last connected host but UUID is unknown to discovery...")
|
||||
}
|
||||
PlatformHelper.hideSplashScreen();
|
||||
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"), StackView.Immediate)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ Page {
|
||||
}
|
||||
onClicked: {
|
||||
if (index === 2) {
|
||||
var host = discovery.nymeaHosts.createHost("Demo server", "nymea://nymea.nymea.io:2222")
|
||||
var host = discovery.nymeaHosts.createHost("Demo server", "nymea://nymea.nymea.io:2222", Connection.BearerTypeCloud)
|
||||
engine.connection.connect(host)
|
||||
} else {
|
||||
pageStack.push(model.get(index).page, {nymeaDiscovery: discovery});
|
||||
@ -128,7 +128,7 @@ Page {
|
||||
width: parent.width
|
||||
height: app.delegateHeight
|
||||
objectName: "discoveryDelegate" + index
|
||||
property var nymeaHost: discovery.nymeaHosts.get(index)
|
||||
property var nymeaHost: hostsProxy.get(index)
|
||||
property string defaultConnectionIndex: {
|
||||
var usedConfigIndex = 0;
|
||||
for (var i = 1; i < nymeaHost.connections.count; i++) {
|
||||
@ -209,7 +209,9 @@ Page {
|
||||
onClicked: {
|
||||
if (model.deviceType === NymeaHost.DeviceTypeNetwork) {
|
||||
swipe.close()
|
||||
var popup = infoDialog.createObject(app,{nymeaHost: discovery.nymeaHosts.get(index)})
|
||||
var nymeaHost = hostsProxy.get(index);
|
||||
print("Getting info for", nymeaHost.name)
|
||||
var popup = infoDialog.createObject(app,{nymeaHost: nymeaHost})
|
||||
popup.open()
|
||||
}
|
||||
}
|
||||
@ -267,7 +269,7 @@ Page {
|
||||
visible: discovery.nymeaHosts.count === 0
|
||||
text: qsTr("Demo mode (online)")
|
||||
onClicked: {
|
||||
var host = nymeaHosts.createHost("Demo server", "nymea://nymea.nymea.io:2222")
|
||||
var host = nymeaHosts.createHost("Demo server", "nymea://nymea.nymea.io:2222", Connection.BearerTypeCloud)
|
||||
engine.connection.connect(host)
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ Page {
|
||||
errorMessage = qsTr("%1:core could not be found on this address. Please make sure you entered the address correctly and that the box is powered on.").arg(app.systemName);
|
||||
break;
|
||||
case NymeaConnection.ConnectionStatusConnectionRefused:
|
||||
errorMessage = qsTr("The host has rejected our connection. This probably means that %1 stopped running. Did you unplug your %1 box?").arg(app.systemName);
|
||||
errorMessage = qsTr("The host has rejected our connection. This probably means that %1 is not running on this host. Perhaps it's restarting?").arg(app.systemName);
|
||||
break;
|
||||
case NymeaConnection.ConnectionStatusRemoteHostClosed:
|
||||
errorMessage = qsTr("%1:core has closed the connection. This probably means it has been turned off or restarted.").arg(app.systemName);
|
||||
@ -70,7 +70,7 @@ Page {
|
||||
break;
|
||||
case NymeaConnection.ConnectionStatusUnknownError:
|
||||
default:
|
||||
errorMessage = qsTr("An unknown error happened. We're very sorry for that. (Error code: %1)").arg(engine.connection.connectionStatus);
|
||||
errorMessage = qsTr("An unknown error happened. We're very sorry for that.").arg(engine.connection.connectionStatus);
|
||||
}
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
@ -96,12 +96,8 @@ Page {
|
||||
}
|
||||
|
||||
print("Try to connect ", rpcUrl)
|
||||
engine.connection.connect(rpcUrl)
|
||||
var page = pageStack.push(Qt.resolvedUrl("ConnectingPage.qml"))
|
||||
page.cancel.connect(function() {
|
||||
engine.connection.disconnect()
|
||||
pageStack.pop(root)
|
||||
})
|
||||
var host = discovery.nymeaHosts.createHost("Manual connection", rpcUrl, Connection.BearerTypeCloud);
|
||||
engine.connection.connect(host)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,7 +185,7 @@ Item {
|
||||
readonly property var powerState: device.states.getState(powerStateType.id)
|
||||
|
||||
readonly property var brightnessStateType: deviceClass.stateTypes.findByName("brightness");
|
||||
readonly property var brightnessState: device.states.getState(brightnessStateType.id)
|
||||
readonly property var brightnessState: brightnessStateType ? device.states.getState(brightnessStateType.id) : null
|
||||
|
||||
ThrottledSlider {
|
||||
Layout.fillWidth: true
|
||||
@ -195,7 +195,7 @@ Item {
|
||||
enabled: opacity > 0
|
||||
from: 0
|
||||
to: 100
|
||||
value: brightnessState.value
|
||||
value: brightnessState ? brightnessState.value : 0
|
||||
onMoved: {
|
||||
var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId);
|
||||
var actionType = deviceClass.actionTypes.findByName("brightness");
|
||||
|
||||
Reference in New Issue
Block a user