Prima versione di ThinQ: stato e comandi della lavasciuga via cloud LG
- elenco delle macchine e stato in lettura, fasi tradotte in italiano - avvio, stop, spegnimento, ripresa e stop ritardato da 3 a 19 ore - chiave di accesso custodita solo sul telefono, nel file privato dell'app - 44 verifiche automatiche sul nucleo (scripts/test-core.sh) - interfaccia italiana o inglese secondo la lingua del telefono
This commit is contained in:
commit
b5f6e79146
32 files changed
+2859
No files matched your search
@@ -0,0 +1,119 @@
|
||||
#ifndef THINQCLIENT_H
|
||||
#define THINQCLIENT_H
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QTimer>
|
||||
|
||||
#include "thinqjson.h"
|
||||
|
||||
class Settings;
|
||||
class QNetworkReply;
|
||||
|
||||
// Parla direttamente con il cloud LG ThinQ Connect: nessun ponte, nessun
|
||||
// server di mezzo. Il token di accesso sta nelle impostazioni dell'app.
|
||||
class ThinQClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool configured READ configured NOTIFY infoChanged)
|
||||
Q_PROPERTY(QString alias READ alias NOTIFY infoChanged)
|
||||
Q_PROPERTY(bool hasState READ hasState NOTIFY stateChanged)
|
||||
Q_PROPERTY(QString phaseText READ phaseText NOTIFY stateChanged)
|
||||
Q_PROPERTY(int statusLevel READ statusLevel NOTIFY stateChanged)
|
||||
Q_PROPERTY(QString remainText READ remainText NOTIFY stateChanged)
|
||||
Q_PROPERTY(QString totalText READ totalText NOTIFY stateChanged)
|
||||
Q_PROPERTY(int cycleCount READ cycleCount NOTIFY stateChanged)
|
||||
Q_PROPERTY(bool remoteEnabled READ remoteEnabled NOTIFY stateChanged)
|
||||
Q_PROPERTY(QString primaryLabel READ primaryLabel NOTIFY stateChanged)
|
||||
Q_PROPERTY(bool canCommand READ canCommand NOTIFY stateChanged)
|
||||
Q_PROPERTY(QString updatedText READ updatedText NOTIFY stateChanged)
|
||||
Q_PROPERTY(bool stale READ stale NOTIFY stateChanged)
|
||||
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
|
||||
Q_PROPERTY(bool polling READ polling NOTIFY pollingChanged)
|
||||
Q_PROPERTY(QString notice READ notice NOTIFY noticeChanged)
|
||||
Q_PROPERTY(bool noticeIsError READ noticeIsError NOTIFY noticeChanged)
|
||||
Q_PROPERTY(QStringList deviceLabels READ deviceLabels NOTIFY devicesChanged)
|
||||
Q_PROPERTY(int deviceCount READ deviceCount NOTIFY devicesChanged)
|
||||
Q_PROPERTY(int selectedDevice READ selectedDevice NOTIFY devicesChanged)
|
||||
Q_PROPERTY(int delayHours READ delayHours WRITE setDelayHours NOTIFY delayHoursChanged)
|
||||
|
||||
public:
|
||||
explicit ThinQClient(Settings *settings, QObject *parent = nullptr);
|
||||
|
||||
bool configured() const;
|
||||
QString alias() const;
|
||||
bool hasState() const { return m_state.valid; }
|
||||
QString phaseText() const;
|
||||
int statusLevel() const;
|
||||
QString remainText() const;
|
||||
QString totalText() const;
|
||||
int cycleCount() const { return m_state.cycleCount; }
|
||||
bool remoteEnabled() const { return m_state.remoteEnabled; }
|
||||
QString primaryLabel() const;
|
||||
bool canCommand() const;
|
||||
QString updatedText() const;
|
||||
bool stale() const { return m_stale; }
|
||||
bool busy() const { return m_busy; }
|
||||
bool polling() const { return m_pollTimer.isActive(); }
|
||||
QString notice() const { return m_notice; }
|
||||
bool noticeIsError() const { return m_noticeIsError; }
|
||||
QStringList deviceLabels() const { return m_deviceLabels; }
|
||||
int deviceCount() const { return m_deviceLabels.size(); }
|
||||
int selectedDevice() const { return m_selected; }
|
||||
int delayHours() const { return m_delayHours; }
|
||||
void setDelayHours(int hours);
|
||||
|
||||
Q_INVOKABLE void refresh();
|
||||
Q_INVOKABLE void discover();
|
||||
Q_INVOKABLE void chooseDevice(int index);
|
||||
Q_INVOKABLE void runPrimary();
|
||||
Q_INVOKABLE void powerOff();
|
||||
Q_INVOKABLE void wakeUp();
|
||||
Q_INVOKABLE void sendDelay();
|
||||
Q_INVOKABLE void startPolling();
|
||||
Q_INVOKABLE void stopPolling();
|
||||
Q_INVOKABLE void clearNotice();
|
||||
Q_INVOKABLE void reloadCredentials();
|
||||
Q_INVOKABLE QString durationText(int minutes) const;
|
||||
|
||||
signals:
|
||||
void infoChanged();
|
||||
void stateChanged();
|
||||
void busyChanged();
|
||||
void pollingChanged();
|
||||
void noticeChanged();
|
||||
void devicesChanged();
|
||||
void delayHoursChanged();
|
||||
|
||||
private:
|
||||
enum RequestKind { KindDevices, KindState, KindCommand };
|
||||
|
||||
void prepare(QNetworkRequest &request, bool command) const;
|
||||
void get(const QString &endpoint, RequestKind kind);
|
||||
void post(const QString &endpoint, const QString &payload);
|
||||
void applyState(const WasherState &state);
|
||||
void handleFailure(int httpStatus, const QByteArray &body, const QString &networkError,
|
||||
bool commandRequest);
|
||||
void setNotice(const QString &text, bool isError);
|
||||
void setBusy(bool busy);
|
||||
void scheduleNextPoll();
|
||||
|
||||
Settings *m_settings;
|
||||
QNetworkAccessManager m_nam;
|
||||
QTimer m_pollTimer;
|
||||
WasherState m_state;
|
||||
QStringList m_deviceLabels;
|
||||
QStringList m_deviceIds;
|
||||
int m_selected = -1;
|
||||
int m_pollInterval = 45000;
|
||||
int m_delayHours = 4;
|
||||
bool m_busy = false;
|
||||
bool m_stale = false;
|
||||
bool m_pendingCommand = false;
|
||||
QString m_notice;
|
||||
bool m_noticeIsError = false;
|
||||
QString m_updated;
|
||||
};
|
||||
|
||||
#endif // THINQCLIENT_H
|
||||
Reference in new issue
Block a user