10#include "SinricProRequest.h"
11#include "SinricProDeviceInterface.h"
14#include "SinricProNamespace.h"
15namespace 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 String sign(
const String&
message);
40 virtual String getProductType();
41 virtual void begin(SinricProInterface *eventSender);
42 bool handleRequest(SinricProRequest &
request);
45 std::vector<SinricProRequestHandler> requestHandlers;
48 SinricProInterface *eventSender;
52SinricProDevice::SinricProDevice(
const String &deviceId,
const String &productType) :
55 productType(productType) {
58SinricProDevice::~SinricProDevice() {}
60void SinricProDevice::begin(SinricProInterface* eventSender) {
61 this->eventSender = eventSender;
64String SinricProDevice::getDeviceId() {
68bool SinricProDevice::operator==(
const String &other) {
69 return other == deviceId;
72JsonDocument SinricProDevice::prepareEvent(
const char* action,
const char* cause) {
73 if (eventSender)
return eventSender->prepareEvent(deviceId, action, cause);
74 DEBUG_SINRIC(
"[SinricProDevice:prepareEvent()]: Device \"%s\" isn't configured correctly! The \'%s\' event will be ignored.\r\n", deviceId.c_str(), action);
75 return JsonDocument();
78String SinricProDevice::sign(
const String& message) {
79 if (eventSender)
return eventSender->sign(message);
83bool SinricProDevice::sendEvent(JsonDocument& event) {
84 if (!SinricPro.isConnected()) {
85 DEBUG_SINRIC(
"[SinricProDevice::sendEvent]: The event could not be sent. No connection to the SinricPro server.\r\n");
90 eventSender->sendMessage(event);
97void SinricProDevice::registerRequestHandler(
const SinricProRequestHandler &requestHandler) {
98 requestHandlers.push_back(requestHandler);
101unsigned long SinricProDevice::getTimestamp() {
102 if (eventSender)
return eventSender->getTimestamp();
106String SinricProDevice::getProductType() {
107 return String(
"sinric.device.type.")+productType;
110bool SinricProDevice::handleRequest(SinricProRequest &request) {
111 for (
auto& requestHandler : requestHandlers) {
112 if (requestHandler(request))
return true;
119using SinricProDevice = SINRICPRO_NAMESPACE::SinricProDevice;
AirQuality.
Definition AirQualitySensor.h:19
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