Things/things/DeviceRelay.cpp

35 lines
763 B
C++
Raw Normal View History

#include "DeviceRelay.h"
void DeviceRelay::setRelay(bool value) {
digitalWrite(pinRelay, value);
}
void DeviceRelay::deviceSetup() {
pinMode(pinRelay, OUTPUT);
setRelay(HIGH);
}
bool DeviceRelay::relayOnHandler(String value) {
if (value == "true") {
setRelay(HIGH);
Homie.setNodeProperty(relayNode, "on", "true");
Serial.println("relay is on");
} else if (value == "false") {
setRelay(LOW);
Homie.setNodeProperty(relayNode, "on", "false");
Serial.println("relay is off");
} else {
return false;
}
return true;
}
void DeviceRelay::deviceRegister() {
relayNode.subscribe("on", [this](String value) { return relayOnHandler(value); });
Homie.registerNode(relayNode);
}
void DeviceRelay::deviceLoop() {
return;
}