Returns a string that is safe to use as an MQTT topic and as a Home Assistant discovery node_id/object_id by
escaping every character that is not alphanumeric or an underscore. This is a reversible, collision-free encoding:
unsupported characters (including a literal hyphen) are percent-style escaped as -XX, where XX is the uppercase
hex value of each UTF-8 byte. A hyphen is used as the escape sigil rather than % because Home Assistant only
accepts [A-Za-z0-9_-] in discovery ids.
Because the encoding is injective, distinct inputs always produce distinct outputs, so entities whose names differ
only in punctuation no longer collide onto the same discovery topic.
Parameters
raw: string
The string to be cleaned
Returns string
A cleaned string containing only alphanumeric characters, underscores, and hyphens
Returns a string that is safe to use as an MQTT topic and as a Home Assistant discovery
node_id/object_idby escaping every character that is not alphanumeric or an underscore. This is a reversible, collision-free encoding: unsupported characters (including a literal hyphen) are percent-style escaped as-XX, whereXXis the uppercase hex value of each UTF-8 byte. A hyphen is used as the escape sigil rather than%because Home Assistant only accepts[A-Za-z0-9_-]in discovery ids.Because the encoding is injective, distinct inputs always produce distinct outputs, so entities whose names differ only in punctuation no longer collide onto the same discovery topic.