From 8229d9047777c3c0331c1e7d829a726d06ce6f55 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 19:02:18 +0200 Subject: [PATCH 001/173] Start with debugging --- plugwise/helper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/helper.py b/plugwise/helper.py index 368f148af..9201e6c18 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1078,6 +1078,7 @@ def _get_appliance_data(self, d_id: str) -> DeviceData: self._cleanup_data(data) + LOGGER.debug("HOI data: %s", data) return data def _rank_thermostat( From 233b03585c4b7dd059eb97d669ad9c257ae7c49e Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 19:02:48 +0200 Subject: [PATCH 002/173] Full test output --- scripts/tests_and_coverage.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/tests_and_coverage.sh b/scripts/tests_and_coverage.sh index 2b4483eaa..2aa49d154 100755 --- a/scripts/tests_and_coverage.sh +++ b/scripts/tests_and_coverage.sh @@ -25,7 +25,8 @@ set +u if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "test_and_coverage" ] ; then # Python tests (rerun with debug if failures) - PYTHONPATH=$(pwd) pytest -qx tests/ --cov='.' --no-cov-on-fail --cov-report term-missing || PYTHONPATH=$(pwd) pytest -xrpP --log-level debug tests/ + # PYTHONPATH=$(pwd) pytest -qx tests/ --cov='.' --no-cov-on-fail --cov-report term-missing || + PYTHONPATH=$(pwd) pytest -xrpP --log-level debug tests/ fi if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "linting" ] ; then From c72f579cb797e241c075733124bda855e1a38306 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 19:42:40 +0200 Subject: [PATCH 003/173] _appliance_measurements(): collect directly in platform-dicts --- plugwise/helper.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 9201e6c18..4fdfe4153 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -867,26 +867,35 @@ def _appliance_measurements( if new_name := getattr(attrs, ATTR_NAME, None): measurement = new_name - data[measurement] = appl_p_loc.text # type: ignore [literal-required] # measurements with states "on" or "off" that need to be passed directly - if measurement not in ("select_dhw_mode"): - data[measurement] = format_measure( # type: ignore [literal-required] + if measurement == "select_dhw_mode": + data["select_dhw_mode"] = appl_p_loc.text + elif measurement in BINARY_SENSORS: + data["binary_sensors"][measurement] = format_measure( + appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) + ) + elif measurement in SENSORS: + data["sensors"][measurement] = format_measure( + appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) + ) + elif measurement in SWITCHES: + data["switches"][measurement] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) # Anna: save cooling-related measurements for later use # Use the local outdoor temperature as reference for turning cooling on/off if measurement == "cooling_activation_outdoor_temperature": - self._cooling_activation_outdoor_temp = data[measurement] # type: ignore [literal-required] + self._cooling_activation_outdoor_temp = data["cooling_activation_outdoor_temperature"] if measurement == "cooling_deactivation_threshold": - self._cooling_deactivation_threshold = data[measurement] # type: ignore [literal-required] + self._cooling_deactivation_threshold = data["cooling_deactivation_threshold"] if measurement == "outdoor_air_temperature": - self._outdoor_temp = data[measurement] # type: ignore [literal-required] + self._outdoor_temp = data["sensors"]["outdoor_air_temperature"] i_locator = f'.//logs/interval_log[type="{measurement}"]/period/measurement' if (appl_i_loc := appliance.find(i_locator)) is not None: name = f"{measurement}_interval" - data[name] = format_measure(appl_i_loc.text, ENERGY_WATT_HOUR) # type: ignore [literal-required] + data["sensors"][name] = format_measure(appl_i_loc.text, ENERGY_WATT_HOUR) # type: ignore [literal-required] def _wireless_availablity(self, appliance: etree, data: DeviceData) -> None: """Helper-function for _get_appliance_data(). @@ -1018,7 +1027,7 @@ def _get_appliance_data(self, d_id: str) -> DeviceData: Collect the appliance-data based on device id. Determined from APPLIANCES, for legacy from DOMAIN_OBJECTS. """ - data: DeviceData = {} + data: DeviceData = {"binary_sensors": {}, "sensors": {}, "switches": {}} # P1 legacy has no APPLIANCES, also not present in DOMAIN_OBJECTS if self._smile_legacy and self.smile_type == "power": return data From c99a41f820746848890be7fab8feeee1e1e05314 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 19:47:49 +0200 Subject: [PATCH 004/173] More collecting in platform files --- plugwise/helper.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 4fdfe4153..7750d14c9 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1520,14 +1520,14 @@ def _get_lock_state(self, xml: etree, data: DeviceData) -> None: if xml.find("type").text not in SPECIAL_PLUG_TYPES: locator = f"./{actuator}/{func_type}/lock" if (found := xml.find(locator)) is not None: - data["lock"] = found.text == "true" + data["switches"]["lock"] = found.text == "true" def _get_toggle_state( self, xml: etree, toggle: str, name: str, data: DeviceData ) -> None: """Helper-function for _get_appliance_data(). - Obtain the toggle state of 'toggle'. + Obtain the toggle state of a 'toggle' = switch. """ if xml.find("type").text == "heater_central": locator = "./actuator_functionalities/toggle_functionality" @@ -1535,11 +1535,11 @@ def _get_toggle_state( for item in found: if (toggle_type := item.find("type")) is not None: if toggle_type.text == toggle: - data[name] = item.find("state").text == "on" # type: ignore [literal-required] - # Remove the cooling_enabled key when the corresponding toggle is present + data["binary_sensors"][name] = item.find("state").text == "on" # type: ignore [literal-required] + # Remove the cooling_enabled binary_sensor when the corresponding switch is present # Except for Elga if toggle == "cooling_enabled" and not self._elga: - data.pop("cooling_enabled") + data["binary_sensor"].pop("cooling_enabled") def _update_device_with_dicts( self, From 4c6e5ddbf12a3478c09cb8cfd2764b09014d6124 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 19:52:49 +0200 Subject: [PATCH 005/173] Update _all_device_data() --- plugwise/__init__.py | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 7f576c0d0..22884039f 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -82,13 +82,7 @@ def _all_device_data(self) -> None: Collect initial data for each device and add to self.gw_data and self.gw_devices. """ for device_id, device in self._appl_data.items(): - bs_dict: SmileBinarySensors = {} - s_dict: SmileSensors = {} - sw_dict: SmileSwitches = {} - data = self._get_device_data(device_id) - self.gw_devices[device_id] = self._update_device_with_dicts( - device_id, data, device, bs_dict, s_dict, sw_dict - ) + self.gw_devices[device_id] = self._get_device_data(device_id) # Update for cooling if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: @@ -529,17 +523,17 @@ async def async_update(self) -> PlugwiseData: notifs: dict[str, dict[str, str]] = {} if item == "binary_sensors": notifs = self._notifications - if item in dev_dict: - for key in data: - update_helper( - data, - self.gw_devices, - dev_dict, - dev_id, - item, - key, - notifs, - ) + # if item in dev_dict: + # for key in data: + # update_helper( + # data, + # self.gw_devices, + # dev_dict, + # dev_id, + # item, + # key, + # notifs, + # ) # Update for cooling if dev_dict["dev_class"] in ZONE_THERMOSTATS: From 9732fe045cf7a70cbf8a9347b755d4816f12f72b Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 19:58:03 +0200 Subject: [PATCH 006/173] Cleanup, rearrange --- plugwise/__init__.py | 3 +++ plugwise/helper.py | 49 -------------------------------------------- 2 files changed, 3 insertions(+), 49 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 22884039f..e364f3ed8 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -83,6 +83,9 @@ def _all_device_data(self) -> None: """ for device_id, device in self._appl_data.items(): self.gw_devices[device_id] = self._get_device_data(device_id) + # Add plugwise notification binary_sensor to the relevant gateway + if device_id == self.gateway_id and (self._is_thermostat or (not self._smile_legacy and self.smile_type == "power")): + self.gw_devices[device_id]["plugwise_notification"] = False # Update for cooling if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: diff --git a/plugwise/helper.py b/plugwise/helper.py index 7750d14c9..f6a966770 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1541,52 +1541,3 @@ def _get_toggle_state( if toggle == "cooling_enabled" and not self._elga: data["binary_sensor"].pop("cooling_enabled") - def _update_device_with_dicts( - self, - d_id: str, - data: DeviceData, - device_in: ApplianceData, - bs_dict: SmileBinarySensors, - s_dict: SmileSensors, - sw_dict: SmileSwitches, - ) -> DeviceData: - """Helper-function for smile.py: _all_device_data(). - - Move relevant data into dicts of binary_sensors, sensors, switches, - and add these to the output. - """ - device_out: DeviceData = {} - for d_key, d_value in device_in.items(): - device_out.update({d_key: d_value}) # type: ignore [misc] - for key, value in list(data.items()): - for item in BINARY_SENSORS: - if item == key: - data.pop(key) # type: ignore [misc] - if self._opentherm_device or self._on_off_device: - bs_dict[key] = value # type: ignore[literal-required] - for item in SENSORS: - # Filter for actuator_functionalities, they are not sensors - if item == key and not isinstance(value, dict): - data.pop(key) # type: ignore [misc] - s_dict[key] = value # type: ignore[literal-required] - for item in SWITCHES: - if item == key: - data.pop(key) # type: ignore [misc] - sw_dict[key] = value # type: ignore[literal-required] - - # Add plugwise notification binary_sensor to the relevant gateway - if d_id == self.gateway_id: - if self._is_thermostat or ( - not self._smile_legacy and self.smile_type == "power" - ): - bs_dict["plugwise_notification"] = False - - device_out.update(data) - if bs_dict: - device_out["binary_sensors"] = bs_dict - if s_dict: - device_out["sensors"] = s_dict - if sw_dict: - device_out["switches"] = sw_dict - - return device_out From 314554d4cc9563d4003c16799aa4a8118478a9a0 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 20:00:13 +0200 Subject: [PATCH 007/173] Debug --- plugwise/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index e364f3ed8..03acdad9f 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -87,6 +87,7 @@ def _all_device_data(self) -> None: if device_id == self.gateway_id and (self._is_thermostat or (not self._smile_legacy and self.smile_type == "power")): self.gw_devices[device_id]["plugwise_notification"] = False + LOGGER.debug("HOI gw_devices: %s", self.gw_devices) # Update for cooling if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: self.update_for_cooling(self.gw_devices[device_id]) From 822f30cf66a02f1074da147f9d91fae7f7ce2eda Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 20:05:57 +0200 Subject: [PATCH 008/173] Try --- plugwise/__init__.py | 3 ++- plugwise/helper.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 03acdad9f..6f1361e5a 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -154,7 +154,7 @@ def _device_data_switching_group( if member_data.get("relay"): counter += 1 - device_data["relay"] = counter != 0 + device_data["switches"]["relay"] = counter != 0 return device_data @@ -261,6 +261,7 @@ def _get_device_data(self, dev_id: str) -> DeviceData: """ details = self._appl_data[dev_id] device_data = self._get_appliance_data(dev_id) + LOGGER.debug("HOI 1 device_data: %s", device_data) # Remove thermostat-dict for thermo_sensors if details["dev_class"] == "thermo_sensor": device_data.pop("thermostat") diff --git a/plugwise/helper.py b/plugwise/helper.py index f6a966770..beb54f9d7 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1087,7 +1087,7 @@ def _get_appliance_data(self, d_id: str) -> DeviceData: self._cleanup_data(data) - LOGGER.debug("HOI data: %s", data) + LOGGER.debug("HOI 0 data: %s", data) return data def _rank_thermostat( From 5e14699f571b4a2cb1d747267a462a43b3221b5c Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 20:10:49 +0200 Subject: [PATCH 009/173] Fix --- plugwise/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 6f1361e5a..106f1eac8 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -82,12 +82,14 @@ def _all_device_data(self) -> None: Collect initial data for each device and add to self.gw_data and self.gw_devices. """ for device_id, device in self._appl_data.items(): + for key, value in device: + self.gw_devices[device_id][key] = value self.gw_devices[device_id] = self._get_device_data(device_id) # Add plugwise notification binary_sensor to the relevant gateway if device_id == self.gateway_id and (self._is_thermostat or (not self._smile_legacy and self.smile_type == "power")): self.gw_devices[device_id]["plugwise_notification"] = False - LOGGER.debug("HOI gw_devices: %s", self.gw_devices) + LOGGER.debug("HOI 2 gw_devices: %s", self.gw_devices) # Update for cooling if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: self.update_for_cooling(self.gw_devices[device_id]) From c48081f09d568cfdf9a0838930c88a202d5f6eca Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 20:11:31 +0200 Subject: [PATCH 010/173] Fix 2 --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 106f1eac8..6948aa761 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -82,7 +82,7 @@ def _all_device_data(self) -> None: Collect initial data for each device and add to self.gw_data and self.gw_devices. """ for device_id, device in self._appl_data.items(): - for key, value in device: + for key, value in device.items(): self.gw_devices[device_id][key] = value self.gw_devices[device_id] = self._get_device_data(device_id) # Add plugwise notification binary_sensor to the relevant gateway From 2f96dff4cc275026c6cc5f2ff69c3db33bc034b3 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 20:14:18 +0200 Subject: [PATCH 011/173] Fix 3 --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 6948aa761..08053bc52 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -83,7 +83,7 @@ def _all_device_data(self) -> None: """ for device_id, device in self._appl_data.items(): for key, value in device.items(): - self.gw_devices[device_id][key] = value + self.gw_devices[device_id].update({key: value}) # type: ignore [misc] self.gw_devices[device_id] = self._get_device_data(device_id) # Add plugwise notification binary_sensor to the relevant gateway if device_id == self.gateway_id and (self._is_thermostat or (not self._smile_legacy and self.smile_type == "power")): From 7b480c785b042f34249598d2aa10c50c57b6dbdd Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 20:15:52 +0200 Subject: [PATCH 012/173] Fix 4 --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 08053bc52..a60179083 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -83,7 +83,7 @@ def _all_device_data(self) -> None: """ for device_id, device in self._appl_data.items(): for key, value in device.items(): - self.gw_devices[device_id].update({key: value}) # type: ignore [misc] + self.gw_devices.update({device_id: {key: value}}) # type: ignore [misc] self.gw_devices[device_id] = self._get_device_data(device_id) # Add plugwise notification binary_sensor to the relevant gateway if device_id == self.gateway_id and (self._is_thermostat or (not self._smile_legacy and self.smile_type == "power")): From 2033e42d3069354a355a038423188933a0cd5cb1 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 20:18:12 +0200 Subject: [PATCH 013/173] Fix 5 --- plugwise/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index a60179083..240970c57 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -81,6 +81,7 @@ def _all_device_data(self) -> None: Collect initial data for each device and add to self.gw_data and self.gw_devices. """ + LOGGER.debug("HOI 2a _appl_data: %s", self._appl_data.items()) for device_id, device in self._appl_data.items(): for key, value in device.items(): self.gw_devices.update({device_id: {key: value}}) # type: ignore [misc] @@ -89,7 +90,7 @@ def _all_device_data(self) -> None: if device_id == self.gateway_id and (self._is_thermostat or (not self._smile_legacy and self.smile_type == "power")): self.gw_devices[device_id]["plugwise_notification"] = False - LOGGER.debug("HOI 2 gw_devices: %s", self.gw_devices) + LOGGER.debug("HOI 2b gw_devices: %s", self.gw_devices) # Update for cooling if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: self.update_for_cooling(self.gw_devices[device_id]) From e37ad4667daf92d33685d528fa3f46dad9418175 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 20:20:41 +0200 Subject: [PATCH 014/173] Move --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 240970c57..f9c83814d 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -81,8 +81,8 @@ def _all_device_data(self) -> None: Collect initial data for each device and add to self.gw_data and self.gw_devices. """ - LOGGER.debug("HOI 2a _appl_data: %s", self._appl_data.items()) for device_id, device in self._appl_data.items(): + LOGGER.debug("HOI 2a dev_id, device: %s, %s", device_id, device) for key, value in device.items(): self.gw_devices.update({device_id: {key: value}}) # type: ignore [misc] self.gw_devices[device_id] = self._get_device_data(device_id) From e44647d3c31258bf73fa856cb20db2e09c3234b0 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 20:23:57 +0200 Subject: [PATCH 015/173] Fix 6 --- plugwise/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index f9c83814d..c1a67bbdc 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -82,9 +82,7 @@ def _all_device_data(self) -> None: Collect initial data for each device and add to self.gw_data and self.gw_devices. """ for device_id, device in self._appl_data.items(): - LOGGER.debug("HOI 2a dev_id, device: %s, %s", device_id, device) - for key, value in device.items(): - self.gw_devices.update({device_id: {key: value}}) # type: ignore [misc] + self.gw_devices.update({device_id: device}) # type: ignore [misc] self.gw_devices[device_id] = self._get_device_data(device_id) # Add plugwise notification binary_sensor to the relevant gateway if device_id == self.gateway_id and (self._is_thermostat or (not self._smile_legacy and self.smile_type == "power")): From 74d3ab21e9d9671278b9389d4ad9cb441f3807bb Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 20:25:25 +0200 Subject: [PATCH 016/173] Debug --- plugwise/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index c1a67bbdc..b016d977b 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -83,6 +83,7 @@ def _all_device_data(self) -> None: """ for device_id, device in self._appl_data.items(): self.gw_devices.update({device_id: device}) # type: ignore [misc] + LOGGER.debug("HOI 2a gw_devices: %s", self.gw_devices) self.gw_devices[device_id] = self._get_device_data(device_id) # Add plugwise notification binary_sensor to the relevant gateway if device_id == self.gateway_id and (self._is_thermostat or (not self._smile_legacy and self.smile_type == "power")): From d8527500c1a9827117b1c96f79c270f56064ea82 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 20:27:06 +0200 Subject: [PATCH 017/173] Fix 7 --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index b016d977b..9d02d531a 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -84,7 +84,7 @@ def _all_device_data(self) -> None: for device_id, device in self._appl_data.items(): self.gw_devices.update({device_id: device}) # type: ignore [misc] LOGGER.debug("HOI 2a gw_devices: %s", self.gw_devices) - self.gw_devices[device_id] = self._get_device_data(device_id) + self.gw_devices.update({device_id: self._get_device_data(device_id)}) # Add plugwise notification binary_sensor to the relevant gateway if device_id == self.gateway_id and (self._is_thermostat or (not self._smile_legacy and self.smile_type == "power")): self.gw_devices[device_id]["plugwise_notification"] = False From 12fbc189f51fe7ee879147f6fbc68ebac8c2faa0 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 20:30:28 +0200 Subject: [PATCH 018/173] Fix 8 --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 9d02d531a..e9f18b70a 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -84,7 +84,7 @@ def _all_device_data(self) -> None: for device_id, device in self._appl_data.items(): self.gw_devices.update({device_id: device}) # type: ignore [misc] LOGGER.debug("HOI 2a gw_devices: %s", self.gw_devices) - self.gw_devices.update({device_id: self._get_device_data(device_id)}) + self.gw_devices[device_id].update(self._get_device_data(device_id)) # Add plugwise notification binary_sensor to the relevant gateway if device_id == self.gateway_id and (self._is_thermostat or (not self._smile_legacy and self.smile_type == "power")): self.gw_devices[device_id]["plugwise_notification"] = False From 4d85978b76705baa454a2fff5b5dc0d1f049cac7 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 18 Aug 2023 20:32:00 +0200 Subject: [PATCH 019/173] Fix 9 --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index e9f18b70a..de22dee36 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -87,7 +87,7 @@ def _all_device_data(self) -> None: self.gw_devices[device_id].update(self._get_device_data(device_id)) # Add plugwise notification binary_sensor to the relevant gateway if device_id == self.gateway_id and (self._is_thermostat or (not self._smile_legacy and self.smile_type == "power")): - self.gw_devices[device_id]["plugwise_notification"] = False + self.gw_devices[device_id]["binary_sensors"]["plugwise_notification"] = False LOGGER.debug("HOI 2b gw_devices: %s", self.gw_devices) # Update for cooling From c739919bfc20597658c2ed378a5ec434e8514147 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 09:40:58 +0200 Subject: [PATCH 020/173] Remove empty platform dicts --- plugwise/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index de22dee36..8ddd4ecb4 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -94,6 +94,13 @@ def _all_device_data(self) -> None: if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: self.update_for_cooling(self.gw_devices[device_id]) + if not self.gw_devices[device_id]["binary_sensors"]: + self.gw_devices[device_id].pop("binary_sensors") + if not self.gw_devices[device_id]["sensors"]: + self.gw_devices[device_id].pop("sensors") + if not self.gw_devices[device_id]["switches"]: + self.gw_devices[device_id].pop("switche") + self.gw_data.update( {"smile_name": self.smile_name, "gateway_id": self.gateway_id} ) @@ -520,6 +527,12 @@ async def async_update(self) -> PlugwiseData: self.gw_data["notifications"] = self._notifications + # for device_id, device in self._appl_data.items(): + # self.gw_devices.update({device_id: device}) # type: ignore [misc] + # LOGGER.debug("HOI 2a gw_devices: %s", self.gw_devices) + # self.gw_devices[device_id].update(self._get_device_data(device_id)) + + for dev_id, dev_dict in self.gw_devices.items(): data = self._get_device_data(dev_id) for key, value in data.items(): From a68fd10b003568c0053799f6771ea173e93d786e Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 09:42:17 +0200 Subject: [PATCH 021/173] Fix --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 8ddd4ecb4..d08a4b64c 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -99,7 +99,7 @@ def _all_device_data(self) -> None: if not self.gw_devices[device_id]["sensors"]: self.gw_devices[device_id].pop("sensors") if not self.gw_devices[device_id]["switches"]: - self.gw_devices[device_id].pop("switche") + self.gw_devices[device_id].pop("switches") self.gw_data.update( {"smile_name": self.smile_name, "gateway_id": self.gateway_id} From 7a0324f14fd858cea5f2f79788022daf4dac5c02 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 09:44:20 +0200 Subject: [PATCH 022/173] Change debugging --- plugwise/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index d08a4b64c..6090e7f69 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -83,13 +83,11 @@ def _all_device_data(self) -> None: """ for device_id, device in self._appl_data.items(): self.gw_devices.update({device_id: device}) # type: ignore [misc] - LOGGER.debug("HOI 2a gw_devices: %s", self.gw_devices) self.gw_devices[device_id].update(self._get_device_data(device_id)) # Add plugwise notification binary_sensor to the relevant gateway if device_id == self.gateway_id and (self._is_thermostat or (not self._smile_legacy and self.smile_type == "power")): self.gw_devices[device_id]["binary_sensors"]["plugwise_notification"] = False - LOGGER.debug("HOI 2b gw_devices: %s", self.gw_devices) # Update for cooling if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: self.update_for_cooling(self.gw_devices[device_id]) @@ -535,6 +533,7 @@ async def async_update(self) -> PlugwiseData: for dev_id, dev_dict in self.gw_devices.items(): data = self._get_device_data(dev_id) + LOGGER.debug("HOI 3 data: %s", data) for key, value in data.items(): if key in dev_dict: dev_dict[key] = value # type: ignore [literal-required] From 2d71dd3edf54620969e499d8c96730c69c2c673c Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 09:53:06 +0200 Subject: [PATCH 023/173] Update async_update() --- plugwise/__init__.py | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 6090e7f69..92a8335ad 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -525,34 +525,10 @@ async def async_update(self) -> PlugwiseData: self.gw_data["notifications"] = self._notifications - # for device_id, device in self._appl_data.items(): - # self.gw_devices.update({device_id: device}) # type: ignore [misc] - # LOGGER.debug("HOI 2a gw_devices: %s", self.gw_devices) - # self.gw_devices[device_id].update(self._get_device_data(device_id)) - - - for dev_id, dev_dict in self.gw_devices.items(): - data = self._get_device_data(dev_id) - LOGGER.debug("HOI 3 data: %s", data) - for key, value in data.items(): - if key in dev_dict: - dev_dict[key] = value # type: ignore [literal-required] - - for item in ("binary_sensors", "sensors", "switches"): - notifs: dict[str, dict[str, str]] = {} - if item == "binary_sensors": - notifs = self._notifications - # if item in dev_dict: - # for key in data: - # update_helper( - # data, - # self.gw_devices, - # dev_dict, - # dev_id, - # item, - # key, - # notifs, - # ) + for device_id in self.gw_devices: + self.gw_devices[device_id].update(self._get_device_data(device_id)) + if self.gw_devices[device_id]["binary_sensors"]["plugwise_notification"]: + self.gw_devices[device_id]["binary_sensors"]["plugwise_notification"] = self._notifications != {} # Update for cooling if dev_dict["dev_class"] in ZONE_THERMOSTATS: From 0817a5c2fe457dddf514de76b034c17193020630 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 09:54:32 +0200 Subject: [PATCH 024/173] Fix --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 92a8335ad..ab5f9b7a4 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -527,7 +527,7 @@ async def async_update(self) -> PlugwiseData: for device_id in self.gw_devices: self.gw_devices[device_id].update(self._get_device_data(device_id)) - if self.gw_devices[device_id]["binary_sensors"]["plugwise_notification"]: + if " plugwise_notification" in self.gw_devices[device_id]["binary_sensors"] self.gw_devices[device_id]["binary_sensors"]["plugwise_notification"] = self._notifications != {} # Update for cooling From 3d2f66a834253c868af2a1dcb971c16ed733bdd7 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 09:55:14 +0200 Subject: [PATCH 025/173] Add missed --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index ab5f9b7a4..e15503fc1 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -527,7 +527,7 @@ async def async_update(self) -> PlugwiseData: for device_id in self.gw_devices: self.gw_devices[device_id].update(self._get_device_data(device_id)) - if " plugwise_notification" in self.gw_devices[device_id]["binary_sensors"] + if " plugwise_notification" in self.gw_devices[device_id]["binary_sensors"]: self.gw_devices[device_id]["binary_sensors"]["plugwise_notification"] = self._notifications != {} # Update for cooling From 8ebbf66cf18f816280b0867908a743b1d0a3a015 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 09:57:49 +0200 Subject: [PATCH 026/173] Correct updating for cooling --- plugwise/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index e15503fc1..550d7ee4d 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -531,8 +531,8 @@ async def async_update(self) -> PlugwiseData: self.gw_devices[device_id]["binary_sensors"]["plugwise_notification"] = self._notifications != {} # Update for cooling - if dev_dict["dev_class"] in ZONE_THERMOSTATS: - self.update_for_cooling(dev_dict) + if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: + self.update_for_cooling(self.gw_devices[device_id]) return PlugwiseData(self.gw_data, self.gw_devices) From e4f2c6f7e2ae1c1dd2f62f50302268a494970eb9 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 10:00:21 +0200 Subject: [PATCH 027/173] Remove empty platform dicts - II --- fixtures/legacy_anna/all_data.json | 21 ++++++++++++++++----- plugwise/__init__.py | 7 +++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/fixtures/legacy_anna/all_data.json b/fixtures/legacy_anna/all_data.json index 51b2e5d5f..0b82a3c21 100644 --- a/fixtures/legacy_anna/all_data.json +++ b/fixtures/legacy_anna/all_data.json @@ -1,15 +1,15 @@ { "devices": { "0000aaaa0000aaaa0000aaaa0000aa00": { - "binary_sensors": { - "plugwise_notification": false - }, + "binary_sensors": {}, "dev_class": "gateway", "firmware": "1.8.22", "location": "0000aaaa0000aaaa0000aaaa0000aa00", "mac_address": "01:23:45:67:89:AB", "model": "Gateway", "name": "Smile Anna", + "sensors": {}, + "switches": {}, "vendor": "Plugwise" }, "04e4cbfe7f4340f090f85ec3b9e6a950": { @@ -35,11 +35,15 @@ "water_pressure": 1.2, "water_temperature": 23.6 }, + "switches": {}, "vendor": "Bosch Thermotechniek B.V." }, "0d266432d64443e283b5d708ae98b455": { "active_preset": "home", - "available_schedules": ["Thermostat schedule"], + "available_schedules": [ + "Thermostat schedule" + ], + "binary_sensors": {}, "dev_class": "thermostat", "firmware": "2017-03-13T11:54:58+01:00", "hardware": "6539-1301-500", @@ -48,13 +52,20 @@ "mode": "auto", "model": "ThermoTouch", "name": "Anna", - "preset_modes": ["away", "vacation", "asleep", "home", "no_frost"], + "preset_modes": [ + "away", + "vacation", + "asleep", + "home", + "no_frost" + ], "select_schedule": "Thermostat schedule", "sensors": { "illuminance": 151, "setpoint": 20.5, "temperature": 20.4 }, + "switches": {}, "thermostat": { "lower_bound": 4.0, "resolution": 0.1, diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 550d7ee4d..848e8df9e 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -534,6 +534,13 @@ async def async_update(self) -> PlugwiseData: if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: self.update_for_cooling(self.gw_devices[device_id]) + if not self.gw_devices[device_id]["binary_sensors"]: + self.gw_devices[device_id].pop("binary_sensors") + if not self.gw_devices[device_id]["sensors"]: + self.gw_devices[device_id].pop("sensors") + if not self.gw_devices[device_id]["switches"]: + self.gw_devices[device_id].pop("switches") + return PlugwiseData(self.gw_data, self.gw_devices) async def _set_schedule_state_legacy( From aee6111bb944d22b9ab2bbbc04fd1963a9018802 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 10:06:54 +0200 Subject: [PATCH 028/173] Rework --- plugwise/__init__.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 848e8df9e..2b94378c1 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -35,9 +35,6 @@ ApplianceData, DeviceData, PlugwiseData, - SmileBinarySensors, - SmileSensors, - SmileSwitches, ) from .exceptions import ( InvalidSetupError, @@ -45,7 +42,7 @@ ResponseError, UnsupportedDeviceError, ) -from .helper import SmileComm, SmileHelper, update_helper +from .helper import SmileComm, SmileHelper class SmileData(SmileHelper): @@ -83,10 +80,14 @@ def _all_device_data(self) -> None: """ for device_id, device in self._appl_data.items(): self.gw_devices.update({device_id: device}) # type: ignore [misc] - self.gw_devices[device_id].update(self._get_device_data(device_id)) + data = self._get_device_data(device_id) # Add plugwise notification binary_sensor to the relevant gateway - if device_id == self.gateway_id and (self._is_thermostat or (not self._smile_legacy and self.smile_type == "power")): - self.gw_devices[device_id]["binary_sensors"]["plugwise_notification"] = False + if device_id == self.gateway_id and ( + self._is_thermostat + or (not self._smile_legacy and self.smile_type == "power") + ): + data["binary_sensors"]["plugwise_notification"] = False + self.gw_devices[device_id].update(data) # Update for cooling if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: @@ -526,9 +527,12 @@ async def async_update(self) -> PlugwiseData: self.gw_data["notifications"] = self._notifications for device_id in self.gw_devices: - self.gw_devices[device_id].update(self._get_device_data(device_id)) - if " plugwise_notification" in self.gw_devices[device_id]["binary_sensors"]: - self.gw_devices[device_id]["binary_sensors"]["plugwise_notification"] = self._notifications != {} + data = self._get_device_data(device_id) + if "plugwise_notification" in self.gw_devices[device_id]["binary_sensors"]: + data["binary_sensors"]["plugwise_notification"] = ( + self._notifications != {} + ) + self.gw_devices[device_id].update(data) # Update for cooling if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: From 9822e0f37bea019863df8475ac521ae12bae94be Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 10:09:17 +0200 Subject: [PATCH 029/173] Enhance logic --- plugwise/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 2b94378c1..0a8e525b4 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -528,10 +528,11 @@ async def async_update(self) -> PlugwiseData: for device_id in self.gw_devices: data = self._get_device_data(device_id) - if "plugwise_notification" in self.gw_devices[device_id]["binary_sensors"]: - data["binary_sensors"]["plugwise_notification"] = ( - self._notifications != {} - ) + if "binary_sensors" in self.gw_devices[device_id]: + if "plugwise_notification" in self.gw_devices[device_id]["binary_sensors"]: + data["binary_sensors"]["plugwise_notification"] = ( + self._notifications != {} + ) self.gw_devices[device_id].update(data) # Update for cooling From dbf15e8580b4b1765b5edc7e31d5000c71836cef Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 10:12:03 +0200 Subject: [PATCH 030/173] Fix outdoor_temperature handling --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 0a8e525b4..94555158d 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -282,7 +282,7 @@ def _get_device_data(self, dev_id: str) -> DeviceData: self._home_location, "outdoor_temperature" ) if outdoor_temperature is not None: - device_data["outdoor_temperature"] = outdoor_temperature + device_data["sensors"]["outdoor_temperature"] = outdoor_temperature # Show the allowed regulation modes if self._reg_allowed_modes: From 7937b5a9da1ea4078817bba2d98346d1f846068b Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 10:16:30 +0200 Subject: [PATCH 031/173] Fix p1 processing --- plugwise/helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index beb54f9d7..a7e70a926 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1302,7 +1302,7 @@ def _power_data_from_location(self, loc_id: str) -> DeviceData: direct_data = power_data_energy_diff( loc.measurement, loc.net_string, loc.f_val, direct_data ) - direct_data[loc.key_string] = loc.f_val # type: ignore [literal-required] + direct_data["sensors"][loc.key_string] = loc.f_val # type: ignore [literal-required] return direct_data @@ -1335,7 +1335,7 @@ def _power_data_from_modules(self) -> DeviceData: direct_data = power_data_energy_diff( loc.measurement, loc.net_string, loc.f_val, direct_data ) - direct_data[loc.key_string] = loc.f_val # type: ignore [literal-required] + direct_data["sensors"][loc.key_string] = loc.f_val # type: ignore [literal-required] return direct_data From 6119b0b42a25328f2cfe1bd4c40ed8c1a5256843 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 10:18:50 +0200 Subject: [PATCH 032/173] Fix inits --- plugwise/helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index a7e70a926..9652793ab 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1279,7 +1279,7 @@ def _power_data_from_location(self, loc_id: str) -> DeviceData: Collect the power-data based on Location ID, from LOCATIONS. """ - direct_data: DeviceData = {} + direct_data: DeviceData = {"sensors":{}} loc = Munch() log_list: list[str] = ["point_log", "cumulative_log", "interval_log"] peak_list: list[str] = ["nl_peak", "nl_offpeak"] @@ -1311,7 +1311,7 @@ def _power_data_from_modules(self) -> DeviceData: Collect the power-data from MODULES (P1 legacy only). """ - direct_data: DeviceData = {} + direct_data: DeviceData = {"sensors":{}} loc = Munch() mod_list: list[str] = ["interval_meter", "cumulative_meter", "point_meter"] peak_list: list[str] = ["nl_peak", "nl_offpeak"] From bb1e1287011b67e751037929b8b6635c1ebe3a83 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 10:21:15 +0200 Subject: [PATCH 033/173] Fix net_xyz-sensors --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 9652793ab..c325f4360 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -202,7 +202,7 @@ def power_data_energy_diff( tmp_val += float(f_val * diff) tmp_val = float(f"{round(tmp_val, 3):.3f}") - direct_data[net_string] = tmp_val # type: ignore [literal-required] + direct_data["sensors"][net_string] = tmp_val # type: ignore [literal-required] return direct_data From e44e4087674e25ca663afa78de0108e0b44a70ec Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 10:51:19 +0200 Subject: [PATCH 034/173] One more net_xyz-sensor fix --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index c325f4360..c2f4be40a 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -194,7 +194,7 @@ def power_data_energy_diff( if net_string not in direct_data: tmp_val: float | int = 0 else: - tmp_val = direct_data[net_string] # type: ignore [literal-required] + tmp_val = direct_data["sensors"][net_string] # type: ignore [literal-required] if isinstance(f_val, int): tmp_val += f_val * diff From eae2318decc65cd196f6228c23193609de5c524d Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 10:57:49 +0200 Subject: [PATCH 035/173] Fix --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index c2f4be40a..e14c7a284 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -191,7 +191,7 @@ def power_data_energy_diff( diff = 1 if "produced" in measurement: diff = -1 - if net_string not in direct_data: + if net_string not in direct_data["sensors"]: tmp_val: float | int = 0 else: tmp_val = direct_data["sensors"][net_string] # type: ignore [literal-required] From 7d0ac1b8cb106ab8e4c324e87d7d8cbf2aacf8a6 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 11:01:31 +0200 Subject: [PATCH 036/173] Toggles are switches --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index e14c7a284..e76ce8c6a 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1535,7 +1535,7 @@ def _get_toggle_state( for item in found: if (toggle_type := item.find("type")) is not None: if toggle_type.text == toggle: - data["binary_sensors"][name] = item.find("state").text == "on" # type: ignore [literal-required] + data["switches"][name] = item.find("state").text == "on" # type: ignore [literal-required] # Remove the cooling_enabled binary_sensor when the corresponding switch is present # Except for Elga if toggle == "cooling_enabled" and not self._elga: From a703a02eb7ed1a62fdf939145938054d8dc733ff Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 11:08:24 +0200 Subject: [PATCH 037/173] debug --- plugwise/helper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/helper.py b/plugwise/helper.py index e76ce8c6a..1bc401e32 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -966,6 +966,7 @@ def _get_actuator_functionalities(self, xml: etree, data: DeviceData) -> None: if item == DHW_SETPOINT: item = "max_dhw_temperature" if DHW_SETPOINT in data: + LOGGER.debug("HOI A %s", data) data.pop(DHW_SETPOINT) data[item] = temp_dict # type: ignore [literal-required] From 64f4fdc2082b0d67b5491cf3a3decb98a50afd10 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 11:10:05 +0200 Subject: [PATCH 038/173] Debug 2 --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 1bc401e32..bf480d9cc 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -929,6 +929,7 @@ def _get_appliances_with_offset_functionality(self) -> list[str]: def _get_actuator_functionalities(self, xml: etree, data: DeviceData) -> None: """Helper-function for _get_appliance_data().""" + LOGGER.debug("HOI A %s", data) for item in ACTIVE_ACTUATORS: if item == "max_dhw_temperature": continue @@ -966,7 +967,6 @@ def _get_actuator_functionalities(self, xml: etree, data: DeviceData) -> None: if item == DHW_SETPOINT: item = "max_dhw_temperature" if DHW_SETPOINT in data: - LOGGER.debug("HOI A %s", data) data.pop(DHW_SETPOINT) data[item] = temp_dict # type: ignore [literal-required] From 0c846a21ecc0bfcde02a1053ab2f63a4c2cd0d01 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 11:11:59 +0200 Subject: [PATCH 039/173] Better dhw-sensor fix --- plugwise/helper.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index bf480d9cc..b809e88bc 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -929,7 +929,6 @@ def _get_appliances_with_offset_functionality(self) -> list[str]: def _get_actuator_functionalities(self, xml: etree, data: DeviceData) -> None: """Helper-function for _get_appliance_data().""" - LOGGER.debug("HOI A %s", data) for item in ACTIVE_ACTUATORS: if item == "max_dhw_temperature": continue @@ -966,8 +965,8 @@ def _get_actuator_functionalities(self, xml: etree, data: DeviceData) -> None: # rename and remove as sensor if item == DHW_SETPOINT: item = "max_dhw_temperature" - if DHW_SETPOINT in data: - data.pop(DHW_SETPOINT) + if DHW_SETPOINT in data["sensors"]: + data["sensors"].pop(DHW_SETPOINT) data[item] = temp_dict # type: ignore [literal-required] From e02eedf3fb4c43daf2d4a07bc8d37f8430bd6e35 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 11:13:42 +0200 Subject: [PATCH 040/173] Clear debugging --- plugwise/__init__.py | 1 - plugwise/helper.py | 1 - 2 files changed, 2 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 94555158d..5cf31b5af 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -269,7 +269,6 @@ def _get_device_data(self, dev_id: str) -> DeviceData: """ details = self._appl_data[dev_id] device_data = self._get_appliance_data(dev_id) - LOGGER.debug("HOI 1 device_data: %s", device_data) # Remove thermostat-dict for thermo_sensors if details["dev_class"] == "thermo_sensor": device_data.pop("thermostat") diff --git a/plugwise/helper.py b/plugwise/helper.py index b809e88bc..d59ca2478 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1087,7 +1087,6 @@ def _get_appliance_data(self, d_id: str) -> DeviceData: self._cleanup_data(data) - LOGGER.debug("HOI 0 data: %s", data) return data def _rank_thermostat( From cfd75aab10e44ced816551c5742f1818ccc09980 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 12:26:16 +0200 Subject: [PATCH 041/173] Debug --- plugwise/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 5cf31b5af..7934f17ca 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -159,6 +159,7 @@ def _device_data_switching_group( counter = 0 for member in details["members"]: member_data = self._get_appliance_data(member) + LOGGER.debug("HOI %s", member_data) if member_data.get("relay"): counter += 1 From 8913ecbdcb87a7f40b2c4985035551a7c1f2d342 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 12:29:06 +0200 Subject: [PATCH 042/173] Fix switch-group switches --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 7934f17ca..dd3f76934 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -160,7 +160,7 @@ def _device_data_switching_group( for member in details["members"]: member_data = self._get_appliance_data(member) LOGGER.debug("HOI %s", member_data) - if member_data.get("relay"): + if member_data["switches"].get("relay"): counter += 1 device_data["switches"]["relay"] = counter != 0 From dc75b62f12be48fbba7bd42a1c408f17df1d9019 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 12:45:19 +0200 Subject: [PATCH 043/173] Fix _cleanup_data() --- plugwise/helper.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index d59ca2478..0d5fdd87e 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -993,8 +993,10 @@ def _cleanup_data(self, data: DeviceData) -> None: # but, keep cooling_enabled for Elga if not self._cooling_present: for item in ("cooling_state", "cooling_ena_switch"): - if item in data: - data.pop(item) # type: ignore [misc] + if item in data["binary_sensors"]: + data.["binary_sensors"]pop(item) # type: ignore [misc] + if item in data["switches"]: + data.["switches"]pop(item) # type: ignore [misc] if not self._elga and "cooling_enabled" in data: data.pop("cooling_enabled") # pragma: no cover From 154fc6e4c8c22e7c9fb17fa923b5044e120217ef Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 12:46:13 +0200 Subject: [PATCH 044/173] Fix typos --- plugwise/helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 0d5fdd87e..7047ce773 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -994,9 +994,9 @@ def _cleanup_data(self, data: DeviceData) -> None: if not self._cooling_present: for item in ("cooling_state", "cooling_ena_switch"): if item in data["binary_sensors"]: - data.["binary_sensors"]pop(item) # type: ignore [misc] + data["binary_sensors"].pop(item) # type: ignore [misc] if item in data["switches"]: - data.["switches"]pop(item) # type: ignore [misc] + data["switches"].pop(item) # type: ignore [misc] if not self._elga and "cooling_enabled" in data: data.pop("cooling_enabled") # pragma: no cover From e8b60a8f65a9118634c3e18fc84d61ebefb343e0 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 12:48:38 +0200 Subject: [PATCH 045/173] 2nd fix --- plugwise/helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 7047ce773..b8747ff1c 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -986,8 +986,8 @@ def _cleanup_data(self, data: DeviceData) -> None: Clean up the data dict. """ # Fix for Adam + Anna: heating_state also present under Anna, remove - if "temperature" in data: - data.pop("heating_state", None) + if "temperature" in data["binary_sensors"]: + data["binary_sensors"].pop("heating_state", None) # Don't show cooling-related when no cooling present, # but, keep cooling_enabled for Elga From 92b305e7f1862cf4d5269c4167f76a797748b9e7 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 12:51:35 +0200 Subject: [PATCH 046/173] Update _process_c_heating_state() --- plugwise/helper.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index b8747ff1c..aa57d9602 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1009,19 +1009,19 @@ def _process_c_heating_state(self, data: DeviceData) -> None: # Anna + OnOff heater: use central_heating_state to show heating_state # Solution for Core issue #81839 if self.smile_name == "Smile Anna": - data["heating_state"] = data["c_heating_state"] + data["binary_sensors"]["heating_state"] = data["c_heating_state"] # Adam + OnOff cooling: use central_heating_state to show heating/cooling_state if self.smile_name == "Adam": - data["cooling_state"] = data["heating_state"] = False + data["binary_sensors"]["cooling_state"] = data["binary_sensors"]["heating_state"] = False if self._cooling_enabled: - data["cooling_state"] = data["c_heating_state"] + data["binary_sensors"]["cooling_state"] = data["c_heating_state"] else: - data["heating_state"] = data["c_heating_state"] + data["binary_sensors"]["heating_state"] = data["c_heating_state"] # Anna + Elga: use central_heating_state to show heating_state if self._elga: - data["heating_state"] = data["c_heating_state"] + data["binary_sensors"]["heating_state"] = data["c_heating_state"] def _get_appliance_data(self, d_id: str) -> DeviceData: """Helper-function for smile.py: _get_device_data(). From af1351b2b81d2feb802f940d9e28f6936a190394 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 12:54:41 +0200 Subject: [PATCH 047/173] One more heating_state fix --- plugwise/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index dd3f76934..cd478aa6b 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -181,7 +181,9 @@ def _device_data_adam( and self._on_off_device and self._heating_valves() is not None ): - device_data["heating_state"] = self._heating_valves() != 0 + device_data["binary_sensors"]["heating_state"] = ( + self._heating_valves() != 0 + ) return device_data From 5423db4cae296bbb51f12e74081f383cd07d847e Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 12:57:27 +0200 Subject: [PATCH 048/173] Fix cooling-de/activation-sensors --- plugwise/helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index aa57d9602..2c25c8518 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -886,9 +886,9 @@ def _appliance_measurements( # Anna: save cooling-related measurements for later use # Use the local outdoor temperature as reference for turning cooling on/off if measurement == "cooling_activation_outdoor_temperature": - self._cooling_activation_outdoor_temp = data["cooling_activation_outdoor_temperature"] + self._cooling_activation_outdoor_temp = data["sensors"]["cooling_activation_outdoor_temperature"] if measurement == "cooling_deactivation_threshold": - self._cooling_deactivation_threshold = data["cooling_deactivation_threshold"] + self._cooling_deactivation_threshold = data["sensors"]["cooling_deactivation_threshold"] if measurement == "outdoor_air_temperature": self._outdoor_temp = data["sensors"]["outdoor_air_temperature"] From cd25d5bb791c91a7f5d34791353fef795a7624fe Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 13:01:48 +0200 Subject: [PATCH 049/173] Debug --- plugwise/helper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/helper.py b/plugwise/helper.py index 2c25c8518..fcbe8173c 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1005,6 +1005,7 @@ def _process_c_heating_state(self, data: DeviceData) -> None: Process the central_heating_state value. """ + LOGGER.debug("HOI data: %s", data) if self._on_off_device: # Anna + OnOff heater: use central_heating_state to show heating_state # Solution for Core issue #81839 From 9792187eb315a264f0c8de2cae6cd000944280ce Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 13:17:13 +0200 Subject: [PATCH 050/173] Debug --- plugwise/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index cd478aa6b..b733a8096 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -146,6 +146,7 @@ def get_all_devices(self) -> None: self._appl_data.update(group_data) # Collect data for each device via helper function + LOGGER.debug("HOI 0 elga: %s", self._elga) self._all_device_data() def _device_data_switching_group( From 70032f7e1abe01c17f1e62d643d9201f2fe7f355 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 13:19:07 +0200 Subject: [PATCH 051/173] Debug --- plugwise/helper.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugwise/helper.py b/plugwise/helper.py index fcbe8173c..5cf83583a 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1057,6 +1057,8 @@ def _get_appliance_data(self, d_id: str) -> DeviceData: if d_id == self.gateway_id and self.smile_name == "Adam": self._get_regulation_mode(appliance, data) + LOGGER.debug("HOI 1 elga: %s", self._elga) + LOGGER.debug("HOI 1 data: %s", data) if "c_heating_state" in data: self._process_c_heating_state(data) # Remove c_heating_state after processing From 9765ab16b7d46ba8b4eec0a6e4d0fb20707e64ed Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 13:26:23 +0200 Subject: [PATCH 052/173] Output non-platform-measurements --- plugwise/helper.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugwise/helper.py b/plugwise/helper.py index 5cf83583a..0e1c65aad 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -882,6 +882,10 @@ def _appliance_measurements( data["switches"][measurement] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) + else: + data[measurement] = format_measure( + appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) + ) # Anna: save cooling-related measurements for later use # Use the local outdoor temperature as reference for turning cooling on/off @@ -897,6 +901,8 @@ def _appliance_measurements( name = f"{measurement}_interval" data["sensors"][name] = format_measure(appl_i_loc.text, ENERGY_WATT_HOUR) # type: ignore [literal-required] + + def _wireless_availablity(self, appliance: etree, data: DeviceData) -> None: """Helper-function for _get_appliance_data(). From 9cb7d65c7eb96940a9442c118f9800637225eedb Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 13:34:48 +0200 Subject: [PATCH 053/173] Add more platform keys --- plugwise/helper.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 0e1c65aad..aca8861e3 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1074,27 +1074,27 @@ def _get_appliance_data(self, d_id: str) -> DeviceData: # Anna+Elga: base cooling_state on the elga-status-code if "elga_status_code" in data: # Determine _cooling_present and _cooling_enabled - if "cooling_enabled" in data and data["cooling_enabled"]: + if "cooling_enabled" in data["binary_sensors"] and data["binary_sensors"]["cooling_enabled"]: self._cooling_present = self._cooling_enabled = True data["model"] = "Generic heater/cooler" - data["cooling_state"] = self._cooling_active = ( + data["binary_sensors"]["cooling_state"] = self._cooling_active = ( data["elga_status_code"] == 8 ) data.pop("elga_status_code", None) # Elga has no cooling-switch - if "cooling_ena_switch" in data: - data.pop("cooling_ena_switch") + if "cooling_ena_switch" in data["switches"]: + data["switches"].pop("cooling_ena_switch") # Loria/Thermastage: cooling-related is based on cooling_state # and modulation_level else: - if self._cooling_present and "cooling_state" in data: - self._cooling_enabled = data["cooling_state"] - self._cooling_active = data["modulation_level"] == 100 + if self._cooling_present and "cooling_state" in data["binary_sensors"]: + self._cooling_enabled = data["binary_sensors"]["cooling_state"] + self._cooling_active = data["sensors"]["modulation_level"] == 100 # For Loria the above does not work (pw-beta issue #301) - if "cooling_ena_switch" in data: - self._cooling_enabled = data["cooling_ena_switch"] - self._cooling_active = data["cooling_state"] + if "cooling_ena_switch" in data["switches"]: + self._cooling_enabled = data["switches"]["cooling_ena_switch"] + self._cooling_active = data["binary_sensors"]["cooling_state"] self._cleanup_data(data) From 6860249c807ee3e3a7a60b79750307d11afc4522 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 14:58:22 +0200 Subject: [PATCH 054/173] Fix typo --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index aca8861e3..5ae507121 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1549,5 +1549,5 @@ def _get_toggle_state( # Remove the cooling_enabled binary_sensor when the corresponding switch is present # Except for Elga if toggle == "cooling_enabled" and not self._elga: - data["binary_sensor"].pop("cooling_enabled") + data["binary_sensors"].pop("cooling_enabled") From b1900ad62854e545926895a5ce84503de86e3266 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 15:00:34 +0200 Subject: [PATCH 055/173] Remove update_helper() --- plugwise/helper.py | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 5ae507121..3ad82bec4 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -85,35 +85,6 @@ def etree_to_dict(element: etree) -> dict[str, str]: return node -def update_helper( - data: DeviceData, - devices: dict[str, DeviceData], - device_dict: DeviceData, - device_id: str, - bsssw_type: str, - key: str, - notifs: dict[str, dict[str, str]], -) -> None: - """Helper-function for async_update().""" - for item in device_dict[bsssw_type]: # type: ignore [literal-required] - # Update the PW_Notification binary_sensor state - if bsssw_type == "binary_sensors" and item == "plugwise_notification": - devices[device_id][bsssw_type]["plugwise_notification"] = notifs != {} # type: ignore [literal-required] - - if item == key: - for device in devices[device_id][bsssw_type]: # type: ignore [literal-required] - if device == key: - devices[device_id][bsssw_type][device] = data[key] # type: ignore [literal-required] - - -def check_model(name: str | None, vendor_name: str | None) -> str | None: - """Model checking before using version_to_model.""" - if vendor_name == "Plugwise" and ((model := version_to_model(name)) != "Unknown"): - return model - - return name - - def schedules_temps( schedules: dict[str, dict[str, list[float]]], name: str ) -> list[float]: From c1501bdf9f0ad5d68823e7e317a42aaa1d0bde37 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 15:05:40 +0200 Subject: [PATCH 056/173] debug --- plugwise/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index b733a8096..61ce9fa50 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -531,11 +531,13 @@ async def async_update(self) -> PlugwiseData: for device_id in self.gw_devices: data = self._get_device_data(device_id) + LOGGER.debug("HOI 3 data: %s", data) if "binary_sensors" in self.gw_devices[device_id]: if "plugwise_notification" in self.gw_devices[device_id]["binary_sensors"]: data["binary_sensors"]["plugwise_notification"] = ( self._notifications != {} ) + self.gw_devices[device_id].update(data) # Update for cooling From ec3af4c46540170a9706b7eba526ffe0f724095e Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 15:07:45 +0200 Subject: [PATCH 057/173] Revert deletion of check_model() --- plugwise/helper.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugwise/helper.py b/plugwise/helper.py index 3ad82bec4..b653fabc0 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -76,6 +76,14 @@ # from typing import cast +def check_model(name: str | None, vendor_name: str | None) -> str | None: + """Model checking before using version_to_model.""" + if vendor_name == "Plugwise" and ((model := version_to_model(name)) != "Unknown"): + return model + + return name + + def etree_to_dict(element: etree) -> dict[str, str]: """Helper-function translating xml Element to dict.""" node: dict[str, str] = {} From 0aff2cd5f679d49c88b49e6fe71320e2d527c836 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 15:10:07 +0200 Subject: [PATCH 058/173] Correct plugwise_notification assert --- tests/test_smile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_smile.py b/tests/test_smile.py index 12f3efbba..8f6f0bf22 100644 --- a/tests/test_smile.py +++ b/tests/test_smile.py @@ -5066,7 +5066,7 @@ async def test_connect_p1v4(self): "model": "Gateway", "name": "Smile P1", "vendor": "Plugwise", - "binary_sensors": {"plugwise_notification": False}, + "binary_sensors": {"plugwise_notification": True}, }, "ba4de7613517478da82dd9b6abea36af": { "dev_class": "smartmeter", From 41aa4988c4ef1753ba1f2a491de1278aacf64ab3 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 15:14:24 +0200 Subject: [PATCH 059/173] Clean up unused imports --- plugwise/helper.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index b653fabc0..fda56d424 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -55,9 +55,6 @@ DeviceData, GatewayData, ModelData, - SmileBinarySensors, - SmileSensors, - SmileSwitches, ThermoLoc, ) from .exceptions import ( From 2066ad4fa6ac0ca57d4c2fdabfbe286ebdd02a04 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 15:15:13 +0200 Subject: [PATCH 060/173] Ruffed --- plugwise/helper.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index fda56d424..4715ef9f5 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -866,9 +866,13 @@ def _appliance_measurements( # Anna: save cooling-related measurements for later use # Use the local outdoor temperature as reference for turning cooling on/off if measurement == "cooling_activation_outdoor_temperature": - self._cooling_activation_outdoor_temp = data["sensors"]["cooling_activation_outdoor_temperature"] + self._cooling_activation_outdoor_temp = data["sensors"][ + "cooling_activation_outdoor_temperature" + ] if measurement == "cooling_deactivation_threshold": - self._cooling_deactivation_threshold = data["sensors"]["cooling_deactivation_threshold"] + self._cooling_deactivation_threshold = data["sensors"][ + "cooling_deactivation_threshold" + ] if measurement == "outdoor_air_temperature": self._outdoor_temp = data["sensors"]["outdoor_air_temperature"] @@ -877,8 +881,6 @@ def _appliance_measurements( name = f"{measurement}_interval" data["sensors"][name] = format_measure(appl_i_loc.text, ENERGY_WATT_HOUR) # type: ignore [literal-required] - - def _wireless_availablity(self, appliance: etree, data: DeviceData) -> None: """Helper-function for _get_appliance_data(). @@ -996,7 +998,9 @@ def _process_c_heating_state(self, data: DeviceData) -> None: # Adam + OnOff cooling: use central_heating_state to show heating/cooling_state if self.smile_name == "Adam": - data["binary_sensors"]["cooling_state"] = data["binary_sensors"]["heating_state"] = False + data["binary_sensors"]["cooling_state"] = data["binary_sensors"][ + "heating_state" + ] = False if self._cooling_enabled: data["binary_sensors"]["cooling_state"] = data["c_heating_state"] else: @@ -1050,7 +1054,10 @@ def _get_appliance_data(self, d_id: str) -> DeviceData: # Anna+Elga: base cooling_state on the elga-status-code if "elga_status_code" in data: # Determine _cooling_present and _cooling_enabled - if "cooling_enabled" in data["binary_sensors"] and data["binary_sensors"]["cooling_enabled"]: + if ( + "cooling_enabled" in data["binary_sensors"] + and data["binary_sensors"]["cooling_enabled"] + ): self._cooling_present = self._cooling_enabled = True data["model"] = "Generic heater/cooler" data["binary_sensors"]["cooling_state"] = self._cooling_active = ( @@ -1265,7 +1272,7 @@ def _power_data_from_location(self, loc_id: str) -> DeviceData: Collect the power-data based on Location ID, from LOCATIONS. """ - direct_data: DeviceData = {"sensors":{}} + direct_data: DeviceData = {"sensors": {}} loc = Munch() log_list: list[str] = ["point_log", "cumulative_log", "interval_log"] peak_list: list[str] = ["nl_peak", "nl_offpeak"] @@ -1297,7 +1304,7 @@ def _power_data_from_modules(self) -> DeviceData: Collect the power-data from MODULES (P1 legacy only). """ - direct_data: DeviceData = {"sensors":{}} + direct_data: DeviceData = {"sensors": {}} loc = Munch() mod_list: list[str] = ["interval_meter", "cumulative_meter", "point_meter"] peak_list: list[str] = ["nl_peak", "nl_offpeak"] @@ -1526,4 +1533,3 @@ def _get_toggle_state( # Except for Elga if toggle == "cooling_enabled" and not self._elga: data["binary_sensors"].pop("cooling_enabled") - From d2ad42db6c0e063c0efb3a33d2da0a54506f71eb Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 15:17:14 +0200 Subject: [PATCH 061/173] pylinted --- plugwise/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 61ce9fa50..5171afe80 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -182,9 +182,7 @@ def _device_data_adam( and self._on_off_device and self._heating_valves() is not None ): - device_data["binary_sensors"]["heating_state"] = ( - self._heating_valves() != 0 - ) + device_data["binary_sensors"]["heating_state"] = self._heating_valves() != 0 return device_data @@ -533,7 +531,10 @@ async def async_update(self) -> PlugwiseData: data = self._get_device_data(device_id) LOGGER.debug("HOI 3 data: %s", data) if "binary_sensors" in self.gw_devices[device_id]: - if "plugwise_notification" in self.gw_devices[device_id]["binary_sensors"]: + if ( + "plugwise_notification" + in self.gw_devices[device_id]["binary_sensors"] + ): data["binary_sensors"]["plugwise_notification"] = ( self._notifications != {} ) From 0aee5b677d9f618a19009f9f6415fa9aebee4416 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 15:24:46 +0200 Subject: [PATCH 062/173] Correct relevant test-fixtures --- fixtures/legacy_anna/all_data.json | 9 +++------ fixtures/p1v4/all_data.json | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/fixtures/legacy_anna/all_data.json b/fixtures/legacy_anna/all_data.json index 0b82a3c21..e72f44f5f 100644 --- a/fixtures/legacy_anna/all_data.json +++ b/fixtures/legacy_anna/all_data.json @@ -1,15 +1,15 @@ { "devices": { "0000aaaa0000aaaa0000aaaa0000aa00": { - "binary_sensors": {}, + "binary_sensors": { + "plugwise_notification": false + }, "dev_class": "gateway", "firmware": "1.8.22", "location": "0000aaaa0000aaaa0000aaaa0000aa00", "mac_address": "01:23:45:67:89:AB", "model": "Gateway", "name": "Smile Anna", - "sensors": {}, - "switches": {}, "vendor": "Plugwise" }, "04e4cbfe7f4340f090f85ec3b9e6a950": { @@ -35,7 +35,6 @@ "water_pressure": 1.2, "water_temperature": 23.6 }, - "switches": {}, "vendor": "Bosch Thermotechniek B.V." }, "0d266432d64443e283b5d708ae98b455": { @@ -43,7 +42,6 @@ "available_schedules": [ "Thermostat schedule" ], - "binary_sensors": {}, "dev_class": "thermostat", "firmware": "2017-03-13T11:54:58+01:00", "hardware": "6539-1301-500", @@ -65,7 +63,6 @@ "setpoint": 20.5, "temperature": 20.4 }, - "switches": {}, "thermostat": { "lower_bound": 4.0, "resolution": 0.1, diff --git a/fixtures/p1v4/all_data.json b/fixtures/p1v4/all_data.json index a813743fd..a20a11a0a 100644 --- a/fixtures/p1v4/all_data.json +++ b/fixtures/p1v4/all_data.json @@ -2,7 +2,7 @@ "devices": { "a455b61e52394b2db5081ce025a430f3": { "binary_sensors": { - "plugwise_notification": false + "plugwise_notification": true }, "dev_class": "gateway", "firmware": "4.1.1", From 2ff963c27765b8dc2fb0366a26caebfec35992cd Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 15:26:29 +0200 Subject: [PATCH 063/173] Pylint suggestions --- plugwise/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 5171afe80..bafc05913 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -527,7 +527,7 @@ async def async_update(self) -> PlugwiseData: self.gw_data["notifications"] = self._notifications - for device_id in self.gw_devices: + for device_id in self.gw_devices.items(): data = self._get_device_data(device_id) LOGGER.debug("HOI 3 data: %s", data) if "binary_sensors" in self.gw_devices[device_id]: @@ -536,7 +536,7 @@ async def async_update(self) -> PlugwiseData: in self.gw_devices[device_id]["binary_sensors"] ): data["binary_sensors"]["plugwise_notification"] = ( - self._notifications != {} + bool(self._notifications) ) self.gw_devices[device_id].update(data) From 20cfc80275df82e68ecbf1d2b3005802eab25277 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 15:28:41 +0200 Subject: [PATCH 064/173] Try --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index bafc05913..53f6c46cf 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -527,7 +527,7 @@ async def async_update(self) -> PlugwiseData: self.gw_data["notifications"] = self._notifications - for device_id in self.gw_devices.items(): + for device_id, _ in self.gw_devices.items(): data = self._get_device_data(device_id) LOGGER.debug("HOI 3 data: %s", data) if "binary_sensors" in self.gw_devices[device_id]: From 138d8f999f467e4259d297887a7ef89dcb8d05cd Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 15:29:15 +0200 Subject: [PATCH 065/173] Ruffed --- fixtures/stretch_v31/all_data.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fixtures/stretch_v31/all_data.json b/fixtures/stretch_v31/all_data.json index c336a9cb9..ccd8fc883 100644 --- a/fixtures/stretch_v31/all_data.json +++ b/fixtures/stretch_v31/all_data.json @@ -50,7 +50,9 @@ }, "71e1944f2a944b26ad73323e399efef0": { "dev_class": "switching", - "members": ["5ca521ac179d468e91d772eeeb8a2117"], + "members": [ + "5ca521ac179d468e91d772eeeb8a2117" + ], "model": "Switchgroup", "name": "Test", "switches": { From d86ff468e14d27322b3c4358f7e752892bc95e2d Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 15:33:33 +0200 Subject: [PATCH 066/173] Implement pylint suggestions --- plugwise/__init__.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 53f6c46cf..41b0ac022 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -527,30 +527,30 @@ async def async_update(self) -> PlugwiseData: self.gw_data["notifications"] = self._notifications - for device_id, _ in self.gw_devices.items(): + for device_id, device in self.gw_devices.items(): data = self._get_device_data(device_id) LOGGER.debug("HOI 3 data: %s", data) - if "binary_sensors" in self.gw_devices[device_id]: + if "binary_sensors" in device: if ( "plugwise_notification" - in self.gw_devices[device_id]["binary_sensors"] + in device["binary_sensors"] ): - data["binary_sensors"]["plugwise_notification"] = ( - bool(self._notifications) + data["binary_sensors"]["plugwise_notification"] = bool( + self._notifications ) - self.gw_devices[device_id].update(data) + device.update(data) # Update for cooling - if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: - self.update_for_cooling(self.gw_devices[device_id]) - - if not self.gw_devices[device_id]["binary_sensors"]: - self.gw_devices[device_id].pop("binary_sensors") - if not self.gw_devices[device_id]["sensors"]: - self.gw_devices[device_id].pop("sensors") - if not self.gw_devices[device_id]["switches"]: - self.gw_devices[device_id].pop("switches") + if device["dev_class"] in ZONE_THERMOSTATS: + self.update_for_cooling(device) + + if not device["binary_sensors"]: + device.pop("binary_sensors") + if not device["sensors"]: + device.pop("sensors") + if not device["switches"]: + device.pop("switches") return PlugwiseData(self.gw_data, self.gw_devices) From 8c9d1ca1641d9dad0b2da88cf886875bb4fee25e Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 19 Aug 2023 15:35:06 +0200 Subject: [PATCH 067/173] More fixes --- fixtures/legacy_anna/all_data.json | 12 ++---------- fixtures/stretch_v31/all_data.json | 4 +--- plugwise/__init__.py | 5 +---- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/fixtures/legacy_anna/all_data.json b/fixtures/legacy_anna/all_data.json index e72f44f5f..51b2e5d5f 100644 --- a/fixtures/legacy_anna/all_data.json +++ b/fixtures/legacy_anna/all_data.json @@ -39,9 +39,7 @@ }, "0d266432d64443e283b5d708ae98b455": { "active_preset": "home", - "available_schedules": [ - "Thermostat schedule" - ], + "available_schedules": ["Thermostat schedule"], "dev_class": "thermostat", "firmware": "2017-03-13T11:54:58+01:00", "hardware": "6539-1301-500", @@ -50,13 +48,7 @@ "mode": "auto", "model": "ThermoTouch", "name": "Anna", - "preset_modes": [ - "away", - "vacation", - "asleep", - "home", - "no_frost" - ], + "preset_modes": ["away", "vacation", "asleep", "home", "no_frost"], "select_schedule": "Thermostat schedule", "sensors": { "illuminance": 151, diff --git a/fixtures/stretch_v31/all_data.json b/fixtures/stretch_v31/all_data.json index ccd8fc883..c336a9cb9 100644 --- a/fixtures/stretch_v31/all_data.json +++ b/fixtures/stretch_v31/all_data.json @@ -50,9 +50,7 @@ }, "71e1944f2a944b26ad73323e399efef0": { "dev_class": "switching", - "members": [ - "5ca521ac179d468e91d772eeeb8a2117" - ], + "members": ["5ca521ac179d468e91d772eeeb8a2117"], "model": "Switchgroup", "name": "Test", "switches": { diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 41b0ac022..9cd87c37f 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -531,10 +531,7 @@ async def async_update(self) -> PlugwiseData: data = self._get_device_data(device_id) LOGGER.debug("HOI 3 data: %s", data) if "binary_sensors" in device: - if ( - "plugwise_notification" - in device["binary_sensors"] - ): + if "plugwise_notification" in device["binary_sensors"]: data["binary_sensors"]["plugwise_notification"] = bool( self._notifications ) From 99c2c9fdc4f79a198430ea4c944599e3efe5d35a Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sun, 20 Aug 2023 10:50:46 +0200 Subject: [PATCH 068/173] Remove debugging, improve --- plugwise/__init__.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 9cd87c37f..bb9e32c91 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -78,7 +78,7 @@ def _all_device_data(self) -> None: Collect initial data for each device and add to self.gw_data and self.gw_devices. """ - for device_id, device in self._appl_data.items(): + for device_id, _ in self._appl_data.items(): self.gw_devices.update({device_id: device}) # type: ignore [misc] data = self._get_device_data(device_id) # Add plugwise notification binary_sensor to the relevant gateway @@ -93,12 +93,9 @@ def _all_device_data(self) -> None: if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: self.update_for_cooling(self.gw_devices[device_id]) - if not self.gw_devices[device_id]["binary_sensors"]: - self.gw_devices[device_id].pop("binary_sensors") - if not self.gw_devices[device_id]["sensors"]: - self.gw_devices[device_id].pop("sensors") - if not self.gw_devices[device_id]["switches"]: - self.gw_devices[device_id].pop("switches") + for platform in ("binary_sensors", "sensors", "switches"): + if not self.gw_devices[device_id][platform]: + self.gw_devices[device_id].pop(platform) self.gw_data.update( {"smile_name": self.smile_name, "gateway_id": self.gateway_id} @@ -146,7 +143,6 @@ def get_all_devices(self) -> None: self._appl_data.update(group_data) # Collect data for each device via helper function - LOGGER.debug("HOI 0 elga: %s", self._elga) self._all_device_data() def _device_data_switching_group( @@ -160,7 +156,6 @@ def _device_data_switching_group( counter = 0 for member in details["members"]: member_data = self._get_appliance_data(member) - LOGGER.debug("HOI %s", member_data) if member_data["switches"].get("relay"): counter += 1 @@ -529,7 +524,6 @@ async def async_update(self) -> PlugwiseData: for device_id, device in self.gw_devices.items(): data = self._get_device_data(device_id) - LOGGER.debug("HOI 3 data: %s", data) if "binary_sensors" in device: if "plugwise_notification" in device["binary_sensors"]: data["binary_sensors"]["plugwise_notification"] = bool( @@ -542,12 +536,9 @@ async def async_update(self) -> PlugwiseData: if device["dev_class"] in ZONE_THERMOSTATS: self.update_for_cooling(device) - if not device["binary_sensors"]: - device.pop("binary_sensors") - if not device["sensors"]: - device.pop("sensors") - if not device["switches"]: - device.pop("switches") + for platform in ("binary_sensors", "sensors", "switches"): + if not device[platform]: + device.pop(platform) return PlugwiseData(self.gw_data, self.gw_devices) From a46ef2a80fb82f4a0f014dabc83eadcb4b8b9567 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sun, 20 Aug 2023 10:51:57 +0200 Subject: [PATCH 069/173] Fix --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index bb9e32c91..db2fcd8f1 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -78,7 +78,7 @@ def _all_device_data(self) -> None: Collect initial data for each device and add to self.gw_data and self.gw_devices. """ - for device_id, _ in self._appl_data.items(): + for device_id, device in self._appl_data.items(): self.gw_devices.update({device_id: device}) # type: ignore [misc] data = self._get_device_data(device_id) # Add plugwise notification binary_sensor to the relevant gateway From dafd870fd0966a094214eda682b0ccbda3a52732 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sun, 20 Aug 2023 11:22:25 +0200 Subject: [PATCH 070/173] Remove unneeded type-ignore --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index db2fcd8f1..a12ae352a 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -79,7 +79,7 @@ def _all_device_data(self) -> None: Collect initial data for each device and add to self.gw_data and self.gw_devices. """ for device_id, device in self._appl_data.items(): - self.gw_devices.update({device_id: device}) # type: ignore [misc] + self.gw_devices.update({device_id: device}) data = self._get_device_data(device_id) # Add plugwise notification binary_sensor to the relevant gateway if device_id == self.gateway_id and ( From cf0c7b07ce9978e694a2f2df31ed213f6cd86c75 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sun, 20 Aug 2023 15:08:47 +0200 Subject: [PATCH 071/173] Revert improvements --- plugwise/__init__.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index a12ae352a..4db116f63 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -93,9 +93,12 @@ def _all_device_data(self) -> None: if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: self.update_for_cooling(self.gw_devices[device_id]) - for platform in ("binary_sensors", "sensors", "switches"): - if not self.gw_devices[device_id][platform]: - self.gw_devices[device_id].pop(platform) + if not self.gw_devices[device_id]["binary_sensors"]: + self.gw_devices[device_id].pop("binary_sensors") + if not self.gw_devices[device_id]["sensors"]: + self.gw_devices[device_id].pop("sensors") + if not self.gw_devices[device_id]["switches"]: + self.gw_devices[device_id].pop("switches") self.gw_data.update( {"smile_name": self.smile_name, "gateway_id": self.gateway_id} @@ -536,9 +539,12 @@ async def async_update(self) -> PlugwiseData: if device["dev_class"] in ZONE_THERMOSTATS: self.update_for_cooling(device) - for platform in ("binary_sensors", "sensors", "switches"): - if not device[platform]: - device.pop(platform) + if not device["binary_sensors"]: + device.pop("binary_sensors") + if not device["sensors"]: + device.pop("sensors") + if not device["switches"]: + device.pop("switches") return PlugwiseData(self.gw_data, self.gw_devices) From f80d512e3f3723ad11ed9dee5fd1683c7afdeb09 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 18:53:03 +0200 Subject: [PATCH 072/173] Try --- plugwise/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 4db116f63..b9ccfebe6 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -6,6 +6,7 @@ import aiohttp from defusedxml import ElementTree as etree +from typing import cast # Dict as class from munch import Munch @@ -79,7 +80,7 @@ def _all_device_data(self) -> None: Collect initial data for each device and add to self.gw_data and self.gw_devices. """ for device_id, device in self._appl_data.items(): - self.gw_devices.update({device_id: device}) + self.gw_devices.update({device_id: cast(device, DeviceData)}) data = self._get_device_data(device_id) # Add plugwise notification binary_sensor to the relevant gateway if device_id == self.gateway_id and ( From 745b568189b97c14b80e5b7f75139d1e615714ed Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 18:55:21 +0200 Subject: [PATCH 073/173] Switch --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index b9ccfebe6..0be09acaa 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -80,7 +80,7 @@ def _all_device_data(self) -> None: Collect initial data for each device and add to self.gw_data and self.gw_devices. """ for device_id, device in self._appl_data.items(): - self.gw_devices.update({device_id: cast(device, DeviceData)}) + self.gw_devices.update({device_id: cast(DeviceData, device)}) data = self._get_device_data(device_id) # Add plugwise notification binary_sensor to the relevant gateway if device_id == self.gateway_id and ( From 37aa762d1e0bf8b9facaa9d9a1aea14dab6c826b Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:03:52 +0200 Subject: [PATCH 074/173] Add MeasurementType to constants --- plugwise/constants.py | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/plugwise/constants.py b/plugwise/constants.py index f991e46ea..a092a395f 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -260,6 +260,52 @@ ] BINARY_SENSORS: Final[tuple[str, ...]] = get_args(BinarySensorType) +MeasurementType = Literal[ + "electricity_consumed", + "electricity_produced", + "electricity_phase_one_consumed", + "electricity_phase_two_consumed", + "electricity_phase_three_consumed", + "electricity_phase_one_produced", + "electricity_phase_two_produced", + "electricity_phase_three_produced", + "gas_consumed", + "voltage_phase_one", + "voltage_phase_two", + "voltage_phase_three", + "temperature", + "thermostat", + "illuminance", + "cooling_activation_outdoor_temperature", + "cooling_deactivation_threshold", + "battery", + "temperature_difference", + "valve_position", + "humidity", + "relay", + "boiler_temperature", + "domestic_hot_water_mode", + "domestic_hot_water_setpoint", + "domestic_hot_water_state", + "domestic_hot_water_temperature", + "elga_status_code", + "intended_boiler_temperature", + "central_heating_state", + "intended_central_heating_state", + "maximum_boiler_temperature", + "modulation_level", + "return_water_temperature", + "compressor_state", + "cooling_state", + "cooling_enabled", + "slave_boiler_state", + "flame_state", + "central_heater_water_pressure", + "boiler_state", + "intended_boiler_state", + "outdoor_temperature", +] + NumberType = Literal[ "maximum_boiler_temperature", "max_dhw_temperature", From 32ecfd1c7efff55c39fadea470ff609dbdcf6959 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:04:57 +0200 Subject: [PATCH 075/173] Implement --- plugwise/helper.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugwise/helper.py b/plugwise/helper.py index 4715ef9f5..aca41a075 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -54,6 +54,7 @@ ApplianceData, DeviceData, GatewayData, + MeasurementType, ModelData, ThermoLoc, ) @@ -826,6 +827,7 @@ def _appliance_measurements( measurements: dict[str, DATA | UOM], ) -> None: """Helper-function for _get_appliance_data() - collect appliance measurement data.""" + measurement: MeasurementType for measurement, attrs in measurements.items(): p_locator = f'.//logs/point_log[type="{measurement}"]/period/measurement' if (appl_p_loc := appliance.find(p_locator)) is not None: From dbaffd4b6a148faede0903de6b0ce0f1846b4a27 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:06:25 +0200 Subject: [PATCH 076/173] 2nd Try --- plugwise/helper.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index aca41a075..6edc12362 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -824,10 +824,9 @@ def _appliance_measurements( self, appliance: etree, data: DeviceData, - measurements: dict[str, DATA | UOM], + measurements: dict[MeasurementType, DATA | UOM], ) -> None: """Helper-function for _get_appliance_data() - collect appliance measurement data.""" - measurement: MeasurementType for measurement, attrs in measurements.items(): p_locator = f'.//logs/point_log[type="{measurement}"]/period/measurement' if (appl_p_loc := appliance.find(p_locator)) is not None: From 9e6ebb74d1c70bcb4039d20303da5544279db34a Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:11:06 +0200 Subject: [PATCH 077/173] Try 3 --- plugwise/helper.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 6edc12362..ad1f8460e 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -52,10 +52,13 @@ UOM, ActuatorData, ApplianceData, + BinarySensorType, DeviceData, GatewayData, MeasurementType, ModelData, + SensorType, + SwitchType ThermoLoc, ) from .exceptions import ( @@ -824,7 +827,7 @@ def _appliance_measurements( self, appliance: etree, data: DeviceData, - measurements: dict[MeasurementType, DATA | UOM], + measurements: dict[MeasurementType | BinarySensorType | SensorType | SwitchType, DATA | UOM], ) -> None: """Helper-function for _get_appliance_data() - collect appliance measurement data.""" for measurement, attrs in measurements.items(): From ddfaa070f8956d4870e043c247ea584157eb0141 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:11:38 +0200 Subject: [PATCH 078/173] Fix --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index ad1f8460e..02fe50431 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -58,7 +58,7 @@ MeasurementType, ModelData, SensorType, - SwitchType + SwitchType, ThermoLoc, ) from .exceptions import ( From 853cd77a8f7629978ec2a59ee8b5ea9df2baccb4 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:13:06 +0200 Subject: [PATCH 079/173] Try 4 --- plugwise/helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 02fe50431..c4d323da5 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -827,7 +827,7 @@ def _appliance_measurements( self, appliance: etree, data: DeviceData, - measurements: dict[MeasurementType | BinarySensorType | SensorType | SwitchType, DATA | UOM], + measurements: dict[MeasurementType, DATA | UOM], ) -> None: """Helper-function for _get_appliance_data() - collect appliance measurement data.""" for measurement, attrs in measurements.items(): @@ -845,7 +845,7 @@ def _appliance_measurements( continue if new_name := getattr(attrs, ATTR_NAME, None): - measurement = new_name + measurement: BinarySensorType | SensorType | SwitchType = new_name # measurements with states "on" or "off" that need to be passed directly if measurement == "select_dhw_mode": From d0d5d3163ab0cca9c79a797ffbafd1261144e7f7 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:16:00 +0200 Subject: [PATCH 080/173] Try 5 --- plugwise/helper.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index c4d323da5..2fe27b30c 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -844,14 +844,15 @@ def _appliance_measurements( ): continue + meas_2: MeasurementType | BinarySensorType | SensorType | SwitchTyp = measurement if new_name := getattr(attrs, ATTR_NAME, None): - measurement: BinarySensorType | SensorType | SwitchType = new_name + meas_2: MeasurementType | BinarySensorType | SensorType | SwitchType = new_name # measurements with states "on" or "off" that need to be passed directly - if measurement == "select_dhw_mode": + if meas_2 == "select_dhw_mode": data["select_dhw_mode"] = appl_p_loc.text - elif measurement in BINARY_SENSORS: - data["binary_sensors"][measurement] = format_measure( + elif meas_2 in BINARY_SENSORS: + data["binary_sensors"][meas_2] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) elif measurement in SENSORS: From 65ca136f3be4e28d098ea4f9d69d355c963eebe8 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:17:28 +0200 Subject: [PATCH 081/173] Try 6 --- plugwise/helper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 2fe27b30c..d7314be29 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -844,9 +844,9 @@ def _appliance_measurements( ): continue - meas_2: MeasurementType | BinarySensorType | SensorType | SwitchTyp = measurement - if new_name := getattr(attrs, ATTR_NAME, None): - meas_2: MeasurementType | BinarySensorType | SensorType | SwitchType = new_name + meas_2: MeasurementType | BinarySensorType | SensorType | SwitchType = measurement + if new_name: MeasurementType | BinarySensorType | SensorType | SwitchType := getattr(attrs, ATTR_NAME, None): + meas_2 = new_name # measurements with states "on" or "off" that need to be passed directly if meas_2 == "select_dhw_mode": From 3de134c0b28d792441363ccfc66f0c1cfe8aa6ab Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:18:31 +0200 Subject: [PATCH 082/173] Try 7 --- plugwise/helper.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index d7314be29..fd27b3256 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -845,7 +845,8 @@ def _appliance_measurements( continue meas_2: MeasurementType | BinarySensorType | SensorType | SwitchType = measurement - if new_name: MeasurementType | BinarySensorType | SensorType | SwitchType := getattr(attrs, ATTR_NAME, None): + new_name: MeasurementType | BinarySensorType | SensorType | SwitchType + if new_name := getattr(attrs, ATTR_NAME, None): meas_2 = new_name # measurements with states "on" or "off" that need to be passed directly From f7acfe0b18afee21ab1a4d3f140905adc48fa181 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:20:14 +0200 Subject: [PATCH 083/173] Try 8 --- plugwise/helper.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index fd27b3256..521229b79 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -845,9 +845,8 @@ def _appliance_measurements( continue meas_2: MeasurementType | BinarySensorType | SensorType | SwitchType = measurement - new_name: MeasurementType | BinarySensorType | SensorType | SwitchType if new_name := getattr(attrs, ATTR_NAME, None): - meas_2 = new_name + cast(MeasurementType | BinarySensorType | SensorType | SwitchType, meas_2) = new_name # measurements with states "on" or "off" that need to be passed directly if meas_2 == "select_dhw_mode": From 781e4f34040eb16d15eb2dadc5af88a8b8684a06 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:21:10 +0200 Subject: [PATCH 084/173] try 9 --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 521229b79..3fc672079 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -846,7 +846,7 @@ def _appliance_measurements( meas_2: MeasurementType | BinarySensorType | SensorType | SwitchType = measurement if new_name := getattr(attrs, ATTR_NAME, None): - cast(MeasurementType | BinarySensorType | SensorType | SwitchType, meas_2) = new_name + meas_2 = cast(MeasurementType | BinarySensorType | SensorType | SwitchType, new_name) # measurements with states "on" or "off" that need to be passed directly if meas_2 == "select_dhw_mode": From 6100ead717f2748ea846174ce566c5640b06ec51 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:21:41 +0200 Subject: [PATCH 085/173] Try 10 --- plugwise/helper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/helper.py b/plugwise/helper.py index 3fc672079..ac70e41ea 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -6,6 +6,7 @@ import asyncio import datetime as dt +from typing import cast # This way of importing aiohttp is because of patch/mocking in testing (aiohttp timeouts) from aiohttp import BasicAuth, ClientError, ClientResponse, ClientSession, ClientTimeout From 321cfd58b55b8ac178a1d94c0f1a738bab063268 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:23:51 +0200 Subject: [PATCH 086/173] Add SelectType --- plugwise/helper.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index ac70e41ea..e5e9c2ff3 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -58,6 +58,7 @@ GatewayData, MeasurementType, ModelData, + SelectType, SensorType, SwitchType, ThermoLoc, @@ -845,9 +846,9 @@ def _appliance_measurements( ): continue - meas_2: MeasurementType | BinarySensorType | SensorType | SwitchType = measurement + meas_2: MeasurementType | BinarySensorType | SelectType |SensorType | SwitchType = measurement if new_name := getattr(attrs, ATTR_NAME, None): - meas_2 = cast(MeasurementType | BinarySensorType | SensorType | SwitchType, new_name) + meas_2 = cast(MeasurementType | BinarySensorType | SelectType | SensorType | SwitchType, new_name) # measurements with states "on" or "off" that need to be passed directly if meas_2 == "select_dhw_mode": From adc50b4e28dc4b6d7bc6b4b640f4788f3e4beca9 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:34:12 +0200 Subject: [PATCH 087/173] Try11 --- plugwise/helper.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index e5e9c2ff3..04eba1b22 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -846,7 +846,7 @@ def _appliance_measurements( ): continue - meas_2: MeasurementType | BinarySensorType | SelectType |SensorType | SwitchType = measurement + meas_2: MeasurementType | BinarySensorType | SelectType | SensorType | SwitchType = measurement if new_name := getattr(attrs, ATTR_NAME, None): meas_2 = cast(MeasurementType | BinarySensorType | SelectType | SensorType | SwitchType, new_name) @@ -857,30 +857,30 @@ def _appliance_measurements( data["binary_sensors"][meas_2] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) - elif measurement in SENSORS: - data["sensors"][measurement] = format_measure( + elif meas_2 in SENSORS: + data["sensors"][meas_2] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) - elif measurement in SWITCHES: - data["switches"][measurement] = format_measure( + elif meas_2 in SWITCHES: + data["switches"][meas_2] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) else: - data[measurement] = format_measure( + data[meas_2] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) # Anna: save cooling-related measurements for later use # Use the local outdoor temperature as reference for turning cooling on/off - if measurement == "cooling_activation_outdoor_temperature": + if meas_2 == "cooling_activation_outdoor_temperature": self._cooling_activation_outdoor_temp = data["sensors"][ "cooling_activation_outdoor_temperature" ] - if measurement == "cooling_deactivation_threshold": + if meas_2 == "cooling_deactivation_threshold": self._cooling_deactivation_threshold = data["sensors"][ "cooling_deactivation_threshold" ] - if measurement == "outdoor_air_temperature": + if meas_2 == "outdoor_air_temperature": self._outdoor_temp = data["sensors"]["outdoor_air_temperature"] i_locator = f'.//logs/interval_log[type="{measurement}"]/period/measurement' From 891d1f05167bea7f58db8f08846544e5c5f816c4 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:36:38 +0200 Subject: [PATCH 088/173] Replace str- by MeasurementType-typing --- plugwise/constants.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugwise/constants.py b/plugwise/constants.py index a092a395f..bdfa36c28 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -143,7 +143,7 @@ UOM = namedtuple("UOM", "unit_of_measurement") DATA = namedtuple("DATA", "name unit_of_measurement") # P1 related measurements: -P1_MEASUREMENTS: Final[dict[str, UOM]] = { +P1_MEASUREMENTS: Final[dict[MeasurementType, UOM]] = { "electricity_consumed": UOM(POWER_WATT), "electricity_produced": UOM(POWER_WATT), "electricity_phase_one_consumed": UOM(POWER_WATT), @@ -157,7 +157,7 @@ "voltage_phase_two": UOM(ELECTRIC_POTENTIAL_VOLT), "voltage_phase_three": UOM(ELECTRIC_POTENTIAL_VOLT), } -P1_LEGACY_MEASUREMENTS: Final[dict[str, UOM]] = { +P1_LEGACY_MEASUREMENTS: Final[dict[MeasurementType, UOM]] = { "electricity_consumed": UOM(POWER_WATT), "electricity_produced": UOM(POWER_WATT), "gas_consumed": UOM(VOLUME_CUBIC_METERS), @@ -167,7 +167,7 @@ # zone_thermosstat: 'temperature_offset' # radiator_valve: 'uncorrected_temperature', 'temperature_offset' -DEVICE_MEASUREMENTS: Final[dict[str, DATA | UOM]] = { +DEVICE_MEASUREMENTS: Final[dict[MeasurementType, DATA | UOM]] = { # HA Core thermostat current_temperature "temperature": UOM(TEMP_CELSIUS), # HA Core thermostat setpoint @@ -190,7 +190,7 @@ } # Heater Central related measurements -HEATER_CENTRAL_MEASUREMENTS: Final[dict[str, DATA | UOM]] = { +HEATER_CENTRAL_MEASUREMENTS: Final[dict[MeasurementType, DATA | UOM]] = { "boiler_temperature": DATA("water_temperature", TEMP_CELSIUS), "domestic_hot_water_mode": DATA("select_dhw_mode", NONE), "domestic_hot_water_setpoint": UOM(TEMP_CELSIUS), From 1d6b62611e1a1b8acf5f43d1e95fa6d59910c9ac Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:56:33 +0200 Subject: [PATCH 089/173] Shorten MeasurementType list --- plugwise/constants.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/plugwise/constants.py b/plugwise/constants.py index bdfa36c28..204eac73a 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -261,18 +261,6 @@ BINARY_SENSORS: Final[tuple[str, ...]] = get_args(BinarySensorType) MeasurementType = Literal[ - "electricity_consumed", - "electricity_produced", - "electricity_phase_one_consumed", - "electricity_phase_two_consumed", - "electricity_phase_three_consumed", - "electricity_phase_one_produced", - "electricity_phase_two_produced", - "electricity_phase_three_produced", - "gas_consumed", - "voltage_phase_one", - "voltage_phase_two", - "voltage_phase_three", "temperature", "thermostat", "illuminance", From 15dfa8b1fe337279f916e79a69272980820d8fcc Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:57:54 +0200 Subject: [PATCH 090/173] Reverse back to str for P1 measurements --- plugwise/constants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugwise/constants.py b/plugwise/constants.py index 204eac73a..144e61dc2 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -143,7 +143,7 @@ UOM = namedtuple("UOM", "unit_of_measurement") DATA = namedtuple("DATA", "name unit_of_measurement") # P1 related measurements: -P1_MEASUREMENTS: Final[dict[MeasurementType, UOM]] = { +P1_MEASUREMENTS: Final[dict[str, UOM]] = { "electricity_consumed": UOM(POWER_WATT), "electricity_produced": UOM(POWER_WATT), "electricity_phase_one_consumed": UOM(POWER_WATT), @@ -157,7 +157,7 @@ "voltage_phase_two": UOM(ELECTRIC_POTENTIAL_VOLT), "voltage_phase_three": UOM(ELECTRIC_POTENTIAL_VOLT), } -P1_LEGACY_MEASUREMENTS: Final[dict[MeasurementType, UOM]] = { +P1_LEGACY_MEASUREMENTS: Final[dict[str, UOM]] = { "electricity_consumed": UOM(POWER_WATT), "electricity_produced": UOM(POWER_WATT), "gas_consumed": UOM(VOLUME_CUBIC_METERS), From ee323d93d76f657b6a7ff61cf7922ba6333d5628 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 19:59:12 +0200 Subject: [PATCH 091/173] Add back Plug measurements --- plugwise/constants.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugwise/constants.py b/plugwise/constants.py index 144e61dc2..a4de1541a 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -261,6 +261,8 @@ BINARY_SENSORS: Final[tuple[str, ...]] = get_args(BinarySensorType) MeasurementType = Literal[ + "electricity_consumed", + "electricity_produced", "temperature", "thermostat", "illuminance", From 3b088c6604c9308102cc3dd34fa0e6c67f0a395f Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 20:05:23 +0200 Subject: [PATCH 092/173] Debug --- plugwise/helper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/helper.py b/plugwise/helper.py index 04eba1b22..d3e51c12b 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -849,6 +849,7 @@ def _appliance_measurements( meas_2: MeasurementType | BinarySensorType | SelectType | SensorType | SwitchType = measurement if new_name := getattr(attrs, ATTR_NAME, None): meas_2 = cast(MeasurementType | BinarySensorType | SelectType | SensorType | SwitchType, new_name) + LOGGER.debug("HOI old, new: %s, %s", measurement, meas_2) # measurements with states "on" or "off" that need to be passed directly if meas_2 == "select_dhw_mode": From 80593e8a46cdad66aca5bb9999ad5b24b637b556 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 21 Aug 2023 20:07:10 +0200 Subject: [PATCH 093/173] Ruffed --- plugwise/helper.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index d3e51c12b..b7328c88f 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -846,9 +846,18 @@ def _appliance_measurements( ): continue - meas_2: MeasurementType | BinarySensorType | SelectType | SensorType | SwitchType = measurement + meas_2: MeasurementType | BinarySensorType | SelectType | SensorType | SwitchType = ( + measurement + ) if new_name := getattr(attrs, ATTR_NAME, None): - meas_2 = cast(MeasurementType | BinarySensorType | SelectType | SensorType | SwitchType, new_name) + meas_2 = cast( + MeasurementType + | BinarySensorType + | SelectType + | SensorType + | SwitchType, + new_name, + ) LOGGER.debug("HOI old, new: %s, %s", measurement, meas_2) # measurements with states "on" or "off" that need to be passed directly From ee32aca963025528c6813647056f4f90c3a55118 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:08:59 +0200 Subject: [PATCH 094/173] Revert back to `in (select_dhw_mode)` --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index b7328c88f..e99477967 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -861,7 +861,7 @@ def _appliance_measurements( LOGGER.debug("HOI old, new: %s, %s", measurement, meas_2) # measurements with states "on" or "off" that need to be passed directly - if meas_2 == "select_dhw_mode": + if meas_2 in ("select_dhw_mode"): data["select_dhw_mode"] = appl_p_loc.text elif meas_2 in BINARY_SENSORS: data["binary_sensors"][meas_2] = format_measure( From 7352e4eecc1671ee868494d2c00994f72790b526 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:11:46 +0200 Subject: [PATCH 095/173] Debug --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index e99477967..e53b8cd14 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -858,12 +858,12 @@ def _appliance_measurements( | SwitchType, new_name, ) - LOGGER.debug("HOI old, new: %s, %s", measurement, meas_2) # measurements with states "on" or "off" that need to be passed directly if meas_2 in ("select_dhw_mode"): data["select_dhw_mode"] = appl_p_loc.text elif meas_2 in BINARY_SENSORS: + LOGGER.debug("HOI type meas_2: %s", type(meas_2)) data["binary_sensors"][meas_2] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) From efee82437a99f1afa0d008a414a504c3198a074b Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:15:09 +0200 Subject: [PATCH 096/173] Debug 2 --- plugwise/helper.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index e53b8cd14..3a3d9988c 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -860,10 +860,11 @@ def _appliance_measurements( ) # measurements with states "on" or "off" that need to be passed directly + LOGGER.debug("HOI0 type meas_2: %s", type(meas_2)) if meas_2 in ("select_dhw_mode"): data["select_dhw_mode"] = appl_p_loc.text elif meas_2 in BINARY_SENSORS: - LOGGER.debug("HOI type meas_2: %s", type(meas_2)) + LOGGER.debug("HOI1 type meas_2: %s", type(meas_2)) data["binary_sensors"][meas_2] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) @@ -1006,7 +1007,6 @@ def _process_c_heating_state(self, data: DeviceData) -> None: Process the central_heating_state value. """ - LOGGER.debug("HOI data: %s", data) if self._on_off_device: # Anna + OnOff heater: use central_heating_state to show heating_state # Solution for Core issue #81839 @@ -1060,8 +1060,6 @@ def _get_appliance_data(self, d_id: str) -> DeviceData: if d_id == self.gateway_id and self.smile_name == "Adam": self._get_regulation_mode(appliance, data) - LOGGER.debug("HOI 1 elga: %s", self._elga) - LOGGER.debug("HOI 1 data: %s", data) if "c_heating_state" in data: self._process_c_heating_state(data) # Remove c_heating_state after processing From 9cfd12e840536a6edc8a8bc589c85b0c8a9b2787 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:20:14 +0200 Subject: [PATCH 097/173] Revert partly --- plugwise/helper.py | 49 +++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 3a3d9988c..864a3da52 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -846,52 +846,53 @@ def _appliance_measurements( ): continue - meas_2: MeasurementType | BinarySensorType | SelectType | SensorType | SwitchType = ( - measurement - ) + # meas_2: MeasurementType | BinarySensorType | SelectType | SensorType | SwitchType = ( + # measurement + # ) if new_name := getattr(attrs, ATTR_NAME, None): - meas_2 = cast( - MeasurementType - | BinarySensorType - | SelectType - | SensorType - | SwitchType, - new_name, - ) + measurement = new_name + # meas_2 = cast( + # MeasurementType + # | BinarySensorType + # | SelectType + # | SensorType + # | SwitchType, + # new_name, + # ) # measurements with states "on" or "off" that need to be passed directly - LOGGER.debug("HOI0 type meas_2: %s", type(meas_2)) - if meas_2 in ("select_dhw_mode"): + LOGGER.debug("HOI0 type meas_2: %s", type(measurement)) + if measurement in ("select_dhw_mode"): data["select_dhw_mode"] = appl_p_loc.text - elif meas_2 in BINARY_SENSORS: - LOGGER.debug("HOI1 type meas_2: %s", type(meas_2)) - data["binary_sensors"][meas_2] = format_measure( + elif measurement in BINARY_SENSORS: + LOGGER.debug("HOI1 type meas_2: %s", type(measurement)) + data["binary_sensors"][measurement] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) - elif meas_2 in SENSORS: - data["sensors"][meas_2] = format_measure( + elif measurement in SENSORS: + data["sensors"][measurement] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) - elif meas_2 in SWITCHES: - data["switches"][meas_2] = format_measure( + elif measurement in SWITCHES: + data["switches"][measurement] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) else: - data[meas_2] = format_measure( + data[measurement] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) # Anna: save cooling-related measurements for later use # Use the local outdoor temperature as reference for turning cooling on/off - if meas_2 == "cooling_activation_outdoor_temperature": + if measurement == "cooling_activation_outdoor_temperature": self._cooling_activation_outdoor_temp = data["sensors"][ "cooling_activation_outdoor_temperature" ] - if meas_2 == "cooling_deactivation_threshold": + if measurement == "cooling_deactivation_threshold": self._cooling_deactivation_threshold = data["sensors"][ "cooling_deactivation_threshold" ] - if meas_2 == "outdoor_air_temperature": + if measurement == "outdoor_air_temperature": self._outdoor_temp = data["sensors"]["outdoor_air_temperature"] i_locator = f'.//logs/interval_log[type="{measurement}"]/period/measurement' From 3ba3a3bc9c579bc25838acdf27137a8f77b130f7 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:23:52 +0200 Subject: [PATCH 098/173] Try 12 --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 864a3da52..b396378e1 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -829,7 +829,7 @@ def _appliance_measurements( self, appliance: etree, data: DeviceData, - measurements: dict[MeasurementType, DATA | UOM], + measurements: dict[str, DATA | UOM], ) -> None: """Helper-function for _get_appliance_data() - collect appliance measurement data.""" for measurement, attrs in measurements.items(): From ef3651afe2923d883ba4e5822464bc3777e3d539 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:26:28 +0200 Subject: [PATCH 099/173] Revert more typing --- plugwise/constants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugwise/constants.py b/plugwise/constants.py index a4de1541a..6bc169e6c 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -167,7 +167,7 @@ # zone_thermosstat: 'temperature_offset' # radiator_valve: 'uncorrected_temperature', 'temperature_offset' -DEVICE_MEASUREMENTS: Final[dict[MeasurementType, DATA | UOM]] = { +DEVICE_MEASUREMENTS: Final[dict[str, DATA | UOM]] = { # HA Core thermostat current_temperature "temperature": UOM(TEMP_CELSIUS), # HA Core thermostat setpoint @@ -190,7 +190,7 @@ } # Heater Central related measurements -HEATER_CENTRAL_MEASUREMENTS: Final[dict[MeasurementType, DATA | UOM]] = { +HEATER_CENTRAL_MEASUREMENTS: Final[dict[str, DATA | UOM]] = { "boiler_temperature": DATA("water_temperature", TEMP_CELSIUS), "domestic_hot_water_mode": DATA("select_dhw_mode", NONE), "domestic_hot_water_setpoint": UOM(TEMP_CELSIUS), From 5c0cf118ce0c343914f08aa2fb063c80481fffd4 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:28:28 +0200 Subject: [PATCH 100/173] Try 13 --- plugwise/helper.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index b396378e1..b6050b3a8 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -865,8 +865,9 @@ def _appliance_measurements( if measurement in ("select_dhw_mode"): data["select_dhw_mode"] = appl_p_loc.text elif measurement in BINARY_SENSORS: - LOGGER.debug("HOI1 type meas_2: %s", type(measurement)) - data["binary_sensors"][measurement] = format_measure( + key = cast(BinarySensorType, measurement) + LOGGER.debug("HOI1 type meas_2: %s", type(key)) + data["binary_sensors"][key] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) elif measurement in SENSORS: From 5a9c36ec4b0e5a63dcad0e3af8bd12b455465f89 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:35:01 +0200 Subject: [PATCH 101/173] Try 14 --- plugwise/helper.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index b6050b3a8..358d4830f 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -866,10 +866,9 @@ def _appliance_measurements( data["select_dhw_mode"] = appl_p_loc.text elif measurement in BINARY_SENSORS: key = cast(BinarySensorType, measurement) + value = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) LOGGER.debug("HOI1 type meas_2: %s", type(key)) - data["binary_sensors"][key] = format_measure( - appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) - ) + data["binary_sensors"][key] = value elif measurement in SENSORS: data["sensors"][measurement] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) From 49d5799dcdd36a605bd672c86cb3c4c97aafbb5e Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:37:18 +0200 Subject: [PATCH 102/173] Try 15 --- plugwise/helper.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 358d4830f..0c31f0cd9 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -870,12 +870,13 @@ def _appliance_measurements( LOGGER.debug("HOI1 type meas_2: %s", type(key)) data["binary_sensors"][key] = value elif measurement in SENSORS: - data["sensors"][measurement] = format_measure( - appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) - ) + key = cast(SensorType, measurement) + value = format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT)) + data["sensors"][key] = value elif measurement in SWITCHES: - data["switches"][measurement] = format_measure( - appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) + key = cast(SwitchType, measurement) + value = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) + data["switches"][key] = value ) else: data[measurement] = format_measure( From eacdc1978bcb4801a964ec500851d4a4523a258c Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:38:30 +0200 Subject: [PATCH 103/173] Try 16 --- plugwise/helper.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 0c31f0cd9..8023d0409 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -877,7 +877,6 @@ def _appliance_measurements( key = cast(SwitchType, measurement) value = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) data["switches"][key] = value - ) else: data[measurement] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) From 7b1138f11c094e93dba3a560d1c134a970a34742 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:42:33 +0200 Subject: [PATCH 104/173] Try 17 --- plugwise/helper.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 8023d0409..91a3fffed 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -865,18 +865,17 @@ def _appliance_measurements( if measurement in ("select_dhw_mode"): data["select_dhw_mode"] = appl_p_loc.text elif measurement in BINARY_SENSORS: - key = cast(BinarySensorType, measurement) - value = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) - LOGGER.debug("HOI1 type meas_2: %s", type(key)) - data["binary_sensors"][key] = value + bs_key = cast(BinarySensorType, measurement) + bs_value_ = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) + data["binary_sensors"][bs_key] = bs_value_ elif measurement in SENSORS: - key = cast(SensorType, measurement) - value = format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT)) - data["sensors"][key] = value + s_key = cast(SensorType, measurement) + s_value = format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT)) + data["sensors"][s_key] = s_value elif measurement in SWITCHES: - key = cast(SwitchType, measurement) - value = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) - data["switches"][key] = value + sw_key = cast(SwitchType, measurement) + sw_value = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) + data["switches"][sw_key] = sw_value else: data[measurement] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) From 77caee0c5b1a6ab29806114de1d6dd1816321036 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:44:49 +0200 Subject: [PATCH 105/173] Try 18 --- plugwise/helper.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 91a3fffed..4cc5bcf3c 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -846,22 +846,9 @@ def _appliance_measurements( ): continue - # meas_2: MeasurementType | BinarySensorType | SelectType | SensorType | SwitchType = ( - # measurement - # ) if new_name := getattr(attrs, ATTR_NAME, None): measurement = new_name - # meas_2 = cast( - # MeasurementType - # | BinarySensorType - # | SelectType - # | SensorType - # | SwitchType, - # new_name, - # ) - # measurements with states "on" or "off" that need to be passed directly - LOGGER.debug("HOI0 type meas_2: %s", type(measurement)) if measurement in ("select_dhw_mode"): data["select_dhw_mode"] = appl_p_loc.text elif measurement in BINARY_SENSORS: @@ -877,7 +864,8 @@ def _appliance_measurements( sw_value = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) data["switches"][sw_key] = sw_value else: - data[measurement] = format_measure( + rm_key = cast(MeasurementType, measurement) + data[rm_key] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) From 4638a20f6c04d3323f0c572f8dfee2e04d212a39 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:48:42 +0200 Subject: [PATCH 106/173] Try 19 --- plugwise/helper.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 4cc5bcf3c..773e7c322 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -846,40 +846,41 @@ def _appliance_measurements( ): continue + meas_rn = measurement if new_name := getattr(attrs, ATTR_NAME, None): - measurement = new_name + meas_rn = new_name # measurements with states "on" or "off" that need to be passed directly - if measurement in ("select_dhw_mode"): + if meas_rn in ("select_dhw_mode"): data["select_dhw_mode"] = appl_p_loc.text - elif measurement in BINARY_SENSORS: - bs_key = cast(BinarySensorType, measurement) + elif meas_rn in BINARY_SENSORS: + bs_key = cast(BinarySensorType, meas_rn) bs_value_ = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) data["binary_sensors"][bs_key] = bs_value_ - elif measurement in SENSORS: - s_key = cast(SensorType, measurement) + elif meas_rn in SENSORS: + s_key = cast(SensorType, meas_rn) s_value = format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT)) data["sensors"][s_key] = s_value - elif measurement in SWITCHES: - sw_key = cast(SwitchType, measurement) + elif meas_rn in SWITCHES: + sw_key = cast(SwitchType, meas_rn) sw_value = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) data["switches"][sw_key] = sw_value else: - rm_key = cast(MeasurementType, measurement) + rm_key = cast(Literal, meas_rn) data[rm_key] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) # Anna: save cooling-related measurements for later use # Use the local outdoor temperature as reference for turning cooling on/off - if measurement == "cooling_activation_outdoor_temperature": + if meas_rn == "cooling_activation_outdoor_temperature": self._cooling_activation_outdoor_temp = data["sensors"][ "cooling_activation_outdoor_temperature" ] - if measurement == "cooling_deactivation_threshold": + if meas_rn == "cooling_deactivation_threshold": self._cooling_deactivation_threshold = data["sensors"][ "cooling_deactivation_threshold" ] - if measurement == "outdoor_air_temperature": + if meas_rn == "outdoor_air_temperature": self._outdoor_temp = data["sensors"]["outdoor_air_temperature"] i_locator = f'.//logs/interval_log[type="{measurement}"]/period/measurement' From b1ab8802c54b9155bab74a3475ac9ffffb7874e3 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:49:21 +0200 Subject: [PATCH 107/173] Try 20 --- plugwise/helper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/helper.py b/plugwise/helper.py index 773e7c322..26f5f8748 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -3,6 +3,7 @@ Plugwise Smile protocol helpers. """ from __future__ import annotations +from typing import Literal import asyncio import datetime as dt From 7ed51437a69ab99cbb62bbf162e379fb9d39b7a7 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:50:06 +0200 Subject: [PATCH 108/173] Try 21 --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 26f5f8748..aff6753eb 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -866,7 +866,7 @@ def _appliance_measurements( sw_value = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) data["switches"][sw_key] = sw_value else: - rm_key = cast(Literal, meas_rn) + rm_key = cast(Literal[str], meas_rn) data[rm_key] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) From 1dde85d98404f283ee40ff6828bdaa960dc77841 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:51:05 +0200 Subject: [PATCH 109/173] Try 22 --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index aff6753eb..867608bd7 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -866,7 +866,7 @@ def _appliance_measurements( sw_value = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) data["switches"][sw_key] = sw_value else: - rm_key = cast(Literal[str], meas_rn) + rm_key = Literal[meas_rn] data[rm_key] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) From 07098e4fbff275b4b4a926c9906a8aeb7be159c4 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:51:58 +0200 Subject: [PATCH 110/173] Try 23 --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 867608bd7..b053774a6 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -866,7 +866,7 @@ def _appliance_measurements( sw_value = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) data["switches"][sw_key] = sw_value else: - rm_key = Literal[meas_rn] + rm_key = Literal[str(meas_rn)] data[rm_key] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) From c66e1318dc5966173b973d3fc1e781d98386e91c Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:52:53 +0200 Subject: [PATCH 111/173] Try 24 --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index b053774a6..d8dfb4710 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -866,7 +866,7 @@ def _appliance_measurements( sw_value = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) data["switches"][sw_key] = sw_value else: - rm_key = Literal[str(meas_rn)] + rm_key = meas_rn data[rm_key] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) From 65d9a22788ae1b6c1b6d74663a026bfe920db812 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:56:48 +0200 Subject: [PATCH 112/173] Remove boiler_temp from MeasurementType --- plugwise/constants.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugwise/constants.py b/plugwise/constants.py index 6bc169e6c..359676280 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -273,7 +273,6 @@ "valve_position", "humidity", "relay", - "boiler_temperature", "domestic_hot_water_mode", "domestic_hot_water_setpoint", "domestic_hot_water_state", From fcafc3e86710e03b2d76f786885386bb5180d621 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:57:27 +0200 Subject: [PATCH 113/173] Try 25 --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index d8dfb4710..9b212a766 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -866,7 +866,7 @@ def _appliance_measurements( sw_value = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) data["switches"][sw_key] = sw_value else: - rm_key = meas_rn + rm_key = cast(MeasurementType, meas_rn) data[rm_key] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) From 6de1d905cb46f316b269f08b1477a62bd38e39d9 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 19:59:24 +0200 Subject: [PATCH 114/173] Add select_dhw-mode to MeasurementType --- plugwise/constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/constants.py b/plugwise/constants.py index 359676280..d10c8d5a1 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -272,6 +272,7 @@ "temperature_difference", "valve_position", "humidity", + "select_dhw_mode", "relay", "domestic_hot_water_mode", "domestic_hot_water_setpoint", From a2bb56ff8eec333cb1e090c62716b6fe28f6c9d8 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 20:00:59 +0200 Subject: [PATCH 115/173] Remove domestic_hot_water_mode --- plugwise/constants.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugwise/constants.py b/plugwise/constants.py index d10c8d5a1..bf9ff2584 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -274,7 +274,6 @@ "humidity", "select_dhw_mode", "relay", - "domestic_hot_water_mode", "domestic_hot_water_setpoint", "domestic_hot_water_state", "domestic_hot_water_temperature", From d3788e24a6ff9f013a33ec175ecc95af0fd43f0f Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 20:04:13 +0200 Subject: [PATCH 116/173] Try 26 --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 9b212a766..e7844c8f0 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -866,7 +866,7 @@ def _appliance_measurements( sw_value = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) data["switches"][sw_key] = sw_value else: - rm_key = cast(MeasurementType, meas_rn) + rm_key = cast(SelectType, meas_rn) data[rm_key] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) From 3adf5b3925c617bd3a472039f6c9f26a930a660a Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 20:05:53 +0200 Subject: [PATCH 117/173] Debug --- plugwise/helper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/helper.py b/plugwise/helper.py index e7844c8f0..7d5b78b6b 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -867,6 +867,7 @@ def _appliance_measurements( data["switches"][sw_key] = sw_value else: rm_key = cast(SelectType, meas_rn) + LOGGER.debug("HOI meas_rn: %s", meas_rn) data[rm_key] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) From 9a55c1b05337eef9e6fe266aa80c9ae863bbab4b Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 20:09:10 +0200 Subject: [PATCH 118/173] Add c_heating_state to MeasurementTypes --- plugwise/constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/constants.py b/plugwise/constants.py index bf9ff2584..f9a6dcfdf 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -281,6 +281,7 @@ "intended_boiler_temperature", "central_heating_state", "intended_central_heating_state", + "c_heating_state", "maximum_boiler_temperature", "modulation_level", "return_water_temperature", From eebbec071c51d96d9c839982ca86a86baabd34dc Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 20:10:35 +0200 Subject: [PATCH 119/173] Remove maximum_boiler_temperature from HEATER_MEAS, it's a Number. --- plugwise/constants.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugwise/constants.py b/plugwise/constants.py index f9a6dcfdf..9e77447d6 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -206,7 +206,6 @@ "intended_central_heating_state": DATA( "heating_state", NONE ), # This key shows in general the heating-behavior better than c-h_state. except when connected to a heatpump - "maximum_boiler_temperature": UOM(TEMP_CELSIUS), "modulation_level": UOM(PERCENTAGE), "return_water_temperature": DATA("return_temperature", TEMP_CELSIUS), # Used with the Elga heatpump - marcelveldt From cb351716c382f4f10b4abc843dc80ee254bcdac4 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 20:11:56 +0200 Subject: [PATCH 120/173] Ruffed --- plugwise/helper.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 7d5b78b6b..09b9089d6 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -855,15 +855,27 @@ def _appliance_measurements( data["select_dhw_mode"] = appl_p_loc.text elif meas_rn in BINARY_SENSORS: bs_key = cast(BinarySensorType, meas_rn) - bs_value_ = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) + bs_value_ = cast( + bool, + format_measure( + appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) + ), + ) data["binary_sensors"][bs_key] = bs_value_ elif meas_rn in SENSORS: s_key = cast(SensorType, meas_rn) - s_value = format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT)) + s_value = format_measure( + appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) + ) data["sensors"][s_key] = s_value elif meas_rn in SWITCHES: sw_key = cast(SwitchType, meas_rn) - sw_value = cast(bool, format_measure(appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT))) + sw_value = cast( + bool, + format_measure( + appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) + ), + ) data["switches"][sw_key] = sw_value else: rm_key = cast(SelectType, meas_rn) From dd1eb68f63874908e009884994311fc8972d0d29 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 20:17:49 +0200 Subject: [PATCH 121/173] Add NoPlatformType constants, implement --- plugwise/constants.py | 33 +-------------------------------- plugwise/helper.py | 4 ++-- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/plugwise/constants.py b/plugwise/constants.py index 9e77447d6..bfe3715c7 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -259,40 +259,9 @@ ] BINARY_SENSORS: Final[tuple[str, ...]] = get_args(BinarySensorType) -MeasurementType = Literal[ - "electricity_consumed", - "electricity_produced", - "temperature", - "thermostat", - "illuminance", - "cooling_activation_outdoor_temperature", - "cooling_deactivation_threshold", - "battery", - "temperature_difference", - "valve_position", - "humidity", - "select_dhw_mode", - "relay", - "domestic_hot_water_setpoint", - "domestic_hot_water_state", - "domestic_hot_water_temperature", +NoPlatformType = Literal[ "elga_status_code", - "intended_boiler_temperature", - "central_heating_state", - "intended_central_heating_state", "c_heating_state", - "maximum_boiler_temperature", - "modulation_level", - "return_water_temperature", - "compressor_state", - "cooling_state", - "cooling_enabled", - "slave_boiler_state", - "flame_state", - "central_heater_water_pressure", - "boiler_state", - "intended_boiler_state", - "outdoor_temperature", ] NumberType = Literal[ diff --git a/plugwise/helper.py b/plugwise/helper.py index 09b9089d6..cb2397d0e 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -57,7 +57,7 @@ BinarySensorType, DeviceData, GatewayData, - MeasurementType, + NoPlatformType, ModelData, SelectType, SensorType, @@ -878,7 +878,7 @@ def _appliance_measurements( ) data["switches"][sw_key] = sw_value else: - rm_key = cast(SelectType, meas_rn) + rm_key = cast(NoPlatformType, meas_rn) LOGGER.debug("HOI meas_rn: %s", meas_rn) data[rm_key] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) From 0c7e7817391adc59d25c083829c3f8767da645be Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 20:21:29 +0200 Subject: [PATCH 122/173] Try 27 --- plugwise/helper.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index cb2397d0e..53f19bb7d 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -851,7 +851,7 @@ def _appliance_measurements( if new_name := getattr(attrs, ATTR_NAME, None): meas_rn = new_name # measurements with states "on" or "off" that need to be passed directly - if meas_rn in ("select_dhw_mode"): + if meas_rn == "select_dhw_mode": data["select_dhw_mode"] = appl_p_loc.text elif meas_rn in BINARY_SENSORS: bs_key = cast(BinarySensorType, meas_rn) @@ -877,10 +877,12 @@ def _appliance_measurements( ), ) data["switches"][sw_key] = sw_value - else: - rm_key = cast(NoPlatformType, meas_rn) - LOGGER.debug("HOI meas_rn: %s", meas_rn) - data[rm_key] = format_measure( + elif meas_rn == "c_heating_state": + data["c_heating_state"] = format_measure( + appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) + ) + elif meas_rn == "elga_status_code": + data["elga_status_code"] = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) From 8666b9f1ba23ab6675229d66b89e0e0f60fc6dd7 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 20:23:38 +0200 Subject: [PATCH 123/173] Try 28 --- plugwise/helper.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 53f19bb7d..63cf5791f 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -878,13 +878,14 @@ def _appliance_measurements( ) data["switches"][sw_key] = sw_value elif meas_rn == "c_heating_state": - data["c_heating_state"] = format_measure( - appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) + data["c_heating_state"] = cast( + bool, + format_measure( + appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) + ), ) elif meas_rn == "elga_status_code": - data["elga_status_code"] = format_measure( - appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) - ) + data["elga_status_code"] = int(appl_p_loc.text) # Anna: save cooling-related measurements for later use # Use the local outdoor temperature as reference for turning cooling on/off From d85be61faa96cef088844a95dd6a326002c202c6 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 22 Aug 2023 20:25:05 +0200 Subject: [PATCH 124/173] Remove unused --- plugwise/helper.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 63cf5791f..dec27d124 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -3,7 +3,7 @@ Plugwise Smile protocol helpers. """ from __future__ import annotations -from typing import Literal + import asyncio import datetime as dt @@ -57,9 +57,7 @@ BinarySensorType, DeviceData, GatewayData, - NoPlatformType, ModelData, - SelectType, SensorType, SwitchType, ThermoLoc, From 8015e95e812ab668ef8d4c5052f22baf07e2b9ca Mon Sep 17 00:00:00 2001 From: Bouwe Date: Wed, 23 Aug 2023 07:58:10 +0200 Subject: [PATCH 125/173] Remove type-ignore --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index dec27d124..788f9a6b9 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -901,7 +901,7 @@ def _appliance_measurements( i_locator = f'.//logs/interval_log[type="{measurement}"]/period/measurement' if (appl_i_loc := appliance.find(i_locator)) is not None: name = f"{measurement}_interval" - data["sensors"][name] = format_measure(appl_i_loc.text, ENERGY_WATT_HOUR) # type: ignore [literal-required] + data["sensors"][name] = format_measure(appl_i_loc.text, ENERGY_WATT_HOUR) def _wireless_availablity(self, appliance: etree, data: DeviceData) -> None: """Helper-function for _get_appliance_data(). From b3a45a180e71ac72e831b2cd0071be740a99443a Mon Sep 17 00:00:00 2001 From: Bouwe Date: Wed, 23 Aug 2023 08:01:37 +0200 Subject: [PATCH 126/173] Add cast() to SensorType --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 788f9a6b9..f426c5149 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -900,7 +900,7 @@ def _appliance_measurements( i_locator = f'.//logs/interval_log[type="{measurement}"]/period/measurement' if (appl_i_loc := appliance.find(i_locator)) is not None: - name = f"{measurement}_interval" + name = cast(SensorType, f"{measurement}_interval") data["sensors"][name] = format_measure(appl_i_loc.text, ENERGY_WATT_HOUR) def _wireless_availablity(self, appliance: etree, data: DeviceData) -> None: From b3f6b44e9bee55256983ca7e952101f0086bdc31 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Wed, 23 Aug 2023 08:04:49 +0200 Subject: [PATCH 127/173] Remove remaining type-ignores in helper.py --- plugwise/helper.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index f426c5149..72a4f7319 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -175,7 +175,7 @@ def power_data_energy_diff( if net_string not in direct_data["sensors"]: tmp_val: float | int = 0 else: - tmp_val = direct_data["sensors"][net_string] # type: ignore [literal-required] + tmp_val = direct_data["sensors"][net_string] if isinstance(f_val, int): tmp_val += f_val * diff @@ -183,7 +183,7 @@ def power_data_energy_diff( tmp_val += float(f_val * diff) tmp_val = float(f"{round(tmp_val, 3):.3f}") - direct_data["sensors"][net_string] = tmp_val # type: ignore [literal-required] + direct_data["sensors"][net_string] = tmp_val return direct_data @@ -603,7 +603,7 @@ def _p1_smartmeter_info_finder(self, appl: Munch) -> None: "vendor": appl.vendor_name, }.items(): if value is not None or key == "location": - self._appl_data[appl.dev_id].update({key: value}) # type: ignore[misc] + self._appl_data[appl.dev_id].update({key: value}) def _create_legacy_gateway(self) -> None: """Create the (missing) gateway devices for legacy Anna, P1 and Stretch. @@ -625,7 +625,7 @@ def _create_legacy_gateway(self) -> None: "vendor": "Plugwise", }.items(): if value is not None: - self._appl_data[self.gateway_id].update({key: value}) # type: ignore[misc] + self._appl_data[self.gateway_id].update({key: value}) def _all_appliances(self) -> None: """Collect all appliances with relevant info.""" @@ -699,7 +699,7 @@ def _all_appliances(self) -> None: "vendor": appl.vendor_name, }.items(): if value is not None or key == "location": - self._appl_data[appl.dev_id].update({key: value}) # type: ignore[misc] + self._appl_data[appl.dev_id].update({key: value}) # For non-legacy P1 collect the connected SmartMeter info if self.smile_type == "power": @@ -964,7 +964,7 @@ def _get_actuator_functionalities(self, xml: etree, data: DeviceData) -> None: # Rename offset to setpoint key = "setpoint" - temp_dict[key] = format_measure(function.text, TEMP_CELSIUS) # type: ignore [literal-required] + temp_dict[key] = format_measure(function.text, TEMP_CELSIUS) if temp_dict: # If domestic_hot_water_setpoint is present as actuator, @@ -974,7 +974,7 @@ def _get_actuator_functionalities(self, xml: etree, data: DeviceData) -> None: if DHW_SETPOINT in data["sensors"]: data["sensors"].pop(DHW_SETPOINT) - data[item] = temp_dict # type: ignore [literal-required] + data[item] = temp_dict def _get_regulation_mode(self, appliance: etree, data: DeviceData) -> None: """Helper-function for _get_appliance_data(). @@ -1000,9 +1000,9 @@ def _cleanup_data(self, data: DeviceData) -> None: if not self._cooling_present: for item in ("cooling_state", "cooling_ena_switch"): if item in data["binary_sensors"]: - data["binary_sensors"].pop(item) # type: ignore [misc] + data["binary_sensors"].pop(item) if item in data["switches"]: - data["switches"].pop(item) # type: ignore [misc] + data["switches"].pop(item) if not self._elga and "cooling_enabled" in data: data.pop("cooling_enabled") # pragma: no cover @@ -1314,7 +1314,7 @@ def _power_data_from_location(self, loc_id: str) -> DeviceData: direct_data = power_data_energy_diff( loc.measurement, loc.net_string, loc.f_val, direct_data ) - direct_data["sensors"][loc.key_string] = loc.f_val # type: ignore [literal-required] + direct_data["sensors"][loc.key_string] = loc.f_val return direct_data @@ -1347,7 +1347,7 @@ def _power_data_from_modules(self) -> DeviceData: direct_data = power_data_energy_diff( loc.measurement, loc.net_string, loc.f_val, direct_data ) - direct_data["sensors"][loc.key_string] = loc.f_val # type: ignore [literal-required] + direct_data["sensors"][loc.key_string] = loc.f_val return direct_data @@ -1547,7 +1547,7 @@ def _get_toggle_state( for item in found: if (toggle_type := item.find("type")) is not None: if toggle_type.text == toggle: - data["switches"][name] = item.find("state").text == "on" # type: ignore [literal-required] + data["switches"][name] = item.find("state").text == "on" # Remove the cooling_enabled binary_sensor when the corresponding switch is present # Except for Elga if toggle == "cooling_enabled" and not self._elga: From 594e5ddf39fb19f0d4d49713b1d04a79d1c7d1ef Mon Sep 17 00:00:00 2001 From: Bouwe Date: Wed, 23 Aug 2023 08:08:10 +0200 Subject: [PATCH 128/173] Type net_string as SensorType --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 72a4f7319..d5f6995df 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -161,7 +161,7 @@ def power_data_local_format( def power_data_energy_diff( - measurement: str, net_string: str, f_val: float | int, direct_data: DeviceData + measurement: str, net_string: SensorType, f_val: float | int, direct_data: DeviceData ) -> DeviceData: """Calculate differential energy.""" if ( From 39902e7f00f08e386b329df9e077d6a2c4af392c Mon Sep 17 00:00:00 2001 From: Bouwe Date: Wed, 23 Aug 2023 08:12:39 +0200 Subject: [PATCH 129/173] Cast as ApplianceData --- plugwise/helper.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugwise/helper.py b/plugwise/helper.py index d5f6995df..4ce4d22c3 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -603,6 +603,7 @@ def _p1_smartmeter_info_finder(self, appl: Munch) -> None: "vendor": appl.vendor_name, }.items(): if value is not None or key == "location": + key = cast(ApplianceData, key) self._appl_data[appl.dev_id].update({key: value}) def _create_legacy_gateway(self) -> None: @@ -625,6 +626,7 @@ def _create_legacy_gateway(self) -> None: "vendor": "Plugwise", }.items(): if value is not None: + key = cast(ApplianceData, key) self._appl_data[self.gateway_id].update({key: value}) def _all_appliances(self) -> None: From 4754645d9a90fc7c245bb9426c325994c28b60a8 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Wed, 23 Aug 2023 08:14:03 +0200 Subject: [PATCH 130/173] Try 29 --- plugwise/helper.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 4ce4d22c3..90f23c356 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -603,8 +603,8 @@ def _p1_smartmeter_info_finder(self, appl: Munch) -> None: "vendor": appl.vendor_name, }.items(): if value is not None or key == "location": - key = cast(ApplianceData, key) - self._appl_data[appl.dev_id].update({key: value}) + p1_key = cast(ApplianceData, key) + self._appl_data[appl.dev_id].update({p1_key: value}) def _create_legacy_gateway(self) -> None: """Create the (missing) gateway devices for legacy Anna, P1 and Stretch. @@ -626,8 +626,8 @@ def _create_legacy_gateway(self) -> None: "vendor": "Plugwise", }.items(): if value is not None: - key = cast(ApplianceData, key) - self._appl_data[self.gateway_id].update({key: value}) + gw_key = cast(ApplianceData, key) + self._appl_data[self.gateway_id].update({gw_key: value}) def _all_appliances(self) -> None: """Collect all appliances with relevant info.""" From 03173ca8f70342bfd5d072b6751cc76747d7e96d Mon Sep 17 00:00:00 2001 From: Bouwe Date: Wed, 23 Aug 2023 08:18:01 +0200 Subject: [PATCH 131/173] Add ApplianceType constant, implement --- plugwise/constants.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugwise/constants.py b/plugwise/constants.py index bfe3715c7..6d6fb711f 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -247,6 +247,19 @@ # All available Binary Sensor, Sensor, and Switch Types +ApplianceType = Literal[ + "dev_class", + "firmware", + "hardware", + "location", + "mac_address", + "members", + "model", + "name", + "vendor", + "zigbee_mac_address", +] + BinarySensorType = Literal[ "cooling_enabled", "compressor_state", From 9839ad2fe53fc66cf24cb875989280dfe50df21b Mon Sep 17 00:00:00 2001 From: Bouwe Date: Wed, 23 Aug 2023 08:18:37 +0200 Subject: [PATCH 132/173] And implement --- plugwise/helper.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 90f23c356..807bb4402 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -54,6 +54,7 @@ UOM, ActuatorData, ApplianceData, + ApplianceType, BinarySensorType, DeviceData, GatewayData, @@ -603,7 +604,7 @@ def _p1_smartmeter_info_finder(self, appl: Munch) -> None: "vendor": appl.vendor_name, }.items(): if value is not None or key == "location": - p1_key = cast(ApplianceData, key) + p1_key = cast(ApplianceType, key) self._appl_data[appl.dev_id].update({p1_key: value}) def _create_legacy_gateway(self) -> None: @@ -626,7 +627,7 @@ def _create_legacy_gateway(self) -> None: "vendor": "Plugwise", }.items(): if value is not None: - gw_key = cast(ApplianceData, key) + gw_key = cast(ApplianceType, key) self._appl_data[self.gateway_id].update({gw_key: value}) def _all_appliances(self) -> None: From b4d1bf30c45d72f535031e8ae29d9ca320133d53 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Wed, 23 Aug 2023 18:29:32 +0200 Subject: [PATCH 133/173] Try 30 --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 807bb4402..0152dad4c 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -605,7 +605,7 @@ def _p1_smartmeter_info_finder(self, appl: Munch) -> None: }.items(): if value is not None or key == "location": p1_key = cast(ApplianceType, key) - self._appl_data[appl.dev_id].update({p1_key: value}) + self._appl_data[appl.dev_id][p1_key] = value def _create_legacy_gateway(self) -> None: """Create the (missing) gateway devices for legacy Anna, P1 and Stretch. From 63002b3fa7db1f7220f30a25654ececad4727096 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Wed, 23 Aug 2023 18:32:09 +0200 Subject: [PATCH 134/173] Try 31 --- plugwise/helper.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 0152dad4c..e9ca20059 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -628,7 +628,7 @@ def _create_legacy_gateway(self) -> None: }.items(): if value is not None: gw_key = cast(ApplianceType, key) - self._appl_data[self.gateway_id].update({gw_key: value}) + self._appl_data[self.gateway_id][gw_key] = value def _all_appliances(self) -> None: """Collect all appliances with relevant info.""" @@ -702,7 +702,8 @@ def _all_appliances(self) -> None: "vendor": appl.vendor_name, }.items(): if value is not None or key == "location": - self._appl_data[appl.dev_id].update({key: value}) + appl_key = cast(ApplianceType, key) + self._appl_data[appl.dev_id][appl_key] = value # For non-legacy P1 collect the connected SmartMeter info if self.smile_type == "power": From f60225a2b07352c3bb4e8474e6e17817e8ea6011 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Wed, 23 Aug 2023 18:35:15 +0200 Subject: [PATCH 135/173] Try 32 --- plugwise/helper.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index e9ca20059..7ca3c4cb8 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1002,11 +1002,10 @@ def _cleanup_data(self, data: DeviceData) -> None: # Don't show cooling-related when no cooling present, # but, keep cooling_enabled for Elga if not self._cooling_present: - for item in ("cooling_state", "cooling_ena_switch"): - if item in data["binary_sensors"]: - data["binary_sensors"].pop(item) - if item in data["switches"]: - data["switches"].pop(item) + if "cooling_state" in data["binary_sensors"]: + data["binary_sensors"].pop("cooling_state") + if "cooling_ena_switch" in data["switches"]: + data["switches"].pop("cooling_ena_switch") if not self._elga and "cooling_enabled" in data: data.pop("cooling_enabled") # pragma: no cover From 45341f257ce3b915e20a40888ae74016883d6987 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Wed, 23 Aug 2023 18:38:47 +0200 Subject: [PATCH 136/173] Try 33 --- plugwise/helper.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 7ca3c4cb8..bebf849fb 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1317,7 +1317,8 @@ def _power_data_from_location(self, loc_id: str) -> DeviceData: direct_data = power_data_energy_diff( loc.measurement, loc.net_string, loc.f_val, direct_data ) - direct_data["sensors"][loc.key_string] = loc.f_val + key = cast(SensorType, loc.key_string) + direct_data["sensors"][key] = loc.f_val return direct_data @@ -1350,7 +1351,8 @@ def _power_data_from_modules(self) -> DeviceData: direct_data = power_data_energy_diff( loc.measurement, loc.net_string, loc.f_val, direct_data ) - direct_data["sensors"][loc.key_string] = loc.f_val + key = cast(SensorType, loc.key_string) + direct_data["sensors"][key] = loc.f_val return direct_data From 36627b9577b89f20044d0526925a0b34eee7f161 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Wed, 23 Aug 2023 18:43:28 +0200 Subject: [PATCH 137/173] Add ToggleNameType and implement --- plugwise/constants.py | 5 +++++ plugwise/helper.py | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plugwise/constants.py b/plugwise/constants.py index 6d6fb711f..fa49e4ac9 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -225,6 +225,11 @@ "outdoor_temperature": DATA("outdoor_air_temperature", TEMP_CELSIUS), } +ToggleNameType = Literal[ + "cooling_ena_switch", + "dhw_cm_switch", +] + TOGGLES: Final[dict[str, str]] = { "cooling_enabled": "cooling_ena_switch", "domestic_hot_water_comfort_mode": "dhw_cm_switch", diff --git a/plugwise/helper.py b/plugwise/helper.py index bebf849fb..8fa818d16 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -62,6 +62,7 @@ SensorType, SwitchType, ThermoLoc, + ToggleNameType, ) from .exceptions import ( ConnectionFailedError, @@ -1540,7 +1541,7 @@ def _get_lock_state(self, xml: etree, data: DeviceData) -> None: data["switches"]["lock"] = found.text == "true" def _get_toggle_state( - self, xml: etree, toggle: str, name: str, data: DeviceData + self, xml: etree, toggle: str, name: ToggleNameType, data: DeviceData ) -> None: """Helper-function for _get_appliance_data(). From 05a9ff6ac8c1e9e8a5feed6e6c756ccd1b4b8a66 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Thu, 24 Aug 2023 07:55:36 +0200 Subject: [PATCH 138/173] Fix typing --- plugwise/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/constants.py b/plugwise/constants.py index fa49e4ac9..a2750f3ac 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -230,7 +230,7 @@ "dhw_cm_switch", ] -TOGGLES: Final[dict[str, str]] = { +TOGGLES: Final[dict[str, ToggleNameType]] = { "cooling_enabled": "cooling_ena_switch", "domestic_hot_water_comfort_mode": "dhw_cm_switch", } From c8ce73b824aad6b2248449726d2b400a1439c077 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Thu, 24 Aug 2023 08:00:41 +0200 Subject: [PATCH 139/173] Add ActuatorType in constants and implement --- plugwise/constants.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugwise/constants.py b/plugwise/constants.py index a2750f3ac..96c39e58d 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -38,13 +38,16 @@ "zone_thermometer", "zone_thermostat", ) -ACTIVE_ACTUATORS: Final[tuple[str, ...]] = ( + +ActuatorType: Literal[ "domestic_hot_water_setpoint", "max_dhw_temperature", "maximum_boiler_temperature", "temperature_offset", "thermostat", -) +] +ACTIVE_ACTUATORS: Final[tuple[str, ...]] = get_args(ActuatorType) + DAYS: Final[dict[str, int]] = { "mo": 0, "tu": 1, From e1616f07c6986b61904d868a6954e5f8f8eee8a3 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Thu, 24 Aug 2023 08:04:10 +0200 Subject: [PATCH 140/173] Implement in helper.py --- plugwise/helper.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 8fa818d16..0f9dd2674 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -979,7 +979,8 @@ def _get_actuator_functionalities(self, xml: etree, data: DeviceData) -> None: if DHW_SETPOINT in data["sensors"]: data["sensors"].pop(DHW_SETPOINT) - data[item] = temp_dict + act_item = cast(ActuatorType, item) + data[act_item] = temp_dict def _get_regulation_mode(self, appliance: etree, data: DeviceData) -> None: """Helper-function for _get_appliance_data(). From 66ee262d1356c85ac300f37c34fb3c1e37ab181a Mon Sep 17 00:00:00 2001 From: Bouwe Date: Thu, 24 Aug 2023 08:04:38 +0200 Subject: [PATCH 141/173] Import --- plugwise/helper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/helper.py b/plugwise/helper.py index 0f9dd2674..d4a650501 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -53,6 +53,7 @@ TOGGLES, UOM, ActuatorData, + ActuatorType, ApplianceData, ApplianceType, BinarySensorType, From f9b2438d6d7ce4095dd1e5760e70b93ebf82f665 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Thu, 24 Aug 2023 08:08:18 +0200 Subject: [PATCH 142/173] Fix typo --- plugwise/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/constants.py b/plugwise/constants.py index 96c39e58d..973a8f042 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -39,7 +39,7 @@ "zone_thermostat", ) -ActuatorType: Literal[ +ActuatorType = Literal[ "domestic_hot_water_setpoint", "max_dhw_temperature", "maximum_boiler_temperature", From c53bfe1891a900dd094ef371c8fe2de324058adf Mon Sep 17 00:00:00 2001 From: Bouwe Date: Thu, 24 Aug 2023 08:11:54 +0200 Subject: [PATCH 143/173] Add ActuatorDataType Literals --- plugwise/constants.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugwise/constants.py b/plugwise/constants.py index 973a8f042..6f6a89380 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -47,7 +47,14 @@ "thermostat", ] ACTIVE_ACTUATORS: Final[tuple[str, ...]] = get_args(ActuatorType) - +ActuatorDataType = Literal[ + "lower_bound", + "resolution", + "setpoint", + "setpoint_high", + "setpoint_low", + "upper_bound", +] DAYS: Final[dict[str, int]] = { "mo": 0, "tu": 1, From 98815bcc1130a7ab2f559196287a61a761575fbd Mon Sep 17 00:00:00 2001 From: Bouwe Date: Thu, 24 Aug 2023 08:13:28 +0200 Subject: [PATCH 144/173] And implement via cast() --- plugwise/helper.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index d4a650501..28b6348a6 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -53,6 +53,7 @@ TOGGLES, UOM, ActuatorData, + ActuatorDataType, ActuatorType, ApplianceData, ApplianceType, @@ -970,7 +971,8 @@ def _get_actuator_functionalities(self, xml: etree, data: DeviceData) -> None: # Rename offset to setpoint key = "setpoint" - temp_dict[key] = format_measure(function.text, TEMP_CELSIUS) + act_key = cast(ActuatorDataType, key) + temp_dict[act_key] = format_measure(function.text, TEMP_CELSIUS) if temp_dict: # If domestic_hot_water_setpoint is present as actuator, From 74468322b065011861f7cce8008b027fc0972e66 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Thu, 24 Aug 2023 08:15:24 +0200 Subject: [PATCH 145/173] Ruffed --- plugwise/helper.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 28b6348a6..e0193d84d 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -4,7 +4,6 @@ """ from __future__ import annotations - import asyncio import datetime as dt from typing import cast @@ -165,7 +164,10 @@ def power_data_local_format( def power_data_energy_diff( - measurement: str, net_string: SensorType, f_val: float | int, direct_data: DeviceData + measurement: str, + net_string: SensorType, + f_val: float | int, + direct_data: DeviceData, ) -> DeviceData: """Calculate differential energy.""" if ( @@ -908,7 +910,9 @@ def _appliance_measurements( i_locator = f'.//logs/interval_log[type="{measurement}"]/period/measurement' if (appl_i_loc := appliance.find(i_locator)) is not None: name = cast(SensorType, f"{measurement}_interval") - data["sensors"][name] = format_measure(appl_i_loc.text, ENERGY_WATT_HOUR) + data["sensors"][name] = format_measure( + appl_i_loc.text, ENERGY_WATT_HOUR + ) def _wireless_availablity(self, appliance: etree, data: DeviceData) -> None: """Helper-function for _get_appliance_data(). @@ -1010,7 +1014,7 @@ def _cleanup_data(self, data: DeviceData) -> None: if "cooling_state" in data["binary_sensors"]: data["binary_sensors"].pop("cooling_state") if "cooling_ena_switch" in data["switches"]: - data["switches"].pop("cooling_ena_switch") + data["switches"].pop("cooling_ena_switch") if not self._elga and "cooling_enabled" in data: data.pop("cooling_enabled") # pragma: no cover From 34ffb6ab8714a2d3973e53996653616587536ecc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 24 Aug 2023 06:17:04 +0000 Subject: [PATCH 146/173] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- plugwise/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 0be09acaa..bcbcd7d9f 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -4,9 +4,10 @@ """ from __future__ import annotations +from typing import cast + import aiohttp from defusedxml import ElementTree as etree -from typing import cast # Dict as class from munch import Munch From 63667cada344cc96776932c007f8de983141a013 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Thu, 24 Aug 2023 18:55:02 +0200 Subject: [PATCH 147/173] Fix and improve logic --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index e0193d84d..d2efdff26 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1005,7 +1005,7 @@ def _cleanup_data(self, data: DeviceData) -> None: Clean up the data dict. """ # Fix for Adam + Anna: heating_state also present under Anna, remove - if "temperature" in data["binary_sensors"]: + if "temperature" in data["sensors"] and "heating_state" in data["binary_sensors"]: data["binary_sensors"].pop("heating_state", None) # Don't show cooling-related when no cooling present, From 98426248556202d5d3b5a290aa3ed5dd0c40040c Mon Sep 17 00:00:00 2001 From: Bouwe Date: Thu, 24 Aug 2023 18:55:50 +0200 Subject: [PATCH 148/173] Ruffed --- plugwise/helper.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index d2efdff26..d4bc7edcb 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1005,7 +1005,10 @@ def _cleanup_data(self, data: DeviceData) -> None: Clean up the data dict. """ # Fix for Adam + Anna: heating_state also present under Anna, remove - if "temperature" in data["sensors"] and "heating_state" in data["binary_sensors"]: + if ( + "temperature" in data["sensors"] + and "heating_state" in data["binary_sensors"] + ): data["binary_sensors"].pop("heating_state", None) # Don't show cooling-related when no cooling present, From 28fb17d070c5ba99ecdd2f7a4200042f4dc0cbfc Mon Sep 17 00:00:00 2001 From: Bouwe Date: Thu, 24 Aug 2023 19:11:24 +0200 Subject: [PATCH 149/173] Cleanup --- plugwise/constants.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/plugwise/constants.py b/plugwise/constants.py index 6f6a89380..aeb7beccd 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -38,7 +38,6 @@ "zone_thermometer", "zone_thermostat", ) - ActuatorType = Literal[ "domestic_hot_water_setpoint", "max_dhw_temperature", @@ -239,7 +238,6 @@ "cooling_ena_switch", "dhw_cm_switch", ] - TOGGLES: Final[dict[str, ToggleNameType]] = { "cooling_enabled": "cooling_ena_switch", "domestic_hot_water_comfort_mode": "dhw_cm_switch", @@ -287,11 +285,6 @@ ] BINARY_SENSORS: Final[tuple[str, ...]] = get_args(BinarySensorType) -NoPlatformType = Literal[ - "elga_status_code", - "c_heating_state", -] - NumberType = Literal[ "maximum_boiler_temperature", "max_dhw_temperature", @@ -303,7 +296,6 @@ "select_regulation_mode", "select_schedule", ] - SelectOptionsType = Literal[ "dhw_modes", "regulation_modes", From fefebda5544bae0f27058045f178da78fa3174d3 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 25 Aug 2023 08:23:01 +0200 Subject: [PATCH 150/173] Improve structure --- plugwise/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index bcbcd7d9f..96b9cc0d8 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -82,6 +82,7 @@ def _all_device_data(self) -> None: """ for device_id, device in self._appl_data.items(): self.gw_devices.update({device_id: cast(DeviceData, device)}) + data = self._get_device_data(device_id) # Add plugwise notification binary_sensor to the relevant gateway if device_id == self.gateway_id and ( @@ -89,6 +90,7 @@ def _all_device_data(self) -> None: or (not self._smile_legacy and self.smile_type == "power") ): data["binary_sensors"]["plugwise_notification"] = False + self.gw_devices[device_id].update(data) # Update for cooling From affbf65d51f0dd63155110ce391cadcfcd98e2f2 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 25 Aug 2023 08:23:59 +0200 Subject: [PATCH 151/173] Revert back to normal testing --- scripts/tests_and_coverage.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/tests_and_coverage.sh b/scripts/tests_and_coverage.sh index 2aa49d154..2b4483eaa 100755 --- a/scripts/tests_and_coverage.sh +++ b/scripts/tests_and_coverage.sh @@ -25,8 +25,7 @@ set +u if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "test_and_coverage" ] ; then # Python tests (rerun with debug if failures) - # PYTHONPATH=$(pwd) pytest -qx tests/ --cov='.' --no-cov-on-fail --cov-report term-missing || - PYTHONPATH=$(pwd) pytest -xrpP --log-level debug tests/ + PYTHONPATH=$(pwd) pytest -qx tests/ --cov='.' --no-cov-on-fail --cov-report term-missing || PYTHONPATH=$(pwd) pytest -xrpP --log-level debug tests/ fi if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "linting" ] ; then From 98f3d041ce541b09b6e6aff5a7835395d995518b Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 25 Aug 2023 19:16:19 +0200 Subject: [PATCH 152/173] Remove Fix for Adam+Anna, case does not happen, After split in DEVICE_MEASUREMENTS and HEATER_CENTRAL_MEASUREMENTS --- plugwise/helper.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index d4bc7edcb..3a2f71754 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1004,13 +1004,6 @@ def _cleanup_data(self, data: DeviceData) -> None: Clean up the data dict. """ - # Fix for Adam + Anna: heating_state also present under Anna, remove - if ( - "temperature" in data["sensors"] - and "heating_state" in data["binary_sensors"] - ): - data["binary_sensors"].pop("heating_state", None) - # Don't show cooling-related when no cooling present, # but, keep cooling_enabled for Elga if not self._cooling_present: From d0ae1978659399e648d4c767d5e3d17ec7bea7bb Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 25 Aug 2023 19:35:31 +0200 Subject: [PATCH 153/173] Add pragma: no cover for line 1013 --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 3a2f71754..0a6b05b4c 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -1010,7 +1010,7 @@ def _cleanup_data(self, data: DeviceData) -> None: if "cooling_state" in data["binary_sensors"]: data["binary_sensors"].pop("cooling_state") if "cooling_ena_switch" in data["switches"]: - data["switches"].pop("cooling_ena_switch") + data["switches"].pop("cooling_ena_switch") # pragma: no cover if not self._elga and "cooling_enabled" in data: data.pop("cooling_enabled") # pragma: no cover From 3fc8bdd961500d3f4a828114a1783e8a5afb5bb6 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 25 Aug 2023 19:53:03 +0200 Subject: [PATCH 154/173] Update CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51b12c3c3..f7ebaca77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v0.32.1 Improve typing, bugfix +- Integrate the process of creating binary_sensors, sensors, and switches dicts. Should make typing simpler. +- Fix an apparent notification-bug for p1v4. +- Improve typing: fix all type-ignores. +- Clean up no longer used code. + ## v0.32.0: New Feature: add support for changing the temperature offset on a supported thermostat device - Add support for changing the temperature-offset on Jip, Lisa, Tom, Floor and on Anna (in some configurations) From 9909cf20fba45c6fb45496ce20ba87dd07b1f502 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 25 Aug 2023 19:53:47 +0200 Subject: [PATCH 155/173] Bump to v0.32.1a0 test-version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0e61d8508..245138f52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "plugwise" -version = "0.32.0" +version = "0.32.1a0" license = {file = "LICENSE"} description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3." readme = "README.md" From b82819da9949d88c3e60850633ebbef7e033a2e9 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 25 Aug 2023 20:02:47 +0200 Subject: [PATCH 156/173] Changelog: add empty line, required --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7ebaca77..38d5c3366 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## v0.32.1 Improve typing, bugfix + - Integrate the process of creating binary_sensors, sensors, and switches dicts. Should make typing simpler. - Fix an apparent notification-bug for p1v4. - Improve typing: fix all type-ignores. From aba012271d05d6c37e1eda5ad6f7233d9b2409a8 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 26 Aug 2023 17:10:40 +0200 Subject: [PATCH 157/173] Combine ifs --- plugwise/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 96b9cc0d8..aebd2d820 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -531,11 +531,13 @@ async def async_update(self) -> PlugwiseData: for device_id, device in self.gw_devices.items(): data = self._get_device_data(device_id) - if "binary_sensors" in device: - if "plugwise_notification" in device["binary_sensors"]: - data["binary_sensors"]["plugwise_notification"] = bool( - self._notifications - ) + if ( + "binary_sensors" in device + and "plugwise_notification" in device["binary_sensors"] + ): + data["binary_sensors"]["plugwise_notification"] = bool( + self._notifications + ) device.update(data) From 53fc7660fbdc94921eef5f0bb9410f7af9cdeb46 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 26 Aug 2023 17:14:44 +0200 Subject: [PATCH 158/173] Remove _ in bs_value_ --- plugwise/helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 0a6b05b4c..1436ba355 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -862,13 +862,13 @@ def _appliance_measurements( data["select_dhw_mode"] = appl_p_loc.text elif meas_rn in BINARY_SENSORS: bs_key = cast(BinarySensorType, meas_rn) - bs_value_ = cast( + bs_value = cast( bool, format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ), ) - data["binary_sensors"][bs_key] = bs_value_ + data["binary_sensors"][bs_key] = bs_value elif meas_rn in SENSORS: s_key = cast(SensorType, meas_rn) s_value = format_measure( From 041c2bb654f3470d22e223612fbbf88adcc64ab4 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 26 Aug 2023 18:11:29 +0200 Subject: [PATCH 159/173] Use match case --- plugwise/helper.py | 74 ++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 1436ba355..36460def7 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -857,42 +857,46 @@ def _appliance_measurements( meas_rn = measurement if new_name := getattr(attrs, ATTR_NAME, None): meas_rn = new_name - # measurements with states "on" or "off" that need to be passed directly - if meas_rn == "select_dhw_mode": - data["select_dhw_mode"] = appl_p_loc.text - elif meas_rn in BINARY_SENSORS: - bs_key = cast(BinarySensorType, meas_rn) - bs_value = cast( - bool, - format_measure( - appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) - ), - ) - data["binary_sensors"][bs_key] = bs_value - elif meas_rn in SENSORS: - s_key = cast(SensorType, meas_rn) - s_value = format_measure( - appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) - ) - data["sensors"][s_key] = s_value - elif meas_rn in SWITCHES: - sw_key = cast(SwitchType, meas_rn) - sw_value = cast( - bool, - format_measure( - appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) - ), - ) - data["switches"][sw_key] = sw_value - elif meas_rn == "c_heating_state": - data["c_heating_state"] = cast( - bool, - format_measure( + match meas_rn: + # measurements with states "on" or "off" that need to be passed directly + case "select_dhw_mode": + data["select_dhw_mode"] = appl_p_loc.text + case _ as meas_rn if meas_rn in BINARY_SENSORS: + bs_key = cast(BinarySensorType, meas_rn) + bs_value = cast( + bool, + format_measure( + appl_p_loc.text, + getattr(attrs, ATTR_UNIT_OF_MEASUREMENT), + ), + ) + data["binary_sensors"][bs_key] = bs_value + case _ as meas_rn if meas_rn in SENSORS: + s_key = cast(SensorType, meas_rn) + s_value = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) - ), - ) - elif meas_rn == "elga_status_code": - data["elga_status_code"] = int(appl_p_loc.text) + ) + data["sensors"][s_key] = s_value + case _ as meas_rn if meas_rn in SWITCHES: + sw_key = cast(SwitchType, meas_rn) + sw_value = cast( + bool, + format_measure( + appl_p_loc.text, + getattr(attrs, ATTR_UNIT_OF_MEASUREMENT), + ), + ) + data["switches"][sw_key] = sw_value + case "c_heating_state": + data["c_heating_state"] = cast( + bool, + format_measure( + appl_p_loc.text, + getattr(attrs, ATTR_UNIT_OF_MEASUREMENT), + ), + ) + case "elga_status_code": + data["elga_status_code"] = int(appl_p_loc.text) # Anna: save cooling-related measurements for later use # Use the local outdoor temperature as reference for turning cooling on/off From 73dc40eee790b1bf3f18b51fb1ae19d2f58e2a2b Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 26 Aug 2023 18:19:23 +0200 Subject: [PATCH 160/173] Remove testing for python 3.9 --- .github/workflows/verify.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 1d2040a27..13665406e 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -167,7 +167,7 @@ jobs: needs: commitcheck strategy: matrix: - python-version: ["3.11", "3.10", "3.9"] + python-version: ["3.11", "3.10"] steps: - name: Check out committed code uses: actions/checkout@v3 @@ -206,7 +206,7 @@ jobs: needs: prepare-test-cache strategy: matrix: - python-version: ["3.11", "3.10", "3.9"] + python-version: ["3.11", "3.10"] steps: - name: Check out committed code From d24d6e5d00a2e85982dbd53b6ba456f12891e4b5 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sun, 27 Aug 2023 09:21:50 +0200 Subject: [PATCH 161/173] Move cooling-related processing under the SENSORS-case --- plugwise/helper.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 36460def7..fbb136465 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -877,6 +877,20 @@ def _appliance_measurements( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) data["sensors"][s_key] = s_value + # Anna: save cooling-related measurements for later use + # Use the local outdoor temperature as reference for turning cooling on/off + if meas_rn == "cooling_activation_outdoor_temperature": + self._cooling_activation_outdoor_temp = data["sensors"][ + "cooling_activation_outdoor_temperature" + ] + if meas_rn == "cooling_deactivation_threshold": + self._cooling_deactivation_threshold = data["sensors"][ + "cooling_deactivation_threshold" + ] + if meas_rn == "outdoor_air_temperature": + self._outdoor_temp = data["sensors"][ + "outdoor_air_temperature" + ] case _ as meas_rn if meas_rn in SWITCHES: sw_key = cast(SwitchType, meas_rn) sw_value = cast( @@ -898,19 +912,6 @@ def _appliance_measurements( case "elga_status_code": data["elga_status_code"] = int(appl_p_loc.text) - # Anna: save cooling-related measurements for later use - # Use the local outdoor temperature as reference for turning cooling on/off - if meas_rn == "cooling_activation_outdoor_temperature": - self._cooling_activation_outdoor_temp = data["sensors"][ - "cooling_activation_outdoor_temperature" - ] - if meas_rn == "cooling_deactivation_threshold": - self._cooling_deactivation_threshold = data["sensors"][ - "cooling_deactivation_threshold" - ] - if meas_rn == "outdoor_air_temperature": - self._outdoor_temp = data["sensors"]["outdoor_air_temperature"] - i_locator = f'.//logs/interval_log[type="{measurement}"]/period/measurement' if (appl_i_loc := appliance.find(i_locator)) is not None: name = cast(SensorType, f"{measurement}_interval") From 39c374ff45f96ae02d78bb27e9adc6373c76330f Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sun, 27 Aug 2023 14:10:01 +0200 Subject: [PATCH 162/173] Use assert isinstance() instead of cast() --- plugwise/helper.py | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index fbb136465..9d8a4b789 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -78,8 +78,6 @@ version_to_model, ) -# from typing import cast - def check_model(name: str | None, vendor_name: str | None) -> str | None: """Model checking before using version_to_model.""" @@ -863,13 +861,10 @@ def _appliance_measurements( data["select_dhw_mode"] = appl_p_loc.text case _ as meas_rn if meas_rn in BINARY_SENSORS: bs_key = cast(BinarySensorType, meas_rn) - bs_value = cast( - bool, - format_measure( - appl_p_loc.text, - getattr(attrs, ATTR_UNIT_OF_MEASUREMENT), - ), + bs_value = format_measure( + appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) + assert isinstance(bs_value, bool) data["binary_sensors"][bs_key] = bs_value case _ as meas_rn if meas_rn in SENSORS: s_key = cast(SensorType, meas_rn) @@ -893,22 +888,17 @@ def _appliance_measurements( ] case _ as meas_rn if meas_rn in SWITCHES: sw_key = cast(SwitchType, meas_rn) - sw_value = cast( - bool, - format_measure( - appl_p_loc.text, - getattr(attrs, ATTR_UNIT_OF_MEASUREMENT), - ), + value = format_measure( + appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) + sw_value = cast(bool, value) data["switches"][sw_key] = sw_value case "c_heating_state": - data["c_heating_state"] = cast( - bool, - format_measure( - appl_p_loc.text, - getattr(attrs, ATTR_UNIT_OF_MEASUREMENT), - ), + value = format_measure( + appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) + assert isinstance(value, bool) + data["c_heating_state"] = value case "elga_status_code": data["elga_status_code"] = int(appl_p_loc.text) From 4e09d44ea2184d85a5501469a552aeaf7d93a8e0 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sun, 27 Aug 2023 14:24:33 +0200 Subject: [PATCH 163/173] Improve format_measure() a little --- plugwise/util.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plugwise/util.py b/plugwise/util.py index 71b68696d..4a2a8c535 100644 --- a/plugwise/util.py +++ b/plugwise/util.py @@ -20,12 +20,12 @@ def escape_illegal_xml_characters(xmldata: str) -> str: return re.sub(r"&([^a-zA-Z#])", r"&\1", xmldata) -def format_measure(measure: str, unit: str) -> float | int | bool: +def format_measure(measure: str, unit: str) -> bool | float | int: """Format measure to correct type.""" # TODO: handle with appropriate care 20220405 # continuously reassigning the same value with different type isn't # to typings liking - result: int | float | bool = False + result: bool | float | int = False try: result = int(measure) if unit == TEMP_CELSIUS: @@ -52,10 +52,8 @@ def format_measure(measure: str, unit: str) -> float | int | bool: elif abs(float_measure) >= 100: result = int(round(float_measure)) except ValueError: - if measure in ["on", "true"]: - result = True - if measure in ["off", "false"]: - result = False + result = measure in ["on", "true"] + return result From e1513ad1275e78fa341d9f50f9ae1e21e3af39f5 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sun, 27 Aug 2023 14:26:02 +0200 Subject: [PATCH 164/173] Remove TODO comment --- plugwise/util.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugwise/util.py b/plugwise/util.py index 4a2a8c535..1c72e69d3 100644 --- a/plugwise/util.py +++ b/plugwise/util.py @@ -22,9 +22,6 @@ def escape_illegal_xml_characters(xmldata: str) -> str: def format_measure(measure: str, unit: str) -> bool | float | int: """Format measure to correct type.""" - # TODO: handle with appropriate care 20220405 - # continuously reassigning the same value with different type isn't - # to typings liking result: bool | float | int = False try: result = int(measure) From 0134aa08153e464829be8824bac8b17f34c9a469 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 28 Aug 2023 18:00:36 +0200 Subject: [PATCH 165/173] Remove boolean-output from format_measure() --- plugwise/helper.py | 16 +++++----------- plugwise/util.py | 43 ++++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 9d8a4b789..e06723cf9 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -861,10 +861,9 @@ def _appliance_measurements( data["select_dhw_mode"] = appl_p_loc.text case _ as meas_rn if meas_rn in BINARY_SENSORS: bs_key = cast(BinarySensorType, meas_rn) - bs_value = format_measure( - appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) + bs_value = appl_p_loc.text in ["on", "true"] ) - assert isinstance(bs_value, bool) + # assert isinstance(bs_value, bool) data["binary_sensors"][bs_key] = bs_value case _ as meas_rn if meas_rn in SENSORS: s_key = cast(SensorType, meas_rn) @@ -888,16 +887,11 @@ def _appliance_measurements( ] case _ as meas_rn if meas_rn in SWITCHES: sw_key = cast(SwitchType, meas_rn) - value = format_measure( - appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) - ) - sw_value = cast(bool, value) + sw_value = appl_p_loc.text in ["on", "true"] data["switches"][sw_key] = sw_value case "c_heating_state": - value = format_measure( - appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) - ) - assert isinstance(value, bool) + value = appl_p_loc.text in ["on", "true"] + # assert isinstance(value, bool) data["c_heating_state"] = value case "elga_status_code": data["elga_status_code"] = int(appl_p_loc.text) diff --git a/plugwise/util.py b/plugwise/util.py index 1c72e69d3..ffd91ee61 100644 --- a/plugwise/util.py +++ b/plugwise/util.py @@ -20,36 +20,33 @@ def escape_illegal_xml_characters(xmldata: str) -> str: return re.sub(r"&([^a-zA-Z#])", r"&\1", xmldata) -def format_measure(measure: str, unit: str) -> bool | float | int: +def format_measure(measure: str, unit: str) -> float | int: """Format measure to correct type.""" - result: bool | float | int = False + result: float | int = 0 try: result = int(measure) if unit == TEMP_CELSIUS: result = float(measure) except ValueError: - try: - float_measure = float(measure) - if unit == PERCENTAGE: - if 0 < float_measure <= 1: - return int(float_measure * 100) - - if unit == ENERGY_KILO_WATT_HOUR: - float_measure = float_measure / 1000 - - if unit in SPECIAL_FORMAT: - result = float(f"{round(float_measure, 3):.3f}") - elif unit == ELECTRIC_POTENTIAL_VOLT: + float_measure = float(measure) + if unit == PERCENTAGE: + if 0 < float_measure <= 1: + return int(float_measure * 100) + + if unit == ENERGY_KILO_WATT_HOUR: + float_measure = float_measure / 1000 + + if unit in SPECIAL_FORMAT: + result = float(f"{round(float_measure, 3):.3f}") + elif unit == ELECTRIC_POTENTIAL_VOLT: + result = float(f"{round(float_measure, 1):.1f}") + else: + if abs(float_measure) < 10: + result = float(f"{round(float_measure, 2):.2f}") + elif abs(float_measure) >= 10 and abs(float_measure) < 100: result = float(f"{round(float_measure, 1):.1f}") - else: - if abs(float_measure) < 10: - result = float(f"{round(float_measure, 2):.2f}") - elif abs(float_measure) >= 10 and abs(float_measure) < 100: - result = float(f"{round(float_measure, 1):.1f}") - elif abs(float_measure) >= 100: - result = int(round(float_measure)) - except ValueError: - result = measure in ["on", "true"] + elif abs(float_measure) >= 100: + result = int(round(float_measure)) return result From a10f65b5795bbd4ad78f028c89c8a1e54d573194 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 28 Aug 2023 18:01:12 +0200 Subject: [PATCH 166/173] Fix --- plugwise/helper.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index e06723cf9..ecc1229e2 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -862,7 +862,6 @@ def _appliance_measurements( case _ as meas_rn if meas_rn in BINARY_SENSORS: bs_key = cast(BinarySensorType, meas_rn) bs_value = appl_p_loc.text in ["on", "true"] - ) # assert isinstance(bs_value, bool) data["binary_sensors"][bs_key] = bs_value case _ as meas_rn if meas_rn in SENSORS: From 8bf1d5a32af219cba79edf00115bd6c5a978f9d6 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 28 Aug 2023 18:03:05 +0200 Subject: [PATCH 167/173] Clean up --- plugwise/helper.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index ecc1229e2..9d8977712 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -862,7 +862,6 @@ def _appliance_measurements( case _ as meas_rn if meas_rn in BINARY_SENSORS: bs_key = cast(BinarySensorType, meas_rn) bs_value = appl_p_loc.text in ["on", "true"] - # assert isinstance(bs_value, bool) data["binary_sensors"][bs_key] = bs_value case _ as meas_rn if meas_rn in SENSORS: s_key = cast(SensorType, meas_rn) @@ -890,7 +889,6 @@ def _appliance_measurements( data["switches"][sw_key] = sw_value case "c_heating_state": value = appl_p_loc.text in ["on", "true"] - # assert isinstance(value, bool) data["c_heating_state"] = value case "elga_status_code": data["elga_status_code"] = int(appl_p_loc.text) From 23e6a40296ee93a002fb6dda175927cb74ffbc65 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 28 Aug 2023 18:21:10 +0200 Subject: [PATCH 168/173] Bump to a1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 245138f52..40f589ecb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "plugwise" -version = "0.32.1a0" +version = "0.32.1a1" license = {file = "LICENSE"} description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3." readme = "README.md" From 06919eee7df8b85ac62dc50d08e8599faa10f2bd Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 28 Aug 2023 19:08:04 +0200 Subject: [PATCH 169/173] Simplify, improve readability --- plugwise/helper.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 9d8977712..42d7837df 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -852,39 +852,39 @@ def _appliance_measurements( ): continue - meas_rn = measurement if new_name := getattr(attrs, ATTR_NAME, None): - meas_rn = new_name - match meas_rn: + measurement = new_name + + match measurement: # measurements with states "on" or "off" that need to be passed directly case "select_dhw_mode": data["select_dhw_mode"] = appl_p_loc.text - case _ as meas_rn if meas_rn in BINARY_SENSORS: - bs_key = cast(BinarySensorType, meas_rn) + case _ as measurement if measurement in BINARY_SENSORS: + bs_key = cast(BinarySensorType, measurement) bs_value = appl_p_loc.text in ["on", "true"] data["binary_sensors"][bs_key] = bs_value - case _ as meas_rn if meas_rn in SENSORS: - s_key = cast(SensorType, meas_rn) + case _ as measurement if measurement in SENSORS: + s_key = cast(SensorType, measurement) s_value = format_measure( appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT) ) data["sensors"][s_key] = s_value # Anna: save cooling-related measurements for later use # Use the local outdoor temperature as reference for turning cooling on/off - if meas_rn == "cooling_activation_outdoor_temperature": + if measurement == "cooling_activation_outdoor_temperature": self._cooling_activation_outdoor_temp = data["sensors"][ "cooling_activation_outdoor_temperature" ] - if meas_rn == "cooling_deactivation_threshold": + if measurement == "cooling_deactivation_threshold": self._cooling_deactivation_threshold = data["sensors"][ "cooling_deactivation_threshold" ] - if meas_rn == "outdoor_air_temperature": + if measurement == "outdoor_air_temperature": self._outdoor_temp = data["sensors"][ "outdoor_air_temperature" ] - case _ as meas_rn if meas_rn in SWITCHES: - sw_key = cast(SwitchType, meas_rn) + case _ as measurement if measurement in SWITCHES: + sw_key = cast(SwitchType, measurement) sw_value = appl_p_loc.text in ["on", "true"] data["switches"][sw_key] = sw_value case "c_heating_state": From d81a67b4562f0fb9540c358c2dec6e8462052233 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 29 Aug 2023 08:06:37 +0200 Subject: [PATCH 170/173] Add remove_empty_platform_dicts() function and implement --- plugwise/__init__.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index aebd2d820..3bbd2afdc 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -47,6 +47,18 @@ from .helper import SmileComm, SmileHelper +def remove_empty_platform_dicts(data: DeviceData) -> DeviceData: + """Helper-function for removing any empty platform dicts.""" + if not data["binary_sensors"]: + data.pop("binary_sensors") + if not data["sensors"]: + data.pop("sensors") + if not data["switches"]: + data.pop("switches") + + return data + + class SmileData(SmileHelper): """The Plugwise Smile main class.""" @@ -97,12 +109,7 @@ def _all_device_data(self) -> None: if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: self.update_for_cooling(self.gw_devices[device_id]) - if not self.gw_devices[device_id]["binary_sensors"]: - self.gw_devices[device_id].pop("binary_sensors") - if not self.gw_devices[device_id]["sensors"]: - self.gw_devices[device_id].pop("sensors") - if not self.gw_devices[device_id]["switches"]: - self.gw_devices[device_id].pop("switches") + remove_empty_platform_dicts(self.gw_devices[device_id]) self.gw_data.update( {"smile_name": self.smile_name, "gateway_id": self.gateway_id} @@ -545,12 +552,7 @@ async def async_update(self) -> PlugwiseData: if device["dev_class"] in ZONE_THERMOSTATS: self.update_for_cooling(device) - if not device["binary_sensors"]: - device.pop("binary_sensors") - if not device["sensors"]: - device.pop("sensors") - if not device["switches"]: - device.pop("switches") + remove_empty_platform_dicts(device) return PlugwiseData(self.gw_data, self.gw_devices) From f97e3585f987a3b4993b9b057a70bef092798001 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 29 Aug 2023 08:11:12 +0200 Subject: [PATCH 171/173] Remove more python3.9 references --- pyproject.toml | 3 +-- scripts/python-venv.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 40f589ecb..3398b12f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,6 @@ classifiers = [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Topic :: Home Automation", @@ -26,7 +25,7 @@ maintainers = [ { name = "bouwew"}, { name = "CoMPaTech" } ] -requires-python = ">=3.9.0" +requires-python = ">=3.10.0" dependencies = [ "aiohttp", "async_timeout", diff --git a/scripts/python-venv.sh b/scripts/python-venv.sh index 743ad570a..7473b6e6e 100755 --- a/scripts/python-venv.sh +++ b/scripts/python-venv.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eu -pyversions=(3.11 3.10 3.9) +pyversions=(3.11 3.10) my_path=$(git rev-parse --show-toplevel) my_venv=${my_path}/venv From 5c11fe1f3b11471529acabbafaa02d750d302977 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 29 Aug 2023 08:12:32 +0200 Subject: [PATCH 172/173] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38d5c3366..717254038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fix an apparent notification-bug for p1v4. - Improve typing: fix all type-ignores. - Clean up no longer used code. +- Remove support for python3.9. ## v0.32.0: New Feature: add support for changing the temperature offset on a supported thermostat device From 1fceb165b39884dc26027a5bdc9696ac5c8ab7a8 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 29 Aug 2023 08:14:14 +0200 Subject: [PATCH 173/173] Bump to v0.32.1 release-version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3398b12f3..8299659d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "plugwise" -version = "0.32.1a1" +version = "0.32.1" license = {file = "LICENSE"} description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3." readme = "README.md"