2021-09-20 11:47:51 +02:00
|
|
|
#include "util.h"
|
|
|
|
#include "esphome/core/defines.h"
|
|
|
|
|
|
|
|
#ifdef USE_WIFI
|
|
|
|
#include "esphome/components/wifi/wifi_component.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_ETHERNET
|
|
|
|
#include "esphome/components/ethernet/ethernet_component.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace esphome {
|
|
|
|
namespace network {
|
|
|
|
|
|
|
|
bool is_connected() {
|
|
|
|
#ifdef USE_ETHERNET
|
|
|
|
if (ethernet::global_eth_component != nullptr && ethernet::global_eth_component->is_connected())
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_WIFI
|
|
|
|
if (wifi::global_wifi_component != nullptr)
|
|
|
|
return wifi::global_wifi_component->is_connected();
|
|
|
|
#endif
|
|
|
|
|
2023-05-10 11:38:18 +12:00
|
|
|
#ifdef USE_HOST
|
|
|
|
return true; // Assume its connected
|
|
|
|
#endif
|
2021-09-20 11:47:51 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-15 10:51:45 +13:00
|
|
|
bool is_disabled() {
|
|
|
|
#ifdef USE_WIFI
|
|
|
|
if (wifi::global_wifi_component != nullptr)
|
|
|
|
return wifi::global_wifi_component->is_disabled();
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-02-27 09:16:20 +01:00
|
|
|
network::IPAddresses get_ip_addresses() {
|
2021-09-20 11:47:51 +02:00
|
|
|
#ifdef USE_ETHERNET
|
|
|
|
if (ethernet::global_eth_component != nullptr)
|
2024-02-27 09:16:20 +01:00
|
|
|
return ethernet::global_eth_component->get_ip_addresses();
|
2021-09-20 11:47:51 +02:00
|
|
|
#endif
|
|
|
|
#ifdef USE_WIFI
|
|
|
|
if (wifi::global_wifi_component != nullptr)
|
2024-02-27 09:16:20 +01:00
|
|
|
return wifi::global_wifi_component->get_ip_addresses();
|
2021-09-20 11:47:51 +02:00
|
|
|
#endif
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string get_use_address() {
|
|
|
|
#ifdef USE_ETHERNET
|
|
|
|
if (ethernet::global_eth_component != nullptr)
|
|
|
|
return ethernet::global_eth_component->get_use_address();
|
|
|
|
#endif
|
|
|
|
#ifdef USE_WIFI
|
|
|
|
if (wifi::global_wifi_component != nullptr)
|
|
|
|
return wifi::global_wifi_component->get_use_address();
|
|
|
|
#endif
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace network
|
|
|
|
} // namespace esphome
|