-
Notifications
You must be signed in to change notification settings - Fork 0
/
homecaptapi.h
126 lines (109 loc) · 3.32 KB
/
homecaptapi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef HOMECAPTAPI_H
#define HOMECAPTAPI_H
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QAuthenticator>
#include <QString>
#include <QJsonArray>
#include <QJsonObject>
#include <QMap>
#include <QVector>
#include <QtCharts/QLineSeries>
QT_CHARTS_USE_NAMESPACE
class HomeCaptAPI : public QObject
{
Q_OBJECT
public:
typedef struct {
int id;
QString quantity;
QString unit;
} SensorType;
typedef struct {
int id;
int type;
int location;
QString owner;
QString name;
QString comment;
} Sensor;
typedef struct {
int id;
QString owner;
QString name;
} Location;
typedef struct {
int date;
float value;
} Data;
private:
bool _ready;
QString _url;
QString _user;
QString _password;
QNetworkRequest _request;
QNetworkAccessManager _manager;
QNetworkReply::NetworkError _error;
QVector<Sensor> _sensors;
QVector<Location> _locations;
QMap<int,SensorType> _sensorTypes;
QVector<Data> _data;
QList<QPointF> _dataFrom;
QJsonArray getResult(const QByteArray reply);
public:
explicit HomeCaptAPI(QObject *parent = nullptr);
Q_INVOKABLE QString host() const;
Q_INVOKABLE QString user() const;
Q_INVOKABLE bool isReady() const;
QNetworkReply::NetworkError getError() const;
Q_INVOKABLE const QVector<Location> &locations() const;
Q_INVOKABLE const QVector<Sensor> &sensors() const;
Q_INVOKABLE const QMap<int,SensorType> &sensorTypesMap() const;
Q_INVOKABLE const QVector<SensorType> sensorTypes() const;
Q_INVOKABLE bool createLocation(const QString &name);
Q_INVOKABLE bool createSensor(const QString &name, const int location, const int type, const QString &comment);
Q_INVOKABLE const QVector<Data> &data();
Q_INVOKABLE void data(QLineSeries* serie) const;
Q_INVOKABLE void preComputeDate(const int lastDays, const int nmax);
Q_INVOKABLE qint64 xmin();
Q_INVOKABLE qint64 xmax();
Q_INVOKABLE double ymin();
Q_INVOKABLE double ymax();
Q_INVOKABLE QString location(const int id);
Q_INVOKABLE QString sensor(const int id);
Q_INVOKABLE QString sensorUnit(const int id);
signals:
void errorConnect();
void errorAuth();
void errorJson(const QString);
void errorReply(const QString);
void isConnected();
void isConnectedNotSafe();
void isAuthenticated();
void hasSensorTypes();
void hasLocations();
void hasSensors();
void preLocationCreation();
void locationCreated();
void sensorCreated();
void preSensorCreation();
void hasData();
public slots:
void connect(const QString &url);
void auth(const QString &user, const QString &password);
void fetchSensorTypes();
void fetchSensors();
void fetchLocations();
void fetchData(int sensor, int from=0, int npoints=-1);
protected slots:
void replyFinishedConnect(QNetworkReply *rep);
void replyFinishedAuth(QNetworkReply *rep);
void buildSensorTypes(QNetworkReply *rep);
void buildLocations(QNetworkReply *rep);
void buildSensors(QNetworkReply *rep);
void checkLocationCreated(QNetworkReply *rep);
void checkSensorCreated(QNetworkReply *rep);
void buildData(QNetworkReply *rep);
};
#endif // HOMECAPTAPI_H