10 #include "SinricProRequest.h"
11 #include "SinricProDeviceInterface.h"
14 #include "SinricProNamespace.h"
15 namespace SINRICPRO_NAMESPACE {
27 SinricProDevice(
const String &deviceId,
const String &productType =
"");
28 bool operator==(
const String& other);
30 virtual String getDeviceId();
34 void registerRequestHandler(
const SinricProRequestHandler &requestHandler);
35 unsigned long getTimestamp();
36 virtual bool sendEvent(JsonDocument &event);
37 virtual JsonDocument prepareEvent(
const char *action,
const char *cause);
39 virtual String getProductType();
40 virtual void begin(SinricProInterface *eventSender);
41 bool handleRequest(SinricProRequest &request);
44 std::vector<SinricProRequestHandler> requestHandlers;
47 SinricProInterface *eventSender;
51 SinricProDevice::SinricProDevice(
const String &deviceId,
const String &productType) :
54 productType(productType) {
57 SinricProDevice::~SinricProDevice() {}
59 void SinricProDevice::begin(SinricProInterface* eventSender) {
60 this->eventSender = eventSender;
63 String SinricProDevice::getDeviceId() {
67 bool SinricProDevice::operator==(
const String &other) {
68 return other == deviceId;
71 JsonDocument SinricProDevice::prepareEvent(
const char* action,
const char* cause) {
72 if (eventSender)
return eventSender->prepareEvent(deviceId, action, cause);
73 DEBUG_SINRIC(
"[SinricProDevice:prepareEvent()]: Device \"%s\" isn't configured correctly! The \'%s\' event will be ignored.\r\n", deviceId.c_str(), action);
74 return JsonDocument();
78 bool SinricProDevice::sendEvent(JsonDocument& event) {
79 if (!SinricPro.isConnected()) {
80 DEBUG_SINRIC(
"[SinricProDevice::sendEvent]: The event could not be sent. No connection to the SinricPro server.\r\n");
85 eventSender->sendMessage(event);
92 void SinricProDevice::registerRequestHandler(
const SinricProRequestHandler &requestHandler) {
93 requestHandlers.push_back(requestHandler);
96 unsigned long SinricProDevice::getTimestamp() {
97 if (eventSender)
return eventSender->getTimestamp();
101 String SinricProDevice::getProductType() {
102 return String(
"sinric.device.type.")+productType;
105 bool SinricProDevice::handleRequest(SinricProRequest &request) {
106 for (
auto& requestHandler : requestHandlers) {
107 if (requestHandler(request))
return true;
114 using SinricProDevice = SINRICPRO_NAMESPACE::SinricProDevice;
The main class of this library, handling communication between SinricPro Server and your devices.
Definition: SinricPro.h:89
Base class for all device types.
Definition: SinricProDevice.h:24