ESPHome
2026.5.0b1
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::demo
{
8
9
class
DemoTextSensor
:
public
text_sensor::TextSensor
,
public
PollingComponent
{
10
public
:
11
void
update
()
override
{
12
float
val
=
random_float
();
13
if
(
val
< 0.33) {
14
this->
publish_state
(
"foo"
);
15
}
else
if
(val < 0.66) {
16
this->
publish_state
(
"bar"
);
17
}
else
{
18
this->
publish_state
(
"foobar"
);
19
}
20
}
21
};
22
23
}
// namespace esphome::demo
esphome::PollingComponent
This class simplifies creating components that periodically check a state.
Definition
component.h:602
esphome::demo::DemoTextSensor
Definition
demo_text_sensor.h:9
esphome::demo::DemoTextSensor::update
void update() override
Definition
demo_text_sensor.h:11
esphome::text_sensor::TextSensor
Definition
text_sensor.h:28
esphome::text_sensor::TextSensor::publish_state
void publish_state(const std::string &state)
Definition
text_sensor.cpp:21
component.h
helpers.h
val
mopeka_std_values val[3]
Definition
mopeka_std_check.h:8
esphome::demo
Definition
demo_alarm_control_panel.h:6
esphome::random_float
float random_float()
Return a random float between 0 and 1.
Definition
helpers.cpp:198
text_sensor.h
Generated by
1.12.0