From 190ef4ee35d781693c1d511a5b731da2d7f205ed Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 7 Apr 2022 15:06:34 +0200 Subject: [PATCH] Use EntityFeature enum in components (s** 2/2) (#69441) --- homeassistant/components/soma/cover.py | 22 +++---- homeassistant/components/somfy/climate.py | 13 ++--- homeassistant/components/somfy/cover.py | 25 +++----- .../components/songpal/media_player.py | 34 ++++------- .../components/sonos/media_player.py | 52 ++++++----------- .../components/soundtouch/media_player.py | 50 ++++++---------- .../components/spc/alarm_control_panel.py | 17 +++--- homeassistant/components/spider/climate.py | 10 ++-- .../components/spotify/media_player.py | 39 ++++++------- .../components/squeezebox/media_player.py | 57 +++++++------------ .../components/stiebel_eltron/climate.py | 16 ++---- homeassistant/components/switchbot/cover.py | 10 ++-- .../components/synology_dsm/camera.py | 8 +-- tests/components/songpal/test_media_player.py | 11 +++- 14 files changed, 143 insertions(+), 221 deletions(-) diff --git a/homeassistant/components/soma/cover.py b/homeassistant/components/soma/cover.py index 81cdd470615..abc6d828acc 100644 --- a/homeassistant/components/soma/cover.py +++ b/homeassistant/components/soma/cover.py @@ -4,16 +4,9 @@ from __future__ import annotations from homeassistant.components.cover import ( ATTR_POSITION, ATTR_TILT_POSITION, - SUPPORT_CLOSE, - SUPPORT_CLOSE_TILT, - SUPPORT_OPEN, - SUPPORT_OPEN_TILT, - SUPPORT_SET_POSITION, - SUPPORT_SET_TILT_POSITION, - SUPPORT_STOP, - SUPPORT_STOP_TILT, CoverDeviceClass, CoverEntity, + CoverEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -50,10 +43,10 @@ class SomaTilt(SomaEntity, CoverEntity): _attr_device_class = CoverDeviceClass.BLIND _attr_supported_features = ( - SUPPORT_OPEN_TILT - | SUPPORT_CLOSE_TILT - | SUPPORT_STOP_TILT - | SUPPORT_SET_TILT_POSITION + CoverEntityFeature.OPEN_TILT + | CoverEntityFeature.CLOSE_TILT + | CoverEntityFeature.STOP_TILT + | CoverEntityFeature.SET_TILT_POSITION ) @property @@ -124,7 +117,10 @@ class SomaShade(SomaEntity, CoverEntity): _attr_device_class = CoverDeviceClass.SHADE _attr_supported_features = ( - SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION + CoverEntityFeature.OPEN + | CoverEntityFeature.CLOSE + | CoverEntityFeature.STOP + | CoverEntityFeature.SET_POSITION ) @property diff --git a/homeassistant/components/somfy/climate.py b/homeassistant/components/somfy/climate.py index 1e1e3cdca95..67e4a337092 100644 --- a/homeassistant/components/somfy/climate.py +++ b/homeassistant/components/somfy/climate.py @@ -10,7 +10,7 @@ from pymfy.api.devices.thermostat import ( Thermostat, ) -from homeassistant.components.climate import ClimateEntity +from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature from homeassistant.components.climate.const import ( HVAC_MODE_AUTO, HVAC_MODE_COOL, @@ -18,8 +18,6 @@ from homeassistant.components.climate.const import ( PRESET_AWAY, PRESET_HOME, PRESET_SLEEP, - SUPPORT_PRESET_MODE, - SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS @@ -69,6 +67,10 @@ async def async_setup_entry( class SomfyClimate(SomfyEntity, ClimateEntity): """Representation of a Somfy thermostat device.""" + _attr_supported_features = ( + ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE + ) + def __init__(self, coordinator, device_id): """Initialize the Somfy device.""" super().__init__(coordinator, device_id) @@ -79,11 +81,6 @@ class SomfyClimate(SomfyEntity, ClimateEntity): """Update the device with the latest data.""" self._climate = Thermostat(self.device, self.coordinator.client) - @property - def supported_features(self) -> int: - """Return the list of supported features.""" - return SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE - @property def temperature_unit(self): """Return the unit of measurement used by the platform.""" diff --git a/homeassistant/components/somfy/cover.py b/homeassistant/components/somfy/cover.py index 91bebc1da0d..a2a72d4ce98 100644 --- a/homeassistant/components/somfy/cover.py +++ b/homeassistant/components/somfy/cover.py @@ -9,16 +9,9 @@ from pymfy.api.devices.category import Category from homeassistant.components.cover import ( ATTR_POSITION, ATTR_TILT_POSITION, - SUPPORT_CLOSE, - SUPPORT_CLOSE_TILT, - SUPPORT_OPEN, - SUPPORT_OPEN_TILT, - SUPPORT_SET_POSITION, - SUPPORT_SET_TILT_POSITION, - SUPPORT_STOP, - SUPPORT_STOP_TILT, CoverDeviceClass, CoverEntity, + CoverEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_OPTIMISTIC, STATE_CLOSED, STATE_OPEN @@ -82,19 +75,19 @@ class SomfyCover(SomfyEntity, RestoreEntity, CoverEntity): """Flag supported features.""" supported_features = 0 if self.has_capability("open"): - supported_features |= SUPPORT_OPEN + supported_features |= CoverEntityFeature.OPEN if self.has_capability("close"): - supported_features |= SUPPORT_CLOSE + supported_features |= CoverEntityFeature.CLOSE if self.has_capability("stop"): - supported_features |= SUPPORT_STOP + supported_features |= CoverEntityFeature.STOP if self.has_capability("position"): - supported_features |= SUPPORT_SET_POSITION + supported_features |= CoverEntityFeature.SET_POSITION if self.has_capability("rotation"): supported_features |= ( - SUPPORT_OPEN_TILT - | SUPPORT_CLOSE_TILT - | SUPPORT_STOP_TILT - | SUPPORT_SET_TILT_POSITION + CoverEntityFeature.OPEN_TILT + | CoverEntityFeature.CLOSE_TILT + | CoverEntityFeature.STOP_TILT + | CoverEntityFeature.SET_TILT_POSITION ) return supported_features diff --git a/homeassistant/components/songpal/media_player.py b/homeassistant/components/songpal/media_player.py index e161f818c8c..fed1762bb44 100644 --- a/homeassistant/components/songpal/media_player.py +++ b/homeassistant/components/songpal/media_player.py @@ -16,14 +16,9 @@ from songpal import ( ) import voluptuous as vol -from homeassistant.components.media_player import MediaPlayerEntity -from homeassistant.components.media_player.const import ( - SUPPORT_SELECT_SOURCE, - SUPPORT_TURN_OFF, - SUPPORT_TURN_ON, - SUPPORT_VOLUME_MUTE, - SUPPORT_VOLUME_SET, - SUPPORT_VOLUME_STEP, +from homeassistant.components.media_player import ( + MediaPlayerEntity, + MediaPlayerEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_NAME, EVENT_HOMEASSISTANT_STOP, STATE_OFF, STATE_ON @@ -45,15 +40,6 @@ _LOGGER = logging.getLogger(__name__) PARAM_NAME = "name" PARAM_VALUE = "value" -SUPPORT_SONGPAL = ( - SUPPORT_VOLUME_SET - | SUPPORT_VOLUME_STEP - | SUPPORT_VOLUME_MUTE - | SUPPORT_SELECT_SOURCE - | SUPPORT_TURN_ON - | SUPPORT_TURN_OFF -) - INITIAL_RETRY_DELAY = 10 @@ -103,6 +89,15 @@ async def async_setup_entry( class SongpalEntity(MediaPlayerEntity): """Class representing a Songpal device.""" + _attr_supported_features = ( + MediaPlayerEntityFeature.VOLUME_SET + | MediaPlayerEntityFeature.VOLUME_STEP + | MediaPlayerEntityFeature.VOLUME_MUTE + | MediaPlayerEntityFeature.SELECT_SOURCE + | MediaPlayerEntityFeature.TURN_ON + | MediaPlayerEntityFeature.TURN_OFF + ) + def __init__(self, name, device): """Init.""" self._name = name @@ -354,8 +349,3 @@ class SongpalEntity(MediaPlayerEntity): def is_volume_muted(self): """Return whether the device is muted.""" return self._is_muted - - @property - def supported_features(self): - """Return supported features.""" - return SUPPORT_SONGPAL diff --git a/homeassistant/components/sonos/media_player.py b/homeassistant/components/sonos/media_player.py index 16d805a578a..4b4dc99ad71 100644 --- a/homeassistant/components/sonos/media_player.py +++ b/homeassistant/components/sonos/media_player.py @@ -19,6 +19,7 @@ import voluptuous as vol from homeassistant.components import media_source, spotify from homeassistant.components.media_player import ( MediaPlayerEntity, + MediaPlayerEntityFeature, async_process_play_media_url, ) from homeassistant.components.media_player.const import ( @@ -32,21 +33,6 @@ from homeassistant.components.media_player.const import ( REPEAT_MODE_ALL, REPEAT_MODE_OFF, REPEAT_MODE_ONE, - SUPPORT_BROWSE_MEDIA, - SUPPORT_CLEAR_PLAYLIST, - SUPPORT_GROUPING, - SUPPORT_NEXT_TRACK, - SUPPORT_PAUSE, - SUPPORT_PLAY, - SUPPORT_PLAY_MEDIA, - SUPPORT_PREVIOUS_TRACK, - SUPPORT_REPEAT_SET, - SUPPORT_SEEK, - SUPPORT_SELECT_SOURCE, - SUPPORT_SHUFFLE_SET, - SUPPORT_STOP, - SUPPORT_VOLUME_MUTE, - SUPPORT_VOLUME_SET, ) from homeassistant.components.plex.const import PLEX_URI_SCHEME from homeassistant.components.plex.services import process_plex_payload @@ -80,24 +66,6 @@ from .speaker import SonosMedia, SonosSpeaker _LOGGER = logging.getLogger(__name__) -SUPPORT_SONOS = ( - SUPPORT_BROWSE_MEDIA - | SUPPORT_CLEAR_PLAYLIST - | SUPPORT_GROUPING - | SUPPORT_NEXT_TRACK - | SUPPORT_PAUSE - | SUPPORT_PLAY - | SUPPORT_PLAY_MEDIA - | SUPPORT_PREVIOUS_TRACK - | SUPPORT_REPEAT_SET - | SUPPORT_SEEK - | SUPPORT_SELECT_SOURCE - | SUPPORT_SHUFFLE_SET - | SUPPORT_STOP - | SUPPORT_VOLUME_MUTE - | SUPPORT_VOLUME_SET -) - VOLUME_INCREMENT = 2 REPEAT_TO_SONOS = { @@ -250,7 +218,23 @@ async def async_setup_entry( class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity): """Representation of a Sonos entity.""" - _attr_supported_features = SUPPORT_SONOS + _attr_supported_features = ( + MediaPlayerEntityFeature.BROWSE_MEDIA + | MediaPlayerEntityFeature.CLEAR_PLAYLIST + | MediaPlayerEntityFeature.GROUPING + | MediaPlayerEntityFeature.NEXT_TRACK + | MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.PLAY + | MediaPlayerEntityFeature.PLAY_MEDIA + | MediaPlayerEntityFeature.PREVIOUS_TRACK + | MediaPlayerEntityFeature.REPEAT_SET + | MediaPlayerEntityFeature.SEEK + | MediaPlayerEntityFeature.SELECT_SOURCE + | MediaPlayerEntityFeature.SHUFFLE_SET + | MediaPlayerEntityFeature.STOP + | MediaPlayerEntityFeature.VOLUME_MUTE + | MediaPlayerEntityFeature.VOLUME_SET + ) _attr_media_content_type = MEDIA_TYPE_MUSIC def __init__(self, speaker: SonosSpeaker) -> None: diff --git a/homeassistant/components/soundtouch/media_player.py b/homeassistant/components/soundtouch/media_player.py index f8c398c1c88..2a19ed10833 100644 --- a/homeassistant/components/soundtouch/media_player.py +++ b/homeassistant/components/soundtouch/media_player.py @@ -8,19 +8,10 @@ from libsoundtouch import soundtouch_device from libsoundtouch.utils import Source import voluptuous as vol -from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity -from homeassistant.components.media_player.const import ( - SUPPORT_NEXT_TRACK, - SUPPORT_PAUSE, - SUPPORT_PLAY, - SUPPORT_PLAY_MEDIA, - SUPPORT_PREVIOUS_TRACK, - SUPPORT_SELECT_SOURCE, - SUPPORT_TURN_OFF, - SUPPORT_TURN_ON, - SUPPORT_VOLUME_MUTE, - SUPPORT_VOLUME_SET, - SUPPORT_VOLUME_STEP, +from homeassistant.components.media_player import ( + PLATFORM_SCHEMA, + MediaPlayerEntity, + MediaPlayerEntityFeature, ) from homeassistant.const import ( CONF_HOST, @@ -75,20 +66,6 @@ SOUNDTOUCH_REMOVE_ZONE_SCHEMA = vol.Schema( DEFAULT_NAME = "Bose Soundtouch" DEFAULT_PORT = 8090 -SUPPORT_SOUNDTOUCH = ( - SUPPORT_PAUSE - | SUPPORT_VOLUME_STEP - | SUPPORT_VOLUME_MUTE - | SUPPORT_PREVIOUS_TRACK - | SUPPORT_NEXT_TRACK - | SUPPORT_TURN_OFF - | SUPPORT_VOLUME_SET - | SUPPORT_TURN_ON - | SUPPORT_PLAY - | SUPPORT_PLAY_MEDIA - | SUPPORT_SELECT_SOURCE -) - PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_HOST): cv.string, @@ -199,6 +176,20 @@ def setup_platform( class SoundTouchDevice(MediaPlayerEntity): """Representation of a SoundTouch Bose device.""" + _attr_supported_features = ( + MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.VOLUME_STEP + | MediaPlayerEntityFeature.VOLUME_MUTE + | MediaPlayerEntityFeature.PREVIOUS_TRACK + | MediaPlayerEntityFeature.NEXT_TRACK + | MediaPlayerEntityFeature.TURN_OFF + | MediaPlayerEntityFeature.VOLUME_SET + | MediaPlayerEntityFeature.TURN_ON + | MediaPlayerEntityFeature.PLAY + | MediaPlayerEntityFeature.PLAY_MEDIA + | MediaPlayerEntityFeature.SELECT_SOURCE + ) + def __init__(self, name, config): """Create Soundtouch Entity.""" @@ -264,11 +255,6 @@ class SoundTouchDevice(MediaPlayerEntity): """Boolean if volume is currently muted.""" return self._volume.muted - @property - def supported_features(self): - """Flag media player features that are supported.""" - return SUPPORT_SOUNDTOUCH - def turn_off(self): """Turn off media player.""" self._device.power_off() diff --git a/homeassistant/components/spc/alarm_control_panel.py b/homeassistant/components/spc/alarm_control_panel.py index 4fe1bd4d5d7..d519e6b7f2b 100644 --- a/homeassistant/components/spc/alarm_control_panel.py +++ b/homeassistant/components/spc/alarm_control_panel.py @@ -4,11 +4,7 @@ from __future__ import annotations from pyspcwebgw.const import AreaMode import homeassistant.components.alarm_control_panel as alarm -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 AlarmControlPanelEntityFeature from homeassistant.const import ( STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, @@ -55,6 +51,12 @@ async def async_setup_platform( class SpcAlarm(alarm.AlarmControlPanelEntity): """Representation of the SPC alarm panel.""" + _attr_supported_features = ( + AlarmControlPanelEntityFeature.ARM_HOME + | AlarmControlPanelEntityFeature.ARM_AWAY + | AlarmControlPanelEntityFeature.ARM_NIGHT + ) + def __init__(self, area, api): """Initialize the SPC alarm panel.""" self._area = area @@ -95,11 +97,6 @@ class SpcAlarm(alarm.AlarmControlPanelEntity): """Return the state of the device.""" return _get_alarm_state(self._area) - @property - def supported_features(self) -> int: - """Return the list of supported features.""" - return SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY | SUPPORT_ALARM_ARM_NIGHT - async def async_alarm_disarm(self, code=None): """Send disarm command.""" diff --git a/homeassistant/components/spider/climate.py b/homeassistant/components/spider/climate.py index 40b9f377b31..d2748af4aec 100644 --- a/homeassistant/components/spider/climate.py +++ b/homeassistant/components/spider/climate.py @@ -1,11 +1,9 @@ """Support for Spider thermostats.""" -from homeassistant.components.climate import ClimateEntity +from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature from homeassistant.components.climate.const import ( HVAC_MODE_COOL, HVAC_MODE_HEAT, HVAC_MODE_OFF, - SUPPORT_FAN_MODE, - SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS @@ -66,8 +64,10 @@ class SpiderThermostat(ClimateEntity): def supported_features(self): """Return the list of supported features.""" if self.thermostat.has_fan_mode: - return SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE - return SUPPORT_TARGET_TEMPERATURE + return ( + ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE + ) + return ClimateEntityFeature.TARGET_TEMPERATURE @property def unique_id(self): diff --git a/homeassistant/components/spotify/media_player.py b/homeassistant/components/spotify/media_player.py index 3ed7be99041..7d24f1deee8 100644 --- a/homeassistant/components/spotify/media_player.py +++ b/homeassistant/components/spotify/media_player.py @@ -10,7 +10,11 @@ import requests from spotipy import SpotifyException from yarl import URL -from homeassistant.components.media_player import BrowseMedia, MediaPlayerEntity +from homeassistant.components.media_player import ( + BrowseMedia, + MediaPlayerEntity, + MediaPlayerEntityFeature, +) from homeassistant.components.media_player.const import ( MEDIA_TYPE_EPISODE, MEDIA_TYPE_MUSIC, @@ -19,17 +23,6 @@ from homeassistant.components.media_player.const import ( REPEAT_MODE_ALL, REPEAT_MODE_OFF, REPEAT_MODE_ONE, - SUPPORT_BROWSE_MEDIA, - SUPPORT_NEXT_TRACK, - SUPPORT_PAUSE, - SUPPORT_PLAY, - SUPPORT_PLAY_MEDIA, - SUPPORT_PREVIOUS_TRACK, - SUPPORT_REPEAT_SET, - SUPPORT_SEEK, - SUPPORT_SELECT_SOURCE, - SUPPORT_SHUFFLE_SET, - SUPPORT_VOLUME_SET, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_ID, STATE_IDLE, STATE_PAUSED, STATE_PLAYING @@ -50,17 +43,17 @@ _LOGGER = logging.getLogger(__name__) SCAN_INTERVAL = timedelta(minutes=1) SUPPORT_SPOTIFY = ( - SUPPORT_BROWSE_MEDIA - | SUPPORT_NEXT_TRACK - | SUPPORT_PAUSE - | SUPPORT_PLAY - | SUPPORT_PLAY_MEDIA - | SUPPORT_PREVIOUS_TRACK - | SUPPORT_REPEAT_SET - | SUPPORT_SEEK - | SUPPORT_SELECT_SOURCE - | SUPPORT_SHUFFLE_SET - | SUPPORT_VOLUME_SET + MediaPlayerEntityFeature.BROWSE_MEDIA + | MediaPlayerEntityFeature.NEXT_TRACK + | MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.PLAY + | MediaPlayerEntityFeature.PLAY_MEDIA + | MediaPlayerEntityFeature.PREVIOUS_TRACK + | MediaPlayerEntityFeature.REPEAT_SET + | MediaPlayerEntityFeature.SEEK + | MediaPlayerEntityFeature.SELECT_SOURCE + | MediaPlayerEntityFeature.SHUFFLE_SET + | MediaPlayerEntityFeature.VOLUME_SET ) REPEAT_MODE_MAPPING_TO_HA = { diff --git a/homeassistant/components/squeezebox/media_player.py b/homeassistant/components/squeezebox/media_player.py index d8a1c29b723..384da3f59a8 100644 --- a/homeassistant/components/squeezebox/media_player.py +++ b/homeassistant/components/squeezebox/media_player.py @@ -9,7 +9,10 @@ from pysqueezebox import Server, async_discover import voluptuous as vol from homeassistant.components import media_source -from homeassistant.components.media_player import MediaPlayerEntity +from homeassistant.components.media_player import ( + MediaPlayerEntity, + MediaPlayerEntityFeature, +) from homeassistant.components.media_player.browse_media import ( async_process_play_media_url, ) @@ -17,20 +20,6 @@ from homeassistant.components.media_player.const import ( ATTR_MEDIA_ENQUEUE, MEDIA_TYPE_MUSIC, MEDIA_TYPE_PLAYLIST, - SUPPORT_BROWSE_MEDIA, - SUPPORT_CLEAR_PLAYLIST, - SUPPORT_NEXT_TRACK, - SUPPORT_PAUSE, - SUPPORT_PLAY, - SUPPORT_PLAY_MEDIA, - SUPPORT_PREVIOUS_TRACK, - SUPPORT_SEEK, - SUPPORT_SHUFFLE_SET, - SUPPORT_STOP, - SUPPORT_TURN_OFF, - SUPPORT_TURN_ON, - SUPPORT_VOLUME_MUTE, - SUPPORT_VOLUME_SET, ) from homeassistant.config_entries import SOURCE_INTEGRATION_DISCOVERY, ConfigEntry from homeassistant.const import ( @@ -79,22 +68,6 @@ _LOGGER = logging.getLogger(__name__) DISCOVERY_INTERVAL = 60 -SUPPORT_SQUEEZEBOX = ( - SUPPORT_BROWSE_MEDIA - | SUPPORT_PAUSE - | SUPPORT_VOLUME_SET - | SUPPORT_VOLUME_MUTE - | SUPPORT_PREVIOUS_TRACK - | SUPPORT_NEXT_TRACK - | SUPPORT_SEEK - | SUPPORT_TURN_ON - | SUPPORT_TURN_OFF - | SUPPORT_PLAY_MEDIA - | SUPPORT_PLAY - | SUPPORT_SHUFFLE_SET - | SUPPORT_CLEAR_PLAYLIST - | SUPPORT_STOP -) KNOWN_SERVERS = "known_servers" ATTR_PARAMETERS = "parameters" @@ -240,6 +213,23 @@ class SqueezeBoxEntity(MediaPlayerEntity): Wraps a pysqueezebox.Player() object. """ + _attr_supported_features = ( + MediaPlayerEntityFeature.BROWSE_MEDIA + | MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.VOLUME_SET + | MediaPlayerEntityFeature.VOLUME_MUTE + | MediaPlayerEntityFeature.PREVIOUS_TRACK + | MediaPlayerEntityFeature.NEXT_TRACK + | MediaPlayerEntityFeature.SEEK + | MediaPlayerEntityFeature.TURN_ON + | MediaPlayerEntityFeature.TURN_OFF + | MediaPlayerEntityFeature.PLAY_MEDIA + | MediaPlayerEntityFeature.PLAY + | MediaPlayerEntityFeature.SHUFFLE_SET + | MediaPlayerEntityFeature.CLEAR_PLAYLIST + | MediaPlayerEntityFeature.STOP + ) + def __init__(self, player): """Initialize the SqueezeBox device.""" self._player = player @@ -382,11 +372,6 @@ class SqueezeBoxEntity(MediaPlayerEntity): """Boolean if shuffle is enabled.""" return self._player.shuffle - @property - def supported_features(self): - """Flag media player features that are supported.""" - return SUPPORT_SQUEEZEBOX - @property def sync_group(self): """List players we are synced with.""" diff --git a/homeassistant/components/stiebel_eltron/climate.py b/homeassistant/components/stiebel_eltron/climate.py index 65df643f434..3b349713877 100644 --- a/homeassistant/components/stiebel_eltron/climate.py +++ b/homeassistant/components/stiebel_eltron/climate.py @@ -3,14 +3,12 @@ from __future__ import annotations import logging -from homeassistant.components.climate import ClimateEntity +from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature from homeassistant.components.climate.const import ( HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF, PRESET_ECO, - SUPPORT_PRESET_MODE, - SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.core import HomeAssistant @@ -27,7 +25,6 @@ PRESET_DAY = "day" PRESET_SETBACK = "setback" PRESET_EMERGENCY = "emergency" -SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE SUPPORT_HVAC = [HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF] SUPPORT_PRESET = [PRESET_ECO, PRESET_DAY, PRESET_EMERGENCY, PRESET_SETBACK] @@ -74,6 +71,10 @@ def setup_platform( class StiebelEltron(ClimateEntity): """Representation of a STIEBEL ELTRON heat pump.""" + _attr_supported_features = ( + ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE + ) + def __init__(self, name, ste_data): """Initialize the unit.""" self._name = name @@ -85,11 +86,6 @@ class StiebelEltron(ClimateEntity): self._force_update = False self._ste_data = ste_data - @property - def supported_features(self): - """Return the list of supported features.""" - return SUPPORT_FLAGS - def update(self): """Update unit attributes.""" self._ste_data.update(no_throttle=self._force_update) @@ -115,7 +111,7 @@ class StiebelEltron(ClimateEntity): """Return the name of the climate device.""" return self._name - # Handle SUPPORT_TARGET_TEMPERATURE + # Handle ClimateEntityFeature.TARGET_TEMPERATURE @property def temperature_unit(self): """Return the unit of measurement.""" diff --git a/homeassistant/components/switchbot/cover.py b/homeassistant/components/switchbot/cover.py index 97ca1aa15bb..9f265d696ad 100644 --- a/homeassistant/components/switchbot/cover.py +++ b/homeassistant/components/switchbot/cover.py @@ -9,12 +9,9 @@ from switchbot import SwitchbotCurtain # pylint: disable=import-error from homeassistant.components.cover import ( ATTR_CURRENT_POSITION, ATTR_POSITION, - SUPPORT_CLOSE, - SUPPORT_OPEN, - SUPPORT_SET_POSITION, - SUPPORT_STOP, CoverDeviceClass, CoverEntity, + CoverEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_MAC, CONF_NAME, CONF_PASSWORD @@ -61,7 +58,10 @@ class SwitchBotCurtainEntity(SwitchbotEntity, CoverEntity, RestoreEntity): _attr_device_class = CoverDeviceClass.CURTAIN _attr_supported_features = ( - SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION + CoverEntityFeature.OPEN + | CoverEntityFeature.CLOSE + | CoverEntityFeature.STOP + | CoverEntityFeature.SET_POSITION ) _attr_assumed_state = True diff --git a/homeassistant/components/synology_dsm/camera.py b/homeassistant/components/synology_dsm/camera.py index 0999ef858c6..ddf6531cae5 100644 --- a/homeassistant/components/synology_dsm/camera.py +++ b/homeassistant/components/synology_dsm/camera.py @@ -11,9 +11,9 @@ from synology_dsm.exceptions import ( ) from homeassistant.components.camera import ( - SUPPORT_STREAM, Camera, CameraEntityDescription, + CameraEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -67,6 +67,7 @@ async def async_setup_entry( class SynoDSMCamera(SynologyDSMBaseEntity, Camera): """Representation a Synology camera.""" + _attr_supported_features = CameraEntityFeature.STREAM coordinator: DataUpdateCoordinator[dict[str, dict[str, SynoCamera]]] entity_description: SynologyDSMCameraEntityDescription @@ -119,11 +120,6 @@ class SynoDSMCamera(SynologyDSMBaseEntity, Camera): """Return the availability of the camera.""" return self.camera_data.is_enabled and self.coordinator.last_update_success - @property - def supported_features(self) -> int: - """Return supported features of this camera.""" - return SUPPORT_STREAM - @property def is_recording(self) -> bool: """Return true if the device is recording.""" diff --git a/tests/components/songpal/test_media_player.py b/tests/components/songpal/test_media_player.py index 815995814f9..edaafed1aa4 100644 --- a/tests/components/songpal/test_media_player.py +++ b/tests/components/songpal/test_media_player.py @@ -12,8 +12,8 @@ from songpal import ( ) from homeassistant.components import media_player, songpal +from homeassistant.components.media_player import MediaPlayerEntityFeature from homeassistant.components.songpal.const import SET_SOUND_SETTING -from homeassistant.components.songpal.media_player import SUPPORT_SONGPAL from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.setup import async_setup_component @@ -36,6 +36,15 @@ from . import ( from tests.common import MockConfigEntry, async_fire_time_changed +SUPPORT_SONGPAL = ( + MediaPlayerEntityFeature.VOLUME_SET + | MediaPlayerEntityFeature.VOLUME_STEP + | MediaPlayerEntityFeature.VOLUME_MUTE + | MediaPlayerEntityFeature.SELECT_SOURCE + | MediaPlayerEntityFeature.TURN_ON + | MediaPlayerEntityFeature.TURN_OFF +) + def _get_attributes(hass): state = hass.states.get(ENTITY_ID)