ESPHome 2026.3.3
Loading...
Searching...
No Matches
util.cpp
Go to the documentation of this file.
1#include "util.h"
3#ifdef USE_NETWORK
4
5namespace esphome::network {
6
7// The order of the components is important: WiFi should come after any possible main interfaces (it may be used as
8// an AP that uses a previous interface for NAT).
9
11#ifdef USE_MODEM
12 if (modem::global_modem_component != nullptr)
13 return modem::global_modem_component->is_disabled();
14#endif
15
16#ifdef USE_WIFI
17 if (wifi::global_wifi_component != nullptr)
19#endif
20 return false;
21}
22
24#ifdef USE_ETHERNET
25 if (ethernet::global_eth_component != nullptr)
27#endif
28
29#ifdef USE_MODEM
30 if (modem::global_modem_component != nullptr)
31 return modem::global_modem_component->get_ip_addresses();
32#endif
33
34#ifdef USE_WIFI
35 if (wifi::global_wifi_component != nullptr)
37#endif
38#ifdef USE_OPENTHREAD
41#endif
42 return {};
43}
44
45const char *get_use_address() {
46 // Global component pointers are guaranteed to be set by component constructors when USE_* is defined
47#ifdef USE_ETHERNET
49#endif
50
51#ifdef USE_MODEM
52 return modem::global_modem_component->get_use_address();
53#endif
54
55#ifdef USE_WIFI
57#endif
58
59#ifdef USE_OPENTHREAD
61#endif
62
63#if !defined(USE_ETHERNET) && !defined(USE_MODEM) && !defined(USE_WIFI) && !defined(USE_OPENTHREAD)
64 // Fallback when no network component is defined (e.g., host platform)
65 return "";
66#endif
67}
68
69} // namespace esphome::network
70#endif
network::IPAddresses get_ip_addresses()
const char * get_use_address() const
EthernetComponent * global_eth_component
std::array< IPAddress, 5 > IPAddresses
Definition ip_address.h:187
const char * get_use_address()
Get the active network hostname.
Definition util.cpp:45
network::IPAddresses get_ip_addresses()
Definition util.cpp:23
bool is_disabled()
Return whether the network is disabled (only wifi for now)
Definition util.cpp:10
OpenThreadComponent * global_openthread_component
WiFiComponent * global_wifi_component