diff --git a/PyViCare/PyViCareHeatPump.py b/PyViCare/PyViCareHeatPump.py index 28680a0e..aaee19c4 100644 --- a/PyViCare/PyViCareHeatPump.py +++ b/PyViCare/PyViCareHeatPump.py @@ -1,9 +1,11 @@ from __future__ import annotations +from contextlib import suppress from typing import Any, List from deprecated import deprecated from PyViCare.PyViCareHeatingDevice import HeatingDevice, HeatingDeviceWithComponent -from PyViCare.PyViCareUtils import handleAPICommandErrors, handleNotSupported +from PyViCare.PyViCareUtils import (PyViCareNotSupportedFeatureError, + handleAPICommandErrors, handleNotSupported) from PyViCare.PyViCareVentilationDevice import VentilationDevice @@ -320,6 +322,39 @@ def getHeatingRodPowerConsumptionHeatingThisYear(self) -> float: def getHeatingRodPowerConsumptionTotalThisYear(self) -> float: return float(self.getProperty("heating.heatingRod.power.consumption.total")["properties"]["year"]["value"][0]) + # Cooling circuits + @property + def coolingCircuits(self) -> List[CoolingCircuit]: + return [self.getCoolingCircuit(x) for x in self.getAvailableCoolingCircuits()] + + def getCoolingCircuit(self, circuit) -> CoolingCircuit: + return CoolingCircuit(self, circuit) + + def getAvailableCoolingCircuits(self): + """Detect available cooling circuits (0, 1, 2, etc.).""" + available = [] + for circuit in ['0', '1', '2', '3']: + with suppress(KeyError, PyViCareNotSupportedFeatureError): + if self.getProperty(f"heating.coolingCircuits.{circuit}.type") is not None: + available.append(circuit) + return available + + +class CoolingCircuit(HeatingDeviceWithComponent): + """Cooling circuit component for heat pumps with cooling capability.""" + + @property + def circuit(self) -> str: + return self.component + + @handleNotSupported + def getType(self) -> str: + return str(self.getProperty(f"heating.coolingCircuits.{self.circuit}.type")["properties"]["value"]["value"]) + + @handleNotSupported + def getReverseActive(self) -> bool: + return bool(self.getProperty(f"heating.coolingCircuits.{self.circuit}.reverse")["properties"]["active"]["value"]) + class Compressor(HeatingDeviceWithComponent): diff --git a/tests/test_TestForMissingProperties.py b/tests/test_TestForMissingProperties.py index 5f8a21b9..79307853 100644 --- a/tests/test_TestForMissingProperties.py +++ b/tests/test_TestForMissingProperties.py @@ -201,8 +201,6 @@ def test_missingProperties(self): 'heating.configuration.dhwHeater', 'heating.configuration.flow.temperature.max', 'heating.configuration.flow.temperature.min', - 'heating.coolingCircuits.0.reverse', - 'heating.coolingCircuits.0.type', 'heating.cop.cooling', 'heating.cop.dhw', 'heating.cop.green', @@ -359,7 +357,7 @@ def test_unverifiedProperties(self): continue for match in re.findall(r'getProperty\(\s*?f?"(.*)"\s*?\)', all_python_files[python]): - feature_name = re.sub(r'{self.(circuit|burner|compressor|condensor|evaporator|inverter)}', '0', match) + feature_name = re.sub(r'{(self\.)?(circuit|burner|compressor|condensor|evaporator|inverter)}', '0', match) feature_name = re.sub(r'{burner}', '0', feature_name) feature_name = re.sub(r'\.{(quickmode|mode|program|active_program)}', '', feature_name) used_features.append(feature_name) diff --git a/tests/test_Vitocal300G.py b/tests/test_Vitocal300G.py index 5e49327b..59434471 100644 --- a/tests/test_Vitocal300G.py +++ b/tests/test_Vitocal300G.py @@ -80,3 +80,16 @@ def test_getModes(self): def test_getDomesticHotWaterCirculationPumpActive(self): self.assertEqual( self.device.getDomesticHotWaterCirculationPumpActive(), False) + + # Cooling circuit tests + def test_getAvailableCoolingCircuits(self): + self.assertEqual( + self.device.getAvailableCoolingCircuits(), ['0']) + + def test_coolingCircuit_getType(self): + self.assertEqual( + self.device.coolingCircuits[0].getType(), "VC 3xx-G Emerson") + + def test_coolingCircuit_getReverseActive(self): + self.assertEqual( + self.device.coolingCircuits[0].getReverseActive(), False)