improved available state
This commit is contained in:
parent
f3f1d06fd5
commit
df4e2a6e10
@ -161,8 +161,6 @@ void IntegrationPluginNetatmo::setupThing(ThingSetupInfo *info)
|
|||||||
|
|
||||||
// Update thing connected state based on OAuth connected state
|
// Update thing connected state based on OAuth connected state
|
||||||
connect(authentication, &OAuth2::authenticationChanged, thing, [this, thing, authentication](){
|
connect(authentication, &OAuth2::authenticationChanged, thing, [this, thing, authentication](){
|
||||||
//FIXME connected states should only change if the server is not reachable
|
|
||||||
thing->setStateValue(netatmoConnectionConnectedStateTypeId, authentication->authenticated());
|
|
||||||
thing->setStateValue(netatmoConnectionLoggedInStateTypeId, authentication->authenticated());
|
thing->setStateValue(netatmoConnectionLoggedInStateTypeId, authentication->authenticated());
|
||||||
if (authentication->authenticated()) {
|
if (authentication->authenticated()) {
|
||||||
refreshData(thing, authentication->token());
|
refreshData(thing, authentication->token());
|
||||||
@ -251,9 +249,15 @@ void IntegrationPluginNetatmo::thingRemoved(Thing *thing)
|
|||||||
outdoor->deleteLater();
|
outdoor->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myThings().isEmpty() && m_pluginTimer) {
|
if (myThings().isEmpty()) {
|
||||||
hardwareManager()->pluginTimerManager()->unregisterTimer(m_pluginTimer);
|
if (m_pluginTimer3s) {
|
||||||
m_pluginTimer = nullptr;
|
hardwareManager()->pluginTimerManager()->unregisterTimer(m_pluginTimer3s);
|
||||||
|
m_pluginTimer3s = nullptr;
|
||||||
|
}
|
||||||
|
if (m_pluginTimer10m) {
|
||||||
|
hardwareManager()->pluginTimerManager()->unregisterTimer(m_pluginTimer10m);
|
||||||
|
m_pluginTimer10m = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,9 +275,25 @@ void IntegrationPluginNetatmo::postSetupThing(Thing *thing)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_pluginTimer) {
|
if (!m_pluginTimer3s) {
|
||||||
m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(600);
|
m_pluginTimer3s = hardwareManager()->pluginTimerManager()->registerTimer(3);
|
||||||
connect(m_pluginTimer, &PluginTimer::timeout, this, &IntegrationPluginNetatmo::onPluginTimer);
|
connect(m_pluginTimer3s, &PluginTimer::timeout, this, [this] {
|
||||||
|
// Checking the connection to the Netatmo server
|
||||||
|
NetworkAccessManager *network = hardwareManager()->networkManager();
|
||||||
|
QNetworkReply *reply = network->get(QNetworkRequest(QUrl("https://api.netatmo.net")));
|
||||||
|
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||||
|
connect(reply, &QNetworkReply::finished, this, [reply, this] {
|
||||||
|
|
||||||
|
bool connected = (reply->error() != QNetworkReply::NetworkError::HostNotFoundError);
|
||||||
|
Q_FOREACH(Thing *thing, myThings().filterByThingClassId(netatmoConnectionThingClassId)) {
|
||||||
|
thing->setStateValue(netatmoConnectionConnectedStateTypeId, connected);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!m_pluginTimer10m) {
|
||||||
|
m_pluginTimer10m = hardwareManager()->pluginTimerManager()->registerTimer(600);
|
||||||
|
connect(m_pluginTimer10m, &PluginTimer::timeout, this, &IntegrationPluginNetatmo::onPluginTimer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -56,7 +56,8 @@ public:
|
|||||||
void postSetupThing(Thing *thing) override;
|
void postSetupThing(Thing *thing) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PluginTimer *m_pluginTimer = nullptr;
|
PluginTimer *m_pluginTimer3s = nullptr;
|
||||||
|
PluginTimer *m_pluginTimer10m = nullptr;
|
||||||
|
|
||||||
QHash<QString, QVariantMap> m_indoorStationInitData;
|
QHash<QString, QVariantMap> m_indoorStationInitData;
|
||||||
QHash<QString, QVariantMap> m_outdoorStationInitData;
|
QHash<QString, QVariantMap> m_outdoorStationInitData;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user