ESPHome
2026.3.0
Loading...
Searching...
No Matches
esphome
components
status
status_binary_sensor.cpp
Go to the documentation of this file.
1
#include "
status_binary_sensor.h
"
2
#include "
esphome/core/log.h
"
3
#include "
esphome/components/network/util.h
"
4
#include "
esphome/core/defines.h
"
5
6
#ifdef USE_MQTT
7
#include "
esphome/components/mqtt/mqtt_client.h
"
8
#endif
9
#ifdef USE_API
10
#include "
esphome/components/api/api_server.h
"
11
#endif
12
13
namespace
esphome::status
{
14
15
static
const
char
*
const
TAG =
"status"
;
16
17
void
StatusBinarySensor::update
() {
18
bool
status
=
network::is_connected
();
19
#ifdef USE_MQTT
20
if
(
mqtt::global_mqtt_client
!=
nullptr
) {
21
status
=
status
&&
mqtt::global_mqtt_client
->
is_connected
();
22
}
23
#endif
24
#ifdef USE_API
25
if
(
api::global_api_server
!=
nullptr
) {
26
status
=
status
&&
api::global_api_server
->
is_connected
();
27
}
28
#endif
29
30
this->
publish_state
(status);
31
}
32
void
StatusBinarySensor::setup
() { this->
publish_initial_state
(
false
); }
33
void
StatusBinarySensor::dump_config
() { LOG_BINARY_SENSOR(
""
,
"Status Binary Sensor"
,
this
); }
34
35
}
// namespace esphome::status
api_server.h
status
uint8_t status
Definition
bl0942.h:8
esphome::api::APIServer::is_connected
bool is_connected() const
Definition
api_server.h:189
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::mqtt::MQTTClientComponent::is_connected
bool is_connected()
esphome::status::StatusBinarySensor::setup
void setup() override
Definition
status_binary_sensor.cpp:32
esphome::status::StatusBinarySensor::dump_config
void dump_config() override
Definition
status_binary_sensor.cpp:33
esphome::status::StatusBinarySensor::update
void update() override
Definition
status_binary_sensor.cpp:17
util.h
defines.h
log.h
mqtt_client.h
esphome::api::global_api_server
APIServer * global_api_server
Definition
api_server.cpp:29
esphome::mqtt::global_mqtt_client
MQTTClientComponent * global_mqtt_client
esphome::network::is_connected
ESPHOME_ALWAYS_INLINE bool is_connected()
Return whether the node is connected to the network (through wifi, eth, ...)
Definition
util.h:27
esphome::status
Definition
status_binary_sensor.cpp:13
status_binary_sensor.h
Generated by
1.12.0