first working netatmo version
This commit is contained in:
parent
5f66f0cbe3
commit
4f76a64dfd
@ -143,6 +143,7 @@ void OAuth2::setAuthenticated(const bool &authenticated)
|
|||||||
if (authenticated) {
|
if (authenticated) {
|
||||||
qCDebug(dcOAuth2) << "Authenticated successfully" << m_username;
|
qCDebug(dcOAuth2) << "Authenticated successfully" << m_username;
|
||||||
} else {
|
} else {
|
||||||
|
m_timer->stop();
|
||||||
qCWarning(dcOAuth2) << "Authentication failed" << m_username;
|
qCWarning(dcOAuth2) << "Authentication failed" << m_username;
|
||||||
}
|
}
|
||||||
m_authenticated = authenticated;
|
m_authenticated = authenticated;
|
||||||
|
|||||||
@ -82,8 +82,9 @@ DeviceManager::DeviceSetupStatus DevicePluginNetatmo::setupDevice(Device *device
|
|||||||
qCDebug(dcNetatmo) << "Setup netatmo indoor base station" << device->params();
|
qCDebug(dcNetatmo) << "Setup netatmo indoor base station" << device->params();
|
||||||
NetatmoBaseStation *indoor = new NetatmoBaseStation(device->paramValue("name").toString(),
|
NetatmoBaseStation *indoor = new NetatmoBaseStation(device->paramValue("name").toString(),
|
||||||
device->paramValue("mac address").toString(),
|
device->paramValue("mac address").toString(),
|
||||||
device->paramValue("connection id").toString(), this);
|
device->paramValue("connection").toString(), this);
|
||||||
|
|
||||||
|
device->setParentId(DeviceId(indoor->connectionId()));
|
||||||
m_indoorDevices.insert(indoor, device);
|
m_indoorDevices.insert(indoor, device);
|
||||||
connect(indoor, SIGNAL(statesChanged()), this, SLOT(onIndoorStatesChanged()));
|
connect(indoor, SIGNAL(statesChanged()), this, SLOT(onIndoorStatesChanged()));
|
||||||
|
|
||||||
@ -91,9 +92,11 @@ DeviceManager::DeviceSetupStatus DevicePluginNetatmo::setupDevice(Device *device
|
|||||||
} else if (device->deviceClassId() == outdoorDeviceClassId) {
|
} else if (device->deviceClassId() == outdoorDeviceClassId) {
|
||||||
qCDebug(dcNetatmo) << "Setup netatmo outdoor module" << device->params();
|
qCDebug(dcNetatmo) << "Setup netatmo outdoor module" << device->params();
|
||||||
NetatmoOutdoorModule *outdoor = new NetatmoOutdoorModule(device->paramValue("name").toString(),
|
NetatmoOutdoorModule *outdoor = new NetatmoOutdoorModule(device->paramValue("name").toString(),
|
||||||
device->paramValue("mac address").toString(),
|
device->paramValue("mac address").toString(),
|
||||||
device->paramValue("connection id").toString(), this);
|
device->paramValue("connection").toString(),
|
||||||
|
device->paramValue("base station").toString(),this);
|
||||||
|
|
||||||
|
device->setParentId(DeviceId(outdoor->connectionId()));
|
||||||
m_outdoorDevices.insert(outdoor, device);
|
m_outdoorDevices.insert(outdoor, device);
|
||||||
connect(outdoor, SIGNAL(statesChanged()), this, SLOT(onOutdoorStatesChanged()));
|
connect(outdoor, SIGNAL(statesChanged()), this, SLOT(onOutdoorStatesChanged()));
|
||||||
|
|
||||||
@ -108,6 +111,14 @@ void DevicePluginNetatmo::deviceRemoved(Device *device)
|
|||||||
OAuth2 * authentication = m_authentications.key(device);
|
OAuth2 * authentication = m_authentications.key(device);
|
||||||
m_authentications.remove(authentication);
|
m_authentications.remove(authentication);
|
||||||
authentication->deleteLater();
|
authentication->deleteLater();
|
||||||
|
} else if (device->deviceClassId() == indoorDeviceClassId) {
|
||||||
|
NetatmoBaseStation *indoor = m_indoorDevices.key(device);
|
||||||
|
m_indoorDevices.remove(indoor);
|
||||||
|
indoor->deleteLater();
|
||||||
|
} else if (device->deviceClassId() == outdoorDeviceClassId) {
|
||||||
|
NetatmoOutdoorModule *outdoor = m_outdoorDevices.key(device);
|
||||||
|
m_outdoorDevices.remove(outdoor);
|
||||||
|
outdoor->deleteLater();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +133,7 @@ void DevicePluginNetatmo::networkManagerReplyReady(QNetworkReply *reply)
|
|||||||
// check HTTP status code
|
// check HTTP status code
|
||||||
if (status != 200) {
|
if (status != 200) {
|
||||||
qCWarning(dcNetatmo) << "Device list reply HTTP error:" << status << reply->errorString();
|
qCWarning(dcNetatmo) << "Device list reply HTTP error:" << status << reply->errorString();
|
||||||
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure);
|
device->setStateValue(availableStateTypeId, false);
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -132,7 +143,6 @@ void DevicePluginNetatmo::networkManagerReplyReady(QNetworkReply *reply)
|
|||||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
qCWarning(dcNetatmo) << "Device list reply JSON error:" << error.errorString();
|
qCWarning(dcNetatmo) << "Device list reply JSON error:" << error.errorString();
|
||||||
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure);
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -146,13 +156,11 @@ void DevicePluginNetatmo::networkManagerReplyReady(QNetworkReply *reply)
|
|||||||
|
|
||||||
void DevicePluginNetatmo::guhTimer()
|
void DevicePluginNetatmo::guhTimer()
|
||||||
{
|
{
|
||||||
foreach (Device *device, myDevices()) {
|
foreach (OAuth2 *authentication, m_authentications.keys()) {
|
||||||
if (device->deviceClassId() == connectionDeviceClassId) {
|
if (authentication->authenticated()) {
|
||||||
OAuth2 *authentication = m_authentications.key(device);
|
refreshData(m_authentications.value(authentication), authentication->token());
|
||||||
// TODO: check if authenticated
|
} else {
|
||||||
if (authentication->authenticated()) {
|
authentication->startAuthentication();
|
||||||
refreshData(device, authentication->token());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -196,7 +204,7 @@ void DevicePluginNetatmo::processRefreshData(const QVariantMap &data, const QStr
|
|||||||
ParamList params;
|
ParamList params;
|
||||||
params.append(Param("name", deviceMap.value("station_name").toString()));
|
params.append(Param("name", deviceMap.value("station_name").toString()));
|
||||||
params.append(Param("mac address", deviceMap.value("_id").toString()));
|
params.append(Param("mac address", deviceMap.value("_id").toString()));
|
||||||
params.append(Param("connection id", connectionId));
|
params.append(Param("connection", connectionId));
|
||||||
descriptor.setParams(params);
|
descriptor.setParams(params);
|
||||||
emit autoDevicesAppeared(indoorDeviceClassId, QList<DeviceDescriptor>() << descriptor);
|
emit autoDevicesAppeared(indoorDeviceClassId, QList<DeviceDescriptor>() << descriptor);
|
||||||
} else {
|
} else {
|
||||||
@ -223,7 +231,8 @@ void DevicePluginNetatmo::processRefreshData(const QVariantMap &data, const QStr
|
|||||||
ParamList params;
|
ParamList params;
|
||||||
params.append(Param("name", moduleMap.value("module_name").toString()));
|
params.append(Param("name", moduleMap.value("module_name").toString()));
|
||||||
params.append(Param("mac address", moduleMap.value("_id").toString()));
|
params.append(Param("mac address", moduleMap.value("_id").toString()));
|
||||||
params.append(Param("connection id", connectionId));
|
params.append(Param("connection", connectionId));
|
||||||
|
params.append(Param("base station", moduleMap.value("main_device").toString()));
|
||||||
descriptor.setParams(params);
|
descriptor.setParams(params);
|
||||||
emit autoDevicesAppeared(outdoorDeviceClassId, QList<DeviceDescriptor>() << descriptor);
|
emit autoDevicesAppeared(outdoorDeviceClassId, QList<DeviceDescriptor>() << descriptor);
|
||||||
} else {
|
} else {
|
||||||
@ -266,16 +275,20 @@ void DevicePluginNetatmo::onAuthenticationChanged()
|
|||||||
OAuth2 *authentication = static_cast<OAuth2 *>(sender());
|
OAuth2 *authentication = static_cast<OAuth2 *>(sender());
|
||||||
Device *device = m_authentications.value(authentication);
|
Device *device = m_authentications.value(authentication);
|
||||||
|
|
||||||
|
if (!device)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// set the available state
|
||||||
|
device->setStateValue(availableStateTypeId, authentication->authenticated());
|
||||||
|
|
||||||
// check if this is was a setup athentication
|
// check if this is was a setup athentication
|
||||||
if (m_asyncSetups.contains(device)) {
|
if (m_asyncSetups.contains(device)) {
|
||||||
m_asyncSetups.removeAll(device);
|
|
||||||
if (authentication->authenticated()) {
|
if (authentication->authenticated()) {
|
||||||
|
m_asyncSetups.removeAll(device);
|
||||||
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess);
|
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess);
|
||||||
refreshData(device, authentication->token());
|
refreshData(device, authentication->token());
|
||||||
} else {
|
} else {
|
||||||
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure);
|
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure);
|
||||||
m_authentications.remove(authentication);
|
|
||||||
authentication->deleteLater();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,7 +59,7 @@
|
|||||||
"readOnly": true
|
"readOnly": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "connection id",
|
"name": "connection",
|
||||||
"type": "QString",
|
"type": "QString",
|
||||||
"inputType": "TextLine",
|
"inputType": "TextLine",
|
||||||
"readOnly": true
|
"readOnly": true
|
||||||
@ -158,8 +158,15 @@
|
|||||||
"inputType": "TextLine",
|
"inputType": "TextLine",
|
||||||
"readOnly": true
|
"readOnly": true
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "basestation id",
|
"name": "connection",
|
||||||
|
"type": "QString",
|
||||||
|
"inputType": "TextLine",
|
||||||
|
"readOnly": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "base station",
|
||||||
"type": "QString",
|
"type": "QString",
|
||||||
"inputType": "TextLine",
|
"inputType": "TextLine",
|
||||||
"readOnly": true
|
"readOnly": true
|
||||||
|
|||||||
@ -22,11 +22,12 @@
|
|||||||
|
|
||||||
#include <QVariantMap>
|
#include <QVariantMap>
|
||||||
|
|
||||||
NetatmoOutdoorModule::NetatmoOutdoorModule(const QString &name, const QString &macAddress, const QString &connectionId, QObject *parent) :
|
NetatmoOutdoorModule::NetatmoOutdoorModule(const QString &name, const QString &macAddress, const QString &connectionId, const QString &baseStation, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_name(name),
|
m_name(name),
|
||||||
m_macAddress(macAddress),
|
m_macAddress(macAddress),
|
||||||
m_connectionId(connectionId)
|
m_connectionId(connectionId),
|
||||||
|
m_baseStation(baseStation)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,6 +46,11 @@ QString NetatmoOutdoorModule::connectionId() const
|
|||||||
return m_connectionId;
|
return m_connectionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString NetatmoOutdoorModule::baseStation() const
|
||||||
|
{
|
||||||
|
return m_baseStation;
|
||||||
|
}
|
||||||
|
|
||||||
int NetatmoOutdoorModule::lastUpdate() const
|
int NetatmoOutdoorModule::lastUpdate() const
|
||||||
{
|
{
|
||||||
return m_lastUpdate;
|
return m_lastUpdate;
|
||||||
|
|||||||
@ -27,12 +27,13 @@ class NetatmoOutdoorModule : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit NetatmoOutdoorModule(const QString &name, const QString &macAddress, const QString &connectionId, QObject *parent = 0);
|
explicit NetatmoOutdoorModule(const QString &name, const QString &macAddress, const QString &connectionId, const QString &baseStation, QObject *parent = 0);
|
||||||
|
|
||||||
// Params
|
// Params
|
||||||
QString name() const;
|
QString name() const;
|
||||||
QString macAddress() const;
|
QString macAddress() const;
|
||||||
QString connectionId() const;
|
QString connectionId() const;
|
||||||
|
QString baseStation() const;
|
||||||
|
|
||||||
// States
|
// States
|
||||||
int lastUpdate() const;
|
int lastUpdate() const;
|
||||||
@ -50,6 +51,7 @@ private:
|
|||||||
QString m_name;
|
QString m_name;
|
||||||
QString m_macAddress;
|
QString m_macAddress;
|
||||||
QString m_connectionId;
|
QString m_connectionId;
|
||||||
|
QString m_baseStation;
|
||||||
|
|
||||||
// States
|
// States
|
||||||
int m_lastUpdate;
|
int m_lastUpdate;
|
||||||
|
|||||||
Reference in New Issue
Block a user