Skip to content

Commit 2cbd488

Browse files
committed
Move count_data_items function to utils
1 parent 31e9b7e commit 2cbd488

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

plugwise/common.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,6 @@ def _collect_power_values(
135135
key = cast(SensorType, loc.key_string)
136136
data["sensors"][key] = loc.f_val
137137

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

plugwise/helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from plugwise.util import (
4646
check_model,
4747
common_match_cases,
48+
count_data_items,
4849
format_measure,
4950
skip_obsolete_measurements,
5051
)
@@ -424,7 +425,7 @@ def _appliance_measurements(
424425
appl_i_loc.text, ENERGY_WATT_HOUR
425426
)
426427

427-
self._count_data_items(data)
428+
self._count = count_data_items(self._count, data)
428429

429430
def _get_toggle_state(
430431
self, xml: etree, toggle: str, name: ToggleNameType, data: GwEntityData

plugwise/legacy/helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
)
3737
from plugwise.util import (
3838
common_match_cases,
39+
count_data_items,
3940
format_measure,
4041
skip_obsolete_measurements,
4142
version_to_model,
@@ -340,7 +341,7 @@ def _appliance_measurements(
340341
appl_i_loc.text, ENERGY_WATT_HOUR
341342
)
342343

343-
self._count_data_items(data)
344+
self._count = count_data_items(self._count, data)
344345

345346
def _get_actuator_functionalities(
346347
self, xml: etree, entity: GwEntityData, data: GwEntityData

plugwise/util.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,22 @@ def common_match_cases(
145145
data["binary_sensors"]["low_battery"] = False
146146

147147

148+
def count_data_items(count: int, data: GwEntityData) -> int:
149+
"""When present, count the binary_sensors, sensors and switches dict-items, don't count the dicts.
150+
151+
Also, count the remaining single data items, the amount of dicts present have already been pre-subtracted in the previous step.
152+
"""
153+
if "binary_sensors" in data:
154+
count += len(data["binary_sensors"]) - 1
155+
if "sensors" in data:
156+
count += len(data["sensors"]) - 1
157+
if "switches" in data:
158+
count += len(data["switches"]) - 1
159+
160+
count += len(data)
161+
return count
162+
163+
148164
def escape_illegal_xml_characters(xmldata: str) -> str:
149165
"""Replace illegal &-characters."""
150166
return re.sub(r"&([^a-zA-Z#])", r"&\1", xmldata)

0 commit comments

Comments
 (0)