Skip to content

Commit

Permalink
Merge pull request #10 from pinpoint87/master
Browse files Browse the repository at this point in the history
Replaced .replace with regex to allow users with square-, round- and …
  • Loading branch information
LordBoos authored May 4, 2020
2 parents dd71b85 + 810fc55 commit ee481a8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion custom_components/discord_game/sensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import json
import logging
import re

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit ee481a8

Please sign in to comment.