ESPHome 2026.11.0b6
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 SUB_SENSOR(last_duty_time)
17
18 public:
19 void setup() override;
20 void update() override;
21 void loop() override;
22 void dump_config() override;
23
24 void start();
25 void stop();
26 bool is_running() const { return this->last_state_; }
27 void reset() { this->set_value_(0); }
28
29#ifdef USE_BINARY_SENSOR
30 void set_sensor(binary_sensor::BinarySensor *sensor);
31#endif
32 void set_lambda(std::function<bool()> &&func) { this->func_ = std::move(func); }
33 void set_restore(bool restore) { this->restore_ = restore; }
34
35 protected:
36 void set_value_(uint32_t sec);
37 void process_state_(bool state);
39
40 std::function<bool()> func_{nullptr};
42
46 bool last_state_{false};
48};
49
50} // namespace esphome::duty_time_sensor
virtual void setup()
Where the component's initialization should happen.
Definition component.cpp:84
This class simplifies creating components that periodically check a state.
Definition component.h:532
Base class for all binary_sensor-type classes.
void publish_and_save_(uint32_t sec, uint32_t ms)
Base-class for all sensors.
Definition sensor.h:48
float state
This member variable stores the last state that has passed through all filters.
Definition sensor.h:141
static void uint32_t