Skip to content

Commit

Permalink
extract quickmodes feature
Browse files Browse the repository at this point in the history
  • Loading branch information
CFenner committed Dec 23, 2024
1 parent 6d33879 commit ef6f4c7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
26 changes: 26 additions & 0 deletions PyViCare/Features/FeatureVentilationQuickmodes.py
Original file line number Diff line number Diff line change
@@ -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", {})
Empty file added PyViCare/Features/__init__.py
Empty file.
24 changes: 3 additions & 21 deletions PyViCare/PyViCareVentilationDevice.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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", {})

0 comments on commit ef6f4c7

Please sign in to comment.