Skip to content

Commit

Permalink
Use VacuumEntityFeature in tuya (#70563)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed Apr 23, 2022
1 parent 4247318 commit 43b9c62
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions homeassistant/components/tuya/vacuum.py
Expand Up @@ -9,19 +9,8 @@
STATE_CLEANING,
STATE_DOCKED,
STATE_RETURNING,
SUPPORT_BATTERY,
SUPPORT_FAN_SPEED,
SUPPORT_LOCATE,
SUPPORT_PAUSE,
SUPPORT_RETURN_HOME,
SUPPORT_SEND_COMMAND,
SUPPORT_START,
SUPPORT_STATE,
SUPPORT_STATUS,
SUPPORT_STOP,
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
StateVacuumEntity,
VacuumEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_IDLE, STATE_PAUSED
Expand Down Expand Up @@ -95,39 +84,45 @@ def __init__(self, device: TuyaDevice, device_manager: TuyaDeviceManager) -> Non
"""Init Tuya vacuum."""
super().__init__(device, device_manager)

self._supported_features |= SUPPORT_SEND_COMMAND
self._supported_features |= VacuumEntityFeature.SEND_COMMAND
if self.find_dpcode(DPCode.PAUSE, prefer_function=True):
self._supported_features |= SUPPORT_PAUSE
self._supported_features |= VacuumEntityFeature.PAUSE

if self.find_dpcode(DPCode.SWITCH_CHARGE, prefer_function=True):
self._supported_features |= SUPPORT_RETURN_HOME
self._supported_features |= VacuumEntityFeature.RETURN_HOME
elif (
enum_type := self.find_dpcode(
DPCode.MODE, dptype=DPType.ENUM, prefer_function=True
)
) and TUYA_MODE_RETURN_HOME in enum_type.range:
self._supported_features |= SUPPORT_RETURN_HOME
self._supported_features |= VacuumEntityFeature.RETURN_HOME

if self.find_dpcode(DPCode.SEEK, prefer_function=True):
self._supported_features |= SUPPORT_LOCATE
self._supported_features |= VacuumEntityFeature.LOCATE

if self.find_dpcode(DPCode.STATUS, prefer_function=True):
self._supported_features |= SUPPORT_STATE | SUPPORT_STATUS
self._supported_features |= (
VacuumEntityFeature.STATE | VacuumEntityFeature.STATUS
)

if self.find_dpcode(DPCode.POWER, prefer_function=True):
self._supported_features |= SUPPORT_TURN_ON | SUPPORT_TURN_OFF
self._supported_features |= (
VacuumEntityFeature.TURN_ON | VacuumEntityFeature.TURN_OFF
)

if self.find_dpcode(DPCode.POWER_GO, prefer_function=True):
self._supported_features |= SUPPORT_STOP | SUPPORT_START
self._supported_features |= (
VacuumEntityFeature.STOP | VacuumEntityFeature.START
)

if enum_type := self.find_dpcode(
DPCode.SUCTION, dptype=DPType.ENUM, prefer_function=True
):
self._supported_features |= SUPPORT_FAN_SPEED
self._supported_features |= VacuumEntityFeature.FAN_SPEED
self._fan_speed = enum_type

if int_type := self.find_dpcode(DPCode.ELECTRICITY_LEFT, dptype=DPType.INTEGER):
self._supported_features |= SUPPORT_BATTERY
self._supported_features |= VacuumEntityFeature.BATTERY
self._battery_level = int_type

@property
Expand Down

0 comments on commit 43b9c62

Please sign in to comment.