Use EntityFeature enum in esphome (#69386)

pull/69415/head
epenet 2022-04-06 11:52:59 +02:00 committed by GitHub
parent 78045df227
commit dae2cf2827
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 35 deletions

View File

@ -13,7 +13,7 @@ from aioesphomeapi import (
ClimateSwingMode,
)
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate.const import (
ATTR_HVAC_MODE,
ATTR_TARGET_TEMP_HIGH,
@ -48,11 +48,6 @@ from homeassistant.components.climate.const import (
PRESET_HOME,
PRESET_NONE,
PRESET_SLEEP,
SUPPORT_FAN_MODE,
SUPPORT_PRESET_MODE,
SUPPORT_SWING_MODE,
SUPPORT_TARGET_TEMPERATURE,
SUPPORT_TARGET_TEMPERATURE_RANGE,
SWING_BOTH,
SWING_HORIZONTAL,
SWING_OFF,
@ -223,15 +218,15 @@ class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEnti
"""Return the list of supported features."""
features = 0
if self._static_info.supports_two_point_target_temperature:
features |= SUPPORT_TARGET_TEMPERATURE_RANGE
features |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
else:
features |= SUPPORT_TARGET_TEMPERATURE
features |= ClimateEntityFeature.TARGET_TEMPERATURE
if self.preset_modes:
features |= SUPPORT_PRESET_MODE
features |= ClimateEntityFeature.PRESET_MODE
if self.fan_modes:
features |= SUPPORT_FAN_MODE
features |= ClimateEntityFeature.FAN_MODE
if self.swing_modes:
features |= SUPPORT_SWING_MODE
features |= ClimateEntityFeature.SWING_MODE
return features
@esphome_state_property

View File

@ -9,14 +9,8 @@ from homeassistant.components.cover import (
ATTR_POSITION,
ATTR_TILT_POSITION,
DEVICE_CLASSES,
SUPPORT_CLOSE,
SUPPORT_CLOSE_TILT,
SUPPORT_OPEN,
SUPPORT_OPEN_TILT,
SUPPORT_SET_POSITION,
SUPPORT_SET_TILT_POSITION,
SUPPORT_STOP,
CoverEntity,
CoverEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -50,11 +44,17 @@ class EsphomeCover(EsphomeEntity[CoverInfo, CoverState], CoverEntity):
@property
def supported_features(self) -> int:
"""Flag supported features."""
flags = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP
flags = (
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
)
if self._static_info.supports_position:
flags |= SUPPORT_SET_POSITION
flags |= CoverEntityFeature.SET_POSITION
if self._static_info.supports_tilt:
flags |= SUPPORT_OPEN_TILT | SUPPORT_CLOSE_TILT | SUPPORT_SET_TILT_POSITION
flags |= (
CoverEntityFeature.OPEN_TILT
| CoverEntityFeature.CLOSE_TILT
| CoverEntityFeature.SET_TILT_POSITION
)
return flags
@property

View File

@ -9,10 +9,8 @@ from aioesphomeapi import FanDirection, FanInfo, FanSpeed, FanState
from homeassistant.components.fan import (
DIRECTION_FORWARD,
DIRECTION_REVERSE,
SUPPORT_DIRECTION,
SUPPORT_OSCILLATE,
SUPPORT_SET_SPEED,
FanEntity,
FanEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -161,9 +159,9 @@ class EsphomeFan(EsphomeEntity[FanInfo, FanState], FanEntity):
"""Flag supported features."""
flags = 0
if self._static_info.supports_oscillation:
flags |= SUPPORT_OSCILLATE
flags |= FanEntityFeature.OSCILLATE
if self._static_info.supports_speed:
flags |= SUPPORT_SET_SPEED
flags |= FanEntityFeature.SET_SPEED
if self._static_info.supports_direction:
flags |= SUPPORT_DIRECTION
flags |= FanEntityFeature.DIRECTION
return flags

View File

@ -25,10 +25,8 @@ from homeassistant.components.light import (
COLOR_MODE_WHITE,
FLASH_LONG,
FLASH_SHORT,
SUPPORT_EFFECT,
SUPPORT_FLASH,
SUPPORT_TRANSITION,
LightEntity,
LightEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -354,14 +352,14 @@ class EsphomeLight(EsphomeEntity[LightInfo, LightState], LightEntity):
@property
def supported_features(self) -> int:
"""Flag supported features."""
flags = SUPPORT_FLASH
flags: int = LightEntityFeature.FLASH
# All color modes except UNKNOWN,ON_OFF support transition
modes = self._native_supported_color_modes
if any(m not in (0, LightColorCapability.ON_OFF) for m in modes):
flags |= SUPPORT_TRANSITION
flags |= LightEntityFeature.TRANSITION
if self._static_info.effects:
flags |= SUPPORT_EFFECT
flags |= LightEntityFeature.EFFECT
return flags
@property

View File

@ -5,7 +5,7 @@ from typing import Any
from aioesphomeapi import LockCommand, LockEntityState, LockInfo, LockState
from homeassistant.components.lock import SUPPORT_OPEN, LockEntity
from homeassistant.components.lock import LockEntity, LockEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_CODE
from homeassistant.core import HomeAssistant
@ -44,7 +44,7 @@ class EsphomeLock(EsphomeEntity[LockInfo, LockEntityState], LockEntity):
@property
def supported_features(self) -> int:
"""Flag supported features."""
return SUPPORT_OPEN if self._static_info.supports_open else 0
return LockEntityFeature.OPEN if self._static_info.supports_open else 0
@property
def code_format(self) -> str | None: