From 54e01c1fc8cc75d07160e467f91289dae7f94f64 Mon Sep 17 00:00:00 2001 From: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Date: Fri, 16 Aug 2024 22:49:11 +0200 Subject: [PATCH 1/4] feat: expose hysteresis value data points (#19) * update test data * add hysteresis getter * add setDomesticHotWaterHysteresis * move to heat pump * add test case * update --- PyViCare/PyViCareHeatPump.py | 46 +++++++++++++++++++++++++- tests/test_TestForMissingProperties.py | 1 - tests/test_Vitocal250A.py | 16 +++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/PyViCare/PyViCareHeatPump.py b/PyViCare/PyViCareHeatPump.py index f893af53..79553abb 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): @@ -152,6 +152,50 @@ def activateVentilationProgram(self, program): """ return self.service.setProperty(f"ventilation.operating.programs.{program}", "activate", {}) + + @handleNotSupported + def getDomesticHotWaterHysteresis(self): + return self.service.getProperty("heating.dhw.temperature.hysteresis")["properties"]["value"]["value"] + + @handleNotSupported + def getDomesticHotWaterHysteresisMin(self): + return self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresis"]["params"]["hysteresis"]["constraints"]["min"] + + @handleNotSupported + def getDomesticHotWaterHysteresisMax(self): + return self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresis"]["params"]["hysteresis"]["constraints"]["max"] + + @handleNotSupported + def getDomesticHotWaterHysteresisStepping(self): + return self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresis"]["params"]["hysteresis"]["constraints"]["stepping"] + + @handleNotSupported + def getDomesticHotWaterHysteresisUnit(self): + return self.service.getProperty("heating.dhw.temperature.hysteresis")["properties"]["value"]["unit"] + + @handleAPICommandErrors + def setDomesticHotWaterHysteresis(self, temperature): + """ 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': int(temperature)}) + + @handleNotSupported + def getDomesticHotWaterHysteresisSwitchOn(self): + return self.service.getProperty("heating.dhw.temperature.hysteresis")["properties"]["switchOnValue"]["value"] + + @handleNotSupported + def getDomesticHotWaterHysteresisSwitchOff(self): + return self.service.getProperty("heating.dhw.temperature.hysteresis")["properties"]["switchOffValue"]["value"] + 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..06f69894 100644 --- a/tests/test_Vitocal250A.py +++ b/tests/test_Vitocal250A.py @@ -128,3 +128,19 @@ def test_getPowerSummaryConsumptionDomesticHotWaterLastYear(self): def test_getCompressorPhase(self): self.assertEqual( self.device.getCompressor(0).getPhase(), "ready") + + def test_getFrostProtectionActive(self): + self.assertEqual( + self.device.circuits[0].getFrostProtectionActive(), False) + + def test_getDomesticHotWaterHysteresis(self): + self.assertEqual( + self.device.getDomesticHotWaterHysteresis(), 5) + self.assertEqual( + self.device.getDomesticHotWaterHysteresisUnit(), 'kelvin') + self.assertEqual( + self.device.getDomesticHotWaterHysteresisMin(), 1) + self.assertEqual( + self.device.getDomesticHotWaterHysteresisMax(), 10) + self.assertEqual( + self.device.getDomesticHotWaterHysteresisStepping(), 0.5) From a9bdfc5d0f34359d6e75f9038ce7202f3f1e918a Mon Sep 17 00:00:00 2001 From: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Date: Mon, 19 Aug 2024 10:27:38 +0200 Subject: [PATCH 2/4] 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 --- PyViCare/PyViCareHeatPump.py | 87 +++++++++++++++++++++++++++++------- tests/test_Vitocal250A.py | 54 +++++++++++++++++++++- 2 files changed, 122 insertions(+), 19 deletions(-) diff --git a/PyViCare/PyViCareHeatPump.py b/PyViCare/PyViCareHeatPump.py index 79553abb..47e12995 100644 --- a/PyViCare/PyViCareHeatPump.py +++ b/PyViCare/PyViCareHeatPump.py @@ -152,29 +152,28 @@ def activateVentilationProgram(self, program): """ return self.service.setProperty(f"ventilation.operating.programs.{program}", "activate", {}) - @handleNotSupported - def getDomesticHotWaterHysteresis(self): - return self.service.getProperty("heating.dhw.temperature.hysteresis")["properties"]["value"]["value"] + def getDomesticHotWaterHysteresisUnit(self) -> str: + return str(self.service.getProperty("heating.dhw.temperature.hysteresis")["properties"]["value"]["unit"]) @handleNotSupported - def getDomesticHotWaterHysteresisMin(self): - return self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresis"]["params"]["hysteresis"]["constraints"]["min"] + def getDomesticHotWaterHysteresis(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["properties"]["value"]["value"]) @handleNotSupported - def getDomesticHotWaterHysteresisMax(self): - return self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresis"]["params"]["hysteresis"]["constraints"]["max"] + def getDomesticHotWaterHysteresisMin(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresis"]["params"]["hysteresis"]["constraints"]["min"]) @handleNotSupported - def getDomesticHotWaterHysteresisStepping(self): - return self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresis"]["params"]["hysteresis"]["constraints"]["stepping"] + def getDomesticHotWaterHysteresisMax(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresis"]["params"]["hysteresis"]["constraints"]["max"]) @handleNotSupported - def getDomesticHotWaterHysteresisUnit(self): - return self.service.getProperty("heating.dhw.temperature.hysteresis")["properties"]["value"]["unit"] + def getDomesticHotWaterHysteresisStepping(self) -> float: + return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresis"]["params"]["hysteresis"]["constraints"]["stepping"]) @handleAPICommandErrors - def setDomesticHotWaterHysteresis(self, temperature): + def setDomesticHotWaterHysteresis(self, temperature: float) -> Any: """ Set the hysteresis temperature for domestic host water Parameters ---------- @@ -186,15 +185,69 @@ def setDomesticHotWaterHysteresis(self, temperature): result: json json representation of the answer """ - return self.service.setProperty("heating.dhw.temperature.hysteresis", "setHysteresis", {'hysteresis': int(temperature)}) + 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 getDomesticHotWaterHysteresisSwitchOn(self): - return self.service.getProperty("heating.dhw.temperature.hysteresis")["properties"]["switchOnValue"]["value"] + 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): - return self.service.getProperty("heating.dhw.temperature.hysteresis")["properties"]["switchOffValue"]["value"] + 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): + 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): diff --git a/tests/test_Vitocal250A.py b/tests/test_Vitocal250A.py index 06f69894..1ca04c8f 100644 --- a/tests/test_Vitocal250A.py +++ b/tests/test_Vitocal250A.py @@ -134,13 +134,63 @@ def test_getFrostProtectionActive(self): self.device.circuits[0].getFrostProtectionActive(), False) def test_getDomesticHotWaterHysteresis(self): - self.assertEqual( - self.device.getDomesticHotWaterHysteresis(), 5) 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}) From cf7c895a281645343bd3f2180b82b6632e4476cb Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Fri, 6 Sep 2024 15:43:04 +0200 Subject: [PATCH 3/4] remove duplicate test case --- tests/test_Vitocal250A.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test_Vitocal250A.py b/tests/test_Vitocal250A.py index 1ca04c8f..cbaff416 100644 --- a/tests/test_Vitocal250A.py +++ b/tests/test_Vitocal250A.py @@ -129,10 +129,6 @@ def test_getCompressorPhase(self): self.assertEqual( self.device.getCompressor(0).getPhase(), "ready") - def test_getFrostProtectionActive(self): - self.assertEqual( - self.device.circuits[0].getFrostProtectionActive(), False) - def test_getDomesticHotWaterHysteresis(self): self.assertEqual( self.device.getDomesticHotWaterHysteresisUnit(), 'kelvin') From 3ef785cf36b5a4e9dfeb1ba590eeff41961e840e Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Fri, 6 Sep 2024 15:55:36 +0200 Subject: [PATCH 4/4] add missing type --- PyViCare/PyViCareHeatPump.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/PyViCare/PyViCareHeatPump.py b/PyViCare/PyViCareHeatPump.py index 47e12995..89f3c399 100644 --- a/PyViCare/PyViCareHeatPump.py +++ b/PyViCare/PyViCareHeatPump.py @@ -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 @@ -227,7 +227,7 @@ def getDomesticHotWaterHysteresisSwitchOffMin(self) -> float: return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresisSwitchOffValue"]["params"]["hysteresis"]["constraints"]["min"]) @handleNotSupported - def getDomesticHotWaterHysteresisSwitchOffMax(self): + def getDomesticHotWaterHysteresisSwitchOffMax(self) -> float: return float(self.service.getProperty("heating.dhw.temperature.hysteresis")["commands"]["setHysteresisSwitchOffValue"]["params"]["hysteresis"]["constraints"]["max"]) @handleNotSupported @@ -249,6 +249,7 @@ def setDomesticHotWaterHysteresisSwitchOff(self, temperature: float) -> Any: """ return self.service.setProperty("heating.dhw.temperature.hysteresis", "setHysteresisSwitchOffValue", {'hysteresis': temperature}) + class Compressor(HeatingDeviceWithComponent): @property