Use EntityFeature enum in components (g**) (#69394)

pull/69397/head
epenet 2022-04-06 10:46:44 +02:00 committed by GitHub
parent 42d0a4b81e
commit 20c1a155b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 60 additions and 97 deletions

View File

@ -9,8 +9,8 @@ import voluptuous as vol
from homeassistant.components.camera import (
DEFAULT_CONTENT_TYPE,
PLATFORM_SCHEMA,
SUPPORT_STREAM,
Camera,
CameraEntityFeature,
)
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import (
@ -150,7 +150,9 @@ class GenericCamera(Camera):
self._stream_source.hass = hass
self._limit_refetch = device_info[CONF_LIMIT_REFETCH_TO_URL_CHANGE]
self._attr_frame_interval = 1 / device_info[CONF_FRAMERATE]
self._supported_features = SUPPORT_STREAM if self._stream_source else 0
self._attr_supported_features = (
CameraEntityFeature.STREAM if self._stream_source else 0
)
self.content_type = device_info[CONF_CONTENT_TYPE]
self.verify_ssl = device_info[CONF_VERIFY_SSL]
if device_info.get(CONF_RTSP_TRANSPORT):
@ -162,11 +164,6 @@ class GenericCamera(Camera):
self._last_url = None
self._last_image = None
@property
def supported_features(self):
"""Return supported features for this camera."""
return self._supported_features
async def async_camera_image(
self, width: int | None = None, height: int | None = None
) -> bytes | None:

View File

@ -8,12 +8,12 @@ from homeassistant.components.humidifier import (
PLATFORM_SCHEMA,
HumidifierDeviceClass,
HumidifierEntity,
HumidifierEntityFeature,
)
from homeassistant.components.humidifier.const import (
ATTR_HUMIDITY,
MODE_AWAY,
MODE_NORMAL,
SUPPORT_MODES,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
@ -57,7 +57,6 @@ _LOGGER = logging.getLogger(__name__)
ATTR_SAVED_HUMIDITY = "saved_humidity"
SUPPORT_FLAGS = 0
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(HYGROSTAT_SCHEMA.schema)
@ -148,9 +147,9 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
self._min_humidity = min_humidity
self._max_humidity = max_humidity
self._target_humidity = target_humidity
self._support_flags = SUPPORT_FLAGS
self._attr_supported_features = 0
if away_humidity:
self._support_flags = SUPPORT_FLAGS | SUPPORT_MODES
self._attr_supported_features |= HumidifierEntityFeature.MODES
self._away_humidity = away_humidity
self._away_fixed = away_fixed
self._sensor_stale_duration = sensor_stale_duration
@ -434,11 +433,6 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
"""If the toggleable device is currently active."""
return self.hass.states.is_state(self._switch_entity_id, STATE_ON)
@property
def supported_features(self):
"""Return the list of supported features."""
return self._support_flags
async def _async_device_turn_on(self):
"""Turn humidifier toggleable device on."""
data = {ATTR_ENTITY_ID: self._switch_entity_id}

View File

@ -7,7 +7,11 @@ import math
import voluptuous as vol
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity
from homeassistant.components.climate import (
PLATFORM_SCHEMA,
ClimateEntity,
ClimateEntityFeature,
)
from homeassistant.components.climate.const import (
ATTR_PRESET_MODE,
CURRENT_HVAC_COOL,
@ -23,8 +27,6 @@ from homeassistant.components.climate.const import (
PRESET_HOME,
PRESET_NONE,
PRESET_SLEEP,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
@ -73,7 +75,6 @@ CONF_HOT_TOLERANCE = "hot_tolerance"
CONF_KEEP_ALIVE = "keep_alive"
CONF_INITIAL_HVAC_MODE = "initial_hvac_mode"
CONF_PRECISION = "precision"
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE
CONF_PRESETS = {
p: f"{p}_temp"
@ -210,9 +211,9 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
self._target_temp = target_temp
self._unit = unit
self._unique_id = unique_id
self._support_flags = SUPPORT_FLAGS
self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
if len(presets):
self._support_flags = SUPPORT_FLAGS | SUPPORT_PRESET_MODE
self._attr_supported_features |= ClimateEntityFeature.PRESET_MODE
self._attr_preset_modes = [PRESET_NONE] + list(presets.keys())
else:
self._attr_preset_modes = [PRESET_NONE]
@ -524,11 +525,6 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
return self.hass.states.is_state(self.heater_entity_id, STATE_ON)
@property
def supported_features(self):
"""Return the list of supported features."""
return self._support_flags
async def _async_heater_turn_on(self):
"""Turn heater toggleable device on."""
data = {ATTR_ENTITY_ID: self.heater_entity_id}

View File

@ -9,10 +9,9 @@ from ismartgate.common import (
)
from homeassistant.components.cover import (
SUPPORT_CLOSE,
SUPPORT_OPEN,
CoverDeviceClass,
CoverEntity,
CoverEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -45,6 +44,8 @@ async def async_setup_entry(
class DeviceCover(GoGoGate2Entity, CoverEntity):
"""Cover entity for gogogate2."""
_attr_supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
def __init__(
self,
config_entry: ConfigEntry,
@ -54,7 +55,6 @@ class DeviceCover(GoGoGate2Entity, CoverEntity):
"""Initialize the object."""
unique_id = cover_unique_id(config_entry, door)
super().__init__(config_entry, data_update_coordinator, door, unique_id)
self._attr_supported_features = SUPPORT_OPEN | SUPPORT_CLOSE
self._attr_device_class = (
CoverDeviceClass.GATE if self.door.gate else CoverDeviceClass.GARAGE
)

View File

@ -11,16 +11,12 @@ import voluptuous as vol
from websocket import _exceptions, create_connection
from homeassistant.components import configurator
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity
from homeassistant.components.media_player.const import (
MEDIA_TYPE_MUSIC,
SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE,
SUPPORT_PLAY,
SUPPORT_PREVIOUS_TRACK,
SUPPORT_SEEK,
SUPPORT_VOLUME_SET,
from homeassistant.components.media_player import (
PLATFORM_SCHEMA,
MediaPlayerEntity,
MediaPlayerEntityFeature,
)
from homeassistant.components.media_player.const import MEDIA_TYPE_MUSIC
from homeassistant.const import (
CONF_HOST,
CONF_NAME,
@ -44,15 +40,6 @@ DEFAULT_PORT = 5672
GPMDP_CONFIG_FILE = "gpmpd.conf"
SUPPORT_GPMDP = (
SUPPORT_PAUSE
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_NEXT_TRACK
| SUPPORT_SEEK
| SUPPORT_VOLUME_SET
| SUPPORT_PLAY
)
PLAYBACK_DICT = {"0": STATE_PAUSED, "1": STATE_PAUSED, "2": STATE_PLAYING} # Stopped
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
@ -179,6 +166,15 @@ def setup_platform(
class GPMDP(MediaPlayerEntity):
"""Representation of a GPMDP."""
_attr_supported_features = (
MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.PREVIOUS_TRACK
| MediaPlayerEntityFeature.NEXT_TRACK
| MediaPlayerEntityFeature.SEEK
| MediaPlayerEntityFeature.VOLUME_SET
| MediaPlayerEntityFeature.PLAY
)
def __init__(self, name, url, code):
"""Initialize the media player."""
@ -321,11 +317,6 @@ class GPMDP(MediaPlayerEntity):
"""Return the name of the device."""
return self._name
@property
def supported_features(self):
"""Flag media player features that are supported."""
return SUPPORT_GPMDP
def media_next_track(self):
"""Send media_next command to media player."""
self.send_gpmdp_msg("playback", "forward", False)

View File

@ -15,7 +15,7 @@ from greeclimate.device import (
VerticalSwing,
)
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate.const import (
FAN_AUTO,
FAN_HIGH,
@ -32,10 +32,6 @@ from homeassistant.components.climate.const import (
PRESET_ECO,
PRESET_NONE,
PRESET_SLEEP,
SUPPORT_FAN_MODE,
SUPPORT_PRESET_MODE,
SUPPORT_SWING_MODE,
SUPPORT_TARGET_TEMPERATURE,
SWING_BOTH,
SWING_HORIZONTAL,
SWING_OFF,
@ -96,13 +92,6 @@ FAN_MODES_REVERSE = {v: k for k, v in FAN_MODES.items()}
SWING_MODES = [SWING_OFF, SWING_VERTICAL, SWING_HORIZONTAL, SWING_BOTH]
SUPPORTED_FEATURES = (
SUPPORT_TARGET_TEMPERATURE
| SUPPORT_FAN_MODE
| SUPPORT_PRESET_MODE
| SUPPORT_SWING_MODE
)
async def async_setup_entry(
hass: HomeAssistant,
@ -127,6 +116,13 @@ async def async_setup_entry(
class GreeClimateEntity(CoordinatorEntity, ClimateEntity):
"""Representation of a Gree HVAC device."""
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.SWING_MODE
)
def __init__(self, coordinator):
"""Initialize the Gree device."""
super().__init__(coordinator)
@ -365,8 +361,3 @@ class GreeClimateEntity(CoordinatorEntity, ClimateEntity):
def swing_modes(self) -> list[str]:
"""Return the swing modes currently supported for this device."""
return SWING_MODES
@property
def supported_features(self) -> int:
"""Return the supported features for this device integration."""
return SUPPORTED_FEATURES

View File

@ -6,15 +6,12 @@ import logging
from gsp import GstreamerPlayer
import voluptuous as vol
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity
from homeassistant.components.media_player.const import (
MEDIA_TYPE_MUSIC,
SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE,
SUPPORT_PLAY,
SUPPORT_PLAY_MEDIA,
SUPPORT_VOLUME_SET,
from homeassistant.components.media_player import (
PLATFORM_SCHEMA,
MediaPlayerEntity,
MediaPlayerEntityFeature,
)
from homeassistant.components.media_player.const import MEDIA_TYPE_MUSIC
from homeassistant.const import CONF_NAME, EVENT_HOMEASSISTANT_STOP, STATE_IDLE
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
@ -27,14 +24,6 @@ CONF_PIPELINE = "pipeline"
DOMAIN = "gstreamer"
SUPPORT_GSTREAMER = (
SUPPORT_VOLUME_SET
| SUPPORT_PLAY
| SUPPORT_PAUSE
| SUPPORT_PLAY_MEDIA
| SUPPORT_NEXT_TRACK
)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_PIPELINE): cv.string}
)
@ -63,6 +52,14 @@ def setup_platform(
class GstreamerDevice(MediaPlayerEntity):
"""Representation of a Gstreamer device."""
_attr_supported_features = (
MediaPlayerEntityFeature.VOLUME_SET
| MediaPlayerEntityFeature.PLAY
| MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.PLAY_MEDIA
| MediaPlayerEntityFeature.NEXT_TRACK
)
def __init__(self, player, name):
"""Initialize the Gstreamer device."""
self._player = player
@ -128,11 +125,6 @@ class GstreamerDevice(MediaPlayerEntity):
"""Return the volume level."""
return self._volume
@property
def supported_features(self):
"""Flag media player features that are supported."""
return SUPPORT_GSTREAMER
@property
def state(self):
"""Return the state of the player."""

View File

@ -6,6 +6,7 @@ from greeclimate.device import HorizontalSwing, VerticalSwing
from greeclimate.exceptions import DeviceNotBoundError, DeviceTimeoutError
import pytest
from homeassistant.components.climate import ClimateEntityFeature
from homeassistant.components.climate.const import (
ATTR_CURRENT_TEMPERATURE,
ATTR_FAN_MODE,
@ -38,11 +39,7 @@ from homeassistant.components.climate.const import (
SWING_OFF,
SWING_VERTICAL,
)
from homeassistant.components.gree.climate import (
FAN_MODES_REVERSE,
HVAC_MODES_REVERSE,
SUPPORTED_FEATURES,
)
from homeassistant.components.gree.climate import FAN_MODES_REVERSE, HVAC_MODES_REVERSE
from homeassistant.components.gree.const import FAN_MEDIUM_HIGH, FAN_MEDIUM_LOW
from homeassistant.const import (
ATTR_ENTITY_ID,
@ -771,4 +768,9 @@ async def test_supported_features_with_turnon(hass, discovery, device):
"""Test for supported_features property."""
await async_setup_gree(hass)
state = hass.states.get(ENTITY_ID)
assert state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORTED_FEATURES
assert state.attributes[ATTR_SUPPORTED_FEATURES] == (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.SWING_MODE
)