ESPHome
2023.5.5
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/components/sun/sun.h
"
5
#include "
esphome/components/text_sensor/text_sensor.h
"
6
7
namespace
esphome
{
8
namespace
sun {
9
10
class
SunTextSensor
:
public
text_sensor::TextSensor
,
public
PollingComponent
{
11
public
:
12
void
set_parent
(
Sun
*parent) {
parent_
= parent; }
13
void
set_elevation
(
double
elevation) {
elevation_
= elevation; }
14
void
set_sunrise
(
bool
sunrise) {
sunrise_
= sunrise; }
15
void
set_format
(
const
std::string &format) {
format_
= format; }
16
17
void
update
()
override
{
18
optional<time::ESPTime>
res;
19
if
(this->
sunrise_
) {
20
res = this->
parent_
->
sunrise
(this->
elevation_
);
21
}
else
{
22
res = this->
parent_
->
sunset
(this->
elevation_
);
23
}
24
if
(!res) {
25
this->
publish_state
(
""
);
26
return
;
27
}
28
29
this->
publish_state
(res->strftime(this->format_));
30
}
31
32
void
dump_config
()
override
;
33
34
protected
:
35
std::string
format_
{};
36
Sun
*
parent_
;
37
double
elevation_
;
38
bool
sunrise_
;
39
};
40
41
}
// namespace sun
42
}
// namespace esphome
esphome::sun::SunTextSensor::set_sunrise
void set_sunrise(bool sunrise)
Definition:
sun_text_sensor.h:14
esphome::sun::SunTextSensor::set_elevation
void set_elevation(double elevation)
Definition:
sun_text_sensor.h:13
sun.h
esphome::sun::SunTextSensor
Definition:
sun_text_sensor.h:10
esphome::sun::SunTextSensor::update
void update() override
Definition:
sun_text_sensor.h:17
esphome::sun::SunTextSensor::set_format
void set_format(const std::string &format)
Definition:
sun_text_sensor.h:15
esphome::PollingComponent
This class simplifies creating components that periodically check a state.
Definition:
component.h:282
esphome::text_sensor::TextSensor::publish_state
void publish_state(const std::string &state)
Definition:
text_sensor.cpp:9
text_sensor.h
esphome::sun::Sun::sunset
optional< time::ESPTime > sunset(double elevation)
Definition:
sun.cpp:315
esphome::sun::SunTextSensor::format_
std::string format_
Definition:
sun_text_sensor.h:35
esphome::text_sensor::TextSensor
Definition:
text_sensor.h:31
esphome::sun::SunTextSensor::sunrise_
bool sunrise_
Definition:
sun_text_sensor.h:38
esphome::sun::SunTextSensor::set_parent
void set_parent(Sun *parent)
Definition:
sun_text_sensor.h:12
esphome::sun::Sun
Definition:
sun.h:53
esphome::sun::SunTextSensor::parent_
Sun * parent_
Definition:
sun_text_sensor.h:36
esphome::sun::SunTextSensor::dump_config
void dump_config() override
Definition:
sun_text_sensor.cpp:9
esphome::sun::Sun::sunrise
optional< time::ESPTime > sunrise(double elevation)
Definition:
sun.cpp:314
esphome::optional
Definition:
optional.h:36
esphome
Definition:
a4988.cpp:4
component.h
esphome::sun::SunTextSensor::elevation_
double elevation_
Definition:
sun_text_sensor.h:37
Generated by
1.8.13