Skip to content

Commit 9cf798a

Browse files
committed
Optimize power_data_local_format()
1 parent 860fe3a commit 9cf798a

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

plugwise/helper.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,13 @@ def power_data_local_format(
160160
attrs: dict[str, str], key_string: str, val: str
161161
) -> float | int | bool:
162162
"""Format power data."""
163-
attrs_uom = getattr(attrs, ATTR_UNIT_OF_MEASUREMENT)
164-
f_val = format_measure(val, attrs_uom)
165-
# Format only P1_MEASUREMENT POWER_WATT values, do not move to util-format_meaure function!
166-
if attrs_uom == POWER_WATT:
167-
f_val = int(round(float(val)))
163+
# Special formatting of P1_MEASUREMENT POWER_WATT values, do not move to util-format_measure() function!
164+
if (attrs_uom := getattr(attrs, ATTR_UNIT_OF_MEASUREMENT)) == POWER_WATT:
165+
return int(round(float(val)))
168166
if all(item in key_string for item in ("electricity", "cumulative")):
169-
f_val = format_measure(val, ENERGY_KILO_WATT_HOUR)
167+
return format_measure(val, ENERGY_KILO_WATT_HOUR)
170168

171-
return f_val
169+
return format_measure(val, attrs_uom)
172170

173171

174172
def power_data_energy_diff(

0 commit comments

Comments
 (0)