diff --git a/CHANGELOG.md b/CHANGELOG.md index d162271b2..a6746c458 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Changelog -## Ongoing +## v1.11.4 +- Correct Anna P1 detection via PR [#879](https://github.com/plugwise/python-plugwise/pull/879) - Create an extra test-fixture for increased test coverage in the Integration via PR [#878](https://github.com/plugwise/python-plugwise/pull/878) - Add missing Emma firmware via PR [#863](https://github.com/plugwise/python-plugwise/pull/863) - Improve test function added in #860 via PR [#862](https://github.com/plugwise/python-plugwise/pull/862) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 9c4cd84dd..efe23dfd4 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -187,26 +187,33 @@ async def _smile_detect( """Helper-function for connect(). Detect which type of Plugwise Gateway is being connected. + Store the collected data, also collect some specific thermostat devices. """ + model = await self._collect_smile_data(dsmrmain, result) + self._store_smile_data(model) + self._process_for_thermostat(result) + + async def _collect_smile_data( + self, dsmrmain: etree.Element, result: etree.Element + ) -> str: + """Collect smile/gateway data.""" model: str = "Unknown" if (gateway := result.find("./gateway")) is not None: self.smile.version = parse(gateway.find("firmware_version").text) self.smile.hw_version = gateway.find("hardware_version").text self.smile.hostname = gateway.find("hostname").text self.smile.mac_address = gateway.find("mac_address").text - if (vendor_model := gateway.find("vendor_model")) is None: - return # pragma: no cover + if (vendor_model := gateway.find("vendor_model")) is not None: + model = vendor_model.text - model = vendor_model.text - elec_measurement = gateway.find( - "gateway_environment/electricity_consumption_tariff_structure" + # Check for Anna P1 function + elec_point_meters = result.findall( + "./location/logs/point_log/electricity_point_meter" ) - if ( - elec_measurement is not None - and elec_measurement.text - and model == "smile_thermo" - ): - self.smile.anna_p1 = True + for meter in elec_point_meters: + if meter.get("id") and model == "smile_thermo": + self.smile.anna_p1 = True + break else: model = await self._smile_detect_legacy(result, dsmrmain, model) @@ -220,6 +227,35 @@ async def _smile_detect( ) raise UnsupportedDeviceError + return model + + def _process_for_thermostat(self, result: etree.Element) -> None: + """Extra processing for thermostats.""" + if self.smile.type != "thermostat": + return + + self._is_thermostat = True + # For Adam, Anna, determine the system capabilities: + # Find the connected heating/cooling device (heater_central), + # e.g. heat-pump or gas-fired heater + onoff_boiler = result.find("./module/protocols/onoff_boiler") + open_therm_boiler = result.find("./module/protocols/open_therm_boiler") + self._on_off_device = onoff_boiler is not None + self._opentherm_device = open_therm_boiler is not None + + # Determine the presence of special features + locator_1 = "./gateway/features/cooling" + locator_2 = "./gateway/features/elga_support" + if result.find(locator_1) is not None: + self._cooling_present = True + if result.find(locator_2) is not None: + self._elga = True + + def _store_smile_data(self, model: str) -> None: + """Store the collected the smile/gateway data. + + Perform some checks, and set a shorter timeout for non-legacy Gateways. + """ version_major = str(self.smile.version.major) self._target_smile = f"{model}_v{version_major}" LOGGER.debug("Plugwise identified as %s", self._target_smile) @@ -251,30 +287,6 @@ async def _smile_detect( if self.smile.type == "stretch": self._stretch_v2 = int(version_major) == 2 - self._process_for_thermostat(result) - - def _process_for_thermostat(self, result: etree.Element) -> None: - """Extra processing for thermostats.""" - if self.smile.type != "thermostat": - return - - self._is_thermostat = True - # For Adam, Anna, determine the system capabilities: - # Find the connected heating/cooling device (heater_central), - # e.g. heat-pump or gas-fired heater - onoff_boiler = result.find("./module/protocols/onoff_boiler") - open_therm_boiler = result.find("./module/protocols/open_therm_boiler") - self._on_off_device = onoff_boiler is not None - self._opentherm_device = open_therm_boiler is not None - - # Determine the presence of special features - locator_1 = "./gateway/features/cooling" - locator_2 = "./gateway/features/elga_support" - if result.find(locator_1) is not None: - self._cooling_present = True - if result.find(locator_2) is not None: - self._elga = True - async def _smile_detect_legacy( self, result: etree.Element, dsmrmain: etree.Element, model: str ) -> str: diff --git a/pyproject.toml b/pyproject.toml index a66c400a2..3333fa6f4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "plugwise" -version = "1.11.3" +version = "1.11.4" license = "MIT" description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3." readme = "README.md"