From 1da52f35481953d4f695a4ed710c1bb0756915af Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Feb 2025 10:34:13 +0100 Subject: [PATCH 01/18] Implement suggestions --- plugwise/util.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/plugwise/util.py b/plugwise/util.py index 839ffe3ba..2b255019b 100644 --- a/plugwise/util.py +++ b/plugwise/util.py @@ -235,14 +235,8 @@ def power_data_energy_diff( 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] - + diff = 1 if "produced" in measurement else -1 + tmp_val: float | int = data["sensors"].get(net_string, 0) if isinstance(f_val, int): tmp_val += f_val * diff else: From 709a681ab92de8a4dcba86ec914e88196a8213fd Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Feb 2025 10:42:41 +0100 Subject: [PATCH 02/18] Improve further --- plugwise/util.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plugwise/util.py b/plugwise/util.py index 2b255019b..6638e186a 100644 --- a/plugwise/util.py +++ b/plugwise/util.py @@ -236,12 +236,10 @@ def power_data_energy_diff( and "interval" not in net_string ): diff = 1 if "produced" in measurement else -1 - tmp_val: float | int = data["sensors"].get(net_string, 0) - 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}") + tmp_val = data["sensors"].get(net_string, 0) + tmp_val += f_val * diff + if isinstance(f_val, float): + tmp_val = f"{round(tmp_val, 3):.3f}" data["sensors"][net_string] = tmp_val From 326956f45b2a831685e950f4b45a17dff14ef723 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Feb 2025 10:46:39 +0100 Subject: [PATCH 03/18] Implement suggestion for format_measure and adapt --- plugwise/util.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/plugwise/util.py b/plugwise/util.py index 6638e186a..e24d0e343 100644 --- a/plugwise/util.py +++ b/plugwise/util.py @@ -192,8 +192,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 +200,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 = f"{round(float_measure, 3):.3f}" elif unit == ELECTRIC_POTENTIAL_VOLT: - result = float(f"{round(float_measure, 1):.1f}") + result = f"{round(float_measure, 1):.1f}" 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 = f"{round(float_measure, 2):.2f}" + else # abs(float_measure) >= 10 + result = f"{round(float_measure, 1):.1f}" return result From d8ce80f63afecb7f80cd9d34fb6062de4251c82b Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Feb 2025 11:04:41 +0100 Subject: [PATCH 04/18] Implement another suggest and adapt --- plugwise/util.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugwise/util.py b/plugwise/util.py index e24d0e343..147b749a7 100644 --- a/plugwise/util.py +++ b/plugwise/util.py @@ -13,6 +13,7 @@ ELECTRIC_POTENTIAL_VOLT, ENERGY_KILO_WATT_HOUR, HW_MODELS, + LOGGER, OBSOLETE_MEASUREMENTS, PERCENTAGE, POWER_WATT, @@ -28,7 +29,7 @@ SpecialType, SwitchType, ) - +from plugwise.exceptions import DataMissingError from defusedxml import ElementTree as etree from munch import Munch @@ -93,6 +94,9 @@ 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: + raise DataMissingError("No Central heating boiler found, please create an Issue") + heater_central_id = list(hc_list[0].keys())[0] if hc_count > 1: for item in hc_list: # pragma: no cover From 8a521ebce9fc10fbf2a5208c4a094c4acfe9b1c4 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Feb 2025 11:11:23 +0100 Subject: [PATCH 05/18] Fix --- plugwise/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/util.py b/plugwise/util.py index 147b749a7..e268f555c 100644 --- a/plugwise/util.py +++ b/plugwise/util.py @@ -209,7 +209,7 @@ def format_measure(measure: str, unit: str) -> float | int: result = f"{round(float_measure, 1):.1f}" elif abs(float_measure) < 10: result = f"{round(float_measure, 2):.2f}" - else # abs(float_measure) >= 10 + else: # abs(float_measure) >= 10 result = f"{round(float_measure, 1):.1f}" return result From b17f6f6d5ecc48d9a88643d0bfeae7a83ffb9411 Mon Sep 17 00:00:00 2001 From: autoruff Date: Thu, 20 Feb 2025 10:13:00 +0000 Subject: [PATCH 06/18] fixup: digisaster-contrib Python code fixed using ruff --- plugwise/util.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugwise/util.py b/plugwise/util.py index e268f555c..ace7cb035 100644 --- a/plugwise/util.py +++ b/plugwise/util.py @@ -95,7 +95,9 @@ def check_heater_central(xml: etree.Element) -> str: hc_list.append({hc_id: has_actuators}) if not hc_list: - raise DataMissingError("No Central heating boiler found, please create an Issue") + raise DataMissingError( + "No Central heating boiler found, please create an Issue" + ) heater_central_id = list(hc_list[0].keys())[0] if hc_count > 1: From 42471815804f0916ab34090bf2e690450d550821 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Feb 2025 19:35:54 +0100 Subject: [PATCH 07/18] Improve further --- plugwise/util.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/plugwise/util.py b/plugwise/util.py index ace7cb035..7fb8c4317 100644 --- a/plugwise/util.py +++ b/plugwise/util.py @@ -13,7 +13,6 @@ ELECTRIC_POTENTIAL_VOLT, ENERGY_KILO_WATT_HOUR, HW_MODELS, - LOGGER, OBSOLETE_MEASUREMENTS, PERCENTAGE, POWER_WATT, @@ -30,6 +29,7 @@ SwitchType, ) from plugwise.exceptions import DataMissingError + from defusedxml import ElementTree as etree from munch import Munch @@ -97,7 +97,7 @@ def check_heater_central(xml: etree.Element) -> str: if not hc_list: raise DataMissingError( "No Central heating boiler found, please create an Issue" - ) + ) # pragma: no cover heater_central_id = list(hc_list[0].keys())[0] if hc_count > 1: @@ -141,7 +141,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 @@ -206,13 +206,13 @@ def format_measure(measure: str, unit: str) -> float | int: float_measure = float_measure / 1000 if unit in SPECIAL_FORMAT: - result = f"{round(float_measure, 3):.3f}" + result = round(float_measure, 3) elif unit == ELECTRIC_POTENTIAL_VOLT: - result = f"{round(float_measure, 1):.1f}" + result = round(float_measure, 1) elif abs(float_measure) < 10: - result = f"{round(float_measure, 2):.2f}" + result = round(float_measure, 2) else: # abs(float_measure) >= 10 - result = f"{round(float_measure, 1):.1f}" + result = round(float_measure, 1) return result @@ -232,23 +232,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 else -1 + 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 = f"{round(tmp_val, 3):.3f}" + 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 From 983042855dbbfe19cca0516dd96d3d0fc18c41e7 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 21 Feb 2025 14:45:18 +0100 Subject: [PATCH 08/18] Revert back to original idea --- plugwise/util.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugwise/util.py b/plugwise/util.py index 7fb8c4317..42cd21804 100644 --- a/plugwise/util.py +++ b/plugwise/util.py @@ -95,9 +95,7 @@ def check_heater_central(xml: etree.Element) -> str: hc_list.append({hc_id: has_actuators}) if not hc_list: - raise DataMissingError( - "No Central heating boiler found, please create an Issue" - ) # pragma: no cover + return # pragma: no cover heater_central_id = list(hc_list[0].keys())[0] if hc_count > 1: From 07261df7ca7a622b6a431d2ad5a1ee5af5e88b0e Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 21 Feb 2025 15:17:09 +0100 Subject: [PATCH 09/18] Improve further --- plugwise/common.py | 3 +++ plugwise/util.py | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/plugwise/common.py b/plugwise/common.py index f20f3d30d..b03e5e8d8 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 is None: + return appl + # Info for On-Off device if self._on_off_device: appl.name = "OnOff" # pragma: no cover diff --git a/plugwise/util.py b/plugwise/util.py index 42cd21804..4776afc1c 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, @@ -95,16 +96,15 @@ def check_heater_central(xml: etree.Element) -> str: hc_list.append({hc_id: has_actuators}) if not hc_list: - return # pragma: no cover + 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 + if next(iter(item.values())): + heater_central_id = next(iter(item)) # pragma: no cover + # Stop when a valid id is found + break # pragma: no cover return heater_central_id From 11f6d227a6b8b902fe774a9b3c7072427805f731 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 21 Feb 2025 15:31:39 +0100 Subject: [PATCH 10/18] Make sure to return empty Munch --- plugwise/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/common.py b/plugwise/common.py index b03e5e8d8..69f28f8b6 100644 --- a/plugwise/common.py +++ b/plugwise/common.py @@ -77,7 +77,7 @@ def _appl_heater_central_info( self._heater_id = check_heater_central(xml_2) if self._heater_id is None: - return appl + return Munch() # Info for On-Off device if self._on_off_device: From 3591dde6596c8bae312fe0de30394fece9f1354d Mon Sep 17 00:00:00 2001 From: autoruff Date: Fri, 21 Feb 2025 14:33:47 +0000 Subject: [PATCH 11/18] fixup: digisaster-contrib Python code fixed using ruff --- plugwise/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/util.py b/plugwise/util.py index 4776afc1c..b6ec50143 100644 --- a/plugwise/util.py +++ b/plugwise/util.py @@ -102,7 +102,7 @@ def check_heater_central(xml: etree.Element) -> str: if hc_count > 1: for item in hc_list: # pragma: no cover if next(iter(item.values())): - heater_central_id = next(iter(item)) # pragma: no cover + heater_central_id = next(iter(item)) # pragma: no cover # Stop when a valid id is found break # pragma: no cover From 1ae576940c849d527d6fca7eae7247f4f0e5c684 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 21 Feb 2025 19:54:15 +0100 Subject: [PATCH 12/18] Remove unused import --- plugwise/util.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugwise/util.py b/plugwise/util.py index b6ec50143..371907217 100644 --- a/plugwise/util.py +++ b/plugwise/util.py @@ -29,7 +29,6 @@ SpecialType, SwitchType, ) -from plugwise.exceptions import DataMissingError from defusedxml import ElementTree as etree from munch import Munch From eb9043f4fab1b9d1e85d61ed0c76673359d793c6 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 21 Feb 2025 19:56:03 +0100 Subject: [PATCH 13/18] Fix None to NONE --- plugwise/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/common.py b/plugwise/common.py index 69f28f8b6..8cdc6184c 100644 --- a/plugwise/common.py +++ b/plugwise/common.py @@ -76,7 +76,7 @@ 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 is None: + if self._heater_id == NONE: return Munch() # Info for On-Off device From e814e3d767b1c706abe9b933cbeccb066c323f68 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 21 Feb 2025 20:13:11 +0100 Subject: [PATCH 14/18] Return empty Much() when encountering an unknown class --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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().""" From 5eddea64a493cb5dac8e1c1b0c1ba75d01a44329 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Mon, 24 Feb 2025 14:30:24 +0100 Subject: [PATCH 15/18] Implement review-suggestion --- plugwise/common.py | 2 +- plugwise/util.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugwise/common.py b/plugwise/common.py index 8cdc6184c..03ec7c865 100644 --- a/plugwise/common.py +++ b/plugwise/common.py @@ -77,7 +77,7 @@ def _appl_heater_central_info( self._heater_id = check_heater_central(xml_2) if self._heater_id == NONE: - return Munch() + return Munch() # pragma: no cover # Info for On-Off device if self._on_off_device: diff --git a/plugwise/util.py b/plugwise/util.py index 371907217..1b4a3efaf 100644 --- a/plugwise/util.py +++ b/plugwise/util.py @@ -99,11 +99,11 @@ def check_heater_central(xml: etree.Element) -> str: heater_central_id = list(hc_list[0].keys())[0] if hc_count > 1: - for item in hc_list: # pragma: no cover - if next(iter(item.values())): - heater_central_id = next(iter(item)) # 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 From 64b68d7c6d364f48abf194b23bcfcac8ee5df1e6 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Mon, 24 Feb 2025 14:40:57 +0100 Subject: [PATCH 16/18] Update CHANGELOG --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fad6e4e9e..64870769e 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 [#712](https://github.com/plugwise/python-plugwise/pull/712) +- 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 From 734b2e248d55ba08be00c4e9ab7794e69a9f9749 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Mon, 24 Feb 2025 14:41:55 +0100 Subject: [PATCH 17/18] Fix wrong PR number --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64870769e..0cba877ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Ongoing -- 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 [#712](https://github.com/plugwise/python-plugwise/pull/712) +- 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 From a5354aa78898a9545f60a0c808616ea420488751 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Mon, 24 Feb 2025 14:49:46 +0100 Subject: [PATCH 18/18] Bump to v1.7.3a2 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"