Home Assistant Unofficial Reference 2024.12.1
const.py
Go to the documentation of this file.
1 """Constants for the KNX integration."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Awaitable, Callable
6 from enum import Enum, StrEnum
7 from typing import TYPE_CHECKING, Final, TypedDict
8 
9 from xknx.dpt.dpt_20 import HVACControllerMode
10 from xknx.telegram import Telegram
11 
12 from homeassistant.components.climate import FAN_AUTO, FAN_OFF, HVACAction, HVACMode
13 from homeassistant.const import Platform
14 from homeassistant.util.hass_dict import HassKey
15 
16 if TYPE_CHECKING:
17  from . import KNXModule
18 
19 DOMAIN: Final = "knx"
20 KNX_MODULE_KEY: HassKey[KNXModule] = HassKey(DOMAIN)
21 
22 # Address is used for configuration and services by the same functions so the key has to match
23 KNX_ADDRESS: Final = "address"
24 
25 CONF_INVERT: Final = "invert"
26 CONF_KNX_EXPOSE: Final = "expose"
27 CONF_KNX_INDIVIDUAL_ADDRESS: Final = "individual_address"
28 
29 ##
30 # Connection constants
31 ##
32 CONF_KNX_CONNECTION_TYPE: Final = "connection_type"
33 CONF_KNX_AUTOMATIC: Final = "automatic"
34 CONF_KNX_ROUTING: Final = "routing"
35 CONF_KNX_ROUTING_BACKBONE_KEY: Final = "backbone_key"
36 CONF_KNX_ROUTING_SYNC_LATENCY_TOLERANCE: Final = "sync_latency_tolerance"
37 CONF_KNX_ROUTING_SECURE: Final = "routing_secure"
38 CONF_KNX_TUNNELING: Final = "tunneling"
39 CONF_KNX_TUNNELING_TCP: Final = "tunneling_tcp"
40 CONF_KNX_TUNNELING_TCP_SECURE: Final = "tunneling_tcp_secure"
41 CONF_KNX_LOCAL_IP: Final = "local_ip"
42 CONF_KNX_MCAST_GRP: Final = "multicast_group"
43 CONF_KNX_MCAST_PORT: Final = "multicast_port"
44 CONF_KNX_TUNNEL_ENDPOINT_IA: Final = "tunnel_endpoint_ia"
45 
46 CONF_KNX_RATE_LIMIT: Final = "rate_limit"
47 CONF_KNX_ROUTE_BACK: Final = "route_back"
48 CONF_KNX_STATE_UPDATER: Final = "state_updater"
49 CONF_KNX_DEFAULT_STATE_UPDATER: Final = True
50 CONF_KNX_DEFAULT_RATE_LIMIT: Final = 0
51 
52 DEFAULT_ROUTING_IA: Final = "0.0.240"
53 
54 CONF_KNX_TELEGRAM_LOG_SIZE: Final = "telegram_log_size"
55 TELEGRAM_LOG_DEFAULT: Final = 1000
56 TELEGRAM_LOG_MAX: Final = 25000 # ~10 MB or ~25 hours of reasonable bus load
57 
58 ##
59 # Secure constants
60 ##
61 CONST_KNX_STORAGE_KEY: Final = "knx/"
62 CONF_KNX_KNXKEY_FILENAME: Final = "knxkeys_filename"
63 CONF_KNX_KNXKEY_PASSWORD: Final = "knxkeys_password"
64 
65 CONF_KNX_SECURE_USER_ID: Final = "user_id"
66 CONF_KNX_SECURE_USER_PASSWORD: Final = "user_password"
67 CONF_KNX_SECURE_DEVICE_AUTHENTICATION: Final = "device_authentication"
68 
69 
70 CONF_PAYLOAD_LENGTH: Final = "payload_length"
71 CONF_RESET_AFTER: Final = "reset_after"
72 CONF_RESPOND_TO_READ: Final = "respond_to_read"
73 CONF_STATE_ADDRESS: Final = "state_address"
74 CONF_SYNC_STATE: Final = "sync_state"
75 
76 # original hass yaml config
77 DATA_HASS_CONFIG: Final = "knx_hass_config"
78 
79 ATTR_COUNTER: Final = "counter"
80 ATTR_SOURCE: Final = "source"
81 
82 
83 type AsyncMessageCallbackType = Callable[[Telegram], Awaitable[None]]
84 type MessageCallbackType = Callable[[Telegram], None]
85 
86 SERVICE_KNX_SEND: Final = "send"
87 SERVICE_KNX_ATTR_PAYLOAD: Final = "payload"
88 SERVICE_KNX_ATTR_TYPE: Final = "type"
89 SERVICE_KNX_ATTR_RESPONSE: Final = "response"
90 SERVICE_KNX_ATTR_REMOVE: Final = "remove"
91 SERVICE_KNX_EVENT_REGISTER: Final = "event_register"
92 SERVICE_KNX_EXPOSURE_REGISTER: Final = "exposure_register"
93 SERVICE_KNX_READ: Final = "read"
94 
95 
96 class KNXConfigEntryData(TypedDict, total=False):
97  """Config entry for the KNX integration."""
98 
99  connection_type: str
100  individual_address: str
101  local_ip: str | None # not required
102  multicast_group: str
103  multicast_port: int
104  route_back: bool # not required
105  host: str # only required for tunnelling
106  port: int # only required for tunnelling
107  tunnel_endpoint_ia: str | None # tunnelling only - not required (use get())
108  # KNX secure
109  user_id: int | None # not required
110  user_password: str | None # not required
111  device_authentication: str | None # not required
112  knxkeys_filename: str # not required
113  knxkeys_password: str # not required
114  backbone_key: str | None # not required
115  sync_latency_tolerance: int | None # not required
116  # OptionsFlow only
117  state_updater: bool
118  rate_limit: int
119  # Integration only (not forwarded to xknx)
120  telegram_log_size: int # not required
121 
122 
123 class ColorTempModes(Enum):
124  """Color temperature modes for config validation."""
125 
126  # YAML uses Enum.name (with vol.Upper), UI uses Enum.value for lookup
127  ABSOLUTE = "7.600"
128  ABSOLUTE_FLOAT = "9"
129  RELATIVE = "5.001"
130 
131 
132 class FanZeroMode(StrEnum):
133  """Enum for setting the fan zero mode."""
134 
135  OFF = FAN_OFF
136  AUTO = FAN_AUTO
137 
138 
139 SUPPORTED_PLATFORMS_YAML: Final = {
140  Platform.BINARY_SENSOR,
141  Platform.BUTTON,
142  Platform.CLIMATE,
143  Platform.COVER,
144  Platform.DATE,
145  Platform.DATETIME,
146  Platform.FAN,
147  Platform.LIGHT,
148  Platform.NOTIFY,
149  Platform.NUMBER,
150  Platform.SCENE,
151  Platform.SELECT,
152  Platform.SENSOR,
153  Platform.SWITCH,
154  Platform.TEXT,
155  Platform.TIME,
156  Platform.WEATHER,
157 }
158 
159 SUPPORTED_PLATFORMS_UI: Final = {Platform.SWITCH, Platform.LIGHT}
160 
161 # Map KNX controller modes to HA modes. This list might not be complete.
162 CONTROLLER_MODES: Final = {
163  # Map DPT 20.105 HVAC control modes
164  HVACControllerMode.AUTO: HVACMode.AUTO,
165  HVACControllerMode.HEAT: HVACMode.HEAT,
166  HVACControllerMode.COOL: HVACMode.COOL,
167  HVACControllerMode.OFF: HVACMode.OFF,
168  HVACControllerMode.FAN_ONLY: HVACMode.FAN_ONLY,
169  HVACControllerMode.DEHUMIDIFICATION: HVACMode.DRY,
170 }
171 
172 CURRENT_HVAC_ACTIONS: Final = {
173  HVACMode.HEAT: HVACAction.HEATING,
174  HVACMode.COOL: HVACAction.COOLING,
175  HVACMode.OFF: HVACAction.OFF,
176  HVACMode.FAN_ONLY: HVACAction.FAN,
177  HVACMode.DRY: HVACAction.DRYING,
178 }