Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add DHW mode functions for E3 devices #427

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions PyViCare/PyViCareHeatingDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,19 @@ 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"]
raise PyViCareNotSupportedFeatureError("getDomesticHotWaterModes")

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
Expand All @@ -103,6 +115,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()

Expand Down
6 changes: 5 additions & 1 deletion tests/ViCareServiceMock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion tests/test_E3_TCU300_ethernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_GenericDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_Solar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_VitoairFs300E.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 9 additions & 1 deletion tests/test_Vitocal151A.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_Vitocal200.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_Vitocal200S.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 10 additions & 1 deletion tests/test_Vitocal222S.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion tests/test_Vitocal250A.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_Vitocal300G.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_Vitocal333G.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 2 additions & 1 deletion tests/test_Vitocaldens222F.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 8 additions & 1 deletion tests/test_VitochargeVX3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion tests/test_VitoconnectOpto1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 6 additions & 1 deletion tests/test_VitoconnectOpto2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_Vitodens100W.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_Vitodens200W.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_Vitodens200W_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_Vitodens222W.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_Vitodens300W.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_Vitodens333F.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/test_VitolaUniferral.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading
Loading