Schermata principale con tutte le macchine, avviso di fine lavaggio, IT/EN
- la chiave si chiede una volta sola: poi la schermata principale mostra ogni macchina dell'account col suo stato e il suo comando - avviso di sistema a fine lavaggio, anche se il ciclo e' finito mentre l'app era chiusa (si annota il numero di ciclo gia' avvisato) - comandi per singola macchina: avvio/stop, spegnimento, risveglio, stop ritardato (nel menu della macchina, tocco prolungato sul nome) - le macchine non raggiungibili vengono segnate come non collegate, senza riempire la barra dei messaggi ad ogni aggiornamento - multilingua italiano/inglese, catalogo verificato dal banco di prova (52 controlli)
This commit is contained in:
1 parent
fe961b438c
commit
e2c6f28613
14 files changed
+1015
-541
No files matched your search
+58
-49
@@ -1,6 +1,7 @@
|
||||
#ifndef THINQCLIENT_H
|
||||
#define THINQCLIENT_H
|
||||
|
||||
#include <QList>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
@@ -11,66 +12,62 @@
|
||||
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.
|
||||
// Tutte le macchine dell'account, ognuna col suo stato. Una sola classe parla
|
||||
// col cloud LG: nessun ponte, nessun server di mezzo, nessun servizio.
|
||||
//
|
||||
// Il QML legge per indice (labelAt/phaseTextAt/...): l'elenco cambia raramente e
|
||||
// cosi' le stesse funzioni servono la schermata principale e la copertina.
|
||||
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(int deviceCount READ deviceCount NOTIFY devicesChanged)
|
||||
Q_PROPERTY(int activeIndex READ activeIndex 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);
|
||||
|
||||
// La chiave di accesso c'e': la schermata principale mostra i dispositivi
|
||||
// invece di chiedere le credenziali.
|
||||
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; }
|
||||
int deviceCount() const { return m_devices.size(); }
|
||||
// La macchina che sta lavorando (per la copertina), altrimenti la prima.
|
||||
int activeIndex() const;
|
||||
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 QString labelAt(int index) const;
|
||||
Q_INVOKABLE bool hasStateAt(int index) const;
|
||||
Q_INVOKABLE bool offlineAt(int index) const;
|
||||
Q_INVOKABLE bool staleAt(int index) const;
|
||||
Q_INVOKABLE QString phaseTextAt(int index) const;
|
||||
Q_INVOKABLE int statusLevelAt(int index) const;
|
||||
Q_INVOKABLE QString remainTextAt(int index) const;
|
||||
Q_INVOKABLE QString totalTextAt(int index) const;
|
||||
Q_INVOKABLE QString totalLineAt(int index) const;
|
||||
Q_INVOKABLE int cycleCountAt(int index) const;
|
||||
Q_INVOKABLE bool remoteEnabledAt(int index) const;
|
||||
Q_INVOKABLE QString primaryLabelAt(int index) const;
|
||||
Q_INVOKABLE bool canCommandAt(int index) const;
|
||||
Q_INVOKABLE QString updatedTextAt(int index) const;
|
||||
Q_INVOKABLE QString deviceIdAt(int index) const;
|
||||
Q_INVOKABLE bool validIndex(int index) const;
|
||||
|
||||
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 runPrimaryAt(int index);
|
||||
Q_INVOKABLE void powerOffAt(int index);
|
||||
Q_INVOKABLE void wakeUpAt(int index);
|
||||
Q_INVOKABLE void sendDelayAt(int index);
|
||||
Q_INVOKABLE void startPolling();
|
||||
Q_INVOKABLE void stopPolling();
|
||||
Q_INVOKABLE void clearNotice();
|
||||
@@ -85,35 +82,47 @@ signals:
|
||||
void noticeChanged();
|
||||
void devicesChanged();
|
||||
void delayHoursChanged();
|
||||
// Fine di un lavaggio: la macchina e' arrivata a END. Il QML lo trasforma in
|
||||
// una notifica di sistema.
|
||||
void cycleFinished(const QString &label, int cycleCount);
|
||||
|
||||
private:
|
||||
enum RequestKind { KindDevices, KindState, KindCommand };
|
||||
|
||||
struct DeviceEntry {
|
||||
QString id;
|
||||
QString label;
|
||||
WasherState state;
|
||||
bool hasState = false;
|
||||
bool offline = false;
|
||||
bool stale = false;
|
||||
QString updated;
|
||||
};
|
||||
|
||||
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 get(const QString &endpoint, RequestKind kind, int deviceIndex = -1);
|
||||
void post(const QString &endpoint, const QString &payload, int deviceIndex);
|
||||
void applyState(int deviceIndex, bool hadState, int previousLevel, const WasherState &state);
|
||||
void handleFailure(int httpStatus, const QByteArray &body, const QString &networkError,
|
||||
bool commandRequest);
|
||||
bool commandRequest, int deviceIndex);
|
||||
void setNotice(const QString &text, bool isError);
|
||||
void setBusy(bool busy);
|
||||
void scheduleNextPoll();
|
||||
void queueAllStates();
|
||||
void pumpQueue();
|
||||
void noteFinished(int deviceIndex, bool hadState, int previousLevel);
|
||||
|
||||
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;
|
||||
QList<DeviceEntry> m_devices;
|
||||
QList<int> m_queue; // macchine da leggere, una richiesta per volta
|
||||
bool m_stateInFlight = false;
|
||||
int m_pollInterval = 45000; // a schermata aperta
|
||||
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