Home Assistant Unofficial Reference 2024.12.1
helper.py
Go to the documentation of this file.
1 """Helper methods for Tado."""
2 
3 from .const import (
4  CONST_OVERLAY_TADO_DEFAULT,
5  CONST_OVERLAY_TADO_MODE,
6  CONST_OVERLAY_TIMER,
7 )
8 from .tado_connector import TadoConnector
9 
10 
12  tado: TadoConnector,
13  duration: int | None,
14  zone_id: int,
15  overlay_mode: str | None = None,
16 ) -> str:
17  """Return correct overlay mode based on the action and defaults."""
18  # If user gave duration then overlay mode needs to be timer
19  if duration:
20  return CONST_OVERLAY_TIMER
21  # If no duration or timer set to fallback setting
22  if overlay_mode is None:
23  overlay_mode = tado.fallback or CONST_OVERLAY_TADO_MODE
24  # If default is Tado default then look it up
25  if overlay_mode == CONST_OVERLAY_TADO_DEFAULT:
26  overlay_mode = (
27  tado.data["zone"][zone_id].default_overlay_termination_type
28  or CONST_OVERLAY_TADO_MODE
29  )
30 
31  return overlay_mode
32 
33 
35  tado: TadoConnector,
36  duration: int | None,
37  zone_id: int,
38  overlay_mode: str | None = None,
39 ) -> None | int:
40  """Return correct duration based on the selected overlay mode/duration and tado config."""
41  # If we ended up with a timer but no duration, set a default duration
42  # If we ended up with a timer but no duration, set a default duration
43  if overlay_mode == CONST_OVERLAY_TIMER and duration is None:
44  duration = (
45  int(tado.data["zone"][zone_id].default_overlay_termination_duration)
46  if tado.data["zone"][zone_id].default_overlay_termination_duration
47  is not None
48  else 3600
49  )
50 
51  return duration
52 
53 
54 def generate_supported_fanmodes(tado_to_ha_mapping: dict[str, str], options: list[str]):
55  """Return correct list of fan modes or None."""
56  supported_fanmodes = [
57  tado_to_ha_mapping.get(option)
58  for option in options
59  if tado_to_ha_mapping.get(option) is not None
60  ]
61  if not supported_fanmodes:
62  return None
63  return supported_fanmodes
None|int decide_duration(TadoConnector tado, int|None duration, int zone_id, str|None overlay_mode=None)
Definition: helper.py:39
def generate_supported_fanmodes(dict[str, str] tado_to_ha_mapping, list[str] options)
Definition: helper.py:54
str decide_overlay_mode(TadoConnector tado, int|None duration, int zone_id, str|None overlay_mode=None)
Definition: helper.py:16