mirror of
https://github.com/esphome/esphome.git
synced 2024-12-28 16:31:44 +01:00
network interface ordering, and missing implementation
This commit is contained in:
parent
490e13c86c
commit
a82e07880a
2 changed files with 26 additions and 9 deletions
|
@ -62,6 +62,7 @@ class ModemComponent : public Component {
|
|||
void enable_cmux() { this->cmux_ = true; }
|
||||
void add_init_at_command(const std::string &cmd) { this->init_at_commands_.push_back(cmd); }
|
||||
bool is_connected() { return this->component_state_ == ModemComponentState::CONNECTED; }
|
||||
bool is_disabled() { return this->component_state_ == ModemComponentState::DISABLED; }
|
||||
std::string send_at(const std::string &cmd);
|
||||
float get_signal_strength();
|
||||
bool get_imei(std::string &result);
|
||||
|
|
|
@ -16,22 +16,25 @@
|
|||
namespace esphome {
|
||||
namespace network {
|
||||
|
||||
// The order of the components is important: WiFi should come after any possible main interfaces (it may be used as
|
||||
// an AP that use a previous interface for NAT).
|
||||
|
||||
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
|
||||
|
||||
#ifdef USE_MODEM
|
||||
if (modem::global_modem_component != nullptr)
|
||||
return modem::global_modem_component->is_connected();
|
||||
#endif
|
||||
|
||||
#ifdef USE_WIFI
|
||||
if (wifi::global_wifi_component != nullptr)
|
||||
return wifi::global_wifi_component->is_connected();
|
||||
#endif
|
||||
|
||||
#ifdef USE_HOST
|
||||
return true; // Assume its connected
|
||||
#endif
|
||||
|
@ -39,6 +42,11 @@ bool is_connected() {
|
|||
}
|
||||
|
||||
bool is_disabled() {
|
||||
#ifdef USE_MODEM
|
||||
if (modem::global_modem_component != nullptr)
|
||||
return modem::global_modem_component->is_disabled();
|
||||
#endif
|
||||
|
||||
#ifdef USE_WIFI
|
||||
if (wifi::global_wifi_component != nullptr)
|
||||
return wifi::global_wifi_component->is_disabled();
|
||||
|
@ -51,6 +59,12 @@ network::IPAddresses get_ip_addresses() {
|
|||
if (ethernet::global_eth_component != nullptr)
|
||||
return ethernet::global_eth_component->get_ip_addresses();
|
||||
#endif
|
||||
|
||||
#ifdef USE_MODEM
|
||||
if (modem::global_modem_component != nullptr)
|
||||
return modem::global_modem_component->get_ip_addresses();
|
||||
#endif
|
||||
|
||||
#ifdef USE_WIFI
|
||||
if (wifi::global_wifi_component != nullptr)
|
||||
return wifi::global_wifi_component->get_ip_addresses();
|
||||
|
@ -64,14 +78,16 @@ std::string get_use_address() {
|
|||
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
|
||||
|
||||
#ifdef USE_MODEM
|
||||
if (modem::global_modem_component != nullptr)
|
||||
return modem::global_modem_component->get_use_address();
|
||||
#endif
|
||||
|
||||
#ifdef USE_WIFI
|
||||
if (wifi::global_wifi_component != nullptr)
|
||||
return wifi::global_wifi_component->get_use_address();
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue