mirror of
https://github.com/esphome/esphome.git
synced 2025-10-14 15:53:48 +01:00
Merge branch 'mdns_esp32_cleanup' into integration
This commit is contained in:
@@ -61,7 +61,7 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
def mdns_txt_record(key: str, value: str):
|
def mdns_txt_record(key: str, value: str):
|
||||||
return cg.StructInitializer(
|
return cg.StructInitializer(
|
||||||
MDNSTXTRecord,
|
MDNSTXTRecord,
|
||||||
("key", key),
|
("key", cg.RawExpression(f"MDNS_STR({cg.safe_exp(key)})")),
|
||||||
("value", value),
|
("value", value),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -71,8 +71,8 @@ def mdns_service(
|
|||||||
):
|
):
|
||||||
return cg.StructInitializer(
|
return cg.StructInitializer(
|
||||||
MDNSService,
|
MDNSService,
|
||||||
("service_type", service),
|
("service_type", cg.RawExpression(f"MDNS_STR({cg.safe_exp(service)})")),
|
||||||
("proto", proto),
|
("proto", cg.RawExpression(f"MDNS_STR({cg.safe_exp(proto)})")),
|
||||||
("port", port),
|
("port", port),
|
||||||
("txt_records", txt_records),
|
("txt_records", txt_records),
|
||||||
)
|
)
|
||||||
@@ -114,7 +114,7 @@ async def to_code(config):
|
|||||||
txt = [
|
txt = [
|
||||||
cg.StructInitializer(
|
cg.StructInitializer(
|
||||||
MDNSTXTRecord,
|
MDNSTXTRecord,
|
||||||
("key", txt_key),
|
("key", cg.RawExpression(f"MDNS_STR({cg.safe_exp(txt_key)})")),
|
||||||
("value", await cg.templatable(txt_value, [], cg.std_string)),
|
("value", await cg.templatable(txt_value, [], cg.std_string)),
|
||||||
)
|
)
|
||||||
for txt_key, txt_value in service[CONF_TXT].items()
|
for txt_key, txt_value in service[CONF_TXT].items()
|
||||||
|
@@ -9,7 +9,6 @@
|
|||||||
#include <pgmspace.h>
|
#include <pgmspace.h>
|
||||||
// Macro to define strings in PROGMEM on ESP8266, regular memory on other platforms
|
// Macro to define strings in PROGMEM on ESP8266, regular memory on other platforms
|
||||||
#define MDNS_STATIC_CONST_CHAR(name, value) static const char name[] PROGMEM = value
|
#define MDNS_STATIC_CONST_CHAR(name, value) static const char name[] PROGMEM = value
|
||||||
#define MDNS_STR(name) (reinterpret_cast<const MDNSString *>(name))
|
|
||||||
// Helper to convert PROGMEM string to std::string for TemplatableValue
|
// Helper to convert PROGMEM string to std::string for TemplatableValue
|
||||||
// Only define this function if we have services that will use it
|
// Only define this function if we have services that will use it
|
||||||
#if defined(USE_API) || defined(USE_PROMETHEUS) || defined(USE_WEBSERVER) || defined(USE_MDNS_EXTRA_SERVICES)
|
#if defined(USE_API) || defined(USE_PROMETHEUS) || defined(USE_WEBSERVER) || defined(USE_MDNS_EXTRA_SERVICES)
|
||||||
@@ -24,7 +23,6 @@ static std::string mdns_str_value(PGM_P str) {
|
|||||||
#else
|
#else
|
||||||
// On non-ESP8266 platforms, use regular const char*
|
// On non-ESP8266 platforms, use regular const char*
|
||||||
#define MDNS_STATIC_CONST_CHAR(name, value) static constexpr const char name[] = value
|
#define MDNS_STATIC_CONST_CHAR(name, value) static constexpr const char name[] = value
|
||||||
#define MDNS_STR(name) (reinterpret_cast<const MDNSString *>(name))
|
|
||||||
#define MDNS_STR_VALUE(name) std::string(name)
|
#define MDNS_STR_VALUE(name) std::string(name)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -12,6 +12,9 @@ namespace mdns {
|
|||||||
// Helper struct that identifies strings that may be stored in flash storage (similar to LogString)
|
// Helper struct that identifies strings that may be stored in flash storage (similar to LogString)
|
||||||
struct MDNSString;
|
struct MDNSString;
|
||||||
|
|
||||||
|
// Macro to cast string literals to MDNSString* (works on all platforms)
|
||||||
|
#define MDNS_STR(name) (reinterpret_cast<const esphome::mdns::MDNSString *>(name))
|
||||||
|
|
||||||
#ifdef USE_ESP8266
|
#ifdef USE_ESP8266
|
||||||
#include <pgmspace.h>
|
#include <pgmspace.h>
|
||||||
#define MDNS_STR_ARG(s) ((PGM_P) (s))
|
#define MDNS_STR_ARG(s) ((PGM_P) (s))
|
||||||
|
Reference in New Issue
Block a user