#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); const 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; } static char* buildId(const char* group, const unsigned char channel) { char* uId = new char[30]; sprintf(uId, "%s_%d", group, channel); return uId; } };