@@ -1713,24 +1713,29 @@ text_sensor:
|
|||||||
internal: false
|
internal: false
|
||||||
disabled_by_default: false
|
disabled_by_default: false
|
||||||
lambda: |-
|
lambda: |-
|
||||||
|
return {"${name}"};
|
||||||
|
filters:
|
||||||
|
- lambda: |-
|
||||||
#ifdef NSPANEL_HA_BLUEPRINT_PREBUILT
|
#ifdef NSPANEL_HA_BLUEPRINT_PREBUILT
|
||||||
std::string suffix;
|
std::string suffix = "00ERROR"; // Default suffix in case of an error
|
||||||
uint8_t mac[6] = {0,0,0,0,0,0};
|
uint8_t mac[6] = {0,0,0,0,0,0};
|
||||||
esp_read_mac(mac, ESP_MAC_WIFI_STA);
|
if (esp_read_mac(mac, ESP_MAC_WIFI_STA) == ESP_OK) {
|
||||||
for (int i = 3; i < 6; ++i) {
|
suffix.clear(); // Clear the default error suffix
|
||||||
|
for (int i = 3; i < 6; ++i) { // Use last 3 bytes of MAC
|
||||||
char hex[3];
|
char hex[3];
|
||||||
snprintf(hex, sizeof(hex), "%02X", mac[i]);
|
snprintf(hex, sizeof(hex), "%02X", mac[i]);
|
||||||
suffix += hex;
|
suffix += hex;
|
||||||
}
|
}
|
||||||
return {"${name}" + "-" + suffix};
|
}
|
||||||
|
// Proceed with suffix (either MAC-based or default error indicator)
|
||||||
|
const std::string raw_name = (x + "-" + suffix);
|
||||||
#else
|
#else
|
||||||
return {"${name}"};
|
const std::string raw_name = x;
|
||||||
#endif
|
#endif
|
||||||
filters:
|
|
||||||
- lambda: |-
|
|
||||||
std::string result;
|
std::string result;
|
||||||
bool last_was_underscore = false;
|
bool last_was_underscore = false;
|
||||||
for (char& c : x) {
|
for (char& c : raw_name) {
|
||||||
if (isalnum(c)) {
|
if (isalnum(c)) {
|
||||||
result += tolower(c); // Add alphanumeric characters as lowercase
|
result += tolower(c); // Add alphanumeric characters as lowercase
|
||||||
last_was_underscore = false;
|
last_was_underscore = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user