rc-gateway/gateway/include/Protocol_2.h

48 lines
1.2 KiB
C++

#pragma once
#include "Protocol.h"
#include "TinyComponent.h"
class Protocol_2 : public Protocol {
public:
Protocol_2() : Protocol(2) {
}
void toJson(unsigned long value, JsonDocument& jsonDoc) override {
switch (value) {
case 637541753L:
case 771759481L: {
JsonObject motion = jsonDoc.createNestedObject("motion");
motion["kitchen"] = value == 637541753L ? "on" : "off";
break;
}
case 1879048230L:
case 1879048198L: {
JsonObject motion = jsonDoc.createNestedObject("motion");
motion["basement"] = value == 1879048230L ? "on" : "off";
break;
}
default:
StaticJsonDocument<200> jsonSensor;
if (buildSensorJson(value, jsonSensor)) {
jsonDoc.set(jsonSensor);
} else {
Protocol::toJson(value, jsonDoc);
}
break;
}
}
static char* buildId(const char* id) {
char* uId = new char[30];
sprintf(uId, "%s", id);
return uId;
}
static char* buildId(unsigned int id) {
char* uId = new char[30];
sprintf(uId, "%d", id);
return uId;
}
};