Skip to content

Commit c5d8262

Browse files
committed
Let float_measure() handle string-type
1 parent f30325a commit c5d8262

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

plugwise/util.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,13 @@ def escape_illegal_xml_characters(xmldata: str) -> str:
193193
return re.sub(r"&([^a-zA-Z#])", r"&\1", xmldata)
194194

195195

196-
def format_measure(measure: str, unit: str) -> float | int:
196+
def format_measure(measure: str, unit: str) -> float | int | str:
197197
"""Format measure to correct type."""
198-
float_measure = float(measure)
198+
try:
199+
float_measure = float(measure)
200+
except ValueError as exc:
201+
return measure # return string
202+
199203
if unit == PERCENTAGE and 0 < float_measure <= 1:
200204
return int(float_measure * 100)
201205

0 commit comments

Comments
 (0)