ESPHome
2024.12.2
esphome
esphome
components
sun
text_sensor
sun_text_sensor.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
esphome/core/component.h
"
4
#include "
esphome/core/time.h
"
5
6
#include "
esphome/components/sun/sun.h
"
7
#include "
esphome/components/text_sensor/text_sensor.h
"
8
9
namespace
esphome
{
10
namespace
sun {
11
12
class
SunTextSensor
:
public
text_sensor::TextSensor
,
public
PollingComponent
{
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
{
20
optional<ESPTime>
res;
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_
{};
38
Sun
*
parent_
;
39
double
elevation_
;
40
bool
sunrise_
;
41
};
42
43
}
// namespace sun
44
}
// namespace esphome
esphome::sun::SunTextSensor::set_sunrise
void set_sunrise(bool sunrise)
Definition:
sun_text_sensor.h:16
time.h
esphome::sun::SunTextSensor::set_elevation
void set_elevation(double elevation)
Definition:
sun_text_sensor.h:15
sun.h
esphome::sun::SunTextSensor
Definition:
sun_text_sensor.h:12
esphome::sun::SunTextSensor::update
void update() override
Definition:
sun_text_sensor.h:19
esphome::sun::SunTextSensor::set_format
void set_format(const std::string &format)
Definition:
sun_text_sensor.h:17
esphome::PollingComponent
This class simplifies creating components that periodically check a state.
Definition:
component.h:283
esphome::text_sensor::TextSensor::publish_state
void publish_state(const std::string &state)
Definition:
text_sensor.cpp:9
esphome::sun::SunTextSensor::format_
std::string format_
Definition:
sun_text_sensor.h:37
esphome::sun::Sun::sunrise
optional< ESPTime > sunrise(double elevation)
Definition:
sun.cpp:314
esphome::sun::Sun::sunset
optional< ESPTime > sunset(double elevation)
Definition:
sun.cpp:315
esphome::text_sensor::TextSensor
Definition:
text_sensor.h:34
esphome::sun::SunTextSensor::sunrise_
bool sunrise_
Definition:
sun_text_sensor.h:40
esphome::sun::SunTextSensor::set_parent
void set_parent(Sun *parent)
Definition:
sun_text_sensor.h:14
esphome::sun::Sun
Definition:
sun.h:55
esphome::sun::SunTextSensor::parent_
Sun * parent_
Definition:
sun_text_sensor.h:38
esphome::sun::SunTextSensor::dump_config
void dump_config() override
Definition:
sun_text_sensor.cpp:9
esphome::optional
Definition:
optional.h:36
esphome
Implementation of SPI Controller mode.
Definition:
a01nyub.cpp:7
component.h
esphome::sun::SunTextSensor::elevation_
double elevation_
Definition:
sun_text_sensor.h:39
text_sensor.h
Generated by
1.8.13