ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
duty_time_sensor.h
Go to the documentation of this file.
1#pragma once
2
3#include <cinttypes>
4#include <utility>
5
9#ifdef USE_BINARY_SENSOR
11#endif
12
14
15class DutyTimeSensor final : public sensor::Sensor, public PollingComponent {
16 public:
17 void setup() override;
18 void update() override;
19 void loop() override;
20 void dump_config() override;
21
22 void start();
23 void stop();
24 bool is_running() const { return this->last_state_; }
25 void reset() { this->set_value_(0); }
26
27#ifdef USE_BINARY_SENSOR
29#endif
30 void set_lambda(std::function<bool()> &&func) { this->func_ = std::move(func); }
32 void set_restore(bool restore) { this->restore_ = restore; }
33
34 protected:
35 void set_value_(uint32_t sec);
36 void process_state_(bool state);
38
39 std::function<bool()> func_{nullptr};
42
46 bool last_state_{false};
48};
49
50} // namespace esphome::duty_time_sensor
This class simplifies creating components that periodically check a state.
Definition component.h:519
Base class for all binary_sensor-type classes.
void publish_and_save_(uint32_t sec, uint32_t ms)
void set_lambda(std::function< bool()> &&func)
void set_sensor(binary_sensor::BinarySensor *sensor)
void set_last_duty_time_sensor(sensor::Sensor *sensor)
Base-class for all sensors.
Definition sensor.h:47
float state
This member variable stores the last state that has passed through all filters.
Definition sensor.h:140
static void uint32_t