Skip to content

Commit 5ad6992

Browse files
authored
Merge pull request #713 from plugwise/digisaster-contrib
Implement improvements based on contributions from digisaster, with some further enhancements.
2 parents 7e2560d + a5354aa commit 5ad6992

File tree

5 files changed

+28
-34
lines changed

5 files changed

+28
-34
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
## Ongoing
44

5-
- Improve readability of xml-data in POST/PUT requests via [#707](https://github.com/plugwise/python-plugwise/pull/707) and [#708](https://github.com/plugwise/python-plugwise/pull/708)
6-
- Continuous improvements [#711](https://github.com/plugwise/python-plugwise/pull/711)
5+
- Improve readability of xml-data in POST/PUT requests via [#707](https://github.com/plugwise/python-plugwise/pull/707), [#708](https://github.com/plugwise/python-plugwise/pull/708) and [#715](https://github.com/plugwise/python-plugwise/pull/715)
6+
- Continuous improvements via [#711](https://github.com/plugwise/python-plugwise/pull/711) and [#713](https://github.com/plugwise/python-plugwise/pull/713)
77

88
## v1.7.2
99

plugwise/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def _appl_heater_central_info(
7676
xml_2 = return_valid(xml_2, self._domain_objects)
7777
self._heater_id = check_heater_central(xml_2)
7878

79+
if self._heater_id == NONE:
80+
return Munch() # pragma: no cover
81+
7982
# Info for On-Off device
8083
if self._on_off_device:
8184
appl.name = "OnOff" # pragma: no cover

plugwise/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def _appliance_info_finder(self, appl: Munch, appliance: etree.Element) -> Munch
253253
appl.zigbee_mac = module_data["zigbee_mac_address"]
254254
return appl
255255
case _: # pragma: no cover
256-
return appl
256+
return Munch()
257257

258258
def _appl_gateway_info(self, appl: Munch, appliance: etree.Element) -> Munch:
259259
"""Helper-function for _appliance_info_finder()."""

plugwise/util.py

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
ELECTRIC_POTENTIAL_VOLT,
1414
ENERGY_KILO_WATT_HOUR,
1515
HW_MODELS,
16+
NONE,
1617
OBSOLETE_MEASUREMENTS,
1718
PERCENTAGE,
1819
POWER_WATT,
@@ -93,14 +94,16 @@ def check_heater_central(xml: etree.Element) -> str:
9394
if heater_central.find("name").text == "Central heating boiler":
9495
hc_list.append({hc_id: has_actuators})
9596

97+
if not hc_list:
98+
return NONE # pragma: no cover
99+
96100
heater_central_id = list(hc_list[0].keys())[0]
97101
if hc_count > 1:
98-
for item in hc_list: # pragma: no cover
99-
for key, value in item.items(): # pragma: no cover
100-
if value: # pragma: no cover
101-
heater_central_id = key # pragma: no cover
102-
# Stop when a valid id is found
103-
break # pragma: no cover
102+
for item in hc_list:
103+
hc_id, has_actuators = next(iter(item.items()))
104+
if has_actuators:
105+
heater_central_id = hc_id
106+
break
104107

105108
return heater_central_id
106109

@@ -135,7 +138,7 @@ def collect_power_values(
135138
if not loc.found:
136139
continue
137140

138-
data = power_data_energy_diff(loc.measurement, loc.net_string, loc.f_val, data)
141+
power_data_energy_diff(loc.measurement, loc.net_string, loc.f_val, data)
139142
key = cast(SensorType, loc.key_string)
140143
data["sensors"][key] = loc.f_val
141144

@@ -192,8 +195,6 @@ def escape_illegal_xml_characters(xmldata: str) -> str:
192195

193196
def format_measure(measure: str, unit: str) -> float | int:
194197
"""Format measure to correct type."""
195-
result: float | int = 0
196-
197198
float_measure = float(measure)
198199
if unit == PERCENTAGE and 0 < float_measure <= 1:
199200
return int(float_measure * 100)
@@ -202,13 +203,13 @@ def format_measure(measure: str, unit: str) -> float | int:
202203
float_measure = float_measure / 1000
203204

204205
if unit in SPECIAL_FORMAT:
205-
result = float(f"{round(float_measure, 3):.3f}")
206+
result = round(float_measure, 3)
206207
elif unit == ELECTRIC_POTENTIAL_VOLT:
207-
result = float(f"{round(float_measure, 1):.1f}")
208+
result = round(float_measure, 1)
208209
elif abs(float_measure) < 10:
209-
result = float(f"{round(float_measure, 2):.2f}")
210-
elif abs(float_measure) >= 10:
211-
result = float(f"{round(float_measure, 1):.1f}")
210+
result = round(float_measure, 2)
211+
else: # abs(float_measure) >= 10
212+
result = round(float_measure, 1)
212213

213214
return result
214215

@@ -228,31 +229,21 @@ def power_data_energy_diff(
228229
net_string: SensorType,
229230
f_val: float | int,
230231
data: GwEntityData,
231-
) -> GwEntityData:
232+
) -> None:
232233
"""Calculate differential energy."""
233234
if (
234235
"electricity" in measurement
235236
and "phase" not in measurement
236237
and "interval" not in net_string
237238
):
238-
diff = 1
239-
if "produced" in measurement:
240-
diff = -1
241-
if net_string not in data["sensors"]:
242-
tmp_val: float | int = 0
243-
else:
244-
tmp_val = data["sensors"][net_string]
245-
246-
if isinstance(f_val, int):
247-
tmp_val += f_val * diff
248-
else:
249-
tmp_val += float(f_val * diff)
250-
tmp_val = float(f"{round(tmp_val, 3):.3f}")
239+
diff = 1 if "consumed" in measurement else -1
240+
tmp_val = data["sensors"].get(net_string, 0)
241+
tmp_val += f_val * diff
242+
if isinstance(f_val, float):
243+
tmp_val = round(tmp_val, 3)
251244

252245
data["sensors"][net_string] = tmp_val
253246

254-
return data
255-
256247

257248
def power_data_local_format(
258249
attrs: dict[str, str], key_string: str, val: str

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "plugwise"
7-
version = "1.7.3a1"
7+
version = "1.7.3a2"
88
license = {file = "LICENSE"}
99
description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3."
1010
readme = "README.md"

0 commit comments

Comments
 (0)