ESPHome
2025.5.0
Loading...
Searching...
No Matches
esphome
components
demo
demo_text_sensor.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
esphome/core/component.h
"
4
#include "
esphome/core/helpers.h
"
5
#include "
esphome/components/text_sensor/text_sensor.h
"
6
7
namespace
esphome
{
8
namespace
demo {
9
10
class
DemoTextSensor
:
public
text_sensor::TextSensor
,
public
PollingComponent
{
11
public
:
12
void
update
()
override
{
13
float
val
=
random_float
();
14
if
(
val
< 0.33) {
15
this->
publish_state
(
"foo"
);
16
}
else
if
(val < 0.66) {
17
this->
publish_state
(
"bar"
);
18
}
else
{
19
this->
publish_state
(
"foobar"
);
20
}
21
}
22
};
23
24
}
// namespace demo
25
}
// namespace esphome
esphome::PollingComponent
This class simplifies creating components that periodically check a state.
Definition
component.h:301
esphome::demo::DemoTextSensor
Definition
demo_text_sensor.h:10
esphome::demo::DemoTextSensor::update
void update() override
Definition
demo_text_sensor.h:12
esphome::text_sensor::TextSensor
Definition
text_sensor.h:34
esphome::text_sensor::TextSensor::publish_state
void publish_state(const std::string &state)
Definition
text_sensor.cpp:9
component.h
helpers.h
val
mopeka_std_values val[4]
Definition
mopeka_std_check.h:8
esphome
Providing packet encoding functions for exchanging data with a remote host.
Definition
a01nyub.cpp:7
esphome::random_float
float random_float()
Return a random float between 0 and 1.
Definition
helpers.cpp:218
text_sensor.h
Generated by
1.12.0