diff --git a/esphome/components/mdns/mdns_component.cpp b/esphome/components/mdns/mdns_component.cpp index 5dfaa7fd4b..8945053b7d 100644 --- a/esphome/components/mdns/mdns_component.cpp +++ b/esphome/components/mdns/mdns_component.cpp @@ -9,7 +9,6 @@ #include // 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_STR(name) (reinterpret_cast(name)) // Helper to convert PROGMEM string to std::string for TemplatableValue // 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) @@ -24,7 +23,6 @@ static std::string mdns_str_value(PGM_P str) { #else // On non-ESP8266 platforms, use regular const char* #define MDNS_STATIC_CONST_CHAR(name, value) static constexpr const char name[] = value -#define MDNS_STR(name) (reinterpret_cast(name)) #define MDNS_STR_VALUE(name) std::string(name) #endif diff --git a/esphome/components/mdns/mdns_component.h b/esphome/components/mdns/mdns_component.h index ef366cd31a..09f6d36a80 100644 --- a/esphome/components/mdns/mdns_component.h +++ b/esphome/components/mdns/mdns_component.h @@ -12,6 +12,9 @@ namespace mdns { // Helper struct that identifies strings that may be stored in flash storage (similar to LogString) struct MDNSString; +// Macro to cast string literals to MDNSString* (works on all platforms) +#define MDNS_STR(name) (reinterpret_cast(name)) + #ifdef USE_ESP8266 #include #define MDNS_STR_ARG(s) ((PGM_P) (s))