ESPHome
2026.5.1
Loading...
Searching...
No Matches
esphome
components
demo
demo_binary_sensor.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
esphome/core/component.h
"
4
#include "
esphome/components/binary_sensor/binary_sensor.h
"
5
6
namespace
esphome::demo
{
7
8
class
DemoBinarySensor
:
public
binary_sensor::BinarySensor
,
public
PollingComponent
{
9
public
:
10
void
setup
()
override
{ this->
publish_initial_state
(
false
); }
11
void
update
()
override
{
12
bool
new_state =
last_state_
= !
last_state_
;
13
this->
publish_state
(new_state);
14
}
15
16
protected
:
17
bool
last_state_
=
false
;
18
};
19
20
}
// namespace esphome::demo
binary_sensor.h
esphome::PollingComponent
This class simplifies creating components that periodically check a state.
Definition
component.h:602
esphome::binary_sensor::BinarySensor
Base class for all binary_sensor-type classes.
Definition
binary_sensor.h:33
esphome::binary_sensor::BinarySensor::publish_state
void publish_state(bool new_state)
Publish a new state to the front-end.
Definition
binary_sensor.cpp:20
esphome::binary_sensor::BinarySensor::publish_initial_state
void publish_initial_state(bool new_state)
Publish the initial state, this will not make the callback manager send callbacks and is meant only f...
Definition
binary_sensor.cpp:31
esphome::demo::DemoBinarySensor
Definition
demo_binary_sensor.h:8
esphome::demo::DemoBinarySensor::last_state_
bool last_state_
Definition
demo_binary_sensor.h:17
esphome::demo::DemoBinarySensor::update
void update() override
Definition
demo_binary_sensor.h:11
esphome::demo::DemoBinarySensor::setup
void setup() override
Definition
demo_binary_sensor.h:10
component.h
esphome::demo
Definition
demo_alarm_control_panel.h:6
Generated by
1.12.0