Skip to content

Commit

Permalink
Refactoring by adding a decorator to hops_tado.py (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
wmalgadey authored Dec 25, 2024
1 parent 5a12dba commit 904f92a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.DS_Store
35 changes: 23 additions & 12 deletions PyTado/interface/api/hops_tado.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
PyTado interface implementation for hops.tado.com (Tado X).
"""

import functools
import logging
from typing import Any

Expand All @@ -11,6 +12,18 @@
from ...zone import TadoXZone, TadoZone
from .my_tado import Tado, Timetable


def not_supported(reason):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
raise TadoNotSupportedException(f"{func.__name__} is not supported: {reason}")

return wrapper

return decorator


_LOGGER = Logger(__name__)


Expand Down Expand Up @@ -107,12 +120,12 @@ def get_state(self, zone):

return data

@not_supported("This method is not currently supported by the Tado X API")
def get_capabilities(self, zone):
"""
Gets current capabilities of zone.
"""

raise TadoNotSupportedException("This method is not currently supported by the Tado X API")
pass

def get_climate(self, zone):
"""
Expand All @@ -125,15 +138,15 @@ def get_climate(self, zone):
"humidity": data["humidity"]["percentage"],
}

@not_supported("Tado X API only support seven days timetable")
def set_timetable(self, zone: int, timetable: Timetable) -> None:
"""
Set the Timetable type currently active
id = 0 : ONE_DAY (MONDAY_TO_SUNDAY)
id = 1 : THREE_DAY (MONDAY_TO_FRIDAY, SATURDAY, SUNDAY)
id = 3 : SEVEN_DAY (MONDAY, TUESDAY, WEDNESDAY ...)
"""

raise TadoNotSupportedException("Tado X API only support seven days timetable")
pass

def get_schedule(self, zone: int, timetable: Timetable, day=None) -> dict[str, Any]:
"""
Expand Down Expand Up @@ -248,14 +261,12 @@ def set_zone_overlay(

return self._http.request(request)

@not_supported("Concept of zones is not available by Tado X API, they use rooms")
def get_zone_overlay_default(self, zone: int):
"""
Get current overlay default settings for zone.
"""

raise TadoNotSupportedException(
"Concept of zones is not available by Tado X API, they use rooms"
)
pass

def get_open_window_detected(self, zone):
"""
Expand All @@ -269,20 +280,20 @@ def get_open_window_detected(self, zone):
else:
return {"openWindowDetected": False}

@not_supported("This method is not currently supported by the Tado X API")
def set_open_window(self, zone):
"""
Sets the window in zone to open
Note: This can only be set if an open window was detected in this zone
"""
pass

raise TadoNotSupportedException("This method is not currently supported by the Tado X API")

@not_supported("This method is not currently supported by the Tado X API")
def reset_open_window(self, zone):
"""
Sets the window in zone to closed
"""

raise TadoNotSupportedException("This method is not currently supported by the Tado X API")
pass

def get_device_info(self, device_id, cmd=""):
"""
Expand Down

0 comments on commit 904f92a

Please sign in to comment.