1 """Support for Tuya Vacuums."""
3 from __future__
import annotations
7 from tuya_sharing
import CustomerDevice, Manager
21 from .
import TuyaConfigEntry
22 from .const
import TUYA_DISCOVERY_NEW, DPCode, DPType
23 from .entity
import EnumTypeData, IntegerTypeData, TuyaEntity
25 TUYA_MODE_RETURN_HOME =
"chargego"
27 "charge_done": STATE_DOCKED,
28 "chargecompleted": STATE_DOCKED,
29 "chargego": STATE_DOCKED,
30 "charging": STATE_DOCKED,
31 "cleaning": STATE_CLEANING,
32 "docking": STATE_RETURNING,
33 "goto_charge": STATE_RETURNING,
34 "goto_pos": STATE_CLEANING,
35 "mop_clean": STATE_CLEANING,
36 "part_clean": STATE_CLEANING,
37 "paused": STATE_PAUSED,
38 "pick_zone_clean": STATE_CLEANING,
39 "pos_arrived": STATE_CLEANING,
40 "pos_unarrive": STATE_CLEANING,
41 "random": STATE_CLEANING,
43 "smart_clean": STATE_CLEANING,
44 "smart": STATE_CLEANING,
45 "spot_clean": STATE_CLEANING,
46 "standby": STATE_IDLE,
47 "wall_clean": STATE_CLEANING,
48 "wall_follow": STATE_CLEANING,
49 "zone_clean": STATE_CLEANING,
54 hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback
56 """Set up Tuya vacuum dynamically through Tuya discovery."""
57 hass_data = entry.runtime_data
61 """Discover and add a discovered Tuya vacuum."""
62 entities: list[TuyaVacuumEntity] = []
63 for device_id
in device_ids:
64 device = hass_data.manager.device_map[device_id]
65 if device.category ==
"sd":
71 entry.async_on_unload(
77 """Tuya Vacuum Device."""
79 _fan_speed: EnumTypeData |
None =
None
80 _battery_level: IntegerTypeData |
None =
None
83 def __init__(self, device: CustomerDevice, device_manager: Manager) ->
None:
84 """Init Tuya vacuum."""
85 super().
__init__(device, device_manager)
90 VacuumEntityFeature.SEND_COMMAND | VacuumEntityFeature.STATE
99 DPCode.MODE, dptype=DPType.ENUM, prefer_function=
True
102 and TUYA_MODE_RETURN_HOME
in enum_type.range
111 VacuumEntityFeature.STOP | VacuumEntityFeature.START
115 DPCode.SUCTION, dptype=DPType.ENUM, prefer_function=
True
127 """Return Tuya device state."""
129 status := self.
devicedevice.status.get(DPCode.ELECTRICITY_LEFT)
132 return round(self.
_battery_level_battery_level.scale_value(status))
136 """Return the fan speed of the vacuum cleaner."""
137 return self.
devicedevice.status.get(DPCode.SUCTION)
141 """Return Tuya vacuum device state."""
142 if self.
devicedevice.status.get(DPCode.PAUSE)
and not (
143 self.
devicedevice.status.get(DPCode.STATUS)
146 if not (status := self.
devicedevice.status.get(DPCode.STATUS)):
148 return TUYA_STATUS_TO_HA.get(status)
150 def start(self, **kwargs: Any) ->
None:
151 """Start the device."""
152 self.
_send_command_send_command([{
"code": DPCode.POWER_GO,
"value":
True}])
154 def stop(self, **kwargs: Any) ->
None:
155 """Stop the device."""
156 self.
_send_command_send_command([{
"code": DPCode.POWER_GO,
"value":
False}])
158 def pause(self, **kwargs: Any) ->
None:
159 """Pause the device."""
160 self.
_send_command_send_command([{
"code": DPCode.POWER_GO,
"value":
False}])
163 """Return device to dock."""
166 {
"code": DPCode.SWITCH_CHARGE,
"value":
True},
167 {
"code": DPCode.MODE,
"value": TUYA_MODE_RETURN_HOME},
172 """Locate the device."""
173 self.
_send_command_send_command([{
"code": DPCode.SEEK,
"value":
True}])
177 self.
_send_command_send_command([{
"code": DPCode.SUCTION,
"value": fan_speed}])
182 params: dict[str, Any] | list[Any] |
None =
None,
185 """Send raw command."""
187 raise ValueError(
"Params cannot be omitted for Tuya vacuum commands")
188 if not isinstance(params, list):
189 raise TypeError(
"Params must be a list for Tuya vacuum commands")
190 self.
_send_command_send_command([{
"code": command,
"value": params[0]}])
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 stop(self, **Any kwargs)
None __init__(self, CustomerDevice device, Manager device_manager)
None start(self, **Any kwargs)
int|None battery_level(self)
None locate(self, **Any kwargs)
None send_command(self, str command, dict[str, Any]|list[Any]|None params=None, **Any kwargs)
None pause(self, **Any kwargs)
None return_to_base(self, **Any kwargs)
None set_fan_speed(self, str fan_speed, **Any kwargs)
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)