From f194f7809b636013b3a2d5ea3f29384db9993e18 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 7 Apr 2022 08:42:18 +0200 Subject: [PATCH] Use EntityFeature enum in components (v**) (#69465) * Use EntityFeature enum in vallox * Use EntityFeature enum in velbus * Use EntityFeature enum in velux * Use EntityFeature enum in venstar * Use EntityFeature enum in vera * Use EntityFeature enum in verisure * Use EntityFeature enum in vesync * Use EntityFeature enum in vicare * Use EntityFeature enum in vivotek * Use EntityFeature enum in vizio * Use EntityFeature enum in vlc * Use EntityFeature enum in vlc_telnet * Use EntityFeature enum in volumio --- homeassistant/components/vallox/fan.py | 9 +-- homeassistant/components/velbus/climate.py | 12 ++-- homeassistant/components/velbus/cover.py | 16 +++-- homeassistant/components/velux/cover.py | 22 +++---- homeassistant/components/venstar/climate.py | 21 ++++--- homeassistant/components/vera/climate.py | 18 +++--- .../verisure/alarm_control_panel.py | 10 +-- homeassistant/components/vesync/fan.py | 9 +-- homeassistant/components/vicare/climate.py | 15 ++--- .../components/vicare/water_heater.py | 11 +--- homeassistant/components/vivotek/camera.py | 9 +-- .../components/vizio/media_player.py | 12 ++-- homeassistant/components/vlc/media_player.py | 37 +++++------ .../components/vlc_telnet/media_player.py | 52 ++++++---------- .../components/volumio/media_player.py | 61 +++++++------------ 15 files changed, 128 insertions(+), 186 deletions(-) diff --git a/homeassistant/components/vallox/fan.py b/homeassistant/components/vallox/fan.py index 52535be3a29..85b3f501c85 100644 --- a/homeassistant/components/vallox/fan.py +++ b/homeassistant/components/vallox/fan.py @@ -9,8 +9,8 @@ from vallox_websocket_api import Vallox from vallox_websocket_api.exceptions import ValloxApiException from homeassistant.components.fan import ( - SUPPORT_PRESET_MODE, FanEntity, + FanEntityFeature, NotValidPresetModeError, ) from homeassistant.config_entries import ConfigEntry @@ -83,6 +83,8 @@ async def async_setup_entry( class ValloxFan(CoordinatorEntity[ValloxDataUpdateCoordinator], FanEntity): """Representation of the fan.""" + _attr_supported_features = FanEntityFeature.PRESET_MODE + def __init__( self, name: str, @@ -98,11 +100,6 @@ class ValloxFan(CoordinatorEntity[ValloxDataUpdateCoordinator], FanEntity): self._attr_unique_id = str(self.coordinator.data.get_uuid()) - @property - def supported_features(self) -> int: - """Flag supported features.""" - return SUPPORT_PRESET_MODE - @property def preset_modes(self) -> list[str]: """Return a list of available preset modes.""" diff --git a/homeassistant/components/velbus/climate.py b/homeassistant/components/velbus/climate.py index 5dce4033074..886d200028b 100644 --- a/homeassistant/components/velbus/climate.py +++ b/homeassistant/components/velbus/climate.py @@ -5,12 +5,8 @@ from typing import Any from velbusaio.channels import Temperature as VelbusTemp -from homeassistant.components.climate import ClimateEntity -from homeassistant.components.climate.const import ( - HVAC_MODE_HEAT, - SUPPORT_PRESET_MODE, - SUPPORT_TARGET_TEMPERATURE, -) +from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature +from homeassistant.components.climate.const import HVAC_MODE_HEAT from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.core import HomeAssistant @@ -38,7 +34,9 @@ class VelbusClimate(VelbusEntity, ClimateEntity): """Representation of a Velbus thermostat.""" _channel: VelbusTemp - _attr_supported_features = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE + _attr_supported_features = ( + ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE + ) _attr_temperature_unit = TEMP_CELSIUS _attr_hvac_mode = HVAC_MODE_HEAT _attr_hvac_modes = [HVAC_MODE_HEAT] diff --git a/homeassistant/components/velbus/cover.py b/homeassistant/components/velbus/cover.py index 4afe02f4637..6bd1629d3a3 100644 --- a/homeassistant/components/velbus/cover.py +++ b/homeassistant/components/velbus/cover.py @@ -7,11 +7,8 @@ from velbusaio.channels import Blind as VelbusBlind from homeassistant.components.cover import ( ATTR_POSITION, - SUPPORT_CLOSE, - SUPPORT_OPEN, - SUPPORT_SET_POSITION, - SUPPORT_STOP, CoverEntity, + CoverEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -45,10 +42,17 @@ class VelbusCover(VelbusEntity, CoverEntity): super().__init__(channel) if self._channel.support_position(): self._attr_supported_features = ( - SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION + CoverEntityFeature.OPEN + | CoverEntityFeature.CLOSE + | CoverEntityFeature.STOP + | CoverEntityFeature.SET_POSITION ) else: - self._attr_supported_features = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP + self._attr_supported_features = ( + CoverEntityFeature.OPEN + | CoverEntityFeature.CLOSE + | CoverEntityFeature.STOP + ) @property def is_closed(self) -> bool | None: diff --git a/homeassistant/components/velux/cover.py b/homeassistant/components/velux/cover.py index ca529d4c572..f4f449509a0 100644 --- a/homeassistant/components/velux/cover.py +++ b/homeassistant/components/velux/cover.py @@ -7,16 +7,9 @@ from pyvlx.opening_device import Awning, Blind, GarageDoor, Gate, RollerShutter, 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.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -46,14 +39,17 @@ class VeluxCover(VeluxEntity, CoverEntity): def supported_features(self): """Flag supported features.""" supported_features = ( - SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION | SUPPORT_STOP + CoverEntityFeature.OPEN + | CoverEntityFeature.CLOSE + | CoverEntityFeature.SET_POSITION + | CoverEntityFeature.STOP ) if self.current_cover_tilt_position is not None: supported_features |= ( - SUPPORT_OPEN_TILT - | SUPPORT_CLOSE_TILT - | SUPPORT_SET_TILT_POSITION - | SUPPORT_STOP_TILT + CoverEntityFeature.OPEN_TILT + | CoverEntityFeature.CLOSE_TILT + | CoverEntityFeature.SET_TILT_POSITION + | CoverEntityFeature.STOP_TILT ) return supported_features diff --git a/homeassistant/components/venstar/climate.py b/homeassistant/components/venstar/climate.py index 441e46c38b8..41cf1347076 100644 --- a/homeassistant/components/venstar/climate.py +++ b/homeassistant/components/venstar/climate.py @@ -3,7 +3,11 @@ from __future__ import annotations 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_HVAC_MODE, ATTR_TARGET_TEMP_HIGH, @@ -20,11 +24,6 @@ from homeassistant.components.climate.const import ( HVAC_MODE_OFF, PRESET_AWAY, PRESET_NONE, - SUPPORT_FAN_MODE, - SUPPORT_PRESET_MODE, - SUPPORT_TARGET_HUMIDITY, - SUPPORT_TARGET_TEMPERATURE, - SUPPORT_TARGET_TEMPERATURE_RANGE, ) from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.const import ( @@ -134,13 +133,17 @@ class VenstarThermostat(VenstarEntity, ClimateEntity): @property def supported_features(self): """Return the list of supported features.""" - features = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_PRESET_MODE + features = ( + ClimateEntityFeature.TARGET_TEMPERATURE + | ClimateEntityFeature.FAN_MODE + | ClimateEntityFeature.PRESET_MODE + ) if self._client.mode == self._client.MODE_AUTO: - features |= SUPPORT_TARGET_TEMPERATURE_RANGE + features |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE if self._client.hum_setpoint is not None: - features |= SUPPORT_TARGET_HUMIDITY + features |= ClimateEntityFeature.TARGET_HUMIDITY return features diff --git a/homeassistant/components/vera/climate.py b/homeassistant/components/vera/climate.py index 399d4ace278..46784f62f8a 100644 --- a/homeassistant/components/vera/climate.py +++ b/homeassistant/components/vera/climate.py @@ -5,7 +5,11 @@ from typing import Any import pyvera as veraApi -from homeassistant.components.climate import ENTITY_ID_FORMAT, ClimateEntity +from homeassistant.components.climate import ( + ENTITY_ID_FORMAT, + ClimateEntity, + ClimateEntityFeature, +) from homeassistant.components.climate.const import ( FAN_AUTO, FAN_ON, @@ -13,8 +17,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 ( @@ -31,7 +33,6 @@ from .common import ControllerData, get_controller_data FAN_OPERATION_LIST = [FAN_ON, FAN_AUTO] -SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE SUPPORT_HVAC = [HVAC_MODE_COOL, HVAC_MODE_HEAT, HVAC_MODE_HEAT_COOL, HVAC_MODE_OFF] @@ -54,6 +55,10 @@ async def async_setup_entry( class VeraThermostat(VeraDevice[veraApi.VeraThermostat], ClimateEntity): """Representation of a Vera Thermostat.""" + _attr_supported_features = ( + ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE + ) + def __init__( self, vera_device: veraApi.VeraThermostat, controller_data: ControllerData ) -> None: @@ -61,11 +66,6 @@ class VeraThermostat(VeraDevice[veraApi.VeraThermostat], ClimateEntity): VeraDevice.__init__(self, vera_device, controller_data) self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id) - @property - def supported_features(self) -> int: - """Return the list of supported features.""" - return SUPPORT_FLAGS - @property def hvac_mode(self) -> str: """Return hvac operation ie. heat, cool mode. diff --git a/homeassistant/components/verisure/alarm_control_panel.py b/homeassistant/components/verisure/alarm_control_panel.py index 4cc5e8f6cb3..c521befde83 100644 --- a/homeassistant/components/verisure/alarm_control_panel.py +++ b/homeassistant/components/verisure/alarm_control_panel.py @@ -6,10 +6,7 @@ import asyncio from homeassistant.components.alarm_control_panel import ( FORMAT_NUMBER, AlarmControlPanelEntity, -) -from homeassistant.components.alarm_control_panel.const import ( - SUPPORT_ALARM_ARM_AWAY, - SUPPORT_ALARM_ARM_HOME, + AlarmControlPanelEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback @@ -37,7 +34,10 @@ class VerisureAlarm( _attr_code_format = FORMAT_NUMBER _attr_name = "Verisure Alarm" - _attr_supported_features = SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY + _attr_supported_features = ( + AlarmControlPanelEntityFeature.ARM_HOME + | AlarmControlPanelEntityFeature.ARM_AWAY + ) @property def device_info(self) -> DeviceInfo: diff --git a/homeassistant/components/vesync/fan.py b/homeassistant/components/vesync/fan.py index e2fec396770..41ed6109be2 100644 --- a/homeassistant/components/vesync/fan.py +++ b/homeassistant/components/vesync/fan.py @@ -2,7 +2,7 @@ import logging import math -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.dispatcher import async_dispatcher_connect @@ -83,16 +83,13 @@ def _setup_entities(devices, async_add_entities): class VeSyncFanHA(VeSyncDevice, FanEntity): """Representation of a VeSync fan.""" + _attr_supported_features = FanEntityFeature.SET_SPEED + def __init__(self, fan): """Initialize the VeSync fan device.""" super().__init__(fan) self.smartfan = fan - @property - def supported_features(self): - """Flag supported features.""" - return SUPPORT_SET_SPEED - @property def percentage(self): """Return the current speed.""" diff --git a/homeassistant/components/vicare/climate.py b/homeassistant/components/vicare/climate.py index 02998343744..479721cc164 100644 --- a/homeassistant/components/vicare/climate.py +++ b/homeassistant/components/vicare/climate.py @@ -10,7 +10,7 @@ from PyViCare.PyViCareUtils import ( import requests import voluptuous as vol -from homeassistant.components.climate import ClimateEntity +from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature from homeassistant.components.climate.const import ( CURRENT_HVAC_HEAT, CURRENT_HVAC_IDLE, @@ -20,8 +20,6 @@ from homeassistant.components.climate.const import ( PRESET_COMFORT, PRESET_ECO, PRESET_NONE, - SUPPORT_PRESET_MODE, - SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -72,8 +70,6 @@ VICARE_HOLD_MODE_OFF = "off" VICARE_TEMP_HEATING_MIN = 3 VICARE_TEMP_HEATING_MAX = 37 -SUPPORT_FLAGS_HEATING = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE - VICARE_TO_HA_HVAC_HEATING = { VICARE_MODE_DHW: HVAC_MODE_OFF, VICARE_MODE_HEATING: HVAC_MODE_HEAT, @@ -151,6 +147,10 @@ async def async_setup_entry( class ViCareClimate(ClimateEntity): """Representation of the ViCare heating climate device.""" + _attr_supported_features = ( + ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE + ) + def __init__(self, name, api, circuit, device_config, heating_type): """Initialize the climate device.""" self._name = name @@ -249,11 +249,6 @@ class ViCareClimate(ClimateEntity): except PyViCareInvalidDataError as invalid_data_exception: _LOGGER.error("Invalid data from Vicare server: %s", invalid_data_exception) - @property - def supported_features(self): - """Return the list of supported features.""" - return SUPPORT_FLAGS_HEATING - @property def name(self): """Return the name of the climate device.""" diff --git a/homeassistant/components/vicare/water_heater.py b/homeassistant/components/vicare/water_heater.py index e1e44188d28..6f9262200ec 100644 --- a/homeassistant/components/vicare/water_heater.py +++ b/homeassistant/components/vicare/water_heater.py @@ -10,8 +10,8 @@ from PyViCare.PyViCareUtils import ( import requests from homeassistant.components.water_heater import ( - SUPPORT_TARGET_TEMPERATURE, WaterHeaterEntity, + WaterHeaterEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -45,8 +45,6 @@ VICARE_TEMP_WATER_MAX = 60 OPERATION_MODE_ON = "on" OPERATION_MODE_OFF = "off" -SUPPORT_FLAGS_HEATER = SUPPORT_TARGET_TEMPERATURE - VICARE_TO_HA_HVAC_DHW = { VICARE_MODE_DHW: OPERATION_MODE_ON, VICARE_MODE_DHWANDHEATING: OPERATION_MODE_ON, @@ -101,6 +99,8 @@ async def async_setup_entry( class ViCareWater(WaterHeaterEntity): """Representation of the ViCare domestic hot water device.""" + _attr_supported_features = WaterHeaterEntityFeature.TARGET_TEMPERATURE + def __init__(self, name, api, circuit, device_config, heating_type): """Initialize the DHW water_heater device.""" self._name = name @@ -155,11 +155,6 @@ class ViCareWater(WaterHeaterEntity): "configuration_url": "https://developer.viessmann.com/", } - @property - def supported_features(self): - """Return the list of supported features.""" - return SUPPORT_FLAGS_HEATER - @property def name(self): """Return the name of the water_heater device.""" diff --git a/homeassistant/components/vivotek/camera.py b/homeassistant/components/vivotek/camera.py index c8b9f3676f1..c25e96f161e 100644 --- a/homeassistant/components/vivotek/camera.py +++ b/homeassistant/components/vivotek/camera.py @@ -4,7 +4,7 @@ from __future__ import annotations from libpyvivotek import VivotekCamera import voluptuous as vol -from homeassistant.components.camera import PLATFORM_SCHEMA, SUPPORT_STREAM, Camera +from homeassistant.components.camera import PLATFORM_SCHEMA, Camera, CameraEntityFeature from homeassistant.const import ( CONF_AUTHENTICATION, CONF_IP_ADDRESS, @@ -76,6 +76,8 @@ def setup_platform( class VivotekCam(Camera): """A Vivotek IP camera.""" + _attr_supported_features = CameraEntityFeature.STREAM + def __init__(self, config, cam, stream_source): """Initialize a Vivotek camera.""" super().__init__() @@ -87,11 +89,6 @@ class VivotekCam(Camera): self._name = config[CONF_NAME] self._stream_source = stream_source - @property - def supported_features(self): - """Return supported features for this camera.""" - return SUPPORT_STREAM - @property def frame_interval(self): """Return the interval between frames of the mjpeg stream.""" diff --git a/homeassistant/components/vizio/media_player.py b/homeassistant/components/vizio/media_player.py index a076a995f7b..b2d33551020 100644 --- a/homeassistant/components/vizio/media_player.py +++ b/homeassistant/components/vizio/media_player.py @@ -10,9 +10,9 @@ from pyvizio.api.apps import find_app_name from pyvizio.const import APP_HOME, INPUT_APPS, NO_APP_RUNNING, UNKNOWN_APP from homeassistant.components.media_player import ( - SUPPORT_SELECT_SOUND_MODE, MediaPlayerDeviceClass, MediaPlayerEntity, + MediaPlayerEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -229,7 +229,9 @@ class VizioDevice(MediaPlayerEntity): self._attr_is_volume_muted = None if VIZIO_SOUND_MODE in audio_settings: - self._attr_supported_features |= SUPPORT_SELECT_SOUND_MODE + self._attr_supported_features |= ( + MediaPlayerEntityFeature.SELECT_SOUND_MODE + ) self._attr_sound_mode = audio_settings[VIZIO_SOUND_MODE] if not self._attr_sound_mode_list: self._attr_sound_mode_list = await self._device.get_setting_options( @@ -238,8 +240,10 @@ class VizioDevice(MediaPlayerEntity): log_api_exception=False, ) else: - # Explicitly remove SUPPORT_SELECT_SOUND_MODE from supported features - self._attr_supported_features &= ~SUPPORT_SELECT_SOUND_MODE + # Explicitly remove MediaPlayerEntityFeature.SELECT_SOUND_MODE from supported features + self._attr_supported_features &= ( + ~MediaPlayerEntityFeature.SELECT_SOUND_MODE + ) if input_ := await self._device.get_current_input(log_api_exception=False): self._current_input = input_ diff --git a/homeassistant/components/vlc/media_player.py b/homeassistant/components/vlc/media_player.py index 77e2c17bedf..10903295f95 100644 --- a/homeassistant/components/vlc/media_player.py +++ b/homeassistant/components/vlc/media_player.py @@ -6,16 +6,12 @@ import logging import vlc import voluptuous as vol -from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity -from homeassistant.components.media_player.const import ( - MEDIA_TYPE_MUSIC, - SUPPORT_PAUSE, - SUPPORT_PLAY, - SUPPORT_PLAY_MEDIA, - SUPPORT_STOP, - SUPPORT_VOLUME_MUTE, - 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, STATE_IDLE, STATE_PAUSED, STATE_PLAYING from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -28,15 +24,6 @@ _LOGGER = logging.getLogger(__name__) CONF_ARGUMENTS = "arguments" DEFAULT_NAME = "Vlc" -SUPPORT_VLC = ( - SUPPORT_PAUSE - | SUPPORT_VOLUME_SET - | SUPPORT_VOLUME_MUTE - | SUPPORT_PLAY_MEDIA - | SUPPORT_PLAY - | SUPPORT_STOP -) - PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Optional(CONF_ARGUMENTS, default=""): cv.string, @@ -60,6 +47,15 @@ def setup_platform( class VlcDevice(MediaPlayerEntity): """Representation of a vlc player.""" + _attr_supported_features = ( + MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.VOLUME_SET + | MediaPlayerEntityFeature.VOLUME_MUTE + | MediaPlayerEntityFeature.PLAY_MEDIA + | MediaPlayerEntityFeature.PLAY + | MediaPlayerEntityFeature.STOP + ) + def __init__(self, name, arguments): """Initialize the vlc device.""" self._instance = vlc.Instance(arguments) @@ -112,11 +108,6 @@ class VlcDevice(MediaPlayerEntity): """Boolean if volume is currently muted.""" return self._muted - @property - def supported_features(self): - """Flag media player features that are supported.""" - return SUPPORT_VLC - @property def media_content_type(self): """Content type of current playing media.""" diff --git a/homeassistant/components/vlc_telnet/media_player.py b/homeassistant/components/vlc_telnet/media_player.py index 99b37f97e0c..9d4e0a5a7a8 100644 --- a/homeassistant/components/vlc_telnet/media_player.py +++ b/homeassistant/components/vlc_telnet/media_player.py @@ -14,23 +14,10 @@ from homeassistant.components import media_source from homeassistant.components.media_player import ( BrowseMedia, MediaPlayerEntity, + MediaPlayerEntityFeature, async_process_play_media_url, ) -from homeassistant.components.media_player.const import ( - MEDIA_TYPE_MUSIC, - 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_VOLUME_MUTE, - SUPPORT_VOLUME_SET, -) +from homeassistant.components.media_player.const import MEDIA_TYPE_MUSIC from homeassistant.config_entries import SOURCE_HASSIO, ConfigEntry from homeassistant.const import CONF_NAME, STATE_IDLE, STATE_PAUSED, STATE_PLAYING from homeassistant.core import HomeAssistant @@ -44,21 +31,6 @@ from .const import DATA_AVAILABLE, DATA_VLC, DEFAULT_NAME, DOMAIN, LOGGER MAX_VOLUME = 500 -SUPPORT_VLC = ( - SUPPORT_CLEAR_PLAYLIST - | SUPPORT_NEXT_TRACK - | SUPPORT_PAUSE - | SUPPORT_PLAY - | SUPPORT_PLAY_MEDIA - | SUPPORT_PREVIOUS_TRACK - | SUPPORT_SEEK - | SUPPORT_SHUFFLE_SET - | SUPPORT_STOP - | SUPPORT_VOLUME_MUTE - | SUPPORT_VOLUME_SET - | SUPPORT_BROWSE_MEDIA -) - _T = TypeVar("_T", bound="VlcDevice") _P = ParamSpec("_P") @@ -99,6 +71,21 @@ def catch_vlc_errors( class VlcDevice(MediaPlayerEntity): """Representation of a vlc player.""" + _attr_supported_features = ( + MediaPlayerEntityFeature.CLEAR_PLAYLIST + | MediaPlayerEntityFeature.NEXT_TRACK + | MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.PLAY + | MediaPlayerEntityFeature.PLAY_MEDIA + | MediaPlayerEntityFeature.PREVIOUS_TRACK + | MediaPlayerEntityFeature.SEEK + | MediaPlayerEntityFeature.SHUFFLE_SET + | MediaPlayerEntityFeature.STOP + | MediaPlayerEntityFeature.VOLUME_MUTE + | MediaPlayerEntityFeature.VOLUME_SET + | MediaPlayerEntityFeature.BROWSE_MEDIA + ) + def __init__( self, config_entry: ConfigEntry, vlc: Client, name: str, available: bool ) -> None: @@ -214,11 +201,6 @@ class VlcDevice(MediaPlayerEntity): """Boolean if volume is currently muted.""" return self._muted - @property - def supported_features(self) -> int: - """Flag media player features that are supported.""" - return SUPPORT_VLC - @property def media_content_type(self) -> str: """Content type of current playing media.""" diff --git a/homeassistant/components/volumio/media_player.py b/homeassistant/components/volumio/media_player.py index 75a84b4f94a..ec4931ce3bc 100644 --- a/homeassistant/components/volumio/media_player.py +++ b/homeassistant/components/volumio/media_player.py @@ -6,26 +6,14 @@ Volumio rest API: https://volumio.github.io/docs/API/REST_API.html from datetime import timedelta import json -from homeassistant.components.media_player import MediaPlayerEntity +from homeassistant.components.media_player import ( + MediaPlayerEntity, + MediaPlayerEntityFeature, +) from homeassistant.components.media_player.const import ( MEDIA_TYPE_MUSIC, REPEAT_MODE_ALL, REPEAT_MODE_OFF, - SUPPORT_BROWSE_MEDIA, - SUPPORT_CLEAR_PLAYLIST, - 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, - SUPPORT_VOLUME_STEP, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -43,24 +31,6 @@ from homeassistant.util import Throttle from .browse_media import browse_node, browse_top_level from .const import DATA_INFO, DATA_VOLUMIO, DOMAIN -SUPPORT_VOLUMIO = ( - SUPPORT_PAUSE - | SUPPORT_VOLUME_SET - | SUPPORT_VOLUME_MUTE - | SUPPORT_PREVIOUS_TRACK - | SUPPORT_NEXT_TRACK - | SUPPORT_SEEK - | SUPPORT_STOP - | SUPPORT_PLAY - | SUPPORT_PLAY_MEDIA - | SUPPORT_VOLUME_STEP - | SUPPORT_SELECT_SOURCE - | SUPPORT_REPEAT_SET - | SUPPORT_SHUFFLE_SET - | SUPPORT_CLEAR_PLAYLIST - | SUPPORT_BROWSE_MEDIA -) - PLAYLIST_UPDATE_INTERVAL = timedelta(seconds=15) @@ -84,6 +54,24 @@ async def async_setup_entry( class Volumio(MediaPlayerEntity): """Volumio Player Object.""" + _attr_supported_features = ( + MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.VOLUME_SET + | MediaPlayerEntityFeature.VOLUME_MUTE + | MediaPlayerEntityFeature.PREVIOUS_TRACK + | MediaPlayerEntityFeature.NEXT_TRACK + | MediaPlayerEntityFeature.SEEK + | MediaPlayerEntityFeature.STOP + | MediaPlayerEntityFeature.PLAY + | MediaPlayerEntityFeature.PLAY_MEDIA + | MediaPlayerEntityFeature.VOLUME_STEP + | MediaPlayerEntityFeature.SELECT_SOURCE + | MediaPlayerEntityFeature.REPEAT_SET + | MediaPlayerEntityFeature.SHUFFLE_SET + | MediaPlayerEntityFeature.CLEAR_PLAYLIST + | MediaPlayerEntityFeature.BROWSE_MEDIA + ) + def __init__(self, volumio, uid, name, info): """Initialize the media player.""" self._volumio = volumio @@ -203,11 +191,6 @@ class Volumio(MediaPlayerEntity): """Name of the current input source.""" return self._currentplaylist - @property - def supported_features(self): - """Flag of media commands that are supported.""" - return SUPPORT_VOLUMIO - async def async_media_next_track(self): """Send media_next command to media player.""" await self._volumio.next()