SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
enable.h
Go to the documentation of this file.
1#ifndef SENSESP_SRC_SENSESP_TRANSFORMS_ENABLE_H_
2#define SENSESP_SRC_SENSESP_TRANSFORMS_ENABLE_H_
3
6
7namespace sensesp {
8
18template <typename T>
19class Enable : public Transform<T, T> {
20 public:
21 Enable(bool enabled = true, String config_path = "")
22 : Transform<T, T>(config_path) {
23 this->enabled_ = enabled;
24 this->load();
25 }
26 virtual void set(const T& input) override {
27 if (enabled_) {
28 this->emit(input);
29 }
30 }
31 virtual bool to_json(JsonObject& doc) override {
32 doc["enabled"] = enabled_;
33 return true;
34 }
35 virtual bool from_json(const JsonObject& config) override {
36 if (config["enabled"].is<bool>()) {
37 enabled_ = config["enabled"];
38 } else {
39 return false;
40 }
41 return true;
42 }
43
44 private:
45 bool enabled_;
46};
47
48template <typename U>
49const String ConfigSchema(const Enable<U>& obj) {
50 return R"({"type":"object","properties":{"enabled":{"type":"boolean","title":"Enable","description":"Enable or disable the transform output"}}})";
51}
52
53} // namespace sensesp
54
55#endif
On/off switch for signals: input is emitted as-is if the enable flag is set in the web UI.
Definition enable.h:19
Enable(bool enabled=true, String config_path="")
Definition enable.h:21
virtual bool from_json(const JsonObject &config) override
Definition enable.h:35
virtual bool to_json(JsonObject &doc) override
Definition enable.h:31
virtual void set(const T &input) override
Definition enable.h:26
virtual bool load() override
Load and populate the object from a persistent storage.
Definition saveable.cpp:8
The main Transform class. A transform is identified primarily by the type of value that is produces (...
Definition transform.h:53
void emit(const T &new_value)
const String ConfigSchema(const SmartSwitchController &obj)