1 """Support for Tuya select."""
3 from __future__
import annotations
5 from tuya_sharing
import CustomerDevice, Manager
13 from .
import TuyaConfigEntry
14 from .const
import TUYA_DISCOVERY_NEW, DPCode, DPType
15 from .entity
import TuyaEntity
20 SELECTS: dict[str, tuple[SelectEntityDescription, ...]] = {
25 key=DPCode.ALARM_VOLUME,
26 translation_key=
"volume",
27 entity_category=EntityCategory.CONFIG,
34 key=DPCode.CUP_NUMBER,
35 translation_key=
"cups",
38 key=DPCode.CONCENTRATION_SET,
39 translation_key=
"concentration",
40 entity_category=EntityCategory.CONFIG,
44 translation_key=
"material",
45 entity_category=EntityCategory.CONFIG,
49 translation_key=
"mode",
56 key=DPCode.RELAY_STATUS,
57 entity_category=EntityCategory.CONFIG,
58 translation_key=
"relay_status",
61 key=DPCode.LIGHT_MODE,
62 entity_category=EntityCategory.CONFIG,
63 translation_key=
"light_mode",
71 translation_key=
"temperature_level",
78 key=DPCode.WEATHER_DELAY,
79 translation_key=
"weather_delay",
80 entity_category=EntityCategory.CONFIG,
87 key=DPCode.ALARM_VOLUME,
88 translation_key=
"volume",
89 entity_category=EntityCategory.CONFIG,
92 key=DPCode.BRIGHT_STATE,
93 translation_key=
"brightness",
94 entity_category=EntityCategory.CONFIG,
101 key=DPCode.IPC_WORK_MODE,
102 entity_category=EntityCategory.CONFIG,
103 translation_key=
"ipc_work_mode",
106 key=DPCode.DECIBEL_SENSITIVITY,
107 entity_category=EntityCategory.CONFIG,
108 translation_key=
"decibel_sensitivity",
111 key=DPCode.RECORD_MODE,
112 entity_category=EntityCategory.CONFIG,
113 translation_key=
"record_mode",
116 key=DPCode.BASIC_NIGHTVISION,
117 entity_category=EntityCategory.CONFIG,
118 translation_key=
"basic_nightvision",
121 key=DPCode.BASIC_ANTI_FLICKER,
122 entity_category=EntityCategory.CONFIG,
123 translation_key=
"basic_anti_flicker",
126 key=DPCode.MOTION_SENSITIVITY,
127 entity_category=EntityCategory.CONFIG,
128 translation_key=
"motion_sensitivity",
135 key=DPCode.RELAY_STATUS,
136 entity_category=EntityCategory.CONFIG,
137 translation_key=
"relay_status",
140 key=DPCode.LIGHT_MODE,
141 entity_category=EntityCategory.CONFIG,
142 translation_key=
"light_mode",
149 key=DPCode.RELAY_STATUS,
150 entity_category=EntityCategory.CONFIG,
151 translation_key=
"relay_status",
154 key=DPCode.LIGHT_MODE,
155 entity_category=EntityCategory.CONFIG,
156 translation_key=
"light_mode",
159 key=DPCode.LED_TYPE_1,
160 entity_category=EntityCategory.CONFIG,
161 translation_key=
"led_type",
164 key=DPCode.LED_TYPE_2,
165 entity_category=EntityCategory.CONFIG,
166 translation_key=
"led_type_2",
169 key=DPCode.LED_TYPE_3,
170 entity_category=EntityCategory.CONFIG,
171 translation_key=
"led_type_3",
178 key=DPCode.LED_TYPE_1,
179 entity_category=EntityCategory.CONFIG,
180 translation_key=
"led_type",
183 key=DPCode.LED_TYPE_2,
184 entity_category=EntityCategory.CONFIG,
185 translation_key=
"led_type_2",
192 entity_category=EntityCategory.CONFIG,
193 translation_key=
"fingerbot_mode",
201 entity_category=EntityCategory.CONFIG,
202 translation_key=
"vacuum_cistern",
205 key=DPCode.COLLECTION_MODE,
206 entity_category=EntityCategory.CONFIG,
207 translation_key=
"vacuum_collection",
211 entity_category=EntityCategory.CONFIG,
212 translation_key=
"vacuum_mode",
219 key=DPCode.FAN_VERTICAL,
220 entity_category=EntityCategory.CONFIG,
221 translation_key=
"vertical_fan_angle",
224 key=DPCode.FAN_HORIZONTAL,
225 entity_category=EntityCategory.CONFIG,
226 translation_key=
"horizontal_fan_angle",
229 key=DPCode.COUNTDOWN,
230 entity_category=EntityCategory.CONFIG,
231 translation_key=
"countdown",
234 key=DPCode.COUNTDOWN_SET,
235 entity_category=EntityCategory.CONFIG,
236 translation_key=
"countdown",
243 key=DPCode.CONTROL_BACK_MODE,
244 entity_category=EntityCategory.CONFIG,
245 translation_key=
"curtain_motor_mode",
249 entity_category=EntityCategory.CONFIG,
250 translation_key=
"curtain_mode",
257 key=DPCode.SPRAY_MODE,
258 entity_category=EntityCategory.CONFIG,
259 translation_key=
"humidifier_spray_mode",
263 entity_category=EntityCategory.CONFIG,
264 translation_key=
"humidifier_level",
267 key=DPCode.MOODLIGHTING,
268 entity_category=EntityCategory.CONFIG,
269 translation_key=
"humidifier_moodlighting",
272 key=DPCode.COUNTDOWN,
273 entity_category=EntityCategory.CONFIG,
274 translation_key=
"countdown",
277 key=DPCode.COUNTDOWN_SET,
278 entity_category=EntityCategory.CONFIG,
279 translation_key=
"countdown",
286 key=DPCode.COUNTDOWN,
287 entity_category=EntityCategory.CONFIG,
288 translation_key=
"countdown",
291 key=DPCode.COUNTDOWN_SET,
292 entity_category=EntityCategory.CONFIG,
293 translation_key=
"countdown",
300 key=DPCode.COUNTDOWN_SET,
301 entity_category=EntityCategory.CONFIG,
302 translation_key=
"countdown",
305 key=DPCode.DEHUMIDITY_SET_ENUM,
306 translation_key=
"target_humidity",
307 entity_category=EntityCategory.CONFIG,
314 key=DPCode.ALARM_VOLUME,
315 translation_key=
"volume",
316 entity_category=EntityCategory.CONFIG,
323 SELECTS[
"cz"] = SELECTS[
"kg"]
327 SELECTS[
"pc"] = SELECTS[
"kg"]
331 hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback
333 """Set up Tuya select dynamically through Tuya discovery."""
334 hass_data = entry.runtime_data
338 """Discover and add a discovered Tuya select."""
339 entities: list[TuyaSelectEntity] = []
340 for device_id
in device_ids:
341 device = hass_data.manager.device_map[device_id]
342 if descriptions := SELECTS.get(device.category):
345 for description
in descriptions
346 if description.key
in device.status
353 entry.async_on_unload(
359 """Tuya Select Entity."""
363 device: CustomerDevice,
364 device_manager: Manager,
365 description: SelectEntityDescription,
367 """Init Tuya sensor."""
368 super().
__init__(device, device_manager)
374 description.key, dptype=DPType.ENUM, prefer_function=
True
380 """Return the selected entity option to represent the entity state."""
383 if value
is None or value
not in self.
_attr_options_attr_options:
389 """Change the selected option."""
None _send_command(self, list[dict[str, Any]] commands)
DPCode|EnumTypeData|IntegerTypeData|None find_dpcode(self, str|DPCode|tuple[DPCode,...]|None dpcodes, *bool prefer_function=False, DPType|None dptype=None)
IntegerTypeData|None find_dpcode(self, str|DPCode|tuple[DPCode,...]|None dpcodes, *bool prefer_function=False, Literal[DPType.INTEGER] dptype)
DPCode|None find_dpcode(self, str|DPCode|tuple[DPCode,...]|None dpcodes, *bool prefer_function=False)
EnumTypeData|None find_dpcode(self, str|DPCode|tuple[DPCode,...]|None dpcodes, *bool prefer_function=False, Literal[DPType.ENUM] dptype)
None select_option(self, str option)
str|None current_option(self)
None __init__(self, CustomerDevice device, Manager device_manager, SelectEntityDescription description)
ElkSystem|None async_discover_device(HomeAssistant hass, str host)
None async_setup_entry(HomeAssistant hass, TuyaConfigEntry entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)