mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 23:21:54 +00:00 
			
		
		
		
	[improv] Put next_url behind defines to save flash (#11420)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
		| @@ -112,7 +112,7 @@ async def to_code(config): | |||||||
|  |  | ||||||
|     cg.add_define("USE_IMPROV") |     cg.add_define("USE_IMPROV") | ||||||
|  |  | ||||||
|     await improv_base.setup_improv_core(var, config) |     await improv_base.setup_improv_core(var, config, "esp32_improv") | ||||||
|  |  | ||||||
|     cg.add(var.set_identify_duration(config[CONF_IDENTIFY_DURATION])) |     cg.add(var.set_identify_duration(config[CONF_IDENTIFY_DURATION])) | ||||||
|     cg.add(var.set_authorized_duration(config[CONF_AUTHORIZED_DURATION])) |     cg.add(var.set_authorized_duration(config[CONF_AUTHORIZED_DURATION])) | ||||||
|   | |||||||
| @@ -389,11 +389,13 @@ void ESP32ImprovComponent::check_wifi_connection_() { | |||||||
|     std::string url_strings[3]; |     std::string url_strings[3]; | ||||||
|     size_t url_count = 0; |     size_t url_count = 0; | ||||||
|  |  | ||||||
|  | #ifdef USE_ESP32_IMPROV_NEXT_URL | ||||||
|     // Add next_url if configured (should be first per Improv BLE spec) |     // Add next_url if configured (should be first per Improv BLE spec) | ||||||
|     std::string next_url = this->get_formatted_next_url_(); |     std::string next_url = this->get_formatted_next_url_(); | ||||||
|     if (!next_url.empty()) { |     if (!next_url.empty()) { | ||||||
|       url_strings[url_count++] = std::move(next_url); |       url_strings[url_count++] = std::move(next_url); | ||||||
|     } |     } | ||||||
|  | #endif | ||||||
|  |  | ||||||
|     // Add default URLs for backward compatibility |     // Add default URLs for backward compatibility | ||||||
|     url_strings[url_count++] = ESPHOME_MY_LINK; |     url_strings[url_count++] = ESPHOME_MY_LINK; | ||||||
|   | |||||||
| @@ -3,6 +3,8 @@ import re | |||||||
| import esphome.codegen as cg | import esphome.codegen as cg | ||||||
| import esphome.config_validation as cv | import esphome.config_validation as cv | ||||||
| from esphome.const import __version__ | from esphome.const import __version__ | ||||||
|  | from esphome.cpp_generator import MockObj | ||||||
|  | from esphome.types import ConfigType | ||||||
|  |  | ||||||
| CODEOWNERS = ["@esphome/core"] | CODEOWNERS = ["@esphome/core"] | ||||||
|  |  | ||||||
| @@ -35,7 +37,9 @@ def _process_next_url(url: str): | |||||||
|     return url |     return url | ||||||
|  |  | ||||||
|  |  | ||||||
| async def setup_improv_core(var, config): | async def setup_improv_core(var: MockObj, config: ConfigType, component: str): | ||||||
|     if CONF_NEXT_URL in config: |     if next_url := config.get(CONF_NEXT_URL): | ||||||
|         cg.add(var.set_next_url(_process_next_url(config[CONF_NEXT_URL]))) |         cg.add(var.set_next_url(_process_next_url(next_url))) | ||||||
|  |         cg.add_define(f"USE_{component.upper()}_NEXT_URL") | ||||||
|  |  | ||||||
|     cg.add_library("improv/Improv", "1.2.4") |     cg.add_library("improv/Improv", "1.2.4") | ||||||
|   | |||||||
| @@ -2,10 +2,12 @@ | |||||||
|  |  | ||||||
| #include "esphome/components/network/util.h" | #include "esphome/components/network/util.h" | ||||||
| #include "esphome/core/application.h" | #include "esphome/core/application.h" | ||||||
|  | #include "esphome/core/defines.h" | ||||||
|  |  | ||||||
| namespace esphome { | namespace esphome { | ||||||
| namespace improv_base { | namespace improv_base { | ||||||
|  |  | ||||||
|  | #if defined(USE_ESP32_IMPROV_NEXT_URL) || defined(USE_IMPROV_SERIAL_NEXT_URL) | ||||||
| static constexpr const char DEVICE_NAME_PLACEHOLDER[] = "{{device_name}}"; | static constexpr const char DEVICE_NAME_PLACEHOLDER[] = "{{device_name}}"; | ||||||
| static constexpr size_t DEVICE_NAME_PLACEHOLDER_LEN = sizeof(DEVICE_NAME_PLACEHOLDER) - 1; | static constexpr size_t DEVICE_NAME_PLACEHOLDER_LEN = sizeof(DEVICE_NAME_PLACEHOLDER) - 1; | ||||||
| static constexpr const char IP_ADDRESS_PLACEHOLDER[] = "{{ip_address}}"; | static constexpr const char IP_ADDRESS_PLACEHOLDER[] = "{{ip_address}}"; | ||||||
| @@ -43,6 +45,7 @@ std::string ImprovBase::get_formatted_next_url_() { | |||||||
|  |  | ||||||
|   return formatted_url; |   return formatted_url; | ||||||
| } | } | ||||||
|  | #endif | ||||||
|  |  | ||||||
| }  // namespace improv_base | }  // namespace improv_base | ||||||
| }  // namespace esphome | }  // namespace esphome | ||||||
|   | |||||||
| @@ -1,17 +1,22 @@ | |||||||
| #pragma once | #pragma once | ||||||
|  |  | ||||||
| #include <string> | #include <string> | ||||||
|  | #include "esphome/core/defines.h" | ||||||
|  |  | ||||||
| namespace esphome { | namespace esphome { | ||||||
| namespace improv_base { | namespace improv_base { | ||||||
|  |  | ||||||
| class ImprovBase { | class ImprovBase { | ||||||
|  public: |  public: | ||||||
|  | #if defined(USE_ESP32_IMPROV_NEXT_URL) || defined(USE_IMPROV_SERIAL_NEXT_URL) | ||||||
|   void set_next_url(const std::string &next_url) { this->next_url_ = next_url; } |   void set_next_url(const std::string &next_url) { this->next_url_ = next_url; } | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  protected: |  protected: | ||||||
|  | #if defined(USE_ESP32_IMPROV_NEXT_URL) || defined(USE_IMPROV_SERIAL_NEXT_URL) | ||||||
|   std::string get_formatted_next_url_(); |   std::string get_formatted_next_url_(); | ||||||
|   std::string next_url_; |   std::string next_url_; | ||||||
|  | #endif | ||||||
| }; | }; | ||||||
|  |  | ||||||
| }  // namespace improv_base | }  // namespace improv_base | ||||||
|   | |||||||
| @@ -43,4 +43,4 @@ FINAL_VALIDATE_SCHEMA = validate_logger | |||||||
| async def to_code(config): | async def to_code(config): | ||||||
|     var = cg.new_Pvariable(config[CONF_ID]) |     var = cg.new_Pvariable(config[CONF_ID]) | ||||||
|     await cg.register_component(var, config) |     await cg.register_component(var, config) | ||||||
|     await improv_base.setup_improv_core(var, config) |     await improv_base.setup_improv_core(var, config, "improv_serial") | ||||||
|   | |||||||
| @@ -146,9 +146,11 @@ void ImprovSerialComponent::loop() { | |||||||
|  |  | ||||||
| std::vector<uint8_t> ImprovSerialComponent::build_rpc_settings_response_(improv::Command command) { | std::vector<uint8_t> ImprovSerialComponent::build_rpc_settings_response_(improv::Command command) { | ||||||
|   std::vector<std::string> urls; |   std::vector<std::string> urls; | ||||||
|  | #ifdef USE_IMPROV_SERIAL_NEXT_URL | ||||||
|   if (!this->next_url_.empty()) { |   if (!this->next_url_.empty()) { | ||||||
|     urls.push_back(this->get_formatted_next_url_()); |     urls.push_back(this->get_formatted_next_url_()); | ||||||
|   } |   } | ||||||
|  | #endif | ||||||
| #ifdef USE_WEBSERVER | #ifdef USE_WEBSERVER | ||||||
|   for (auto &ip : wifi::global_wifi_component->wifi_sta_ip_addresses()) { |   for (auto &ip : wifi::global_wifi_component->wifi_sta_ip_addresses()) { | ||||||
|     if (ip.is_ip4()) { |     if (ip.is_ip4()) { | ||||||
|   | |||||||
| @@ -44,6 +44,7 @@ | |||||||
| #define USE_GRAPHICAL_DISPLAY_MENU | #define USE_GRAPHICAL_DISPLAY_MENU | ||||||
| #define USE_HOMEASSISTANT_TIME | #define USE_HOMEASSISTANT_TIME | ||||||
| #define USE_HTTP_REQUEST_OTA_WATCHDOG_TIMEOUT 8000  // NOLINT | #define USE_HTTP_REQUEST_OTA_WATCHDOG_TIMEOUT 8000  // NOLINT | ||||||
|  | #define USE_IMPROV_SERIAL_NEXT_URL | ||||||
| #define USE_JSON | #define USE_JSON | ||||||
| #define USE_LIGHT | #define USE_LIGHT | ||||||
| #define USE_LOCK | #define USE_LOCK | ||||||
| @@ -186,6 +187,7 @@ | |||||||
| #define USE_ESP32_CAMERA_JPEG_ENCODER | #define USE_ESP32_CAMERA_JPEG_ENCODER | ||||||
| #define USE_I2C | #define USE_I2C | ||||||
| #define USE_IMPROV | #define USE_IMPROV | ||||||
|  | #define USE_ESP32_IMPROV_NEXT_URL | ||||||
| #define USE_MICROPHONE | #define USE_MICROPHONE | ||||||
| #define USE_PSRAM | #define USE_PSRAM | ||||||
| #define USE_SOCKET_IMPL_BSD_SOCKETS | #define USE_SOCKET_IMPL_BSD_SOCKETS | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user