ESPHome 2026.5.1
Loading...
Searching...
No Matches
duty_time_sensor.h
Go to the documentation of this file.
1#pragma once
2
3#include <cinttypes>
4
9#ifdef USE_BINARY_SENSOR
11#endif
12
14
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_ = 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
50template<typename... Ts> class BaseAction : public Action<Ts...>, public Parented<DutyTimeSensor> {};
51
52template<typename... Ts> class StartAction : public BaseAction<Ts...> {
53 void play(const Ts &...x) override { this->parent_->start(); }
54};
55
56template<typename... Ts> class StopAction : public BaseAction<Ts...> {
57 void play(const Ts &...x) override { this->parent_->stop(); }
58};
59
60template<typename... Ts> class ResetAction : public BaseAction<Ts...> {
61 void play(const Ts &...x) override { this->parent_->reset(); }
62};
63
64template<typename... Ts> class RunningCondition : public Condition<Ts...>, public Parented<DutyTimeSensor> {
65 public:
66 explicit RunningCondition(DutyTimeSensor *parent, bool state) : Parented(parent), state_(state) {}
67
68 protected:
69 bool check(const Ts &...x) override { return this->parent_->is_running() == this->state_; }
70 bool state_;
71};
72
73} // namespace esphome::duty_time_sensor
virtual void stop()
Definition automation.h:554
Base class for all automation conditions.
Definition automation.h:459
Helper class to easily give an object a parent of type T.
Definition helpers.h:1861
This class simplifies creating components that periodically check a state.
Definition component.h:602
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)
RunningCondition(DutyTimeSensor *parent, bool state)
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:138
bool state
Definition fan.h:2
static void uint32_t
uint16_t x
Definition tt21100.cpp:5