Use EntityFeature enum in esphome (#69386)
This commit is contained in:
parent
78045df227
commit
dae2cf2827
5 changed files with 26 additions and 35 deletions
|
@ -13,7 +13,7 @@ from aioesphomeapi import (
|
||||||
ClimateSwingMode,
|
ClimateSwingMode,
|
||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.components.climate import ClimateEntity
|
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
ATTR_HVAC_MODE,
|
ATTR_HVAC_MODE,
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
|
@ -48,11 +48,6 @@ from homeassistant.components.climate.const import (
|
||||||
PRESET_HOME,
|
PRESET_HOME,
|
||||||
PRESET_NONE,
|
PRESET_NONE,
|
||||||
PRESET_SLEEP,
|
PRESET_SLEEP,
|
||||||
SUPPORT_FAN_MODE,
|
|
||||||
SUPPORT_PRESET_MODE,
|
|
||||||
SUPPORT_SWING_MODE,
|
|
||||||
SUPPORT_TARGET_TEMPERATURE,
|
|
||||||
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
|
||||||
SWING_BOTH,
|
SWING_BOTH,
|
||||||
SWING_HORIZONTAL,
|
SWING_HORIZONTAL,
|
||||||
SWING_OFF,
|
SWING_OFF,
|
||||||
|
@ -223,15 +218,15 @@ class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEnti
|
||||||
"""Return the list of supported features."""
|
"""Return the list of supported features."""
|
||||||
features = 0
|
features = 0
|
||||||
if self._static_info.supports_two_point_target_temperature:
|
if self._static_info.supports_two_point_target_temperature:
|
||||||
features |= SUPPORT_TARGET_TEMPERATURE_RANGE
|
features |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
|
||||||
else:
|
else:
|
||||||
features |= SUPPORT_TARGET_TEMPERATURE
|
features |= ClimateEntityFeature.TARGET_TEMPERATURE
|
||||||
if self.preset_modes:
|
if self.preset_modes:
|
||||||
features |= SUPPORT_PRESET_MODE
|
features |= ClimateEntityFeature.PRESET_MODE
|
||||||
if self.fan_modes:
|
if self.fan_modes:
|
||||||
features |= SUPPORT_FAN_MODE
|
features |= ClimateEntityFeature.FAN_MODE
|
||||||
if self.swing_modes:
|
if self.swing_modes:
|
||||||
features |= SUPPORT_SWING_MODE
|
features |= ClimateEntityFeature.SWING_MODE
|
||||||
return features
|
return features
|
||||||
|
|
||||||
@esphome_state_property
|
@esphome_state_property
|
||||||
|
|
|
@ -9,14 +9,8 @@ from homeassistant.components.cover import (
|
||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
ATTR_TILT_POSITION,
|
ATTR_TILT_POSITION,
|
||||||
DEVICE_CLASSES,
|
DEVICE_CLASSES,
|
||||||
SUPPORT_CLOSE,
|
|
||||||
SUPPORT_CLOSE_TILT,
|
|
||||||
SUPPORT_OPEN,
|
|
||||||
SUPPORT_OPEN_TILT,
|
|
||||||
SUPPORT_SET_POSITION,
|
|
||||||
SUPPORT_SET_TILT_POSITION,
|
|
||||||
SUPPORT_STOP,
|
|
||||||
CoverEntity,
|
CoverEntity,
|
||||||
|
CoverEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -50,11 +44,17 @@ class EsphomeCover(EsphomeEntity[CoverInfo, CoverState], CoverEntity):
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> int:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
flags = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP
|
flags = (
|
||||||
|
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
|
||||||
|
)
|
||||||
if self._static_info.supports_position:
|
if self._static_info.supports_position:
|
||||||
flags |= SUPPORT_SET_POSITION
|
flags |= CoverEntityFeature.SET_POSITION
|
||||||
if self._static_info.supports_tilt:
|
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
|
return flags
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -9,10 +9,8 @@ from aioesphomeapi import FanDirection, FanInfo, FanSpeed, FanState
|
||||||
from homeassistant.components.fan import (
|
from homeassistant.components.fan import (
|
||||||
DIRECTION_FORWARD,
|
DIRECTION_FORWARD,
|
||||||
DIRECTION_REVERSE,
|
DIRECTION_REVERSE,
|
||||||
SUPPORT_DIRECTION,
|
|
||||||
SUPPORT_OSCILLATE,
|
|
||||||
SUPPORT_SET_SPEED,
|
|
||||||
FanEntity,
|
FanEntity,
|
||||||
|
FanEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -161,9 +159,9 @@ class EsphomeFan(EsphomeEntity[FanInfo, FanState], FanEntity):
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
flags = 0
|
flags = 0
|
||||||
if self._static_info.supports_oscillation:
|
if self._static_info.supports_oscillation:
|
||||||
flags |= SUPPORT_OSCILLATE
|
flags |= FanEntityFeature.OSCILLATE
|
||||||
if self._static_info.supports_speed:
|
if self._static_info.supports_speed:
|
||||||
flags |= SUPPORT_SET_SPEED
|
flags |= FanEntityFeature.SET_SPEED
|
||||||
if self._static_info.supports_direction:
|
if self._static_info.supports_direction:
|
||||||
flags |= SUPPORT_DIRECTION
|
flags |= FanEntityFeature.DIRECTION
|
||||||
return flags
|
return flags
|
||||||
|
|
|
@ -25,10 +25,8 @@ from homeassistant.components.light import (
|
||||||
COLOR_MODE_WHITE,
|
COLOR_MODE_WHITE,
|
||||||
FLASH_LONG,
|
FLASH_LONG,
|
||||||
FLASH_SHORT,
|
FLASH_SHORT,
|
||||||
SUPPORT_EFFECT,
|
|
||||||
SUPPORT_FLASH,
|
|
||||||
SUPPORT_TRANSITION,
|
|
||||||
LightEntity,
|
LightEntity,
|
||||||
|
LightEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -354,14 +352,14 @@ class EsphomeLight(EsphomeEntity[LightInfo, LightState], LightEntity):
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> int:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
flags = SUPPORT_FLASH
|
flags: int = LightEntityFeature.FLASH
|
||||||
|
|
||||||
# All color modes except UNKNOWN,ON_OFF support transition
|
# All color modes except UNKNOWN,ON_OFF support transition
|
||||||
modes = self._native_supported_color_modes
|
modes = self._native_supported_color_modes
|
||||||
if any(m not in (0, LightColorCapability.ON_OFF) for m in 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:
|
if self._static_info.effects:
|
||||||
flags |= SUPPORT_EFFECT
|
flags |= LightEntityFeature.EFFECT
|
||||||
return flags
|
return flags
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -5,7 +5,7 @@ from typing import Any
|
||||||
|
|
||||||
from aioesphomeapi import LockCommand, LockEntityState, LockInfo, LockState
|
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.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_CODE
|
from homeassistant.const import ATTR_CODE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -44,7 +44,7 @@ class EsphomeLock(EsphomeEntity[LockInfo, LockEntityState], LockEntity):
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> int:
|
||||||
"""Flag supported features."""
|
"""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
|
@property
|
||||||
def code_format(self) -> str | None:
|
def code_format(self) -> str | None:
|
||||||
|
|
Loading…
Add table
Reference in a new issue