diff --git a/PyViCare/Features/FeatureVentilation.py b/PyViCare/Features/FeatureVentilation.py new file mode 100644 index 0000000..a7946a3 --- /dev/null +++ b/PyViCare/Features/FeatureVentilation.py @@ -0,0 +1,72 @@ +from contextlib import suppress + +from PyViCare.PyViCareDevice import Device +from PyViCare.PyViCareUtils import PyViCareNotSupportedFeatureError, handleAPICommandErrors, handleNotSupported + +class FeatureVentilation(Device): + @handleNotSupported + def getVentilationDemand(self) -> str: + return str(self.service.getProperty("ventilation.operating.state")["properties"]["demand"]["value"]) + + @handleNotSupported + def getVentilationLevel(self) -> str: + return str(self.service.getProperty("ventilation.operating.state")["properties"]["level"]["value"]) + + @handleNotSupported + def getVentilationReason(self) -> str: + return str(self.service.getProperty("ventilation.operating.state")["properties"]["reason"]["value"]) + + @handleNotSupported + def getVentilationModes(self) -> list[str]: + return list[str](self.service.getProperty("ventilation.operating.modes.active")["commands"]["setMode"]["params"]["mode"]["constraints"]["enum"]) + + @handleNotSupported + def getVentilationMode(self, mode: str) -> bool: + return bool(self.service.getProperty(f"ventilation.operating.modes.{mode}")["properties"]["active"]["value"]) + + @handleNotSupported + def getActiveVentilationMode(self) -> str: + return str(self.service.getProperty("ventilation.operating.modes.active")["properties"]["value"]["value"]) + + def activateVentilationMode(self, mode: str): + """ Set the active ventilation mode + Parameters + ---------- + mode : str + Valid mode can be obtained using getVentilationModes() + + Returns + ------- + result: json + json representation of the answer + """ + return self.service.setProperty("ventilation.operating.modes.active", "setMode", {'mode': mode}) + + @handleNotSupported + def getVentilationModePermanentLevels(self) -> list[str]: + return list[str](self.service.getProperty("ventilation.operating.modes.permanent")["commands"]["setLevel"]["params"]["level"]["constraints"]["enum"]) + + @handleAPICommandErrors + def setVentilationModePermanentLevel(self, level: str): + return self.service.setProperty("ventilation.operating.modes.permanent", "setLevel", {'level': level}) + + @handleNotSupported + def getVentilationQuickmodes(self) -> list[str]: + available_quickmodes = [] + for quickmode in ['comfort', 'eco', 'forcedLevelFour', 'holiday', 'standby', 'silent']: + with suppress(PyViCareNotSupportedFeatureError): + if self.service.getProperty(f"ventilation.quickmodes.{quickmode}") is not None: + available_quickmodes.append(quickmode) + return available_quickmodes + + @handleNotSupported + def getVentilationQuickmode(self, quickmode: str) -> bool: + return bool(self.service.getProperty(f"ventilation.quickmodes.{quickmode}")["properties"]["active"]["value"]) + + @handleNotSupported + def activateVentilationQuickmode(self, quickmode: str) -> None: + self.service.setProperty(f"ventilation.quickmodes.{quickmode}", "activate", {}) + + @handleNotSupported + def deactivateVentilationQuickmode(self, quickmode: str) -> None: + self.service.setProperty(f"ventilation.quickmodes.{quickmode}", "deactivate", {}) diff --git a/PyViCare/Features/FeatureVentilationModePermanent.py b/PyViCare/Features/FeatureVentilationModePermanent.py deleted file mode 100644 index d140bb0..0000000 --- a/PyViCare/Features/FeatureVentilationModePermanent.py +++ /dev/null @@ -1,11 +0,0 @@ -from PyViCare.PyViCareDevice import Device -from PyViCare.PyViCareUtils import handleAPICommandErrors, handleNotSupported - -class FeatureVentilationModePermanent(Device): - @handleNotSupported - def getVentilationModePermanentLevels(self) -> list[str]: - return list[str](self.service.getProperty("ventilation.operating.modes.permanent")["commands"]["setLevel"]["params"]["level"]["constraints"]["enum"]) - - @handleAPICommandErrors - def setVentilationModePermanentLevel(self, level: str): - return self.service.setProperty("ventilation.operating.modes.permanent", "setLevel", {'level': level}) diff --git a/PyViCare/Features/FeatureVentilationModes.py b/PyViCare/Features/FeatureVentilationModes.py deleted file mode 100644 index 9ed7134..0000000 --- a/PyViCare/Features/FeatureVentilationModes.py +++ /dev/null @@ -1,29 +0,0 @@ -from PyViCare.PyViCareDevice import Device -from PyViCare.PyViCareUtils import handleNotSupported - -class FeatureVentilationModes(Device): - @handleNotSupported - def getVentilationModes(self) -> list[str]: - return list[str](self.service.getProperty("ventilation.operating.modes.active")["commands"]["setMode"]["params"]["mode"]["constraints"]["enum"]) - - @handleNotSupported - def getVentilationMode(self, mode: str) -> bool: - return bool(self.service.getProperty(f"ventilation.operating.modes.{mode}")["properties"]["active"]["value"]) - - @handleNotSupported - def getActiveVentilationMode(self) -> str: - return str(self.service.getProperty("ventilation.operating.modes.active")["properties"]["value"]["value"]) - - def activateVentilationMode(self, mode: str): - """ Set the active ventilation mode - Parameters - ---------- - mode : str - Valid mode can be obtained using getVentilationModes() - - Returns - ------- - result: json - json representation of the answer - """ - return self.service.setProperty("ventilation.operating.modes.active", "setMode", {'mode': mode}) diff --git a/PyViCare/Features/FeatureVentilationQuickmodes.py b/PyViCare/Features/FeatureVentilationQuickmodes.py deleted file mode 100644 index dc639d2..0000000 --- a/PyViCare/Features/FeatureVentilationQuickmodes.py +++ /dev/null @@ -1,26 +0,0 @@ -from contextlib import suppress - -from PyViCare.PyViCareDevice import Device -from PyViCare.PyViCareUtils import (PyViCareNotSupportedFeatureError, handleNotSupported) - -class FeatureVentilationQuickmodes(Device): - @handleNotSupported - def getVentilationQuickmodes(self) -> list[str]: - available_quickmodes = [] - for quickmode in ['comfort', 'eco', 'forcedLevelFour', 'holiday', 'standby', 'silent']: - with suppress(PyViCareNotSupportedFeatureError): - if self.service.getProperty(f"ventilation.quickmodes.{quickmode}") is not None: - available_quickmodes.append(quickmode) - return available_quickmodes - - @handleNotSupported - def getVentilationQuickmode(self, quickmode: str) -> bool: - return bool(self.service.getProperty(f"ventilation.quickmodes.{quickmode}")["properties"]["active"]["value"]) - - @handleNotSupported - def activateVentilationQuickmode(self, quickmode: str) -> None: - self.service.setProperty(f"ventilation.quickmodes.{quickmode}", "activate", {}) - - @handleNotSupported - def deactivateVentilationQuickmode(self, quickmode: str) -> None: - self.service.setProperty(f"ventilation.quickmodes.{quickmode}", "deactivate", {}) diff --git a/PyViCare/Features/FeatureVentilationState.py b/PyViCare/Features/FeatureVentilationState.py deleted file mode 100644 index b791039..0000000 --- a/PyViCare/Features/FeatureVentilationState.py +++ /dev/null @@ -1,15 +0,0 @@ -from PyViCare.PyViCareDevice import Device -from PyViCare.PyViCareUtils import handleNotSupported - -class FeatureVentilationState(Device): - @handleNotSupported - def getVentilationDemand(self) -> str: - return str(self.service.getProperty("ventilation.operating.state")["properties"]["demand"]["value"]) - - @handleNotSupported - def getVentilationLevel(self) -> str: - return str(self.service.getProperty("ventilation.operating.state")["properties"]["level"]["value"]) - - @handleNotSupported - def getVentilationReason(self) -> str: - return str(self.service.getProperty("ventilation.operating.state")["properties"]["reason"]["value"]) diff --git a/PyViCare/PyViCareHeatPump.py b/PyViCare/PyViCareHeatPump.py index 54747e2..e6c5cf3 100644 --- a/PyViCare/PyViCareHeatPump.py +++ b/PyViCare/PyViCareHeatPump.py @@ -1,15 +1,12 @@ from contextlib import suppress from typing import Any, List -from PyViCare.Features.FeatureVentilationModePermanent import FeatureVentilationModePermanent -from PyViCare.Features.FeatureVentilationModes import FeatureVentilationModes -from PyViCare.Features.FeatureVentilationQuickmodes import FeatureVentilationQuickmodes -from PyViCare.Features.FeatureVentilationState import FeatureVentilationState +from PyViCare.Features.FeatureVentilation import FeatureVentilation from PyViCare.PyViCareHeatingDevice import HeatingDevice, HeatingDeviceWithComponent from PyViCare.PyViCareUtils import PyViCareNotSupportedFeatureError, handleAPICommandErrors, handleNotSupported -class HeatPump(FeatureVentilationModePermanent, FeatureVentilationModes, FeatureVentilationQuickmodes, FeatureVentilationState, HeatingDevice): +class HeatPump(FeatureVentilation, HeatingDevice): @property def compressors(self) -> List[Any]: diff --git a/PyViCare/PyViCareVentilationDevice.py b/PyViCare/PyViCareVentilationDevice.py index 16fae89..aed9484 100644 --- a/PyViCare/PyViCareVentilationDevice.py +++ b/PyViCare/PyViCareVentilationDevice.py @@ -1,15 +1,12 @@ from contextlib import suppress -from PyViCare.Features.FeatureVentilationModePermanent import FeatureVentilationModePermanent -from PyViCare.Features.FeatureVentilationModes import FeatureVentilationModes -from PyViCare.Features.FeatureVentilationQuickmodes import FeatureVentilationQuickmodes -from PyViCare.Features.FeatureVentilationState import FeatureVentilationState +from PyViCare.Features.FeatureVentilation import FeatureVentilation from PyViCare.PyViCareDevice import Device from PyViCare.PyViCareUtils import (PyViCareNotSupportedFeatureError, handleAPICommandErrors, handleNotSupported) -class VentilationDevice(FeatureVentilationModePermanent, FeatureVentilationModes, FeatureVentilationQuickmodes, FeatureVentilationState, Device): +class VentilationDevice(FeatureVentilation, Device): """This is the base class for all ventilation devices. This class connects to the Viessmann ViCare API. The authentication is done through OAuth2.