Skip to content

Commit 8f4dd97

Browse files
committed
Implement suggestion for format_measure and adapt
1 parent 23cd423 commit 8f4dd97

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

plugwise/util.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ def escape_illegal_xml_characters(xmldata: str) -> str:
192192

193193
def format_measure(measure: str, unit: str) -> float | int:
194194
"""Format measure to correct type."""
195-
result: float | int = 0
196-
197195
float_measure = float(measure)
198196
if unit == PERCENTAGE and 0 < float_measure <= 1:
199197
return int(float_measure * 100)
@@ -202,13 +200,13 @@ def format_measure(measure: str, unit: str) -> float | int:
202200
float_measure = float_measure / 1000
203201

204202
if unit in SPECIAL_FORMAT:
205-
result = float(f"{round(float_measure, 3):.3f}")
203+
result = f"{round(float_measure, 3):.3f}"
206204
elif unit == ELECTRIC_POTENTIAL_VOLT:
207-
result = float(f"{round(float_measure, 1):.1f}")
205+
result = f"{round(float_measure, 1):.1f}"
208206
elif abs(float_measure) < 10:
209-
result = float(f"{round(float_measure, 2):.2f}")
210-
elif abs(float_measure) >= 10:
211-
result = float(f"{round(float_measure, 1):.1f}")
207+
result = f"{round(float_measure, 2):.2f}"
208+
else # abs(float_measure) >= 10
209+
result = f"{round(float_measure, 1):.1f}"
212210

213211
return result
214212

0 commit comments

Comments
 (0)