rc-gateway/gateway/include/Protocol_1.h

30 lines
939 B
C++

#pragma once
#include "Protocol.h"
#include "RcDecoder.h"
class Protocol_1 : public Protocol {
public:
Protocol_1() : Protocol(1) {
}
void fromJson(JsonObjectConst& rcSwitch, RCSwitch& rcDevice) override {
unsigned int protocol = rcSwitch["protocol"];
rcDevice.setProtocol(protocol);
char* group = rcSwitch["group"];
int channel = rcSwitch["channel"];
rcSwitch["state"] ? rcDevice.switchOn(group, channel) : rcDevice.switchOff(group, channel);
}
void toJson(unsigned long value, JsonDocument& jsonDoc) override {
JsonObject rcSwitch = jsonDoc.createNestedObject("rcSwitch");
rcSwitch["protocol"] = protocol;
RcDecoder decoder;
decoder.decode(value);
rcSwitch["state"] = decoder.state;
rcSwitch["group"] = String(decoder.group, BIN);
rcSwitch["channel"] = decoder.device;
rcSwitch["raw_value"] = value;
}
};