From 4eb97073dc54bc1053e97fea23f9b9ee1ab41ad6 Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Mon, 7 Oct 2024 23:49:40 +0200 Subject: [PATCH 1/3] add dhw mode functions for e2 devices --- PyViCare/PyViCareHeatingDevice.py | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/PyViCare/PyViCareHeatingDevice.py b/PyViCare/PyViCareHeatingDevice.py index b8a12bb1..934aeb55 100644 --- a/PyViCare/PyViCareHeatingDevice.py +++ b/PyViCare/PyViCareHeatingDevice.py @@ -81,7 +81,20 @@ def getHotWaterStorageTemperatureBottom(self): def getDomesticHotWaterConfiguredTemperature2(self): return self.service.getProperty("heating.dhw.temperature.temp2")["properties"]["value"]["value"] + + @handleNotSupported + def getDomesticHotWaterModes(self): + if self.isE3Device(): + return self.service.getProperty("heating.dhw.operating.modes.active")["commands"]["setMode"][ + "params"]["mode"]["constraints"]["enum"] + return [] + + def getDomesticHotWaterActiveMode(self): + if self.isE3Device(): + return self.service.getProperty("heating.dhw.operating.modes.active")["properties"]["value"][ + "value"] + schedule = self.getDomesticHotWaterSchedule() if schedule == "error" or schedule["active"] is not True: return None @@ -103,6 +116,25 @@ def getDomesticHotWaterActiveMode(self): mode = s["mode"] return mode + + def setDomesticHotWaterMode(self, mode): + """ Set the domestic hot water active mode + Parameters + ---------- + mode : str + Valid mode can be obtained using getDomesticHotWaterModes() + + Returns + ------- + result: json + json representation of the answer + """ + if self.isE3Device(): + r = self.service.setProperty("heating.dhw.operating.modes.active", "setMode", {'mode': mode}) + return r + raise PyViCareNotSupportedFeatureError("setDomesticHotWaterMode") + + def getDomesticHotWaterDesiredTemperature(self): mode = self.getDomesticHotWaterActiveMode() From 270da004f728d60e6b25a380f0df6435db08c290 Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Mon, 7 Oct 2024 23:54:51 +0200 Subject: [PATCH 2/3] raise --- PyViCare/PyViCareHeatingDevice.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PyViCare/PyViCareHeatingDevice.py b/PyViCare/PyViCareHeatingDevice.py index 934aeb55..92893748 100644 --- a/PyViCare/PyViCareHeatingDevice.py +++ b/PyViCare/PyViCareHeatingDevice.py @@ -87,8 +87,7 @@ def getDomesticHotWaterModes(self): if self.isE3Device(): return self.service.getProperty("heating.dhw.operating.modes.active")["commands"]["setMode"][ "params"]["mode"]["constraints"]["enum"] - return [] - + raise PyViCareNotSupportedFeatureError("getDomesticHotWaterModes") def getDomesticHotWaterActiveMode(self): if self.isE3Device(): From fdc6b50b3f91a95067e09550f650865d08bfd836 Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Tue, 8 Oct 2024 00:19:42 +0200 Subject: [PATCH 3/3] update test cases --- tests/ViCareServiceMock.py | 6 +++++- tests/test_E3_TCU300_ethernet.py | 8 +++++++- tests/test_GenericDevice.py | 3 +-- tests/test_Solar.py | 3 ++- tests/test_VitoairFs300E.py | 3 ++- tests/test_Vitocal151A.py | 10 +++++++++- tests/test_Vitocal200.py | 3 ++- tests/test_Vitocal200S.py | 3 ++- tests/test_Vitocal222S.py | 11 ++++++++++- tests/test_Vitocal250A.py | 3 ++- tests/test_Vitocal300G.py | 3 ++- tests/test_Vitocal333G.py | 19 +++++++++++++++++++ tests/test_Vitocaldens222F.py | 3 ++- tests/test_VitochargeVX3.py | 9 ++++++++- tests/test_VitoconnectOpto1.py | 6 +++++- tests/test_VitoconnectOpto2.py | 7 ++++++- tests/test_Vitodens100W.py | 3 ++- tests/test_Vitodens200W.py | 3 ++- tests/test_Vitodens200W_2.py | 3 ++- tests/test_Vitodens222W.py | 3 ++- tests/test_Vitodens300W.py | 3 ++- tests/test_Vitodens333F.py | 3 ++- tests/test_VitolaUniferral.py | 3 ++- tests/test_VitovalorPT2.py | 3 ++- tests/test_zigbee_zk03839.py | 8 +++++++- tests/test_zigbee_zk03840.py | 3 ++- 26 files changed, 109 insertions(+), 26 deletions(-) create mode 100644 tests/test_Vitocal333G.py diff --git a/tests/ViCareServiceMock.py b/tests/ViCareServiceMock.py index 0594b409..0a9bb335 100644 --- a/tests/ViCareServiceMock.py +++ b/tests/ViCareServiceMock.py @@ -16,17 +16,21 @@ def MockCircuitsData(circuits): class ViCareServiceMock: - def __init__(self, filename, rawInput=None): + def __init__(self, roles, filename, rawInput=None): if rawInput is None: testData = readJson(filename) self.testData = testData else: self.testData = rawInput + self.roles = roles self.accessor = ViCareDeviceAccessor( '[id]', '[serial]', '[deviceid]') self.setPropertyData = [] + def hasRoles(self, requested_roles) -> bool: + return len(requested_roles) > 0 and set(requested_roles).issubset(set(self.roles)) + def getProperty(self, property_name): entities = self.testData["data"] return readFeature(entities, property_name) diff --git a/tests/test_E3_TCU300_ethernet.py b/tests/test_E3_TCU300_ethernet.py index b3125c10..29aa6de2 100644 --- a/tests/test_E3_TCU300_ethernet.py +++ b/tests/test_E3_TCU300_ethernet.py @@ -4,10 +4,16 @@ from PyViCare.PyViCareUtils import PyViCareNotSupportedFeatureError from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [ + "capability:hems", + "capability:zigbeeCoordinator", + "type:E3", + "type:gateway;TCU300" +] class TCU300_ethernet(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/TCU300_ethernet.json') + self.service = ViCareServiceMock(ROLES, 'response/TCU300_ethernet.json') self.device = Gateway(self.service) def test_getSerial(self): diff --git a/tests/test_GenericDevice.py b/tests/test_GenericDevice.py index 6ad75236..54a79c21 100644 --- a/tests/test_GenericDevice.py +++ b/tests/test_GenericDevice.py @@ -3,11 +3,10 @@ from PyViCare.PyViCareHeatingDevice import HeatingDevice from tests.ViCareServiceMock import MockCircuitsData, ViCareServiceMock - class GenericDeviceTest(unittest.TestCase): def setUp(self): self.service = ViCareServiceMock( - None, {'data': [MockCircuitsData([0])]}) + [], None, {'data': [MockCircuitsData([0])]}) self.device = HeatingDevice(self.service) def test_activateComfort(self): diff --git a/tests/test_Solar.py b/tests/test_Solar.py index bb007697..383f8abf 100644 --- a/tests/test_Solar.py +++ b/tests/test_Solar.py @@ -3,10 +3,11 @@ from PyViCare.PyViCareHeatingDevice import HeatingDevice from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class SolarTest(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/Solar.json') + self.service = ViCareServiceMock(ROLES, 'response/Solar.json') self.device = HeatingDevice(self.service) def test_getSolarStorageTemperature(self): diff --git a/tests/test_VitoairFs300E.py b/tests/test_VitoairFs300E.py index a699a9fc..15606945 100644 --- a/tests/test_VitoairFs300E.py +++ b/tests/test_VitoairFs300E.py @@ -3,10 +3,11 @@ from PyViCare.PyViCareVentilationDevice import VentilationDevice from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class VitoairFs300(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/VitoairFs300E.json') + self.service = ViCareServiceMock(ROLES, 'response/VitoairFs300E.json') self.device = VentilationDevice(self.service) def test_getActiveMode(self): diff --git a/tests/test_Vitocal151A.py b/tests/test_Vitocal151A.py index 512b139c..c099f65d 100644 --- a/tests/test_Vitocal151A.py +++ b/tests/test_Vitocal151A.py @@ -3,10 +3,18 @@ from PyViCare.PyViCareHeatPump import HeatPump from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [ + "type:E3", + "type:cooling;integrated", + "type:dhw;integrated", + "type:heating;integrated", + "type:heatpump", + "type:product;Vitocal_151A" +] class Vitocal200(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/Vitocal151A.json') + self.service = ViCareServiceMock(ROLES, 'response/Vitocal151A.json') self.device = HeatPump(self.service) def test_getPowerConsumptionCooling(self): diff --git a/tests/test_Vitocal200.py b/tests/test_Vitocal200.py index 2bf37d46..88acc019 100644 --- a/tests/test_Vitocal200.py +++ b/tests/test_Vitocal200.py @@ -5,10 +5,11 @@ from tests.helper import now_is from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class Vitocal200(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/Vitocal200.json') + self.service = ViCareServiceMock(ROLES, 'response/Vitocal200.json') self.device = HeatPump(self.service) def test_getCompressorActive(self): diff --git a/tests/test_Vitocal200S.py b/tests/test_Vitocal200S.py index cb8dd6b8..9d6dada4 100644 --- a/tests/test_Vitocal200S.py +++ b/tests/test_Vitocal200S.py @@ -3,10 +3,11 @@ from PyViCare.PyViCareHeatPump import HeatPump from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class Vitocal200S(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/Vitocal200S.json') + self.service = ViCareServiceMock(ROLES, 'response/Vitocal200S.json') self.device = HeatPump(self.service) def test_getDomesticHotWaterConfiguredTemperature(self): diff --git a/tests/test_Vitocal222S.py b/tests/test_Vitocal222S.py index a85b5108..5ca9fdfb 100644 --- a/tests/test_Vitocal222S.py +++ b/tests/test_Vitocal222S.py @@ -4,12 +4,21 @@ from tests.helper import now_is from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [ + "capability:backup;0020_HPMU_VC", + "capability:monetization;AdvancedReport", + "capability:monetization;DhwSavingsCalculator", + "type:E3", + "type:heatpump", + "type:product;Vitocal_222S" +] class Vitocal222S(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/Vitocal222S.json') + self.service = ViCareServiceMock(ROLES, 'response/Vitocal222S.json') self.device = HeatPump(self.service) + @unittest.skip("dump is not up to date, dhw modes where changed for E3 devices in 2023") def test_getDomesticHotWaterActiveMode_10_10_time(self): with now_is('2000-01-01 10:10:00'): self.assertEqual( diff --git a/tests/test_Vitocal250A.py b/tests/test_Vitocal250A.py index 5b2a8f42..38d2adb1 100644 --- a/tests/test_Vitocal250A.py +++ b/tests/test_Vitocal250A.py @@ -3,10 +3,11 @@ from PyViCare.PyViCareHeatPump import HeatPump from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class Vitocal250A(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/Vitocal250A.json') + self.service = ViCareServiceMock(ROLES, 'response/Vitocal250A.json') self.device = HeatPump(self.service) def test_getCompressorActive(self): diff --git a/tests/test_Vitocal300G.py b/tests/test_Vitocal300G.py index 6c26c5e5..543c474e 100644 --- a/tests/test_Vitocal300G.py +++ b/tests/test_Vitocal300G.py @@ -3,10 +3,11 @@ from PyViCare.PyViCareHeatPump import HeatPump from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class Vitocal300G(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/Vitocal300G.json') + self.service = ViCareServiceMock(ROLES, 'response/Vitocal300G.json') self.device = HeatPump(self.service) def test_getCompressorActive(self): diff --git a/tests/test_Vitocal333G.py b/tests/test_Vitocal333G.py new file mode 100644 index 00000000..c36f26ad --- /dev/null +++ b/tests/test_Vitocal333G.py @@ -0,0 +1,19 @@ +import unittest + +from PyViCare.PyViCareHeatPump import HeatPump +from tests.ViCareServiceMock import ViCareServiceMock + +ROLES = [] + +class Vitocal300G(unittest.TestCase): + def setUp(self): + self.service = ViCareServiceMock(ROLES, 'response/Vitocal333G.json') + self.device = HeatPump(self.service) + + def test_getDomesticHotWaterStorageTemperature(self): + self.assertEqual( + self.device.getDomesticHotWaterStorageTemperature(), 47.5) + + def test_getHotWaterStorageTemperatureTop(self): + self.assertEqual( + self.device.getHotWaterStorageTemperatureTop(), 47.5) diff --git a/tests/test_Vitocaldens222F.py b/tests/test_Vitocaldens222F.py index c095ae16..2c160069 100644 --- a/tests/test_Vitocaldens222F.py +++ b/tests/test_Vitocaldens222F.py @@ -3,10 +3,11 @@ from PyViCare.PyViCareHybrid import Hybrid from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class Vitocaldens222F(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/Vitocaldens222F.json') + self.service = ViCareServiceMock(ROLES, 'response/Vitocaldens222F.json') self.device = Hybrid(self.service) def test_getAvailableCircuits(self): diff --git a/tests/test_VitochargeVX3.py b/tests/test_VitochargeVX3.py index 398558e8..0396625d 100644 --- a/tests/test_VitochargeVX3.py +++ b/tests/test_VitochargeVX3.py @@ -3,10 +3,17 @@ from PyViCare.PyViCareElectricalEnergySystem import ElectricalEnergySystem from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [ + "capability:hems", + "type:E3", + "type:ess", + "type:photovoltaic;Internal", + "type:product;Vitocharge" +] class VitochargeVX3(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/VitochargeVX3.json') + self.service = ViCareServiceMock(ROLES, 'response/VitochargeVX3.json') self.device = ElectricalEnergySystem(self.service) def test_getSerial(self): diff --git a/tests/test_VitoconnectOpto1.py b/tests/test_VitoconnectOpto1.py index 1f093d28..0e755078 100644 --- a/tests/test_VitoconnectOpto1.py +++ b/tests/test_VitoconnectOpto1.py @@ -3,10 +3,14 @@ from PyViCare.PyViCareGateway import Gateway from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [ + "type:gateway;VitoconnectOpto1", + "type:legacy" +] class VitoconnectOpto1(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/VitoconnectOpto1.json') + self.service = ViCareServiceMock(ROLES, 'response/VitoconnectOpto1.json') self.device = Gateway(self.service) def test_getSerial(self): diff --git a/tests/test_VitoconnectOpto2.py b/tests/test_VitoconnectOpto2.py index c1ad8e9b..29037556 100644 --- a/tests/test_VitoconnectOpto2.py +++ b/tests/test_VitoconnectOpto2.py @@ -3,10 +3,15 @@ from PyViCare.PyViCareGateway import Gateway from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [ + "type:gateway;VitoconnectOpto2/OT2", + "type:hb2", + "type:legacy" +] class VitoconnectOpto2(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/VitoconnectOpto2.json') + self.service = ViCareServiceMock(ROLES, 'response/VitoconnectOpto2.json') self.device = Gateway(self.service) def test_getSerial(self): diff --git a/tests/test_Vitodens100W.py b/tests/test_Vitodens100W.py index e85450f0..14617565 100644 --- a/tests/test_Vitodens100W.py +++ b/tests/test_Vitodens100W.py @@ -3,10 +3,11 @@ from PyViCare.PyViCareGazBoiler import GazBoiler from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class Vitodens100W(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/Vitodens100W.json') + self.service = ViCareServiceMock(ROLES, 'response/Vitodens100W.json') self.device = GazBoiler(self.service) def test_getActive(self): diff --git a/tests/test_Vitodens200W.py b/tests/test_Vitodens200W.py index 87f21a1b..a1ec4329 100644 --- a/tests/test_Vitodens200W.py +++ b/tests/test_Vitodens200W.py @@ -4,10 +4,11 @@ from tests.helper import now_is from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class Vitodens200W(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/Vitodens200W.json') + self.service = ViCareServiceMock(ROLES, 'response/Vitodens200W.json') self.device = GazBoiler(self.service) def test_getSerial(self): diff --git a/tests/test_Vitodens200W_2.py b/tests/test_Vitodens200W_2.py index 2be07a0e..915720ce 100644 --- a/tests/test_Vitodens200W_2.py +++ b/tests/test_Vitodens200W_2.py @@ -4,10 +4,11 @@ from tests.helper import now_is from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class Vitodens200W_2(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/Vitodens200W_2.json') + self.service = ViCareServiceMock(ROLES, 'response/Vitodens200W_2.json') self.device = GazBoiler(self.service) def test_getSerial(self): diff --git a/tests/test_Vitodens222W.py b/tests/test_Vitodens222W.py index 96fc0df4..1e8fd08a 100644 --- a/tests/test_Vitodens222W.py +++ b/tests/test_Vitodens222W.py @@ -4,10 +4,11 @@ from PyViCare.PyViCareUtils import PyViCareNotSupportedFeatureError from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class Vitodens222W(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/Vitodens222W.json') + self.service = ViCareServiceMock(ROLES, 'response/Vitodens222W.json') self.device = GazBoiler(self.service) def test_getActive(self): diff --git a/tests/test_Vitodens300W.py b/tests/test_Vitodens300W.py index 7edda059..1a995060 100644 --- a/tests/test_Vitodens300W.py +++ b/tests/test_Vitodens300W.py @@ -4,10 +4,11 @@ from PyViCare.PyViCareUtils import PyViCareNotSupportedFeatureError from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class Vitodens300W(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/Vitodens300W.json') + self.service = ViCareServiceMock(ROLES, 'response/Vitodens300W.json') self.device = GazBoiler(self.service) def test_getActive(self): diff --git a/tests/test_Vitodens333F.py b/tests/test_Vitodens333F.py index 9a540d81..8225fc52 100644 --- a/tests/test_Vitodens333F.py +++ b/tests/test_Vitodens333F.py @@ -4,10 +4,11 @@ from PyViCare.PyViCareUtils import PyViCareNotSupportedFeatureError from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class Vitodens333F(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/Vitodens333F.json') + self.service = ViCareServiceMock(ROLES, 'response/Vitodens333F.json') self.device = GazBoiler(self.service) # currently missing an up-to-date test response diff --git a/tests/test_VitolaUniferral.py b/tests/test_VitolaUniferral.py index 6a3eef23..d1498121 100644 --- a/tests/test_VitolaUniferral.py +++ b/tests/test_VitolaUniferral.py @@ -3,10 +3,11 @@ from PyViCare.PyViCareOilBoiler import OilBoiler from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class VitolaUniferral(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/VitolaUniferral.json') + self.service = ViCareServiceMock(ROLES, 'response/VitolaUniferral.json') self.device = OilBoiler(self.service) def test_getDomesticHotWaterConfiguredTemperature(self): diff --git a/tests/test_VitovalorPT2.py b/tests/test_VitovalorPT2.py index 13ebe138..4c67f69a 100644 --- a/tests/test_VitovalorPT2.py +++ b/tests/test_VitovalorPT2.py @@ -3,10 +3,11 @@ from PyViCare.PyViCareFuelCell import FuelCell from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class VitovalorPT2(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/VitovalorPT2.json') + self.service = ViCareServiceMock(ROLES, 'response/VitovalorPT2.json') self.device = FuelCell(self.service) def test_getDomesticHotWaterConfiguredTemperature(self): diff --git a/tests/test_zigbee_zk03839.py b/tests/test_zigbee_zk03839.py index 4a982e77..2954c5c1 100644 --- a/tests/test_zigbee_zk03839.py +++ b/tests/test_zigbee_zk03839.py @@ -3,10 +3,16 @@ from PyViCare.PyViCareRoomSensor import RoomSensor from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [ + "type:E3", + "type:climateSensor", + "type:sensor", + "type:smartRoomDevice" +] class ZK03839(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/zigbee_zk03839.json') + self.service = ViCareServiceMock(ROLES, 'response/zigbee_zk03839.json') self.device = RoomSensor(self.service) def test_getTemperature(self): diff --git a/tests/test_zigbee_zk03840.py b/tests/test_zigbee_zk03840.py index 3bc4ba24..12131bc0 100644 --- a/tests/test_zigbee_zk03840.py +++ b/tests/test_zigbee_zk03840.py @@ -3,10 +3,11 @@ from PyViCare.PyViCareRadiatorActuator import RadiatorActuator from tests.ViCareServiceMock import ViCareServiceMock +ROLES = [] class ZK03840(unittest.TestCase): def setUp(self): - self.service = ViCareServiceMock('response/zigbee_zk03840_trv.json') + self.service = ViCareServiceMock(ROLES, 'response/zigbee_zk03840_trv.json') self.device = RadiatorActuator(self.service) def test_getTemperature(self):