-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcore.h
133 lines (113 loc) · 2.68 KB
/
core.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
127
128
129
130
131
#pragma once
#include <QObject>
#include <QVariantMap>
#include <QMqttSubscription>
class QMqttClient;
class HaControl : public QObject {
public:
HaControl();
~HaControl();
static QMqttClient *mqttClient() {
return s_self->m_client;
}
// you probably want the macro
static bool registerIntegrationFactory(const QFunctionPointer factory);
private:
void doConnect();
static QList<QFunctionPointer> s_integrations;
static HaControl *s_self;
QMqttClient *m_client;
// QNetworkConfigurationManager m_networkConfigurationManager;
};
// Dave's shitty plugin system to avoid updating this file each time we add an integration
#define REGISTER_INTEGRATION(name) \
static bool dummy##name = HaControl::registerIntegrationFactory(&name);
/**
* @brief The Entity class is a base class for types (binary sensor, sensor, etc)
*/
class Entity: public QObject
{
Q_OBJECT
public:
void setId(const QString &newId);
QString id() const;
void setName(const QString &newName);
QString name() const;
void setDiscoveryConfig(const QString &key, const QVariant &value);
Entity(QObject *parent);
QString hostname() const;
QString baseTopic() const;
protected:
/**
* Called on MQTT connect, it may be called more than once
*/
virtual void init();
void sendRegistration();
void setHaType(const QString &newHaType);
QString haType() const;
void setHaConfig(const QVariantMap &newHaConfig);
private:
QString m_id;
QString m_name;
QString m_haType;
QVariantMap m_haConfig;
};
class BinarySensor : public Entity
{
Q_OBJECT
public:
BinarySensor(QObject *parent = nullptr);
void setState(bool state);
bool state() const;
protected:
void init() override;
private:
void publish();
bool m_state = false;
};
class Sensor : public Entity
{
Q_OBJECT
public:
Sensor(QObject *parent = nullptr);
void setState(const QString &state);
protected:
void init() override;
private:
QString m_state;
};
class Event : public Entity
{
Q_OBJECT
public:
Event(QObject *parent = nullptr);
void trigger();
protected:
void init() override;
};
class Button : public Entity
{
Q_OBJECT
public:
Button(QObject *parent = nullptr);
Q_SIGNALS:
void triggered();
protected:
void init() override;
private:
QScopedPointer<QMqttSubscription> m_subscription;
};
class Switch : public Entity
{
Q_OBJECT
public:
Switch(QObject *parent = nullptr);
void setState(bool state);
Q_SIGNALS:
void stateChangeRequested(bool state);
protected:
void init() override;
private:
bool m_state = false;
QScopedPointer<QMqttSubscription> m_subscription;
};