_homeassistant.py 419 B

123456789101112131415161718
  1. import re
  2. import systemctl_mqtt._utils
  3. NODE_ID_ALLOWED_CHARS = r"a-zA-Z0-9_-"
  4. def get_default_node_id() -> str:
  5. return re.sub(
  6. r"[^{}]".format(NODE_ID_ALLOWED_CHARS),
  7. "",
  8. # pylint: disable=protected-access
  9. systemctl_mqtt._utils.get_hostname(),
  10. )
  11. def validate_node_id(node_id: str) -> bool:
  12. return re.match(r"^[{}]+$".format(NODE_ID_ALLOWED_CHARS), node_id) is not None