8
8
#ifndef _SINRIC_H_
9
9
#define _SINRIC_H_
10
10
11
- #include " SinricProEventSender .h"
12
- #include " SinricProDevice .h"
11
+ #include " SinricProInterface .h"
12
+ #include " SinricProDeviceInterface .h"
13
13
#include " SinricProWebsocket.h"
14
14
#include " SinricProUDP.h"
15
15
#include " SinricProSignature.h"
19
19
20
20
#include " extralib/ESPTrueRandom/ESPTrueRandom.h"
21
21
22
- class SinricProClass : public EventSender {
22
+ class SinricProClass : public SinricProInterface {
23
23
public:
24
24
void begin (String socketAuthToken, String signingKey, String serverURL = SERVER_URL);
25
25
template <typename DeviceType>
26
26
DeviceType& add (const char * deviceId, unsigned long eventWaitTime = 1000 );
27
27
28
- void add (SinricProDevice & newDevice);
29
- void add (SinricProDevice * newDevice);
28
+ void add (SinricProDeviceInterface & newDevice);
29
+ void add (SinricProDeviceInterface * newDevice);
30
30
void handle ();
31
31
void stop ();
32
32
bool isConnected ();
@@ -40,7 +40,9 @@ class SinricProClass : public EventSender {
40
40
SinricProClass* ptr;
41
41
String deviceId;
42
42
template <typename DeviceType>
43
- operator DeviceType&() { return ptr->getDeviceInstance <DeviceType>(deviceId); }
43
+ operator DeviceType&() { return as<DeviceType>(); }
44
+ template <typename DeviceType>
45
+ DeviceType& as () { return ptr->getDeviceInstance <DeviceType>(deviceId); }
44
46
};
45
47
46
48
proxy operator [](const String deviceId) { return proxy (this , deviceId); }
@@ -53,12 +55,12 @@ class SinricProClass : public EventSender {
53
55
void reconnect ();
54
56
bool checkDeviceId (String deviceId);
55
57
56
- SinricProDevice * getDevice (String deviceId);
58
+ SinricProDeviceInterface * getDevice (String deviceId);
57
59
58
60
template <typename DeviceType>
59
61
DeviceType& getDeviceInstance (String deviceId) { return (DeviceType&) *getDevice (deviceId); }
60
62
61
- std::vector<SinricProDevice *> devices;
63
+ std::vector<SinricProDeviceInterface *> devices;
62
64
String socketAuthToken;
63
65
String signingKey;
64
66
String serverURL;
@@ -70,7 +72,7 @@ class SinricProClass : public EventSender {
70
72
SinricProQueue_t sendQueue;
71
73
};
72
74
73
- SinricProDevice * SinricProClass::getDevice (String deviceId) {
75
+ SinricProDeviceInterface * SinricProClass::getDevice (String deviceId) {
74
76
for (auto & device : devices) {
75
77
if (deviceId == String (device->getDeviceId ())) return device;
76
78
}
@@ -94,14 +96,18 @@ DeviceType& SinricProClass::add(const char* deviceId, unsigned long eventWaitTim
94
96
return *newDevice;
95
97
}
96
98
97
- void SinricProClass::add (SinricProDevice* newDevice) {
99
+ __attribute__ ((deprecated(" Please use DeviceType& myDevice = SinricPro.add<DeviceType>(DeviceId);" )))
100
+ void SinricProClass::add(SinricProDeviceInterface* newDevice) {
98
101
if (!checkDeviceId (String (newDevice->getDeviceId ()))) return ;
99
102
newDevice->begin (this );
100
103
devices.push_back (newDevice);
101
104
}
102
105
103
- void SinricProClass::add (SinricProDevice& newDevice) {
104
- add (&newDevice);
106
+ __attribute__ ((deprecated(" Please use DeviceType& myDevice = SinricPro.add<DeviceType>(DeviceId);" )))
107
+ void SinricProClass::add(SinricProDeviceInterface& newDevice) {
108
+ if (!checkDeviceId (String (newDevice.getDeviceId ()))) return ;
109
+ newDevice.begin (this );
110
+ devices.push_back (&newDevice);
105
111
}
106
112
107
113
void SinricProClass::handle () {
0 commit comments