ESPHome 2025.5.0
Loading...
Searching...
No Matches
improv_base.cpp
Go to the documentation of this file.
1#include "improv_base.h"
2
5
6namespace esphome {
7namespace 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
const std::string & get_name() const
Get the name of this Application set by pre_setup().
network::IPAddresses get_ip_addresses()
Definition util.cpp:40
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
Application App
Global storage of Application pointer - only one Application can exist.