Skip to content

Commit 5e817cd

Browse files
committed
Remove try-except from format_measure, exception never happens
1 parent 651688d commit 5e817cd

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

plugwise/util.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
SPECIAL_FORMAT,
2121
SPECIALS,
2222
SWITCHES,
23-
TEMP_CELSIUS,
2423
UOM,
2524
BinarySensorType,
2625
GwEntityData,
@@ -151,30 +150,25 @@ def escape_illegal_xml_characters(xmldata: str) -> str:
151150
return re.sub(r"&([^a-zA-Z#])", r"&\1", xmldata)
152151

153152

154-
def format_measure(measure: str, unit: str) -> float | int:
153+
def format_measure(measure: str, unit: str) -> float:
155154
"""Format measure to correct type."""
156-
result: float | int = 0
157-
try:
158-
result = int(measure)
159-
# Return for instance 20 (degrees) as 20.0
160-
if unit == TEMP_CELSIUS:
161-
result = float(measure)
162-
except ValueError:
163-
float_measure = float(measure)
164-
if unit == PERCENTAGE and 0 < float_measure <= 1:
165-
return int(float_measure * 100)
166-
167-
if unit == ENERGY_KILO_WATT_HOUR:
168-
float_measure = float_measure / 1000
169-
170-
if unit in SPECIAL_FORMAT:
171-
result = float(f"{round(float_measure, 3):.3f}")
172-
elif unit == ELECTRIC_POTENTIAL_VOLT:
173-
result = float(f"{round(float_measure, 1):.1f}")
174-
elif abs(float_measure) < 10:
175-
result = float(f"{round(float_measure, 2):.2f}")
176-
elif abs(float_measure) >= 10:
177-
result = float(f"{round(float_measure, 1):.1f}")
155+
result: float = 0.0
156+
157+
float_measure = float(measure)
158+
if unit == PERCENTAGE and 0 < float_measure <= 1:
159+
return int(float_measure * 100)
160+
161+
if unit == ENERGY_KILO_WATT_HOUR:
162+
float_measure = float_measure / 1000
163+
164+
if unit in SPECIAL_FORMAT:
165+
result = float(f"{round(float_measure, 3):.3f}")
166+
elif unit == ELECTRIC_POTENTIAL_VOLT:
167+
result = float(f"{round(float_measure, 1):.1f}")
168+
elif abs(float_measure) < 10:
169+
result = float(f"{round(float_measure, 2):.2f}")
170+
elif abs(float_measure) >= 10:
171+
result = float(f"{round(float_measure, 1):.1f}")
178172

179173
return result
180174

0 commit comments

Comments
 (0)