Controllo ogni mezz'ora, solo a schermata aperta, senza servizi
- intervallo di lettura da 45 secondi a 30 minuti; parte solo con la schermata attiva e si ferma quando esce: nessun processo che resta vivo - il tempo rimanente a schermo continua a scendere: si sottrae il tempo passato dall'ultima lettura (stima locale, zero chiamate di rete), con 6 prove nuove - backoff a un'ora se LG segnala troppe richieste - post e descrizione allineati: versioni 0.3.0, impronte nuove, comportamento dichiarato (avviso di fine lavaggio fino a mezz'ora dopo)
This commit is contained in:
1 parent
2886195e3b
commit
feee03756b
9 files changed
+104
-30
No files matched your search
+2
-2
@@ -21,7 +21,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
||||
|
||||
app->setOrganizationName(QStringLiteral("harbour"));
|
||||
app->setApplicationName(QStringLiteral("thinq"));
|
||||
app->setApplicationVersion(QStringLiteral("0.2.5"));
|
||||
app->setApplicationVersion(QStringLiteral("0.3.0"));
|
||||
|
||||
Settings settings;
|
||||
ThinQClient api(&settings);
|
||||
@@ -34,7 +34,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
||||
QQuickView *view = SailfishApp::createView();
|
||||
|
||||
// Prima riga del log: dice se il device sta girando la build nuova o una stale.
|
||||
qDebug() << "harbour-thinq v0.2.5 build" << __DATE__ << __TIME__;
|
||||
qDebug() << "harbour-thinq v0.3.0 build" << __DATE__ << __TIME__;
|
||||
|
||||
view->rootContext()->setContextProperty(QStringLiteral("appSettings"), &settings);
|
||||
view->rootContext()->setContextProperty(QStringLiteral("api"), &api);
|
||||
|
||||
+32
-6
@@ -16,8 +16,14 @@
|
||||
namespace {
|
||||
|
||||
const int kRequestTimeoutMs = 20000;
|
||||
const int kPollFastMs = 45000; // mentre la schermata e' aperta
|
||||
const int kPollSlowMs = 300000; // dopo un rifiuto per troppe richieste
|
||||
// Un controllo ogni mezz'ora, e solo mentre la schermata e' aperta: nessun
|
||||
// servizio in background, nessun processo che resta vivo. Le macchine cambiando
|
||||
// stato lentamente (un lavaggio dura ore), quindi il dato invecchia poco.
|
||||
const int kPollMs = 1800000;
|
||||
const int kPollBackoffMs = 3600000; // dopo un rifiuto per troppe richieste
|
||||
// Il numero a schermo invece scende ogni minuto: si sottrae il tempo passato
|
||||
// dall'ultima lettura, senza chiamare LG.
|
||||
const int kTickMs = 60000;
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -30,6 +36,15 @@ ThinQClient::ThinQClient(Settings *settings, QObject *parent)
|
||||
// (pumpQueue), cosi' l'app non bombarda il cloud LG.
|
||||
connect(&m_pollTimer, &QTimer::timeout, this, [this]() { refresh(); });
|
||||
|
||||
// Solo presentazione: ricalcola i minuti rimanenti dal tempo trascorso e
|
||||
// avvisa il QML, senza toccare la rete. Gira solo mentre si sta leggendo
|
||||
// (cioe' a schermata aperta).
|
||||
m_tickTimer.setInterval(kTickMs);
|
||||
connect(&m_tickTimer, &QTimer::timeout, this, [this]() {
|
||||
if (m_pollTimer.isActive())
|
||||
emit devicesChanged();
|
||||
});
|
||||
|
||||
connect(m_settings, &Settings::tokenChanged, this, [this]() {
|
||||
m_devices.clear();
|
||||
m_queue.clear();
|
||||
@@ -55,6 +70,13 @@ QVariantList ThinQClient::devices() const
|
||||
const DeviceEntry &e = m_devices.at(i);
|
||||
const QString total = ThinQJson::durationText(e.state.totalMinutes);
|
||||
|
||||
// Minuti passati dall'ultima lettura vera: il conto alla rovescia scende
|
||||
// anche se la prossima chiamata a LG e' fra mezz'ora.
|
||||
int elapsed = 0;
|
||||
if (e.fetchedAt.isValid())
|
||||
elapsed = int(e.fetchedAt.secsTo(QDateTime::currentDateTime()) / 60);
|
||||
const int remain = ThinQJson::remainingAfter(e.state.remainMinutes, elapsed);
|
||||
|
||||
QVariantMap item;
|
||||
item.insert(QStringLiteral("id"), e.id);
|
||||
item.insert(QStringLiteral("label"), e.label.isEmpty()
|
||||
@@ -67,7 +89,7 @@ QVariantList ThinQClient::devices() const
|
||||
? ThinQJson::phaseLabel(e.state)
|
||||
: QCoreApplication::translate("ThinQ", "No data"));
|
||||
item.insert(QStringLiteral("level"), ThinQJson::statusLevel(e.state));
|
||||
item.insert(QStringLiteral("remain"), ThinQJson::durationText(e.state.remainMinutes));
|
||||
item.insert(QStringLiteral("remain"), ThinQJson::durationText(remain));
|
||||
item.insert(QStringLiteral("totalLine"), total.isEmpty() ? QString()
|
||||
: QCoreApplication::translate("ThinQ", "of %1").arg(total));
|
||||
item.insert(QStringLiteral("cycle"), e.state.cycleCount);
|
||||
@@ -166,11 +188,14 @@ void ThinQClient::startPolling()
|
||||
m_pollTimer.start(m_pollInterval);
|
||||
emit pollingChanged();
|
||||
}
|
||||
if (!m_tickTimer.isActive())
|
||||
m_tickTimer.start();
|
||||
}
|
||||
|
||||
void ThinQClient::stopPolling()
|
||||
{
|
||||
m_pollTimer.stop();
|
||||
m_tickTimer.stop();
|
||||
emit pollingChanged();
|
||||
}
|
||||
|
||||
@@ -440,9 +465,10 @@ void ThinQClient::applyState(int deviceIndex, bool hadState, int previousLevel,
|
||||
entry.stale = false;
|
||||
entry.updated = QCoreApplication::translate("ThinQ", "Updated at %1").arg(
|
||||
QLocale().toString(QTime::currentTime(), QLocale::ShortFormat));
|
||||
entry.fetchedAt = QDateTime::currentDateTime();
|
||||
|
||||
if (m_pollInterval != kPollFastMs)
|
||||
m_pollInterval = kPollFastMs;
|
||||
if (m_pollInterval != kPollMs)
|
||||
m_pollInterval = kPollMs;
|
||||
|
||||
emit devicesChanged();
|
||||
emit stateChanged();
|
||||
@@ -518,7 +544,7 @@ void ThinQClient::handleFailure(int httpStatus, const QByteArray &body,
|
||||
|| code == QLatin1String("1302") || httpStatus == 401) {
|
||||
setNotice(QCoreApplication::translate("ThinQ", "The access token is no longer valid: enter a new one in Settings"), true);
|
||||
} else if (code == QLatin1String("1306")) {
|
||||
m_pollInterval = kPollSlowMs;
|
||||
m_pollInterval = kPollBackoffMs;
|
||||
setNotice(QCoreApplication::translate("ThinQ", "Too many requests to LG: slowing down"), true);
|
||||
} else if (code == QLatin1String("1222") || code == QLatin1String("1223")) {
|
||||
setNotice(QCoreApplication::translate("ThinQ", "The washing machine is not connected (switched off or offline)"), true);
|
||||
|
||||
+6
-1
@@ -1,6 +1,7 @@
|
||||
#ifndef THINQCLIENT_H
|
||||
#define THINQCLIENT_H
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QList>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QObject>
|
||||
@@ -87,6 +88,9 @@ private:
|
||||
bool offline = false;
|
||||
bool stale = false;
|
||||
QString updated;
|
||||
// Quando lo stato e' stato letto davvero: serve a far scendere il tempo
|
||||
// rimanente a schermo fra un controllo e l'altro.
|
||||
QDateTime fetchedAt;
|
||||
};
|
||||
|
||||
void prepare(QNetworkRequest &request, bool command) const;
|
||||
@@ -105,10 +109,11 @@ private:
|
||||
Settings *m_settings;
|
||||
QNetworkAccessManager m_nam;
|
||||
QTimer m_pollTimer;
|
||||
QTimer m_tickTimer; // conto alla rovescia a schermo, senza rete
|
||||
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_pollInterval = 1800000; // mezz'ora, e solo a schermata aperta
|
||||
int m_delayHours = 4;
|
||||
bool m_busy = false;
|
||||
QString m_notice;
|
||||
|
||||
@@ -201,4 +201,13 @@ QString durationText(int minutes)
|
||||
return parts.join(QLatin1Char(' '));
|
||||
}
|
||||
|
||||
int remainingAfter(int remainMinutes, int elapsedMinutes)
|
||||
{
|
||||
if (remainMinutes <= 0)
|
||||
return remainMinutes;
|
||||
if (elapsedMinutes <= 0)
|
||||
return remainMinutes;
|
||||
return qMax(0, remainMinutes - elapsedMinutes);
|
||||
}
|
||||
|
||||
} // namespace ThinQJson
|
||||
@@ -51,6 +51,12 @@ QString delayPayload(int hours); // timer.relativeHourToS
|
||||
// Durate in testo leggibile ("1 h 54 min"), vuoto se zero.
|
||||
QString durationText(int minutes);
|
||||
|
||||
// Minuti rimanenti stimati SENZA rete: si sottrae il tempo passato dall'ultima
|
||||
// lettura. Serve perche' il controllo vero avviene di rado (una volta ogni
|
||||
// mezz'ora), ma il numero a schermo deve scendere lo stesso. Un rimanente
|
||||
// sconosciuto (negativo) resta negativo: non si inventa un numero.
|
||||
int remainingAfter(int remainMinutes, int elapsedMinutes);
|
||||
|
||||
} // namespace ThinQJson
|
||||
|
||||
#endif // THINQJSON_H
|
||||
Reference in new issue
Block a user