Skip to content

Commit b586e08

Browse files
committed
Improve further
1 parent 787eae9 commit b586e08

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

plugwise/util.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
ELECTRIC_POTENTIAL_VOLT,
1414
ENERGY_KILO_WATT_HOUR,
1515
HW_MODELS,
16-
LOGGER,
1716
OBSOLETE_MEASUREMENTS,
1817
PERCENTAGE,
1918
POWER_WATT,
@@ -30,6 +29,7 @@
3029
SwitchType,
3130
)
3231
from plugwise.exceptions import DataMissingError
32+
3333
from defusedxml import ElementTree as etree
3434
from munch import Munch
3535

@@ -141,7 +141,7 @@ def collect_power_values(
141141
if not loc.found:
142142
continue
143143

144-
data = power_data_energy_diff(loc.measurement, loc.net_string, loc.f_val, data)
144+
power_data_energy_diff(loc.measurement, loc.net_string, loc.f_val, data)
145145
key = cast(SensorType, loc.key_string)
146146
data["sensors"][key] = loc.f_val
147147

@@ -206,13 +206,13 @@ def format_measure(measure: str, unit: str) -> float | int:
206206
float_measure = float_measure / 1000
207207

208208
if unit in SPECIAL_FORMAT:
209-
result = f"{round(float_measure, 3):.3f}"
209+
result = round(float_measure, 3)
210210
elif unit == ELECTRIC_POTENTIAL_VOLT:
211-
result = f"{round(float_measure, 1):.1f}"
211+
result = round(float_measure, 1)
212212
elif abs(float_measure) < 10:
213-
result = f"{round(float_measure, 2):.2f}"
213+
result = round(float_measure, 2)
214214
else: # abs(float_measure) >= 10
215-
result = f"{round(float_measure, 1):.1f}"
215+
result = round(float_measure, 1)
216216

217217
return result
218218

@@ -232,23 +232,21 @@ def power_data_energy_diff(
232232
net_string: SensorType,
233233
f_val: float | int,
234234
data: GwEntityData,
235-
) -> GwEntityData:
235+
) -> None:
236236
"""Calculate differential energy."""
237237
if (
238238
"electricity" in measurement
239239
and "phase" not in measurement
240240
and "interval" not in net_string
241241
):
242-
diff = 1 if "produced" in measurement else -1
242+
diff = 1 if "consumed" in measurement else -1
243243
tmp_val = data["sensors"].get(net_string, 0)
244244
tmp_val += f_val * diff
245245
if isinstance(f_val, float):
246-
tmp_val = f"{round(tmp_val, 3):.3f}"
246+
tmp_val = round(tmp_val, 3)
247247

248248
data["sensors"][net_string] = tmp_val
249249

250-
return data
251-
252250

253251
def power_data_local_format(
254252
attrs: dict[str, str], key_string: str, val: str

0 commit comments

Comments
 (0)