Skip to content

Commit fd04279

Browse files
committed
Move and combine power_data_energy_diff()
1 parent 60029a6 commit fd04279

File tree

3 files changed

+38
-63
lines changed

3 files changed

+38
-63
lines changed

plugwise/common.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
"""
55
from __future__ import annotations
66

7-
from plugwise.constants import ANNA, SWITCH_GROUP_TYPES, DeviceData, ModelData
7+
from plugwise.constants import (
8+
ANNA,
9+
SWITCH_GROUP_TYPES,
10+
DeviceData,
11+
ModelData,
12+
SensorType,
13+
)
814
from plugwise.util import (
915
check_heater_central,
1016
check_model,
@@ -187,3 +193,34 @@ def _get_group_switches(self) -> dict[str, DeviceData]:
187193
self._count += 4
188194

189195
return switch_groups
196+
197+
def power_data_energy_diff(
198+
self,
199+
measurement: str,
200+
net_string: SensorType,
201+
f_val: float | int,
202+
direct_data: DeviceData,
203+
) -> DeviceData:
204+
"""Calculate differential energy."""
205+
if (
206+
"electricity" in measurement
207+
and "phase" not in measurement
208+
and "interval" not in net_string
209+
):
210+
diff = 1
211+
if "produced" in measurement:
212+
diff = -1
213+
if net_string not in direct_data["sensors"]:
214+
tmp_val: float | int = 0
215+
else:
216+
tmp_val = direct_data["sensors"][net_string]
217+
218+
if isinstance(f_val, int):
219+
tmp_val += f_val * diff
220+
else:
221+
tmp_val += float(f_val * diff)
222+
tmp_val = float(f"{round(tmp_val, 3):.3f}")
223+
224+
direct_data["sensors"][net_string] = tmp_val
225+
226+
return direct_data

plugwise/helper.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -962,37 +962,6 @@ def _heating_valves(self) -> int | bool:
962962

963963
return False if loc_found == 0 else open_valve_count
964964

965-
def power_data_energy_diff(
966-
self,
967-
measurement: str,
968-
net_string: SensorType,
969-
f_val: float | int,
970-
direct_data: DeviceData,
971-
) -> DeviceData:
972-
"""Calculate differential energy."""
973-
if (
974-
"electricity" in measurement
975-
and "phase" not in measurement
976-
and "interval" not in net_string
977-
):
978-
diff = 1
979-
if "produced" in measurement:
980-
diff = -1
981-
if net_string not in direct_data["sensors"]:
982-
tmp_val: float | int = 0
983-
else:
984-
tmp_val = direct_data["sensors"][net_string]
985-
986-
if isinstance(f_val, int):
987-
tmp_val += f_val * diff
988-
else:
989-
tmp_val += float(f_val * diff)
990-
tmp_val = float(f"{round(tmp_val, 3):.3f}")
991-
992-
direct_data["sensors"][net_string] = tmp_val
993-
994-
return direct_data
995-
996965
def _power_data_peak_value(self, loc: Munch) -> Munch:
997966
"""Helper-function for _power_data_from_location() and _power_data_from_modules()."""
998967
loc.found = True

plugwise/legacy/helper.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -453,37 +453,6 @@ def _thermostat_uri(self) -> str:
453453

454454
return f"{APPLIANCES};id={appliance_id}/thermostat"
455455

456-
def power_data_energy_diff(
457-
self,
458-
measurement: str,
459-
net_string: SensorType,
460-
f_val: float | int,
461-
direct_data: DeviceData,
462-
) -> DeviceData:
463-
"""Calculate differential energy."""
464-
if (
465-
"electricity" in measurement
466-
and "phase" not in measurement
467-
and "interval" not in net_string
468-
):
469-
diff = 1
470-
if "produced" in measurement:
471-
diff = -1
472-
if net_string not in direct_data["sensors"]:
473-
tmp_val: float | int = 0
474-
else:
475-
tmp_val = direct_data["sensors"][net_string]
476-
477-
if isinstance(f_val, int):
478-
tmp_val += f_val * diff
479-
else:
480-
tmp_val += float(f_val * diff)
481-
tmp_val = float(f"{round(tmp_val, 3):.3f}")
482-
483-
direct_data["sensors"][net_string] = tmp_val
484-
485-
return direct_data
486-
487456
def _power_data_peak_value(self, loc: Munch) -> Munch:
488457
"""Helper-function for _power_data_from_location() and _power_data_from_modules()."""
489458
loc.found = True

0 commit comments

Comments
 (0)