ESPHome
2022.12.8
esphome
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::demo::DemoTextSensor::update
void update() override
Definition:
demo_text_sensor.h:12
esphome::PollingComponent
This class simplifies creating components that periodically check a state.
Definition:
component.h:267
esphome::text_sensor::TextSensor::publish_state
void publish_state(const std::string &state)
Definition:
text_sensor.cpp:12
text_sensor.h
esphome::text_sensor::TextSensor
Definition:
text_sensor.h:24
esphome::demo::DemoTextSensor
Definition:
demo_text_sensor.h:10
esphome
Definition:
a4988.cpp:4
component.h
val
uint32_t val
Definition:
datatypes.h:85
helpers.h
esphome::random_float
float random_float()
Return a random float between 0 and 1.
Definition:
helpers.cpp:111
Generated by
1.8.13