ESPHome  2024.10.2
status_binary_sensor.cpp
Go to the documentation of this file.
1 #include "status_binary_sensor.h"
2 #include "esphome/core/log.h"
4 #include "esphome/core/defines.h"
5 
6 #ifdef USE_MQTT
8 #endif
9 #ifdef USE_API
11 #endif
12 
13 namespace esphome {
14 namespace status {
15 
16 static const char *const TAG = "status";
17 
20 #ifdef USE_MQTT
21  if (mqtt::global_mqtt_client != nullptr) {
22  status = status && mqtt::global_mqtt_client->is_connected();
23  }
24 #endif
25 #ifdef USE_API
26  if (api::global_api_server != nullptr) {
27  status = status && api::global_api_server->is_connected();
28  }
29 #endif
30 
31  this->publish_state(status);
32 }
34 void StatusBinarySensor::dump_config() { LOG_BINARY_SENSOR("", "Status Binary Sensor", this); }
35 
36 } // namespace status
37 } // namespace esphome
void publish_initial_state(bool state)
Publish the initial state, this will not make the callback manager send callbacks and is meant only f...
bool is_connected() const
Definition: api_server.cpp:388
bool is_connected()
Return whether the node is connected to the network (through wifi, eth, ...)
Definition: util.cpp:15
MQTTClientComponent * global_mqtt_client
void publish_state(bool state)
Publish a new state to the front-end.
uint8_t status
Definition: bl0942.h:74
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
APIServer * global_api_server
Definition: api_server.cpp:347