Skip to content

Commit

Permalink
Make ConstantSensor emit its value without delay to initialize the ou…
Browse files Browse the repository at this point in the history
…tput
  • Loading branch information
mairas committed Apr 29, 2024
1 parent b116f43 commit 08c1ce3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/sensesp/sensors/constant_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class ConstantSensor : public Sensor<T> {
: Sensor<T>(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_); });
}
Expand Down

0 comments on commit 08c1ce3

Please sign in to comment.