diff --git a/CHANGELOG.md b/CHANGELOG.md index fad6e4e9e..0cba877ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/plugwise/common.py b/plugwise/common.py index f20f3d30d..03ec7c865 100644 --- a/plugwise/common.py +++ b/plugwise/common.py @@ -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 diff --git a/plugwise/helper.py b/plugwise/helper.py index 5e1831a3f..35472db5b 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -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().""" diff --git a/plugwise/util.py b/plugwise/util.py index 839ffe3ba..1b4a3efaf 100644 --- a/plugwise/util.py +++ b/plugwise/util.py @@ -13,6 +13,7 @@ ELECTRIC_POTENTIAL_VOLT, ENERGY_KILO_WATT_HOUR, HW_MODELS, + NONE, OBSOLETE_MEASUREMENTS, PERCENTAGE, POWER_WATT, @@ -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 @@ -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 @@ -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) @@ -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 @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 3a4bc2ca2..e5ca6ede0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"