mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Allow WiFi AP to use device name (#1990)
This commit is contained in:
parent
f9797825ad
commit
be61b38a2c
2 changed files with 18 additions and 2 deletions
|
@ -164,7 +164,7 @@ void WiFiComponent::loop() {
|
|||
|
||||
WiFiComponent::WiFiComponent() { global_wifi_component = this; }
|
||||
|
||||
bool WiFiComponent::has_ap() const { return !this->ap_.get_ssid().empty(); }
|
||||
bool WiFiComponent::has_ap() const { return this->has_ap_; }
|
||||
bool WiFiComponent::has_sta() const { return !this->sta_.empty(); }
|
||||
void WiFiComponent::set_fast_connect(bool fast_connect) { this->fast_connect_ = fast_connect; }
|
||||
IPAddress WiFiComponent::get_ip_address() {
|
||||
|
@ -187,6 +187,18 @@ void WiFiComponent::setup_ap_config_() {
|
|||
if (this->ap_setup_)
|
||||
return;
|
||||
|
||||
if (this->ap_.get_ssid().empty()) {
|
||||
std::string name = App.get_name();
|
||||
if (name.length() > 32) {
|
||||
if (App.is_name_add_mac_suffix_enabled()) {
|
||||
name.erase(name.begin() + 25, name.end() - 7); // Remove characters between 25 and the mac address
|
||||
} else {
|
||||
name = name.substr(0, 32);
|
||||
}
|
||||
}
|
||||
this->ap_.set_ssid(name);
|
||||
}
|
||||
|
||||
ESP_LOGCONFIG(TAG, "Setting up AP...");
|
||||
|
||||
ESP_LOGCONFIG(TAG, " AP SSID: '%s'", this->ap_.get_ssid().c_str());
|
||||
|
@ -212,7 +224,10 @@ void WiFiComponent::setup_ap_config_() {
|
|||
float WiFiComponent::get_loop_priority() const {
|
||||
return 10.0f; // before other loop components
|
||||
}
|
||||
void WiFiComponent::set_ap(const WiFiAP &ap) { this->ap_ = ap; }
|
||||
void WiFiComponent::set_ap(const WiFiAP &ap) {
|
||||
this->ap_ = ap;
|
||||
this->has_ap_ = true;
|
||||
}
|
||||
void WiFiComponent::add_sta(const WiFiAP &ap) { this->sta_.push_back(ap); }
|
||||
void WiFiComponent::set_sta(const WiFiAP &ap) {
|
||||
this->clear_sta();
|
||||
|
|
|
@ -282,6 +282,7 @@ class WiFiComponent : public Component {
|
|||
WiFiAP selected_ap_;
|
||||
bool fast_connect_{false};
|
||||
|
||||
bool has_ap_{false};
|
||||
WiFiAP ap_;
|
||||
WiFiComponentState state_{WIFI_COMPONENT_STATE_OFF};
|
||||
uint32_t action_started_;
|
||||
|
|
Loading…
Reference in a new issue