Skip to content

Commit 373c9ce

Browse files
committed
Break out _count_data_items() function and implement
1 parent 51e0eab commit 373c9ce

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

plugwise/common.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ def _collect_power_values(self, data: GwEntityData, loc: Munch, tariff: str, leg
131131
key = cast(SensorType, loc.key_string)
132132
data["sensors"][key] = loc.f_val
133133

134+
def _count_data_items(self, data: GwEntityData) -> None:
135+
"""When present, count the binary_sensors, sensors and switches dict-items, don't count the dicts.
136+
137+
Also, count the remaining single data items, the amount of dicts present have already been pre-subtracted in the previous step.
138+
"""
139+
if "binary_sensors" in data:
140+
self._count += len(data["binary_sensors"]) -1
141+
if "sensors" in data:
142+
self._count += len(data["sensors"]) - 1
143+
if "switches" in data:
144+
self._count += len(data["switches"]) -1
145+
self._count += len(data)
146+
134147
def _power_data_peak_value(self, loc: Munch, legacy: bool) -> Munch:
135148
"""Helper-function for _power_data_from_location() and _power_data_from_modules()."""
136149
loc.found = True

plugwise/helper.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -601,15 +601,7 @@ def _appliance_measurements(
601601
appl_i_loc.text, ENERGY_WATT_HOUR
602602
)
603603

604-
# Don't count the below top-level dicts when present
605-
if "binary_sensors" in data:
606-
self._count += len(data["binary_sensors"]) -1
607-
if "sensors" in data:
608-
self._count += len(data["sensors"]) - 1
609-
if "switches" in data:
610-
self._count += len(data["switches"]) -1
611-
# Count the remaining single data items, with the sub-dicts present already subtracted
612-
self._count += len(data)
604+
self._count_data_items(data)
613605

614606
def _get_toggle_state(
615607
self, xml: etree, toggle: str, name: ToggleNameType, data: GwEntityData

plugwise/legacy/helper.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,7 @@ def _appliance_measurements(
360360
appl_i_loc.text, ENERGY_WATT_HOUR
361361
)
362362

363-
self._count += len(data["binary_sensors"])
364-
self._count += len(data["sensors"])
365-
self._count += len(data["switches"])
366-
# Don't count the above top-level dicts, only the remaining single items
367-
self._count += len(data) - 3
363+
self._count_data_items(data)
368364

369365
def _get_actuator_functionalities(
370366
self,

0 commit comments

Comments
 (0)