1#ifndef SENSESP_TRANSFORMS_DEBOUNCE_H_
2#define SENSESP_TRANSFORMS_DEBOUNCE_H_
34 Debounce(
int ms_min_delay = 15, String config_path =
"")
39 virtual void set(
const T& input)
override {
43 if (input != debounced_value_ || !value_received_) {
44 debounced_value_ = input;
50 event_ =
event_loop()->onDelay(ms_min_delay_, [
this, input]() {
51 this->event_ =
nullptr;
52 this->debounced_value_ = input;
55 value_received_ =
true;
61 bool value_received_ =
false;
63 reactesp::DelayEvent* event_ =
nullptr;
64 virtual bool to_json(JsonObject& doc)
override {
65 doc[
"min_delay"] = ms_min_delay_;
69 virtual bool from_json(
const JsonObject& config)
override {
70 const String expected[] = {
"min_delay"};
71 for (
auto str : expected) {
72 if (!config[str].is<JsonVariant>()) {
76 ms_min_delay_ = config[
"min_delay"];
Implements debounce code for a button or switch.
Debounce(int ms_min_delay=15, String config_path="")
virtual void set(const T &input) override
virtual bool load() override
Load and populate the object from a persistent storage.
void emit(const T &new_value)
const String ConfigSchema(const SmartSwitchController &obj)
std::shared_ptr< reactesp::EventLoop > event_loop()
Debounce< float > DebounceFloat
Debounce< bool > DebounceBool
Debounce< int > DebounceInt