1 """Support for Tuya number."""
3 from __future__
import annotations
5 from tuya_sharing
import CustomerDevice, Manager
10 NumberEntityDescription,
17 from .
import TuyaConfigEntry
18 from .const
import DEVICE_CLASS_UNITS, DOMAIN, TUYA_DISCOVERY_NEW, DPCode, DPType
19 from .entity
import IntegerTypeData, TuyaEntity
24 NUMBERS: dict[str, tuple[NumberEntityDescription, ...]] = {
29 key=DPCode.ALARM_TIME,
30 translation_key=
"time",
31 entity_category=EntityCategory.CONFIG,
39 translation_key=
"temperature",
40 device_class=NumberDeviceClass.TEMPERATURE,
41 entity_category=EntityCategory.CONFIG,
44 key=DPCode.TEMP_SET_F,
45 translation_key=
"temperature",
46 device_class=NumberDeviceClass.TEMPERATURE,
47 entity_category=EntityCategory.CONFIG,
50 key=DPCode.TEMP_BOILING_C,
51 translation_key=
"temperature_after_boiling",
52 device_class=NumberDeviceClass.TEMPERATURE,
53 entity_category=EntityCategory.CONFIG,
56 key=DPCode.TEMP_BOILING_F,
57 translation_key=
"temperature_after_boiling",
58 device_class=NumberDeviceClass.TEMPERATURE,
59 entity_category=EntityCategory.CONFIG,
63 translation_key=
"heat_preservation_time",
64 entity_category=EntityCategory.CONFIG,
71 key=DPCode.MANUAL_FEED,
72 translation_key=
"feed",
75 key=DPCode.VOICE_TIMES,
76 translation_key=
"voice_times",
83 key=DPCode.SENSITIVITY,
84 translation_key=
"sensitivity",
85 entity_category=EntityCategory.CONFIG,
88 key=DPCode.NEAR_DETECTION,
89 translation_key=
"near_detection",
90 device_class=NumberDeviceClass.DISTANCE,
91 entity_category=EntityCategory.CONFIG,
94 key=DPCode.FAR_DETECTION,
95 translation_key=
"far_detection",
96 device_class=NumberDeviceClass.DISTANCE,
97 entity_category=EntityCategory.CONFIG,
100 key=DPCode.TARGET_DIS_CLOSEST,
101 translation_key=
"target_dis_closest",
102 device_class=NumberDeviceClass.DISTANCE,
109 key=DPCode.WATER_SET,
110 translation_key=
"water_level",
111 entity_category=EntityCategory.CONFIG,
115 translation_key=
"temperature",
116 device_class=NumberDeviceClass.TEMPERATURE,
117 entity_category=EntityCategory.CONFIG,
120 key=DPCode.WARM_TIME,
121 translation_key=
"heat_preservation_time",
122 entity_category=EntityCategory.CONFIG,
125 key=DPCode.POWDER_SET,
126 translation_key=
"powder",
127 entity_category=EntityCategory.CONFIG,
134 key=DPCode.COOK_TEMPERATURE,
135 translation_key=
"cook_temperature",
136 entity_category=EntityCategory.CONFIG,
139 key=DPCode.COOK_TIME,
140 translation_key=
"cook_time",
141 native_unit_of_measurement=UnitOfTime.MINUTES,
142 entity_category=EntityCategory.CONFIG,
145 key=DPCode.CLOUD_RECIPE_NUMBER,
146 translation_key=
"cloud_recipe",
147 entity_category=EntityCategory.CONFIG,
154 key=DPCode.VOLUME_SET,
155 translation_key=
"volume",
156 entity_category=EntityCategory.CONFIG,
163 key=DPCode.ALARM_TIME,
164 translation_key=
"time",
165 entity_category=EntityCategory.CONFIG,
172 key=DPCode.BASIC_DEVICE_VOLUME,
173 translation_key=
"volume",
174 entity_category=EntityCategory.CONFIG,
181 key=DPCode.BRIGHTNESS_MIN_1,
182 translation_key=
"minimum_brightness",
183 entity_category=EntityCategory.CONFIG,
186 key=DPCode.BRIGHTNESS_MAX_1,
187 translation_key=
"maximum_brightness",
188 entity_category=EntityCategory.CONFIG,
191 key=DPCode.BRIGHTNESS_MIN_2,
192 translation_key=
"minimum_brightness_2",
193 entity_category=EntityCategory.CONFIG,
196 key=DPCode.BRIGHTNESS_MAX_2,
197 translation_key=
"maximum_brightness_2",
198 entity_category=EntityCategory.CONFIG,
201 key=DPCode.BRIGHTNESS_MIN_3,
202 translation_key=
"minimum_brightness_3",
203 entity_category=EntityCategory.CONFIG,
206 key=DPCode.BRIGHTNESS_MAX_3,
207 translation_key=
"maximum_brightness_3",
208 entity_category=EntityCategory.CONFIG,
215 key=DPCode.BRIGHTNESS_MIN_1,
216 translation_key=
"minimum_brightness",
217 entity_category=EntityCategory.CONFIG,
220 key=DPCode.BRIGHTNESS_MAX_1,
221 translation_key=
"maximum_brightness",
222 entity_category=EntityCategory.CONFIG,
225 key=DPCode.BRIGHTNESS_MIN_2,
226 translation_key=
"minimum_brightness_2",
227 entity_category=EntityCategory.CONFIG,
230 key=DPCode.BRIGHTNESS_MAX_2,
231 translation_key=
"maximum_brightness_2",
232 entity_category=EntityCategory.CONFIG,
239 key=DPCode.SENSITIVITY,
240 translation_key=
"sensitivity",
241 entity_category=EntityCategory.CONFIG,
247 key=DPCode.ARM_DOWN_PERCENT,
248 translation_key=
"move_down",
249 native_unit_of_measurement=PERCENTAGE,
250 entity_category=EntityCategory.CONFIG,
253 key=DPCode.ARM_UP_PERCENT,
254 translation_key=
"move_up",
255 native_unit_of_measurement=PERCENTAGE,
256 entity_category=EntityCategory.CONFIG,
259 key=DPCode.CLICK_SUSTAIN_TIME,
260 translation_key=
"down_delay",
261 entity_category=EntityCategory.CONFIG,
269 translation_key=
"temperature",
270 device_class=NumberDeviceClass.TEMPERATURE,
278 translation_key=
"temperature",
279 device_class=NumberDeviceClass.TEMPERATURE,
282 key=DPCode.TEMP_SET_F,
283 translation_key=
"temperature",
284 device_class=NumberDeviceClass.TEMPERATURE,
291 translation_key=
"temperature",
292 device_class=NumberDeviceClass.TEMPERATURE,
299 key=DPCode.ALARM_TIME,
300 translation_key=
"alarm_duration",
301 native_unit_of_measurement=UnitOfTime.SECONDS,
302 device_class=NumberDeviceClass.DURATION,
303 entity_category=EntityCategory.CONFIG,
310 hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback
312 """Set up Tuya number dynamically through Tuya discovery."""
313 hass_data = entry.runtime_data
317 """Discover and add a discovered Tuya number."""
318 entities: list[TuyaNumberEntity] = []
319 for device_id
in device_ids:
320 device = hass_data.manager.device_map[device_id]
321 if descriptions := NUMBERS.get(device.category):
324 for description
in descriptions
325 if description.key
in device.status
332 entry.async_on_unload(
338 """Tuya Number Entity."""
340 _number: IntegerTypeData |
None =
None
344 device: CustomerDevice,
345 device_manager: Manager,
346 description: NumberEntityDescription,
348 """Init Tuya sensor."""
349 super().
__init__(device, device_manager)
354 description.key, dptype=DPType.INTEGER, prefer_function=
True
366 and description.native_unit_of_measurement
is None
383 if self.
_uom_uom
is None:
390 self.
_uom_uom.conversion_unit
or self.
_uom_uom.unit
395 """Return the entity value to represent the entity state."""
397 if self.
_number_number
is None:
404 return self.
_number_number.scale_value(value)
408 if self.
_number_number
is None:
409 raise RuntimeError(
"Cannot set value, device doesn't provide type data")
415 "value": self.
_number_number.scale_value_back(value),
NumberDeviceClass|None device_class(self)
str|None native_unit_of_measurement(self)
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 set_native_value(self, float value)
_attr_native_unit_of_measurement
None __init__(self, CustomerDevice device, Manager device_manager, NumberEntityDescription description)
float|None native_value(self)
str|None device_class(self)
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)