Skip to content

Commit 53a2688

Browse files
committed
Breakout check_alternative_locations() to util.py
1 parent 63d4f3e commit 53a2688

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

plugwise/common.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
SensorType,
1717
)
1818
from plugwise.util import (
19+
check_alternative_locations,
1920
check_heater_central,
2021
check_model,
2122
get_vendor_name,
@@ -131,17 +132,12 @@ def _collect_power_values(self, data: DeviceData, loc: Munch, tariff: str, legac
131132
key = cast(SensorType, loc.key_string)
132133
data["sensors"][key] = loc.f_val
133134

135+
134136
def _power_data_peak_value(self, loc: Munch, legacy: bool) -> Munch:
135137
"""Helper-function for _power_data_from_location() and _power_data_from_modules()."""
136138
loc.found = True
137-
combination = "log" in loc.log_type and ("gas" in loc.measurement or "phase" in loc.measurement)
138-
if legacy:
139-
combination = "meter" in loc.log_type and ("point" in loc.log_type or "gas" in loc.measurement)
140-
141139
if loc.logs.find(loc.locator) is None:
142-
# If locator not found look for P1 gas_consumed or phase data (without tariff)
143-
# For legacy look for P1 legacy electricity_point_meter or gas_*_meter data
144-
if combination:
140+
if check_alternative_locations(loc, legacy):
145141
# Avoid double processing by skipping one peak-list option
146142
if loc.peak_select == "nl_offpeak":
147143
loc.found = False

plugwise/util.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@
1919
)
2020

2121
from defusedxml import ElementTree as etree
22+
from munch import Munch
23+
24+
25+
def check_alternative_locations(loc: Munch, legacy: bool) -> bool:
26+
"""Look for P1 gas_consumed or phase data (without tariff).
27+
28+
For legacy look for P1 legacy electricity_point_meter or gas_*_meter data.
29+
"""
30+
present = "log" in loc.log_type and (
31+
"gas" in loc.measurement or "phase" in loc.measurement
32+
)
33+
if legacy:
34+
present = "meter" in loc.log_type and (
35+
"point" in loc.log_type or "gas" in loc.measurement
36+
)
37+
38+
return present
2239

2340

2441
def check_heater_central(xml: etree) -> str:

0 commit comments

Comments
 (0)