python-tado 0.19.2__py3-none-any.whl → 0.19.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. PyTado/__init__.py +6 -0
  2. PyTado/__main__.py +15 -9
  3. PyTado/const.py +37 -64
  4. PyTado/exceptions.py +4 -0
  5. PyTado/factory/__init__.py +7 -0
  6. PyTado/factory/initializer.py +90 -0
  7. PyTado/http.py +269 -107
  8. PyTado/interface/api/__init__.py +2 -1
  9. PyTado/interface/api/base_tado.py +601 -0
  10. PyTado/interface/api/hops_tado.py +276 -234
  11. PyTado/interface/api/my_tado.py +167 -427
  12. PyTado/interface/interface.py +71 -261
  13. PyTado/logger.py +1 -1
  14. PyTado/models/__init__.py +8 -0
  15. PyTado/models/common/__init__.py +0 -0
  16. PyTado/models/common/schedule.py +52 -0
  17. PyTado/models/historic.py +137 -0
  18. PyTado/models/home.py +206 -0
  19. PyTado/models/line_x/__init__.py +14 -0
  20. PyTado/models/line_x/device.py +62 -0
  21. PyTado/models/line_x/installation.py +8 -0
  22. PyTado/models/line_x/room.py +90 -0
  23. PyTado/models/line_x/schedule.py +31 -0
  24. PyTado/models/pre_line_x/__init__.py +23 -0
  25. PyTado/models/pre_line_x/boiler.py +36 -0
  26. PyTado/models/pre_line_x/device.py +42 -0
  27. PyTado/models/pre_line_x/flow_temperature_optimization.py +34 -0
  28. PyTado/models/pre_line_x/home.py +7 -0
  29. PyTado/models/pre_line_x/schedule.py +17 -0
  30. PyTado/models/pre_line_x/zone.py +288 -0
  31. PyTado/models/return_models.py +28 -0
  32. PyTado/models/util.py +93 -0
  33. PyTado/types.py +207 -0
  34. PyTado/zone/__init__.py +3 -3
  35. PyTado/zone/base_zone.py +471 -0
  36. PyTado/zone/hops_zone.py +345 -117
  37. PyTado/zone/my_zone.py +471 -180
  38. {python_tado-0.19.2.dist-info → python_tado-0.19.4.dist-info}/METADATA +13 -23
  39. python_tado-0.19.4.dist-info/RECORD +44 -0
  40. {python_tado-0.19.2.dist-info → python_tado-0.19.4.dist-info}/WHEEL +1 -1
  41. python_tado-0.19.2.dist-info/RECORD +0 -20
  42. {python_tado-0.19.2.dist-info → python_tado-0.19.4.dist-info}/entry_points.txt +0 -0
  43. {python_tado-0.19.2.dist-info → python_tado-0.19.4.dist-info/licenses}/AUTHORS +0 -0
  44. {python_tado-0.19.2.dist-info → python_tado-0.19.4.dist-info/licenses}/LICENSE +0 -0
PyTado/__init__.py CHANGED
@@ -0,0 +1,6 @@
1
+ from importlib.metadata import PackageNotFoundError, version
2
+
3
+ try:
4
+ __version__ = version("python-tado")
5
+ except PackageNotFoundError:
6
+ __version__ = "test" # happens when running as pre-commit hook
PyTado/__main__.py CHANGED
@@ -9,7 +9,7 @@ import sys
9
9
  from PyTado.interface import Tado
10
10
 
11
11
 
12
- def log_in(args):
12
+ def log_in(args: argparse.Namespace) -> Tado:
13
13
  """
14
14
  Log in to the Tado API by activating the current device.
15
15
 
@@ -27,7 +27,7 @@ def log_in(args):
27
27
  return t
28
28
 
29
29
 
30
- def get_me(args):
30
+ def get_me(args: argparse.Namespace) -> None:
31
31
  """
32
32
  Retrieve and print home information from the Tado API.
33
33
 
@@ -39,7 +39,7 @@ def get_me(args):
39
39
  print(me)
40
40
 
41
41
 
42
- def get_state(args):
42
+ def get_state(args: argparse.Namespace) -> None:
43
43
  """
44
44
  Retrieve and print the state of a specific zone from the Tado API.
45
45
 
@@ -51,7 +51,7 @@ def get_state(args):
51
51
  print(zone)
52
52
 
53
53
 
54
- def get_states(args):
54
+ def get_states(args: argparse.Namespace) -> None:
55
55
  """
56
56
  Retrieve and print the states of all zones from the Tado API.
57
57
 
@@ -63,7 +63,7 @@ def get_states(args):
63
63
  print(zones)
64
64
 
65
65
 
66
- def get_capabilities(args):
66
+ def get_capabilities(args: argparse.Namespace) -> None:
67
67
  """
68
68
  Retrieve and print the capabilities of a specific zone from the Tado API.
69
69
 
@@ -75,7 +75,7 @@ def get_capabilities(args):
75
75
  print(capabilities)
76
76
 
77
77
 
78
- def main():
78
+ def main() -> None:
79
79
  """
80
80
  Main method for the script.
81
81
 
@@ -109,17 +109,23 @@ def main():
109
109
  show_config_parser = subparsers.add_parser("get_me", help="Get home information.")
110
110
  show_config_parser.set_defaults(func=get_me)
111
111
 
112
- start_activity_parser = subparsers.add_parser("get_state", help="Get state of zone.")
112
+ start_activity_parser = subparsers.add_parser(
113
+ "get_state", help="Get state of zone."
114
+ )
113
115
  start_activity_parser.add_argument("--zone", help="Zone to get the state of.")
114
116
  start_activity_parser.set_defaults(func=get_state)
115
117
 
116
- start_activity_parser = subparsers.add_parser("get_states", help="Get states of all zones.")
118
+ start_activity_parser = subparsers.add_parser(
119
+ "get_states", help="Get states of all zones."
120
+ )
117
121
  start_activity_parser.set_defaults(func=get_states)
118
122
 
119
123
  start_activity_parser = subparsers.add_parser(
120
124
  "get_capabilities", help="Get capabilities of zone."
121
125
  )
122
- start_activity_parser.add_argument("--zone", help="Zone to get the capabilities of.")
126
+ start_activity_parser.add_argument(
127
+ "--zone", help="Zone to get the capabilities of."
128
+ )
123
129
  start_activity_parser.set_defaults(func=get_capabilities)
124
130
 
125
131
  args = parser.parse_args()
PyTado/const.py CHANGED
@@ -1,52 +1,27 @@
1
1
  """Constant values for the Tado component."""
2
2
 
3
+ from PyTado.types import FanLevel, FanSpeed, HvacAction, HvacMode
4
+
3
5
  # API client ID
4
6
  CLIENT_ID_DEVICE = "1bb50063-6b0c-4d11-bd99-387f4a91cc46" # nosec B105
5
7
 
6
- # Types
7
- TYPE_AIR_CONDITIONING = "AIR_CONDITIONING"
8
- TYPE_HEATING = "HEATING"
9
- TYPE_HOT_WATER = "HOT_WATER"
10
-
11
- # Base modes
12
- CONST_MODE_OFF = "OFF"
13
- CONST_MODE_SMART_SCHEDULE = "SMART_SCHEDULE" # Use the schedule
14
- CONST_MODE_AUTO = "AUTO"
15
- CONST_MODE_COOL = "COOL"
16
- CONST_MODE_HEAT = "HEAT"
17
- CONST_MODE_DRY = "DRY"
18
- CONST_MODE_FAN = "FAN"
19
8
 
20
9
  CONST_LINK_OFFLINE = "OFFLINE"
21
10
  CONST_CONNECTION_OFFLINE = "OFFLINE"
22
11
 
23
- CONST_FAN_OFF = "OFF"
24
- CONST_FAN_AUTO = "AUTO"
25
- CONST_FAN_LOW = "LOW"
26
- CONST_FAN_MIDDLE = "MIDDLE"
27
- CONST_FAN_HIGH = "HIGH"
28
-
29
- CONST_FAN_SPEED_OFF = "OFF"
30
- CONST_FAN_SPEED_AUTO = "AUTO"
31
- CONST_FAN_SPEED_SILENT = "SILENT"
32
- CONST_FAN_SPEED_LEVEL1 = "LEVEL1"
33
- CONST_FAN_SPEED_LEVEL2 = "LEVEL1"
34
- CONST_FAN_SPEED_LEVEL3 = "LEVEL3"
35
- CONST_FAN_SPEED_LEVEL4 = "LEVEL4"
36
-
37
- CONST_VERTICAL_SWING_OFF = "OFF"
38
- CONST_VERTICAL_SWING_ON = "ON"
39
12
 
40
- CONST_HORIZONTAL_SWING_OFF = "OFF"
41
- CONST_HORIZONTAL_SWING_ON = "ON"
42
- CONST_HORIZONTAL_SWING_LEFT = "LEFT"
43
- CONST_HORIZONTAL_SWING_MID_LEFT = "MID_LEFT"
44
- CONST_HORIZONTAL_SWING_MID = "MID"
45
- CONST_HORIZONTAL_SWING_MID_RIGHT = "MID_RIGHT"
46
- CONST_HORIZONTAL_SWING_RIGHT = "RIGHT"
13
+ FAN_SPEED_TO_FAN_LEVEL = {
14
+ FanSpeed.OFF: FanLevel.OFF,
15
+ FanSpeed.AUTO: FanLevel.AUTO,
16
+ FanSpeed.LOW: FanLevel.LEVEL1,
17
+ FanSpeed.MIDDLE: FanLevel.LEVEL2,
18
+ FanSpeed.HIGH: FanLevel.LEVEL3,
19
+ }
47
20
 
48
21
  # When we change the temperature setting, we need an overlay mode
49
- CONST_OVERLAY_TADO_MODE = "NEXT_TIME_BLOCK" # wait until tado changes the mode automatic
22
+ CONST_OVERLAY_TADO_MODE = (
23
+ "NEXT_TIME_BLOCK" # wait until tado changes the mode automatic
24
+ )
50
25
  CONST_OVERLAY_MANUAL = "MANUAL" # the user has changed the temperature or mode manually
51
26
  CONST_OVERLAY_TIMER = "TIMER" # the temperature will be reset after a timespan
52
27
 
@@ -55,45 +30,43 @@ CONST_OVERLAY_TIMER = "TIMER" # the temperature will be reset after a timespan
55
30
  # it.
56
31
  # Heat is preferred as it generally has a lower minimum temperature
57
32
  ORDERED_KNOWN_TADO_MODES = [
58
- CONST_MODE_HEAT,
59
- CONST_MODE_COOL,
60
- CONST_MODE_AUTO,
61
- CONST_MODE_DRY,
62
- CONST_MODE_FAN,
33
+ HvacMode.HEAT,
34
+ HvacMode.COOL,
35
+ HvacMode.AUTO,
36
+ HvacMode.DRY,
37
+ HvacMode.FAN,
63
38
  ]
64
39
 
65
- CONST_HVAC_HEAT = "HEATING"
66
- CONST_HVAC_DRY = "DRYING"
67
- CONST_HVAC_FAN = "FAN"
68
- CONST_HVAC_COOL = "COOLING"
69
- CONST_HVAC_IDLE = "IDLE"
70
- CONST_HVAC_OFF = "OFF"
71
- CONST_HVAC_HOT_WATER = TYPE_HOT_WATER
72
-
73
- TADO_MODES_TO_HVAC_ACTION = {
74
- CONST_MODE_HEAT: CONST_HVAC_HEAT,
75
- CONST_MODE_DRY: CONST_HVAC_DRY,
76
- CONST_MODE_FAN: CONST_HVAC_FAN,
77
- CONST_MODE_COOL: CONST_HVAC_COOL,
40
+ TADO_MODES_TO_HVAC_ACTION: dict[HvacMode, HvacAction] = {
41
+ HvacMode.HEAT: HvacAction.HEATING,
42
+ HvacMode.DRY: HvacAction.DRYING,
43
+ HvacMode.FAN: HvacAction.FAN,
44
+ HvacMode.COOL: HvacAction.COOLING,
78
45
  }
79
46
 
80
- TADO_HVAC_ACTION_TO_MODES = {
81
- CONST_HVAC_HEAT: CONST_MODE_HEAT,
82
- CONST_HVAC_HOT_WATER: CONST_HVAC_HEAT,
83
- CONST_HVAC_DRY: CONST_MODE_DRY,
84
- CONST_HVAC_FAN: CONST_MODE_FAN,
85
- CONST_HVAC_COOL: CONST_MODE_COOL,
47
+ TADO_HVAC_ACTION_TO_MODES: dict[HvacAction, HvacMode | HvacAction] = {
48
+ HvacAction.HEATING: HvacMode.HEAT,
49
+ HvacAction.HOT_WATER: HvacAction.HEATING,
50
+ HvacAction.DRYING: HvacMode.DRY,
51
+ HvacAction.FAN: HvacMode.FAN,
52
+ HvacAction.COOLING: HvacMode.COOL,
86
53
  }
87
54
 
88
55
  # These modes will not allow a temp to be set
89
56
  TADO_MODES_WITH_NO_TEMP_SETTING = [
90
- CONST_MODE_AUTO,
91
- CONST_MODE_DRY,
92
- CONST_MODE_FAN,
57
+ HvacMode.AUTO,
58
+ HvacMode.DRY,
59
+ HvacMode.FAN,
93
60
  ]
94
61
 
95
62
  DEFAULT_TADO_PRECISION = 0.1
96
63
  DEFAULT_TADOX_PRECISION = 0.01
64
+ DEFAULT_DATE_FORMAT = "%Y-%m-%d"
65
+
66
+ DEFAULT_TADOX_MIN_TEMP = 5.0
67
+ DEFAULT_TADOX_MAX_TEMP = 30.0
97
68
 
98
69
  HOME_DOMAIN = "homes"
99
70
  DEVICE_DOMAIN = "devices"
71
+
72
+ HTTP_CODES_OK = [200, 201, 202, 204]
PyTado/exceptions.py CHANGED
@@ -19,3 +19,7 @@ class TadoNoCredentialsException(TadoCredentialsException):
19
19
 
20
20
  class TadoWrongCredentialsException(TadoCredentialsException):
21
21
  """Exception to indicate wrong credentials"""
22
+
23
+
24
+ class TadoRateLimitException(TadoException):
25
+ """Exception to indicate API rate limit has been exceeded."""
@@ -0,0 +1,7 @@
1
+ """Factory method for easy initialization."""
2
+
3
+ from ..interface.api.hops_tado import TadoX
4
+ from ..interface.api.my_tado import Tado
5
+ from .initializer import TadoClientInitializer
6
+
7
+ __all__ = ["Tado", "TadoX", "TadoClientInitializer"]
@@ -0,0 +1,90 @@
1
+ """
2
+ PyTado API factory to use app.tado.com or hops.tado.com
3
+ """
4
+
5
+ from typing import Self
6
+
7
+ import requests
8
+
9
+ import PyTado.interface.api as API
10
+ from PyTado.exceptions import TadoException
11
+ from PyTado.http import DeviceActivationStatus, Http
12
+
13
+
14
+ class TadoClientInitializer:
15
+ """Class to authenticate and get the Tado client."""
16
+
17
+ http: Http
18
+ debug: bool = False
19
+ token_file_path: str | None = None
20
+ saved_refresh_token: str | None = None
21
+ http_session: requests.Session | None = None
22
+
23
+ def __init__(
24
+ self,
25
+ token_file_path: str | None = None,
26
+ saved_refresh_token: str | None = None,
27
+ http_session: requests.Session | None = None,
28
+ debug: bool = False,
29
+ ):
30
+ self.token_file_path = token_file_path
31
+ self.saved_refresh_token = saved_refresh_token
32
+ self.http_session = http_session
33
+ self.debug = debug
34
+ self.http = Http(
35
+ token_file_path=token_file_path,
36
+ saved_refresh_token=saved_refresh_token,
37
+ http_session=http_session,
38
+ debug=debug,
39
+ )
40
+
41
+ def get_verification_url(self) -> str | None:
42
+ """Returns the URL for device verification."""
43
+ if self.http.device_activation_status == DeviceActivationStatus.NOT_STARTED:
44
+ self.device_activation()
45
+
46
+ return self.http.device_verification_url
47
+
48
+ def device_activation(self) -> Self:
49
+ """Activates the device.
50
+
51
+ Caution: this method will block until the device is activated or the timeout is reached.
52
+ """
53
+ self.http.device_activation()
54
+
55
+ return self
56
+
57
+ def get_client(self) -> API.TadoX | API.Tado:
58
+ """Returns the client instance after device activation."""
59
+ if self.http.device_activation_status == DeviceActivationStatus.COMPLETED:
60
+ if self.http.is_x_line:
61
+ return API.TadoX.from_http(http=self.http, debug=self.debug)
62
+
63
+ return API.Tado.from_http(http=self.http, debug=self.debug)
64
+
65
+ raise TadoException(
66
+ "Authentication failed. Please check the device verification URL and try again."
67
+ )
68
+
69
+ def authenticate_and_get_client(self) -> API.TadoX | API.Tado:
70
+ """Authenticate and get the client instance, prompting for device activation if needed."""
71
+ print("Starting device activation process...")
72
+ print("Device activation status: ", self.http.device_activation_status)
73
+
74
+ if self.http.device_activation_status != DeviceActivationStatus.COMPLETED:
75
+ print("Click on the link to log in to your Tado account.")
76
+ print("Device verification URL: ", self.get_verification_url())
77
+
78
+ self.device_activation()
79
+
80
+ if (
81
+ self.http.device_activation_status == DeviceActivationStatus.COMPLETED
82
+ ): # pyright: ignore[reportUnnecessaryComparison]
83
+ print("Device activation completed successfully.")
84
+ else:
85
+ raise TadoException(
86
+ "Device activation failed. "
87
+ "Please check the device verification URL and try again."
88
+ )
89
+
90
+ return self.get_client()