From ef6f4c7805e4e50caeb56fc42d423901996361ea Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Mon, 23 Dec 2024 19:31:56 +0100 Subject: [PATCH] extract quickmodes feature --- .../Features/FeatureVentilationQuickmodes.py | 26 +++++++++++++++++++ PyViCare/Features/__init__.py | 0 PyViCare/PyViCareVentilationDevice.py | 24 +++-------------- 3 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 PyViCare/Features/FeatureVentilationQuickmodes.py create mode 100644 PyViCare/Features/__init__.py diff --git a/PyViCare/Features/FeatureVentilationQuickmodes.py b/PyViCare/Features/FeatureVentilationQuickmodes.py new file mode 100644 index 00000000..dc639d25 --- /dev/null +++ b/PyViCare/Features/FeatureVentilationQuickmodes.py @@ -0,0 +1,26 @@ +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/__init__.py b/PyViCare/Features/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/PyViCare/PyViCareVentilationDevice.py b/PyViCare/PyViCareVentilationDevice.py index 347aa167..6094f017 100644 --- a/PyViCare/PyViCareVentilationDevice.py +++ b/PyViCare/PyViCareVentilationDevice.py @@ -1,10 +1,12 @@ + from contextlib import suppress +from PyViCare.Features.FeatureVentilationQuickmodes import FeatureVentilationQuickmodes from PyViCare.PyViCareDevice import Device from PyViCare.PyViCareUtils import (PyViCareNotSupportedFeatureError, handleAPICommandErrors, handleNotSupported) -class VentilationDevice(Device): +class VentilationDevice(FeatureVentilationQuickmodes, Device): """This is the base class for all ventilation devices. This class connects to the Viessmann ViCare API. The authentication is done through OAuth2. @@ -108,23 +110,3 @@ def getVentilationLevel(self) -> str: def getVentilationReason(self) -> str: return str(self.service.getProperty("ventilation.operating.state")["properties"]["reason"]["value"]) - @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", {})