Add has_network() to tell of there is a network

component setup
This commit is contained in:
NP v/d Spek 2023-11-20 19:22:10 +01:00
parent 208edf89dc
commit f659af0f6a
2 changed files with 19 additions and 1 deletions

View file

@ -12,6 +12,23 @@
namespace esphome {
namespace network {
bool has_network() {
#ifdef USE_ETHERNET
if (ethernet::global_eth_component != nullptr)
return true;
#endif
#ifdef USE_WIFI
if (wifi::global_wifi_component != nullptr)
return true;
#endif
#ifdef USE_HOST
return true; // Assume its connected
#endif
return false;
}
bool is_connected() {
#ifdef USE_ETHERNET
if (ethernet::global_eth_component != nullptr && ethernet::global_eth_component->is_connected())

View file

@ -5,7 +5,8 @@
namespace esphome {
namespace network {
/// Return whether has network components enabled (through wifi, eth, ...)
bool has_network();
/// Return whether the node is connected to the network (through wifi, eth, ...)
bool is_connected();
/// Return whether the network is disabled (only wifi for now)