Skip to content

Commit 4e09d44

Browse files
committed
Improve format_measure() a little
1 parent 39c374f commit 4e09d44

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

plugwise/util.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ def escape_illegal_xml_characters(xmldata: str) -> str:
2020
return re.sub(r"&([^a-zA-Z#])", r"&\1", xmldata)
2121

2222

23-
def format_measure(measure: str, unit: str) -> float | int | bool:
23+
def format_measure(measure: str, unit: str) -> bool | float | int:
2424
"""Format measure to correct type."""
2525
# TODO: handle with appropriate care 20220405
2626
# continuously reassigning the same value with different type isn't
2727
# to typings liking
28-
result: int | float | bool = False
28+
result: bool | float | int = False
2929
try:
3030
result = int(measure)
3131
if unit == TEMP_CELSIUS:
@@ -52,10 +52,8 @@ def format_measure(measure: str, unit: str) -> float | int | bool:
5252
elif abs(float_measure) >= 100:
5353
result = int(round(float_measure))
5454
except ValueError:
55-
if measure in ["on", "true"]:
56-
result = True
57-
if measure in ["off", "false"]:
58-
result = False
55+
result = measure in ["on", "true"]
56+
5957
return result
6058

6159

0 commit comments

Comments
 (0)