Skip to content

Commit f6603db

Browse files
committed
Implement count-suggestion
1 parent 51e0eab commit f6603db

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

plugwise/helper.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -601,15 +601,14 @@ 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+
# Count only the items in the binary_sensors, sensors and
605+
# switches dicts, and the single data items in data
606+
total_bsssw_dict_items = sum(
607+
len(data.get(key, {})) for key in ["binary_sensors", "sensors", "switches"]
608+
)
609+
self._count += total_bsssw_dict_items + len(data) - len(
610+
[k for k in data if isinstance(data[k], dict)]
611+
)
613612

614613
def _get_toggle_state(
615614
self, xml: etree, toggle: str, name: ToggleNameType, data: GwEntityData

0 commit comments

Comments
 (0)