ESPHome 2025.5.0
Loading...
Searching...
No Matches
sun_text_sensor.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/time.h"
5
8
9namespace esphome {
10namespace sun {
11
13 public:
14 void set_parent(Sun *parent) { parent_ = parent; }
15 void set_elevation(double elevation) { elevation_ = elevation; }
16 void set_sunrise(bool sunrise) { sunrise_ = sunrise; }
17 void set_format(const std::string &format) { format_ = format; }
18
19 void update() override {
21 if (this->sunrise_) {
22 res = this->parent_->sunrise(this->elevation_);
23 } else {
24 res = this->parent_->sunset(this->elevation_);
25 }
26 if (!res) {
27 this->publish_state("");
28 return;
29 }
30
31 this->publish_state(res->strftime(this->format_));
32 }
33
34 void dump_config() override;
35
36 protected:
37 std::string format_{};
39 double elevation_;
41};
42
43} // namespace sun
44} // namespace esphome
This class simplifies creating components that periodically check a state.
Definition component.h:301
optional< ESPTime > sunset(double elevation)
Definition sun.cpp:315
optional< ESPTime > sunrise(double elevation)
Definition sun.cpp:314
void set_format(const std::string &format)
void set_sunrise(bool sunrise)
void set_elevation(double elevation)
void publish_state(const std::string &state)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7