Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Ongoing

- 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)
- Continuous improvements [#711](https://github.com/plugwise/python-plugwise/pull/711)
- 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)
- Continuous improvements via [#711](https://github.com/plugwise/python-plugwise/pull/711) and [#713](https://github.com/plugwise/python-plugwise/pull/713)

## v1.7.2

Expand Down
3 changes: 3 additions & 0 deletions plugwise/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def _appl_heater_central_info(
xml_2 = return_valid(xml_2, self._domain_objects)
self._heater_id = check_heater_central(xml_2)

if self._heater_id == NONE:
return Munch() # pragma: no cover

# Info for On-Off device
if self._on_off_device:
appl.name = "OnOff" # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion plugwise/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def _appliance_info_finder(self, appl: Munch, appliance: etree.Element) -> Munch
appl.zigbee_mac = module_data["zigbee_mac_address"]
return appl
case _: # pragma: no cover
return appl
return Munch()

def _appl_gateway_info(self, appl: Munch, appliance: etree.Element) -> Munch:
"""Helper-function for _appliance_info_finder()."""
Expand Down
51 changes: 21 additions & 30 deletions plugwise/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ELECTRIC_POTENTIAL_VOLT,
ENERGY_KILO_WATT_HOUR,
HW_MODELS,
NONE,
OBSOLETE_MEASUREMENTS,
PERCENTAGE,
POWER_WATT,
Expand Down Expand Up @@ -93,14 +94,16 @@ def check_heater_central(xml: etree.Element) -> str:
if heater_central.find("name").text == "Central heating boiler":
hc_list.append({hc_id: has_actuators})

if not hc_list:
return NONE # pragma: no cover

heater_central_id = list(hc_list[0].keys())[0]
if hc_count > 1:
for item in hc_list: # pragma: no cover
for key, value in item.items(): # pragma: no cover
if value: # pragma: no cover
heater_central_id = key # pragma: no cover
# Stop when a valid id is found
break # pragma: no cover
for item in hc_list:
hc_id, has_actuators = next(iter(item.items()))
if has_actuators:
heater_central_id = hc_id
break

return heater_central_id

Expand Down Expand Up @@ -135,7 +138,7 @@ def collect_power_values(
if not loc.found:
continue

data = power_data_energy_diff(loc.measurement, loc.net_string, loc.f_val, data)
power_data_energy_diff(loc.measurement, loc.net_string, loc.f_val, data)
key = cast(SensorType, loc.key_string)
data["sensors"][key] = loc.f_val

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

def format_measure(measure: str, unit: str) -> float | int:
"""Format measure to correct type."""
result: float | int = 0

float_measure = float(measure)
if unit == PERCENTAGE and 0 < float_measure <= 1:
return int(float_measure * 100)
Expand All @@ -202,13 +203,13 @@ def format_measure(measure: str, unit: str) -> float | int:
float_measure = float_measure / 1000

if unit in SPECIAL_FORMAT:
result = float(f"{round(float_measure, 3):.3f}")
result = round(float_measure, 3)
elif unit == ELECTRIC_POTENTIAL_VOLT:
result = float(f"{round(float_measure, 1):.1f}")
result = round(float_measure, 1)
elif abs(float_measure) < 10:
result = float(f"{round(float_measure, 2):.2f}")
elif abs(float_measure) >= 10:
result = float(f"{round(float_measure, 1):.1f}")
result = round(float_measure, 2)
else: # abs(float_measure) >= 10
result = round(float_measure, 1)

return result

Expand All @@ -228,31 +229,21 @@ def power_data_energy_diff(
net_string: SensorType,
f_val: float | int,
data: GwEntityData,
) -> GwEntityData:
) -> None:
"""Calculate differential energy."""
if (
"electricity" in measurement
and "phase" not in measurement
and "interval" not in net_string
):
diff = 1
if "produced" in measurement:
diff = -1
if net_string not in data["sensors"]:
tmp_val: float | int = 0
else:
tmp_val = data["sensors"][net_string]

if isinstance(f_val, int):
tmp_val += f_val * diff
else:
tmp_val += float(f_val * diff)
tmp_val = float(f"{round(tmp_val, 3):.3f}")
diff = 1 if "consumed" in measurement else -1
tmp_val = data["sensors"].get(net_string, 0)
tmp_val += f_val * diff
if isinstance(f_val, float):
tmp_val = round(tmp_val, 3)

data["sensors"][net_string] = tmp_val

return data


def power_data_local_format(
attrs: dict[str, str], key_string: str, val: str
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "plugwise"
version = "1.7.3a1"
version = "1.7.3a2"
license = {file = "LICENSE"}
description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3."
readme = "README.md"
Expand Down
Loading