From b116f432fdf8a00b5cfaf06dc707c17e958f632d Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Mon, 29 Apr 2024 10:31:57 +0300 Subject: [PATCH 1/3] Remove ConstantSensor::get_value --- src/sensesp/sensors/constant_sensor.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sensesp/sensors/constant_sensor.h b/src/sensesp/sensors/constant_sensor.h index a433e7c33..c2a658a08 100644 --- a/src/sensesp/sensors/constant_sensor.h +++ b/src/sensesp/sensors/constant_sensor.h @@ -62,7 +62,6 @@ class ConstantSensor : public Sensor { } void set_value(T value) { value_ = value; } - T get_value() { return value_; } protected: virtual void get_configuration(JsonObject &doc) override { From 08c1ce3ae0f662c57c3f6a56db942eff70c88dfa Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Mon, 29 Apr 2024 10:32:35 +0300 Subject: [PATCH 2/3] Make ConstantSensor emit its value without delay to initialize the output --- src/sensesp/sensors/constant_sensor.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sensesp/sensors/constant_sensor.h b/src/sensesp/sensors/constant_sensor.h index c2a658a08..31b29fbe1 100644 --- a/src/sensesp/sensors/constant_sensor.h +++ b/src/sensesp/sensors/constant_sensor.h @@ -57,6 +57,10 @@ class ConstantSensor : public Sensor { : Sensor(config_path), value_{value}, send_interval_{send_interval} { this->load_configuration(); + // Emit the initial value once to set the output + ReactESP::app->onDelay(0, + [this]() { this->emit(value_); }); + // Then, emit the value at the specified interval ReactESP::app->onRepeat(send_interval_ * 1000, [this]() { this->emit(value_); }); } From 60b49e2ff89d408c2e0cc26fb2eabd32b7e79440 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Mon, 29 Apr 2024 10:32:52 +0300 Subject: [PATCH 3/3] Rename ConstantSensor::set_value to set for consistency --- src/sensesp/sensors/constant_sensor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sensesp/sensors/constant_sensor.h b/src/sensesp/sensors/constant_sensor.h index 31b29fbe1..6341d23f5 100644 --- a/src/sensesp/sensors/constant_sensor.h +++ b/src/sensesp/sensors/constant_sensor.h @@ -65,7 +65,7 @@ class ConstantSensor : public Sensor { [this]() { this->emit(value_); }); } - void set_value(T value) { value_ = value; } + void set(T value) { value_ = value; } protected: virtual void get_configuration(JsonObject &doc) override {