esphome/esphome/dashboard/util/text.py
J. Nick Koston 3644853d38
dashboard: fix subprocesses blocking the event loop (#5772)
* dashboard: fix subprocesses blocking the event loop

- break apart the util module
- adds a new util to run subprocesses with asyncio

* take a list
2023-11-15 19:07:51 -05:00

26 lines
534 B
Python

from __future__ import annotations
import unicodedata
from esphome.const import ALLOWED_NAME_CHARS
def strip_accents(value):
return "".join(
c
for c in unicodedata.normalize("NFD", str(value))
if unicodedata.category(c) != "Mn"
)
def friendly_name_slugify(value):
value = (
strip_accents(value)
.lower()
.replace(" ", "-")
.replace("_", "-")
.replace("--", "-")
.strip("-")
)
return "".join(c for c in value if c in ALLOWED_NAME_CHARS)