mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Migrate Tuya vacuum (pause) to use wrapper class (#156947)
This commit is contained in:
@@ -19,7 +19,6 @@ from . import TuyaConfigEntry
|
||||
from .const import TUYA_DISCOVERY_NEW, DeviceCategory, DPCode
|
||||
from .entity import TuyaEntity
|
||||
from .models import DPCodeBooleanWrapper, DPCodeEnumWrapper
|
||||
from .util import get_dpcode
|
||||
|
||||
TUYA_MODE_RETURN_HOME = "chargego"
|
||||
TUYA_STATUS_TO_HA = {
|
||||
@@ -80,6 +79,9 @@ async def async_setup_entry(
|
||||
mode_wrapper=DPCodeEnumWrapper.find_dpcode(
|
||||
device, DPCode.MODE, prefer_function=True
|
||||
),
|
||||
pause_wrapper=DPCodeBooleanWrapper.find_dpcode(
|
||||
device, DPCode.PAUSE
|
||||
),
|
||||
status_wrapper=DPCodeEnumWrapper.find_dpcode(
|
||||
device, DPCode.STATUS
|
||||
),
|
||||
@@ -111,6 +113,7 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity):
|
||||
fan_speed_wrapper: DPCodeEnumWrapper | None,
|
||||
locate_wrapper: DPCodeBooleanWrapper | None,
|
||||
mode_wrapper: DPCodeEnumWrapper | None,
|
||||
pause_wrapper: DPCodeBooleanWrapper | None,
|
||||
status_wrapper: DPCodeEnumWrapper | None,
|
||||
switch_wrapper: DPCodeBooleanWrapper | None,
|
||||
) -> None:
|
||||
@@ -120,6 +123,7 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity):
|
||||
self._fan_speed_wrapper = fan_speed_wrapper
|
||||
self._locate_wrapper = locate_wrapper
|
||||
self._mode_wrapper = mode_wrapper
|
||||
self._pause_wrapper = pause_wrapper
|
||||
self._status_wrapper = status_wrapper
|
||||
self._switch_wrapper = switch_wrapper
|
||||
|
||||
@@ -127,7 +131,7 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity):
|
||||
self._attr_supported_features = (
|
||||
VacuumEntityFeature.SEND_COMMAND | VacuumEntityFeature.STATE
|
||||
)
|
||||
if get_dpcode(self.device, DPCode.PAUSE):
|
||||
if pause_wrapper:
|
||||
self._attr_supported_features |= VacuumEntityFeature.PAUSE
|
||||
|
||||
if charge_wrapper or (
|
||||
@@ -159,7 +163,7 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity):
|
||||
if (status := self._read_wrapper(self._status_wrapper)) is not None:
|
||||
return TUYA_STATUS_TO_HA.get(status)
|
||||
|
||||
if self.device.status.get(DPCode.PAUSE):
|
||||
if self._read_wrapper(self._pause_wrapper):
|
||||
return VacuumActivity.PAUSED
|
||||
return None
|
||||
|
||||
@@ -171,9 +175,9 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity):
|
||||
"""Stop the device."""
|
||||
await self._async_send_dpcode_update(self._switch_wrapper, False)
|
||||
|
||||
def pause(self, **kwargs: Any) -> None:
|
||||
async def async_pause(self, **kwargs: Any) -> None:
|
||||
"""Pause the device."""
|
||||
self._send_command([{"code": DPCode.POWER_GO, "value": False}])
|
||||
await self.async_stop(**kwargs)
|
||||
|
||||
async def async_return_to_base(self, **kwargs: Any) -> None:
|
||||
"""Return device to dock."""
|
||||
|
||||
@@ -13,6 +13,7 @@ from homeassistant.components.vacuum import (
|
||||
ATTR_FAN_SPEED,
|
||||
DOMAIN as VACUUM_DOMAIN,
|
||||
SERVICE_LOCATE,
|
||||
SERVICE_PAUSE,
|
||||
SERVICE_RETURN_TO_BASE,
|
||||
SERVICE_SET_FAN_SPEED,
|
||||
SERVICE_START,
|
||||
@@ -88,6 +89,13 @@ async def test_platform_setup_and_discovery(
|
||||
{},
|
||||
{"code": "power_go", "value": False},
|
||||
),
|
||||
(
|
||||
"sd_lr33znaodtyarrrz",
|
||||
"vacuum.v20",
|
||||
SERVICE_PAUSE,
|
||||
{},
|
||||
{"code": "power_go", "value": False},
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_action(
|
||||
|
||||
Reference in New Issue
Block a user