Skip to content

Commit

Permalink
consolidate
Browse files Browse the repository at this point in the history
  • Loading branch information
CFenner committed Dec 23, 2024
1 parent 676bf2a commit 0d2bdc2
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 91 deletions.
72 changes: 72 additions & 0 deletions PyViCare/Features/FeatureVentilation.py
Original file line number Diff line number Diff line change
@@ -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", {})
11 changes: 0 additions & 11 deletions PyViCare/Features/FeatureVentilationModePermanent.py

This file was deleted.

29 changes: 0 additions & 29 deletions PyViCare/Features/FeatureVentilationModes.py

This file was deleted.

26 changes: 0 additions & 26 deletions PyViCare/Features/FeatureVentilationQuickmodes.py

This file was deleted.

15 changes: 0 additions & 15 deletions PyViCare/Features/FeatureVentilationState.py

This file was deleted.

7 changes: 2 additions & 5 deletions PyViCare/PyViCareHeatPump.py
Original file line number Diff line number Diff line change
@@ -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]:
Expand Down
7 changes: 2 additions & 5 deletions PyViCare/PyViCareVentilationDevice.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 0d2bdc2

Please sign in to comment.