Use VacuumEntityFeature in tuya (#70563)
parent
4247318634
commit
43b9c62aa5
|
@ -9,19 +9,8 @@ from homeassistant.components.vacuum import (
|
|||
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
|
||||
|
@ -95,39 +84,45 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity):
|
|||
"""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
|
||||
|
|
Loading…
Reference in New Issue