Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use VacuumEntityFeature in tuya #70563

Merged
merged 1 commit into from Apr 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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