Use EntityFeature enum in components (w**) (#69468)

* Use EntityFeature enum in webostv

* Use EntityFeature enum in wemo

* Use EntityFeature enum in whirlpool

* Use EntityFeature enum in wilight
pull/69531/head
epenet 2022-04-07 07:12:39 +02:00 committed by GitHub
parent caff81f613
commit a6f112df80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 54 deletions

View File

@ -15,22 +15,9 @@ from homeassistant import util
from homeassistant.components.media_player import (
MediaPlayerDeviceClass,
MediaPlayerEntity,
MediaPlayerEntityFeature,
)
from homeassistant.components.media_player.const import (
MEDIA_TYPE_CHANNEL,
SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE,
SUPPORT_PLAY,
SUPPORT_PLAY_MEDIA,
SUPPORT_PREVIOUS_TRACK,
SUPPORT_SELECT_SOURCE,
SUPPORT_STOP,
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
SUPPORT_VOLUME_MUTE,
SUPPORT_VOLUME_SET,
SUPPORT_VOLUME_STEP,
)
from homeassistant.components.media_player.const import MEDIA_TYPE_CHANNEL
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_ENTITY_ID,
@ -61,17 +48,19 @@ from .const import (
_LOGGER = logging.getLogger(__name__)
SUPPORT_WEBOSTV = (
SUPPORT_TURN_OFF
| SUPPORT_NEXT_TRACK
| SUPPORT_PAUSE
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_SELECT_SOURCE
| SUPPORT_PLAY_MEDIA
| SUPPORT_PLAY
| SUPPORT_STOP
MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.NEXT_TRACK
| MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.PREVIOUS_TRACK
| MediaPlayerEntityFeature.SELECT_SOURCE
| MediaPlayerEntityFeature.PLAY_MEDIA
| MediaPlayerEntityFeature.PLAY
| MediaPlayerEntityFeature.STOP
)
SUPPORT_WEBOSTV_VOLUME = SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_STEP
SUPPORT_WEBOSTV_VOLUME = (
MediaPlayerEntityFeature.VOLUME_MUTE | MediaPlayerEntityFeature.VOLUME_STEP
)
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1)
@ -169,7 +158,8 @@ class LgWebOSMediaPlayerEntity(RestoreEntity, MediaPlayerEntity):
and (state := await self.async_get_last_state()) is not None
):
self._supported_features = (
state.attributes.get(ATTR_SUPPORTED_FEATURES, 0) & ~SUPPORT_TURN_ON
state.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
& ~MediaPlayerEntityFeature.TURN_ON
)
async def async_will_remove_from_hass(self) -> None:
@ -232,7 +222,11 @@ class LgWebOSMediaPlayerEntity(RestoreEntity, MediaPlayerEntity):
if self._client.sound_output in ("external_arc", "external_speaker"):
supported = supported | SUPPORT_WEBOSTV_VOLUME
elif self._client.sound_output != "lineout":
supported = supported | SUPPORT_WEBOSTV_VOLUME | SUPPORT_VOLUME_SET
supported = (
supported
| SUPPORT_WEBOSTV_VOLUME
| MediaPlayerEntityFeature.VOLUME_SET
)
self._supported_features = supported
@ -322,7 +316,7 @@ class LgWebOSMediaPlayerEntity(RestoreEntity, MediaPlayerEntity):
def supported_features(self) -> int:
"""Flag media player features that are supported."""
if self._wrapper.turn_on:
return self._supported_features | SUPPORT_TURN_ON
return self._supported_features | MediaPlayerEntityFeature.TURN_ON
return self._supported_features

View File

@ -9,7 +9,7 @@ from typing import Any
from pywemo.ouimeaux_device.humidifier import DesiredHumidity, FanMode, Humidifier
import voluptuous as vol
from homeassistant.components.fan import SUPPORT_SET_SPEED, FanEntity
from homeassistant.components.fan import FanEntity, FanEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_platform
@ -41,9 +41,6 @@ ATTR_WATER_LEVEL = "water_level"
SPEED_RANGE = (FanMode.Minimum, FanMode.Maximum) # off is not included
SUPPORTED_FEATURES = SUPPORT_SET_SPEED
SET_HUMIDITY_SCHEMA = {
vol.Required(ATTR_TARGET_HUMIDITY): vol.All(
vol.Coerce(float), vol.Range(min=0, max=100)
@ -87,6 +84,7 @@ async def async_setup_entry(
class WemoHumidifier(WemoBinaryStateEntity, FanEntity):
"""Representation of a WeMo humidifier."""
_attr_supported_features = FanEntityFeature.SET_SPEED
wemo: Humidifier
def __init__(self, coordinator: DeviceCoordinator) -> None:
@ -124,11 +122,6 @@ class WemoHumidifier(WemoBinaryStateEntity, FanEntity):
"""Return the number of speeds the fan supports."""
return int_states_in_range(SPEED_RANGE)
@property
def supported_features(self) -> int:
"""Flag supported features."""
return SUPPORTED_FEATURES
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""

View File

@ -6,7 +6,7 @@ import aiohttp
from whirlpool.aircon import Aircon, FanSpeed as AirconFanSpeed, Mode as AirconMode
from whirlpool.auth import Auth
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate.const import (
FAN_AUTO,
FAN_HIGH,
@ -17,9 +17,6 @@ from homeassistant.components.climate.const import (
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
SUPPORT_FAN_MODE,
SUPPORT_SWING_MODE,
SUPPORT_TARGET_TEMPERATURE,
SWING_HORIZONTAL,
SWING_OFF,
)
@ -89,7 +86,9 @@ class AirConEntity(ClimateEntity):
_attr_max_temp = SUPPORTED_MAX_TEMP
_attr_min_temp = SUPPORTED_MIN_TEMP
_attr_supported_features = (
SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_SWING_MODE
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.SWING_MODE
)
_attr_swing_modes = SUPPORTED_SWING_MODES
_attr_target_temperature_step = SUPPORTED_TARGET_TEMPERATURE_STEP

View File

@ -12,12 +12,7 @@ from pywilight.const import (
WL_SPEED_MEDIUM,
)
from homeassistant.components.fan import (
DIRECTION_FORWARD,
SUPPORT_DIRECTION,
SUPPORT_SET_SPEED,
FanEntity,
)
from homeassistant.components.fan import DIRECTION_FORWARD, FanEntity, FanEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -30,8 +25,6 @@ from . import DOMAIN, WiLightDevice
ORDERED_NAMED_FAN_SPEEDS = [WL_SPEED_LOW, WL_SPEED_MEDIUM, WL_SPEED_HIGH]
SUPPORTED_FEATURES = SUPPORT_SET_SPEED | SUPPORT_DIRECTION
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
@ -57,17 +50,14 @@ async def async_setup_entry(
class WiLightFan(WiLightDevice, FanEntity):
"""Representation of a WiLights fan."""
_attr_supported_features = FanEntityFeature.SET_SPEED | FanEntityFeature.DIRECTION
def __init__(self, api_device, index, item_name):
"""Initialize the device."""
super().__init__(api_device, index, item_name)
# Initialize the WiLights fan.
self._direction = WL_DIRECTION_FORWARD
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORTED_FEATURES
@property
def icon(self):
"""Return the icon of device based on its type."""