5namespace duty_time_sensor {
7static const char *
const TAG =
"duty_time_sensor";
9#ifdef USE_BINARY_SENSOR
31 if (this->
func_ ==
nullptr)
59 const uint32_t now =
millis();
64 const uint32_t ms = tm % 1000;
67 this->last_time_ = now - ms;
71 this->last_time_ = ms;
75 const uint32_t turn_on_ms = now - this->
edge_time_;
97 ESP_LOGCONFIG(TAG,
"Duty Time:");
99 ESP_LOGCONFIG(TAG,
" Restore: %s", ONOFF(this->
restore_));
100 LOG_SENSOR(
" ",
"Duty Time Sensor:",
this);
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
uint32_t get_object_id_hash()
virtual uint32_t get_update_interval() const
Get the update interval in ms of this sensor.
Base class for all binary_sensor-type classes.
void add_on_state_callback(std::function< void(bool)> &&callback)
Add a callback to be notified of state changes.
sensor::Sensor * last_duty_time_sensor_
void dump_config() override
std::function< bool()> func_
void publish_and_save_(uint32_t sec, uint32_t ms)
ESPPreferenceObject pref_
void process_state_(bool state)
void set_value_(uint32_t sec)
void set_sensor(binary_sensor::BinarySensor *sensor)
void publish_state(float state)
Publish a new state to the front-end.
float state
This member variable stores the last state that has passed through all filters.
Providing packet encoding functions for exchanging data with a remote host.
ESPPreferences * global_preferences
uint32_t IRAM_ATTR HOT millis()