ESPHome  2024.4.1
improv_base.cpp
Go to the documentation of this file.
1 #include "improv_base.h"
2 
5 
6 namespace esphome {
7 namespace improv_base {
8 
10  if (this->next_url_.empty()) {
11  return "";
12  }
13  std::string copy = this->next_url_;
14  // Device name
15  std::size_t pos = this->next_url_.find("{{device_name}}");
16  if (pos != std::string::npos) {
17  const std::string &device_name = App.get_name();
18  copy.replace(pos, 15, device_name);
19  }
20 
21  // Ip address
22  pos = this->next_url_.find("{{ip_address}}");
23  if (pos != std::string::npos) {
24  for (auto &ip : network::get_ip_addresses()) {
25  if (ip.is_ip4()) {
26  std::string ipa = ip.str();
27  copy.replace(pos, 14, ipa);
28  break;
29  }
30  }
31  }
32 
33  return copy;
34 }
35 
36 } // namespace improv_base
37 } // namespace esphome
network::IPAddresses get_ip_addresses()
Definition: util.cpp:40
Application App
Global storage of Application pointer - only one Application can exist.
const std::string & get_name() const
Get the name of this Application set by pre_setup().
Definition: application.h:174
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7