ESPHome 2026.5.1
Loading...
Searching...
No Matches
demo_datetime.h
Go to the documentation of this file.
1#pragma once
2
4
5#ifdef USE_DATETIME_DATETIME
6
9
10namespace esphome::demo {
11
13 public:
14 void setup() override {
15 this->year_ = 2038;
16 this->month_ = 01;
17 this->day_ = 19;
18 this->hour_ = 3;
19 this->minute_ = 14;
20 this->second_ = 8;
21 this->publish_state();
22 }
23
24 protected:
25 void control(const datetime::DateTimeCall &call) override {
26 this->year_ = call.get_year().value_or(this->year_);
27 this->month_ = call.get_month().value_or(this->month_);
28 this->day_ = call.get_day().value_or(this->day_);
29 this->hour_ = call.get_hour().value_or(this->hour_);
30 this->minute_ = call.get_minute().value_or(this->minute_);
31 this->second_ = call.get_second().value_or(this->second_);
32 this->publish_state();
33 }
34};
35
36} // namespace esphome::demo
37
38#endif
optional< uint16_t > get_year() const
optional< uint8_t > get_hour() const
optional< uint8_t > get_month() const
optional< uint8_t > get_minute() const
optional< uint8_t > get_day() const
optional< uint8_t > get_second() const
void control(const datetime::DateTimeCall &call) override