Filter out HTML greater/less than entities from huawei_lte sensor values (#117209)

This commit is contained in:
Ville Skyttä 2024-05-18 14:45:42 +03:00 committed by GitHub
parent 3a8bdfbfdf
commit a27cc24da2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 1 deletions

View file

@ -54,7 +54,7 @@ def format_default(value: StateType) -> tuple[StateType, str | None]:
if value is not None:
# Clean up value and infer unit, e.g. -71dBm, 15 dB
if match := re.match(
r"([>=<]*)(?P<value>.+?)\s*(?P<unit>[a-zA-Z]+)\s*$", str(value)
r"((&[gl]t;|[><])=?)?(?P<value>.+?)\s*(?P<unit>[a-zA-Z]+)\s*$", str(value)
):
try:
value = float(match.group("value"))

View file

@ -15,6 +15,8 @@ from homeassistant.const import (
("-71 dBm", (-71, SIGNAL_STRENGTH_DECIBELS_MILLIWATT)),
("15dB", (15, SIGNAL_STRENGTH_DECIBELS)),
(">=-51dBm", (-51, SIGNAL_STRENGTH_DECIBELS_MILLIWATT)),
("&lt;-20dB", (-20, SIGNAL_STRENGTH_DECIBELS)),
("&gt;=30dB", (30, SIGNAL_STRENGTH_DECIBELS)),
],
)
def test_format_default(value, expected) -> None: