Use VacuumEntityFeature in tuya (#70563)

pull/69919/head^2
epenet 2022-04-23 23:45:22 +02:00 committed by GitHub
parent 4247318634
commit 43b9c62aa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 22 deletions

View File

@ -9,19 +9,8 @@ from homeassistant.components.vacuum import (
STATE_CLEANING, STATE_CLEANING,
STATE_DOCKED, STATE_DOCKED,
STATE_RETURNING, 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, StateVacuumEntity,
VacuumEntityFeature,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_IDLE, STATE_PAUSED from homeassistant.const import STATE_IDLE, STATE_PAUSED
@ -95,39 +84,45 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity):
"""Init Tuya vacuum.""" """Init Tuya vacuum."""
super().__init__(device, device_manager) 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): 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): if self.find_dpcode(DPCode.SWITCH_CHARGE, prefer_function=True):
self._supported_features |= SUPPORT_RETURN_HOME self._supported_features |= VacuumEntityFeature.RETURN_HOME
elif ( elif (
enum_type := self.find_dpcode( enum_type := self.find_dpcode(
DPCode.MODE, dptype=DPType.ENUM, prefer_function=True DPCode.MODE, dptype=DPType.ENUM, prefer_function=True
) )
) and TUYA_MODE_RETURN_HOME in enum_type.range: ) 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): 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): 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): 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): 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( if enum_type := self.find_dpcode(
DPCode.SUCTION, dptype=DPType.ENUM, prefer_function=True 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 self._fan_speed = enum_type
if int_type := self.find_dpcode(DPCode.ELECTRICITY_LEFT, dptype=DPType.INTEGER): 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 self._battery_level = int_type
@property @property