From 6343752f985de03a1632813c338f68fb7b6b2e9b Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 5 Apr 2022 23:49:20 +0200 Subject: [PATCH] Use EntityFeature enum in components (c**) (#69341) --- .../components/canary/alarm_control_panel.py | 12 +++--- homeassistant/components/cast/media_player.py | 41 +++++++++---------- .../components/channels/media_player.py | 41 ++++++++----------- .../components/clementine/media_player.py | 35 +++++++--------- homeassistant/components/cmus/media_player.py | 39 ++++++++---------- homeassistant/components/comfoconnect/fan.py | 8 +--- .../concord232/alarm_control_panel.py | 15 +++---- homeassistant/components/control4/light.py | 4 +- .../components/coolmaster/climate.py | 15 +++---- 9 files changed, 87 insertions(+), 123 deletions(-) diff --git a/homeassistant/components/canary/alarm_control_panel.py b/homeassistant/components/canary/alarm_control_panel.py index 165bae0b497..d33e98008d6 100644 --- a/homeassistant/components/canary/alarm_control_panel.py +++ b/homeassistant/components/canary/alarm_control_panel.py @@ -10,11 +10,9 @@ from canary.api import ( Location, ) -from homeassistant.components.alarm_control_panel import AlarmControlPanelEntity -from homeassistant.components.alarm_control_panel.const import ( - SUPPORT_ALARM_ARM_AWAY, - SUPPORT_ALARM_ARM_HOME, - SUPPORT_ALARM_ARM_NIGHT, +from homeassistant.components.alarm_control_panel import ( + AlarmControlPanelEntity, + AlarmControlPanelEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -54,7 +52,9 @@ class CanaryAlarm( """Representation of a Canary alarm control panel.""" _attr_supported_features = ( - SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY | SUPPORT_ALARM_ARM_NIGHT + AlarmControlPanelEntityFeature.ARM_HOME + | AlarmControlPanelEntityFeature.ARM_AWAY + | AlarmControlPanelEntityFeature.ARM_NIGHT ) def __init__( diff --git a/homeassistant/components/cast/media_player.py b/homeassistant/components/cast/media_player.py index 091bde53ae0..02d62ca489b 100644 --- a/homeassistant/components/cast/media_player.py +++ b/homeassistant/components/cast/media_player.py @@ -25,6 +25,7 @@ from homeassistant.components.media_player import ( BrowseError, BrowseMedia, MediaPlayerEntity, + MediaPlayerEntityFeature, async_process_play_media_url, ) from homeassistant.components.media_player.const import ( @@ -33,18 +34,6 @@ from homeassistant.components.media_player.const import ( MEDIA_TYPE_MOVIE, MEDIA_TYPE_MUSIC, MEDIA_TYPE_TVSHOW, - SUPPORT_BROWSE_MEDIA, - SUPPORT_NEXT_TRACK, - SUPPORT_PAUSE, - SUPPORT_PLAY, - SUPPORT_PLAY_MEDIA, - SUPPORT_PREVIOUS_TRACK, - SUPPORT_SEEK, - SUPPORT_STOP, - SUPPORT_TURN_OFF, - SUPPORT_TURN_ON, - SUPPORT_VOLUME_MUTE, - SUPPORT_VOLUME_SET, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -83,8 +72,6 @@ APP_IDS_UNRELIABLE_MEDIA_INFO = ("Netflix",) CAST_SPLASH = "https://www.home-assistant.io/images/cast/splash.png" -SUPPORT_CAST = SUPPORT_PLAY_MEDIA | SUPPORT_TURN_OFF - ENTITY_SCHEMA = vol.All( vol.Schema( { @@ -805,30 +792,42 @@ class CastMediaPlayerEntity(CastDevice, MediaPlayerEntity): @property def supported_features(self): """Flag media player features that are supported.""" - support = SUPPORT_CAST + support = ( + MediaPlayerEntityFeature.PLAY_MEDIA | MediaPlayerEntityFeature.TURN_OFF + ) media_status = self._media_status()[0] if self._chromecast and self._chromecast.cast_type in ( pychromecast.const.CAST_TYPE_CHROMECAST, pychromecast.const.CAST_TYPE_AUDIO, ): - support |= SUPPORT_TURN_ON + support |= MediaPlayerEntityFeature.TURN_ON if ( self.cast_status and self.cast_status.volume_control_type != VOLUME_CONTROL_TYPE_FIXED ): - support |= SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_SET + support |= ( + MediaPlayerEntityFeature.VOLUME_MUTE + | MediaPlayerEntityFeature.VOLUME_SET + ) if media_status and self.app_id != CAST_APP_ID_HOMEASSISTANT_LOVELACE: - support |= SUPPORT_PAUSE | SUPPORT_PLAY | SUPPORT_STOP + support |= ( + MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.PLAY + | MediaPlayerEntityFeature.STOP + ) if media_status.supports_queue_next: - support |= SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK + support |= ( + MediaPlayerEntityFeature.PREVIOUS_TRACK + | MediaPlayerEntityFeature.NEXT_TRACK + ) if media_status.supports_seek: - support |= SUPPORT_SEEK + support |= MediaPlayerEntityFeature.SEEK if "media_source" in self.hass.config.components: - support |= SUPPORT_BROWSE_MEDIA + support |= MediaPlayerEntityFeature.BROWSE_MEDIA return support diff --git a/homeassistant/components/channels/media_player.py b/homeassistant/components/channels/media_player.py index d3a076f4a88..36fa2fe7ba0 100644 --- a/homeassistant/components/channels/media_player.py +++ b/homeassistant/components/channels/media_player.py @@ -4,20 +4,16 @@ from __future__ import annotations from pychannels import Channels import voluptuous as vol -from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity +from homeassistant.components.media_player import ( + PLATFORM_SCHEMA, + MediaPlayerEntity, + MediaPlayerEntityFeature, +) from homeassistant.components.media_player.const import ( MEDIA_TYPE_CHANNEL, MEDIA_TYPE_EPISODE, MEDIA_TYPE_MOVIE, MEDIA_TYPE_TVSHOW, - SUPPORT_NEXT_TRACK, - SUPPORT_PAUSE, - SUPPORT_PLAY, - SUPPORT_PLAY_MEDIA, - SUPPORT_PREVIOUS_TRACK, - SUPPORT_SELECT_SOURCE, - SUPPORT_STOP, - SUPPORT_VOLUME_MUTE, ) from homeassistant.const import ( ATTR_SECONDS, @@ -39,17 +35,6 @@ DATA_CHANNELS = "channels" DEFAULT_NAME = "Channels" DEFAULT_PORT = 57000 -FEATURE_SUPPORT = ( - SUPPORT_PLAY - | SUPPORT_PAUSE - | SUPPORT_STOP - | SUPPORT_VOLUME_MUTE - | SUPPORT_NEXT_TRACK - | SUPPORT_PREVIOUS_TRACK - | SUPPORT_PLAY_MEDIA - | SUPPORT_SELECT_SOURCE -) - PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_HOST): cv.string, @@ -91,6 +76,17 @@ async def async_setup_platform( class ChannelsPlayer(MediaPlayerEntity): """Representation of a Channels instance.""" + _attr_supported_features = ( + MediaPlayerEntityFeature.PLAY + | MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.STOP + | MediaPlayerEntityFeature.VOLUME_MUTE + | MediaPlayerEntityFeature.NEXT_TRACK + | MediaPlayerEntityFeature.PREVIOUS_TRACK + | MediaPlayerEntityFeature.PLAY_MEDIA + | MediaPlayerEntityFeature.SELECT_SOURCE + ) + def __init__(self, name, host, port): """Initialize the Channels app.""" @@ -215,11 +211,6 @@ class ChannelsPlayer(MediaPlayerEntity): return None - @property - def supported_features(self): - """Flag of media commands that are supported.""" - return FEATURE_SUPPORT - def mute_volume(self, mute): """Mute (true) or unmute (false) player.""" if mute != self.muted: diff --git a/homeassistant/components/clementine/media_player.py b/homeassistant/components/clementine/media_player.py index 2632d95427b..6b0f74a9e63 100644 --- a/homeassistant/components/clementine/media_player.py +++ b/homeassistant/components/clementine/media_player.py @@ -7,17 +7,12 @@ import time from clementineremote import ClementineRemote 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_PREVIOUS_TRACK, - SUPPORT_SELECT_SOURCE, - SUPPORT_VOLUME_SET, - SUPPORT_VOLUME_STEP, +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_ACCESS_TOKEN, CONF_HOST, @@ -37,16 +32,6 @@ DEFAULT_PORT = 5500 SCAN_INTERVAL = timedelta(seconds=5) -SUPPORT_CLEMENTINE = ( - SUPPORT_PAUSE - | SUPPORT_VOLUME_STEP - | SUPPORT_PREVIOUS_TRACK - | SUPPORT_VOLUME_SET - | SUPPORT_NEXT_TRACK - | SUPPORT_SELECT_SOURCE - | SUPPORT_PLAY -) - PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_HOST): cv.string, @@ -78,7 +63,15 @@ class ClementineDevice(MediaPlayerEntity): """Representation of Clementine Player.""" _attr_media_content_type = MEDIA_TYPE_MUSIC - _attr_supported_features = SUPPORT_CLEMENTINE + _attr_supported_features = ( + MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.VOLUME_STEP + | MediaPlayerEntityFeature.PREVIOUS_TRACK + | MediaPlayerEntityFeature.VOLUME_SET + | MediaPlayerEntityFeature.NEXT_TRACK + | MediaPlayerEntityFeature.SELECT_SOURCE + | MediaPlayerEntityFeature.PLAY + ) def __init__(self, client, name): """Initialize the Clementine device.""" diff --git a/homeassistant/components/cmus/media_player.py b/homeassistant/components/cmus/media_player.py index 199d2c089c7..d80b4f6ffb1 100644 --- a/homeassistant/components/cmus/media_player.py +++ b/homeassistant/components/cmus/media_player.py @@ -6,19 +6,14 @@ import logging from pycmus import exceptions, remote import voluptuous as vol -from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity +from homeassistant.components.media_player import ( + PLATFORM_SCHEMA, + MediaPlayerEntity, + MediaPlayerEntityFeature, +) from homeassistant.components.media_player.const import ( MEDIA_TYPE_MUSIC, MEDIA_TYPE_PLAYLIST, - SUPPORT_NEXT_TRACK, - SUPPORT_PAUSE, - SUPPORT_PLAY, - SUPPORT_PLAY_MEDIA, - SUPPORT_PREVIOUS_TRACK, - SUPPORT_SEEK, - SUPPORT_TURN_OFF, - SUPPORT_TURN_ON, - SUPPORT_VOLUME_SET, ) from homeassistant.const import ( CONF_HOST, @@ -39,18 +34,6 @@ _LOGGER = logging.getLogger(__name__) DEFAULT_NAME = "cmus" DEFAULT_PORT = 3000 -SUPPORT_CMUS = ( - SUPPORT_PAUSE - | SUPPORT_VOLUME_SET - | SUPPORT_TURN_OFF - | SUPPORT_TURN_ON - | SUPPORT_PREVIOUS_TRACK - | SUPPORT_NEXT_TRACK - | SUPPORT_PLAY_MEDIA - | SUPPORT_SEEK - | SUPPORT_PLAY -) - PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Inclusive(CONF_HOST, "remote"): cv.string, @@ -109,7 +92,17 @@ class CmusDevice(MediaPlayerEntity): """Representation of a running cmus.""" _attr_media_content_type = MEDIA_TYPE_MUSIC - _attr_supported_features = SUPPORT_CMUS + _attr_supported_features = ( + MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.VOLUME_SET + | MediaPlayerEntityFeature.TURN_OFF + | MediaPlayerEntityFeature.TURN_ON + | MediaPlayerEntityFeature.PREVIOUS_TRACK + | MediaPlayerEntityFeature.NEXT_TRACK + | MediaPlayerEntityFeature.PLAY_MEDIA + | MediaPlayerEntityFeature.SEEK + | MediaPlayerEntityFeature.PLAY + ) def __init__(self, device, name, server): """Initialize the CMUS device.""" diff --git a/homeassistant/components/comfoconnect/fan.py b/homeassistant/components/comfoconnect/fan.py index b2845068dbe..84d82c170e1 100644 --- a/homeassistant/components/comfoconnect/fan.py +++ b/homeassistant/components/comfoconnect/fan.py @@ -13,7 +13,7 @@ from pycomfoconnect import ( SENSOR_FAN_SPEED_MODE, ) -from homeassistant.components.fan import SUPPORT_SET_SPEED, FanEntity +from homeassistant.components.fan import FanEntity, FanEntityFeature from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -53,6 +53,7 @@ def setup_platform( class ComfoConnectFan(FanEntity): """Representation of the ComfoConnect fan platform.""" + _attr_supported_features = FanEntityFeature.SET_SPEED current_speed = None def __init__(self, ccb: ComfoConnectBridge) -> None: @@ -101,11 +102,6 @@ class ComfoConnectFan(FanEntity): """Return the icon to use in the frontend.""" return "mdi:air-conditioner" - @property - def supported_features(self) -> int: - """Flag supported features.""" - return SUPPORT_SET_SPEED - @property def percentage(self) -> int | None: """Return the current speed percentage.""" diff --git a/homeassistant/components/concord232/alarm_control_panel.py b/homeassistant/components/concord232/alarm_control_panel.py index 15664ebfaf6..d81357b5dc0 100644 --- a/homeassistant/components/concord232/alarm_control_panel.py +++ b/homeassistant/components/concord232/alarm_control_panel.py @@ -11,10 +11,7 @@ import voluptuous as vol import homeassistant.components.alarm_control_panel as alarm from homeassistant.components.alarm_control_panel import ( PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA, -) -from homeassistant.components.alarm_control_panel.const import ( - SUPPORT_ALARM_ARM_AWAY, - SUPPORT_ALARM_ARM_HOME, + AlarmControlPanelEntityFeature, ) from homeassistant.const import ( CONF_CODE, @@ -75,6 +72,11 @@ def setup_platform( class Concord232Alarm(alarm.AlarmControlPanelEntity): """Representation of the Concord232-based alarm panel.""" + _attr_supported_features = ( + AlarmControlPanelEntityFeature.ARM_HOME + | AlarmControlPanelEntityFeature.ARM_AWAY + ) + def __init__(self, url, name, code, mode): """Initialize the Concord232 alarm panel.""" @@ -101,11 +103,6 @@ class Concord232Alarm(alarm.AlarmControlPanelEntity): """Return the state of the device.""" return self._state - @property - def supported_features(self) -> int: - """Return the list of supported features.""" - return SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY - def update(self): """Update values from API.""" try: diff --git a/homeassistant/components/control4/light.py b/homeassistant/components/control4/light.py index e9226cc3716..6e5f5dad1d2 100644 --- a/homeassistant/components/control4/light.py +++ b/homeassistant/components/control4/light.py @@ -13,8 +13,8 @@ from homeassistant.components.light import ( ATTR_TRANSITION, COLOR_MODE_BRIGHTNESS, COLOR_MODE_ONOFF, - SUPPORT_TRANSITION, LightEntity, + LightEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_SCAN_INTERVAL @@ -195,7 +195,7 @@ class Control4Light(Control4Entity, LightEntity): def supported_features(self) -> int: """Flag supported features.""" if self._is_dimmer: - return SUPPORT_TRANSITION + return LightEntityFeature.TRANSITION return 0 async def async_turn_on(self, **kwargs) -> None: diff --git a/homeassistant/components/coolmaster/climate.py b/homeassistant/components/coolmaster/climate.py index de1652d6938..22eaf5281da 100644 --- a/homeassistant/components/coolmaster/climate.py +++ b/homeassistant/components/coolmaster/climate.py @@ -1,7 +1,7 @@ """CoolMasterNet platform to control of CoolMasterNet Climate Devices.""" import logging -from homeassistant.components.climate import ClimateEntity +from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature from homeassistant.components.climate.const import ( HVAC_MODE_COOL, HVAC_MODE_DRY, @@ -9,8 +9,6 @@ from homeassistant.components.climate.const import ( HVAC_MODE_HEAT, HVAC_MODE_HEAT_COOL, HVAC_MODE_OFF, - SUPPORT_FAN_MODE, - SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT @@ -21,8 +19,6 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import CONF_SUPPORTED_MODES, DATA_COORDINATOR, DATA_INFO, DOMAIN -SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE - CM_TO_HA_STATE = { "heat": HVAC_MODE_HEAT, "cool": HVAC_MODE_COOL, @@ -65,6 +61,10 @@ async def async_setup_entry( class CoolmasterClimate(CoordinatorEntity, ClimateEntity): """Representation of a coolmaster climate device.""" + _attr_supported_features = ( + ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE + ) + def __init__(self, coordinator, unit_id, unit, supported_modes, info): """Initialize the climate device.""" super().__init__(coordinator) @@ -94,11 +94,6 @@ class CoolmasterClimate(CoordinatorEntity, ClimateEntity): """Return unique ID for this device.""" return self._unit_id - @property - def supported_features(self): - """Return the list of supported features.""" - return SUPPORT_FLAGS - @property def name(self): """Return the name of the climate device."""