From d601f3eb694cec6f5f38a4c411abbd045be3a345 Mon Sep 17 00:00:00 2001 From: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Date: Fri, 6 Sep 2024 15:56:52 +0200 Subject: [PATCH] feat: expose Hysteresis data points (#392) * feat: expose hysteresis value data points (#19) * update test data * add hysteresis getter * add setDomesticHotWaterHysteresis * move to heat pump * add test case * update * feat: expose Hysteresis data points (#25) * update test data * add hysteresis getter * add setDomesticHotWaterHysteresis * move to heat pump * add test case * update * add switchOn switchOff temp setter * add test cases * add types * fix type in setter * add tes cases * remove duplicate test case * add missing type --- PyViCare/PyViCareHeatPump.py | 104 ++++++++++++++++++++++++- tests/test_TestForMissingProperties.py | 1 - tests/test_Vitocal250A.py | 62 +++++++++++++++ 3 files changed, 163 insertions(+), 4 deletions(-) diff --git a/PyViCare/PyViCareHeatPump.py b/PyViCare/PyViCareHeatPump.py index f893af53..89f3c399 100644 --- a/PyViCare/PyViCareHeatPump.py +++ b/PyViCare/PyViCareHeatPump.py @@ -3,7 +3,7 @@ from PyViCare.PyViCareHeatingDevice import (HeatingDevice, HeatingDeviceWithComponent) -from PyViCare.PyViCareUtils import PyViCareNotSupportedFeatureError, handleNotSupported +from PyViCare.PyViCareUtils import PyViCareNotSupportedFeatureError, handleAPICommandErrors, handleNotSupported class HeatPump(HeatingDevice): @@ -115,7 +115,7 @@ def setActiveVentilationMode(self, mode): ---------- mode : str Valid mode can be obtained using getModes() - + Returns ------- result: json @@ -144,7 +144,7 @@ def activateVentilationProgram(self, program): Parameters ---------- program : str - + Returns ------- result: json @@ -152,6 +152,104 @@ def activateVentilationProgram(self, program): """ return self.service.setProperty(f"ventilation.operating.programs.{program}", "activate", {}) + @handleNotSupported + def getDomesticHotWaterHysteresisUnit(self) -> str: + return str(self.service.getProperty("heating.dhw.temperature.hysteresis")["properties"]["value"]["unit"]) + + @handleNotSupported + def getDomesticHotWaterHysteresis(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["properties"]["value"]["value"]) + + @handleNotSupported + def getDomesticHotWaterHysteresisMin(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresis"]["params"]["hysteresis"]["constraints"]["min"]) + + @handleNotSupported + def getDomesticHotWaterHysteresisMax(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresis"]["params"]["hysteresis"]["constraints"]["max"]) + + @handleNotSupported + def getDomesticHotWaterHysteresisStepping(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresis"]["params"]["hysteresis"]["constraints"]["stepping"]) + + @handleAPICommandErrors + def setDomesticHotWaterHysteresis(self, temperature: float) -> Any: + """ Set the hysteresis temperature for domestic host water + Parameters + ---------- + temperature : float + hysteresis temperature + + Returns + ------- + result: json + json representation of the answer + """ + return self.service.setProperty("heating.dhw.temperature.hysteresis", "setHysteresis", {'hysteresis': temperature}) + + @handleNotSupported + def getDomesticHotWaterHysteresisSwitchOn(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["properties"]["switchOnValue"]["value"]) + + @handleNotSupported + def getDomesticHotWaterHysteresisSwitchOnMin(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresisSwitchOnValue"]["params"]["hysteresis"]["constraints"]["min"]) + + @handleNotSupported + def getDomesticHotWaterHysteresisSwitchOnMax(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresisSwitchOnValue"]["params"]["hysteresis"]["constraints"]["max"]) + + @handleNotSupported + def getDomesticHotWaterHysteresisSwitchOnStepping(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresisSwitchOnValue"]["params"]["hysteresis"]["constraints"]["stepping"]) + + @handleAPICommandErrors + def setDomesticHotWaterHysteresisSwitchOn(self, temperature: float) -> Any: + """ Set the hysteresis switch on temperature for domestic host water + Parameters + ---------- + temperature : float + hysteresis switch on temperature + + Returns + ------- + result: json + json representation of the answer + """ + return self.service.setProperty("heating.dhw.temperature.hysteresis", "setHysteresisSwitchOnValue", {'hysteresis': temperature}) + + @handleNotSupported + def getDomesticHotWaterHysteresisSwitchOff(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["properties"]["switchOffValue"]["value"]) + + @handleNotSupported + def getDomesticHotWaterHysteresisSwitchOffMin(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresisSwitchOffValue"]["params"]["hysteresis"]["constraints"]["min"]) + + @handleNotSupported + def getDomesticHotWaterHysteresisSwitchOffMax(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresisSwitchOffValue"]["params"]["hysteresis"]["constraints"]["max"]) + + @handleNotSupported + def getDomesticHotWaterHysteresisSwitchOffStepping(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresisSwitchOffValue"]["params"]["hysteresis"]["constraints"]["stepping"]) + + @handleAPICommandErrors + def setDomesticHotWaterHysteresisSwitchOff(self, temperature: float) -> Any: + """ Set the hysteresis switch off temperature for domestic host water + Parameters + ---------- + temperature : float + hysteresis switch off temperature + + Returns + ------- + result: json + json representation of the answer + """ + return self.service.setProperty("heating.dhw.temperature.hysteresis", "setHysteresisSwitchOffValue", {'hysteresis': temperature}) + + class Compressor(HeatingDeviceWithComponent): @property diff --git a/tests/test_TestForMissingProperties.py b/tests/test_TestForMissingProperties.py index 4fc2af2e..36c09ba3 100644 --- a/tests/test_TestForMissingProperties.py +++ b/tests/test_TestForMissingProperties.py @@ -31,7 +31,6 @@ def test_missingProperties(self): 'heating.power.consumption', 'heating.circuits.0.temperature.levels', # hint: command - 'heating.dhw.temperature.hysteresis', # hint: command 'heating.dhw.hygiene', 'heating.dhw.temperature', 'heating.burners', diff --git a/tests/test_Vitocal250A.py b/tests/test_Vitocal250A.py index 0582e56d..cbaff416 100644 --- a/tests/test_Vitocal250A.py +++ b/tests/test_Vitocal250A.py @@ -128,3 +128,65 @@ def test_getPowerSummaryConsumptionDomesticHotWaterLastYear(self): def test_getCompressorPhase(self): self.assertEqual( self.device.getCompressor(0).getPhase(), "ready") + + def test_getDomesticHotWaterHysteresis(self): + self.assertEqual( + self.device.getDomesticHotWaterHysteresisUnit(), 'kelvin') + self.assertEqual( + self.device.getDomesticHotWaterHysteresis(), 5) + self.assertEqual( + self.device.getDomesticHotWaterHysteresisMin(), 1) + self.assertEqual( + self.device.getDomesticHotWaterHysteresisMax(), 10) + self.assertEqual( + self.device.getDomesticHotWaterHysteresisStepping(), 0.5) + + def test_getDomesticHotWaterHysteresisSwitchOn(self): + self.assertEqual( + self.device.getDomesticHotWaterHysteresisSwitchOn(), 5) + self.assertEqual( + self.device.getDomesticHotWaterHysteresisSwitchOnMin(), 1) + self.assertEqual( + self.device.getDomesticHotWaterHysteresisSwitchOnMax(), 10) + self.assertEqual( + self.device.getDomesticHotWaterHysteresisSwitchOnStepping(), 0.5) + + def test_getDomesticHotWaterHysteresisSwitchOff(self): + self.assertEqual( + self.device.getDomesticHotWaterHysteresisSwitchOff(), 0) + self.assertEqual( + self.device.getDomesticHotWaterHysteresisSwitchOffMin(), 0) + self.assertEqual( + self.device.getDomesticHotWaterHysteresisSwitchOffMax(), 2.5) + self.assertEqual( + self.device.getDomesticHotWaterHysteresisSwitchOffStepping(), 0.5) + + def test_setDomesticHotWaterHysteresis(self): + self.device.setDomesticHotWaterHysteresis(5) + self.assertEqual(len(self.service.setPropertyData), 1) + self.assertEqual( + self.service.setPropertyData[0]['property_name'], 'heating.dhw.temperature.hysteresis') + self.assertEqual( + self.service.setPropertyData[0]['action'], 'setHysteresis') + self.assertEqual(self.service.setPropertyData[0]['data'], { + 'hysteresis': 5}) + + def test_setDomesticHotWaterHysteresisSwitchOn(self): + self.device.setDomesticHotWaterHysteresisSwitchOn(5) + self.assertEqual(len(self.service.setPropertyData), 1) + self.assertEqual( + self.service.setPropertyData[0]['property_name'], 'heating.dhw.temperature.hysteresis') + self.assertEqual( + self.service.setPropertyData[0]['action'], 'setHysteresisSwitchOnValue') + self.assertEqual(self.service.setPropertyData[0]['data'], { + 'hysteresis': 5}) + + def test_setDomesticHotWaterHysteresisSwitchOff(self): + self.device.setDomesticHotWaterHysteresisSwitchOff(5) + self.assertEqual(len(self.service.setPropertyData), 1) + self.assertEqual( + self.service.setPropertyData[0]['property_name'], 'heating.dhw.temperature.hysteresis') + self.assertEqual( + self.service.setPropertyData[0]['action'], 'setHysteresisSwitchOffValue') + self.assertEqual(self.service.setPropertyData[0]['data'], { + 'hysteresis': 5})