Skip to content

Commit

Permalink
add special rule for "+" and "-"
Browse files Browse the repository at this point in the history
  • Loading branch information
shadow578 authored May 24, 2024
1 parent 1acbaab commit 5ea0d39
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions custom_components/xmltv_epg/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ def normalize_for_entity_id(s: str) -> str:
# lower case
s = s.lower()

# replace umlauts and ß with their base character (ä -> a, ß -> ss)
umlauts = {
# special replacement rules
replacements = {
# replace umlauts with their respective digraphs
"ä": "ae",
"ö": "oe",
"ü": "ue",
"ß": "ss",
# '+' is replaced with ' plus '.
"+": " plus ",
}
for umlaut, replacement in umlauts.items():
for umlaut, replacement in replacements.items():
s = s.replace(umlaut, replacement)

# replace "delimiting characters" and spaces with underscores
Expand Down
4 changes: 4 additions & 0 deletions test/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ def test_normalize_for_entity_id():
normalize_for_entity_id(" Leading and Trailing Spaces ")
== "leading_and_trailing_spaces"
)

# test special replacement rules
# required because both "Sport1" and "Sport1+" are channels that exists in the wild...
assert normalize_for_entity_id("A+B-C") == "a_plus_b_c"

0 comments on commit 5ea0d39

Please sign in to comment.