From 810fc554de54aa13a341750df22d28164a7bbfd8 Mon Sep 17 00:00:00 2001 From: pinpoint87 Date: Mon, 4 May 2020 13:34:11 +0200 Subject: [PATCH] Replaced .replace with regex to allow users with square-, round- and curly- brackets in their names to become visible/ available to HomeAssistant --- custom_components/discord_game/sensor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/custom_components/discord_game/sensor.py b/custom_components/discord_game/sensor.py index 2ce3a9e..bc5d328 100644 --- a/custom_components/discord_game/sensor.py +++ b/custom_components/discord_game/sensor.py @@ -1,6 +1,7 @@ import asyncio import json import logging +import re import homeassistant.helpers.config_validation as cv import voluptuous as vol @@ -219,7 +220,9 @@ def state(self) -> str: @property def entity_id(self): """Return the entity ID.""" - return ENTITY_ID_FORMAT.format(self._member.replace("#", "_").replace(" ", "_").replace(".", "_")).lower() + # 1st Regex; keep a-z0-9 [](){} characters, replace with "_" + # 2nd Regex; keep only a-z0-9_ characters, replace with "" + return ENTITY_ID_FORMAT.format(re.sub('[^a-z0-9_]', '', re.sub('[^a-z0-9 \[\]\(\)\{\}]', '_', self._member.lower()))) @property def name(self):