Use EntityFeature enum in components (u**) (#69462)
This commit is contained in:
parent
95fb4695e4
commit
75eec850c1
6 changed files with 66 additions and 98 deletions
|
@ -6,19 +6,12 @@ import logging
|
|||
import requests
|
||||
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_STOP,
|
||||
SUPPORT_TURN_OFF,
|
||||
SUPPORT_TURN_ON,
|
||||
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_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
|
@ -37,18 +30,6 @@ _LOGGER = logging.getLogger(__name__)
|
|||
ICON = "mdi:radio"
|
||||
URL = "http://decibel.logitechmusic.com/jsonrpc.js"
|
||||
|
||||
SUPPORT_UE_SMART_RADIO = (
|
||||
SUPPORT_PLAY
|
||||
| SUPPORT_PAUSE
|
||||
| SUPPORT_STOP
|
||||
| SUPPORT_PREVIOUS_TRACK
|
||||
| SUPPORT_NEXT_TRACK
|
||||
| SUPPORT_TURN_ON
|
||||
| SUPPORT_TURN_OFF
|
||||
| SUPPORT_VOLUME_SET
|
||||
| SUPPORT_VOLUME_MUTE
|
||||
)
|
||||
|
||||
PLAYBACK_DICT = {"play": STATE_PLAYING, "pause": STATE_PAUSED, "stop": STATE_IDLE}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
@ -103,6 +84,18 @@ def setup_platform(
|
|||
class UERadioDevice(MediaPlayerEntity):
|
||||
"""Representation of a Logitech UE Smart Radio device."""
|
||||
|
||||
_attr_supported_features = (
|
||||
MediaPlayerEntityFeature.PLAY
|
||||
| MediaPlayerEntityFeature.PAUSE
|
||||
| MediaPlayerEntityFeature.STOP
|
||||
| MediaPlayerEntityFeature.PREVIOUS_TRACK
|
||||
| MediaPlayerEntityFeature.NEXT_TRACK
|
||||
| MediaPlayerEntityFeature.TURN_ON
|
||||
| MediaPlayerEntityFeature.TURN_OFF
|
||||
| MediaPlayerEntityFeature.VOLUME_SET
|
||||
| MediaPlayerEntityFeature.VOLUME_MUTE
|
||||
)
|
||||
|
||||
def __init__(self, session, player_id, player_name):
|
||||
"""Initialize the Logitech UE Smart Radio device."""
|
||||
self._session = session
|
||||
|
@ -179,11 +172,6 @@ class UERadioDevice(MediaPlayerEntity):
|
|||
"""Volume level of the media player (0..1)."""
|
||||
return self._volume
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Flag of features that are supported."""
|
||||
return SUPPORT_UE_SMART_RADIO
|
||||
|
||||
@property
|
||||
def media_content_type(self):
|
||||
"""Return the media content type."""
|
||||
|
|
|
@ -8,7 +8,7 @@ from pyunifiprotect.api import ProtectApiClient
|
|||
from pyunifiprotect.data import Camera as UFPCamera, StateType
|
||||
from pyunifiprotect.data.devices import CameraChannel
|
||||
|
||||
from homeassistant.components.camera import SUPPORT_STREAM, Camera
|
||||
from homeassistant.components.camera import Camera, CameraEntityFeature
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -134,7 +134,7 @@ class ProtectCamera(ProtectDeviceEntity, Camera):
|
|||
None if disable_stream else rtsp_url
|
||||
)
|
||||
self._attr_supported_features: int = (
|
||||
SUPPORT_STREAM if self._stream_source else 0
|
||||
CameraEntityFeature.STREAM if self._stream_source else 0
|
||||
)
|
||||
|
||||
@callback
|
||||
|
|
|
@ -13,18 +13,12 @@ from homeassistant.components.media_player import (
|
|||
MediaPlayerDeviceClass,
|
||||
MediaPlayerEntity,
|
||||
MediaPlayerEntityDescription,
|
||||
MediaPlayerEntityFeature,
|
||||
)
|
||||
from homeassistant.components.media_player.browse_media import (
|
||||
async_process_play_media_url,
|
||||
)
|
||||
from homeassistant.components.media_player.const import (
|
||||
MEDIA_TYPE_MUSIC,
|
||||
SUPPORT_BROWSE_MEDIA,
|
||||
SUPPORT_PLAY_MEDIA,
|
||||
SUPPORT_STOP,
|
||||
SUPPORT_VOLUME_SET,
|
||||
SUPPORT_VOLUME_STEP,
|
||||
)
|
||||
from homeassistant.components.media_player.const import MEDIA_TYPE_MUSIC
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import STATE_IDLE, STATE_PLAYING
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
@ -63,6 +57,13 @@ class ProtectMediaPlayer(ProtectDeviceEntity, MediaPlayerEntity):
|
|||
|
||||
device: Camera
|
||||
entity_description: MediaPlayerEntityDescription
|
||||
_attr_supported_features = (
|
||||
MediaPlayerEntityFeature.PLAY_MEDIA
|
||||
| MediaPlayerEntityFeature.VOLUME_SET
|
||||
| MediaPlayerEntityFeature.VOLUME_STEP
|
||||
| MediaPlayerEntityFeature.STOP
|
||||
| MediaPlayerEntityFeature.BROWSE_MEDIA
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -79,13 +80,6 @@ class ProtectMediaPlayer(ProtectDeviceEntity, MediaPlayerEntity):
|
|||
)
|
||||
|
||||
self._attr_name = f"{self.device.name} Speaker"
|
||||
self._attr_supported_features = (
|
||||
SUPPORT_PLAY_MEDIA
|
||||
| SUPPORT_VOLUME_SET
|
||||
| SUPPORT_VOLUME_STEP
|
||||
| SUPPORT_STOP
|
||||
| SUPPORT_BROWSE_MEDIA
|
||||
)
|
||||
self._attr_media_content_type = MEDIA_TYPE_MUSIC
|
||||
|
||||
@callback
|
||||
|
|
|
@ -9,6 +9,7 @@ from homeassistant.components.media_player import (
|
|||
DEVICE_CLASSES_SCHEMA,
|
||||
PLATFORM_SCHEMA,
|
||||
MediaPlayerEntity,
|
||||
MediaPlayerEntityFeature,
|
||||
)
|
||||
from homeassistant.components.media_player.const import (
|
||||
ATTR_APP_ID,
|
||||
|
@ -42,22 +43,6 @@ from homeassistant.components.media_player.const import (
|
|||
SERVICE_PLAY_MEDIA,
|
||||
SERVICE_SELECT_SOUND_MODE,
|
||||
SERVICE_SELECT_SOURCE,
|
||||
SUPPORT_CLEAR_PLAYLIST,
|
||||
SUPPORT_NEXT_TRACK,
|
||||
SUPPORT_PAUSE,
|
||||
SUPPORT_PLAY,
|
||||
SUPPORT_PLAY_MEDIA,
|
||||
SUPPORT_PREVIOUS_TRACK,
|
||||
SUPPORT_REPEAT_SET,
|
||||
SUPPORT_SELECT_SOUND_MODE,
|
||||
SUPPORT_SELECT_SOURCE,
|
||||
SUPPORT_SHUFFLE_SET,
|
||||
SUPPORT_STOP,
|
||||
SUPPORT_TURN_OFF,
|
||||
SUPPORT_TURN_ON,
|
||||
SUPPORT_VOLUME_MUTE,
|
||||
SUPPORT_VOLUME_SET,
|
||||
SUPPORT_VOLUME_STEP,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
|
@ -457,57 +442,57 @@ class UniversalMediaPlayer(MediaPlayerEntity):
|
|||
flags = self._child_attr(ATTR_SUPPORTED_FEATURES) or 0
|
||||
|
||||
if SERVICE_TURN_ON in self._cmds:
|
||||
flags |= SUPPORT_TURN_ON
|
||||
flags |= MediaPlayerEntityFeature.TURN_ON
|
||||
if SERVICE_TURN_OFF in self._cmds:
|
||||
flags |= SUPPORT_TURN_OFF
|
||||
flags |= MediaPlayerEntityFeature.TURN_OFF
|
||||
|
||||
if SERVICE_MEDIA_PLAY_PAUSE in self._cmds:
|
||||
flags |= SUPPORT_PLAY | SUPPORT_PAUSE
|
||||
flags |= MediaPlayerEntityFeature.PLAY | MediaPlayerEntityFeature.PAUSE
|
||||
else:
|
||||
if SERVICE_MEDIA_PLAY in self._cmds:
|
||||
flags |= SUPPORT_PLAY
|
||||
flags |= MediaPlayerEntityFeature.PLAY
|
||||
if SERVICE_MEDIA_PAUSE in self._cmds:
|
||||
flags |= SUPPORT_PAUSE
|
||||
flags |= MediaPlayerEntityFeature.PAUSE
|
||||
|
||||
if SERVICE_MEDIA_STOP in self._cmds:
|
||||
flags |= SUPPORT_STOP
|
||||
flags |= MediaPlayerEntityFeature.STOP
|
||||
|
||||
if SERVICE_MEDIA_NEXT_TRACK in self._cmds:
|
||||
flags |= SUPPORT_NEXT_TRACK
|
||||
flags |= MediaPlayerEntityFeature.NEXT_TRACK
|
||||
if SERVICE_MEDIA_PREVIOUS_TRACK in self._cmds:
|
||||
flags |= SUPPORT_PREVIOUS_TRACK
|
||||
flags |= MediaPlayerEntityFeature.PREVIOUS_TRACK
|
||||
|
||||
if any(cmd in self._cmds for cmd in (SERVICE_VOLUME_UP, SERVICE_VOLUME_DOWN)):
|
||||
flags |= SUPPORT_VOLUME_STEP
|
||||
flags |= MediaPlayerEntityFeature.VOLUME_STEP
|
||||
if SERVICE_VOLUME_SET in self._cmds:
|
||||
flags |= SUPPORT_VOLUME_SET
|
||||
flags |= MediaPlayerEntityFeature.VOLUME_SET
|
||||
|
||||
if SERVICE_VOLUME_MUTE in self._cmds and ATTR_MEDIA_VOLUME_MUTED in self._attrs:
|
||||
flags |= SUPPORT_VOLUME_MUTE
|
||||
flags |= MediaPlayerEntityFeature.VOLUME_MUTE
|
||||
|
||||
if (
|
||||
SERVICE_SELECT_SOURCE in self._cmds
|
||||
and ATTR_INPUT_SOURCE_LIST in self._attrs
|
||||
):
|
||||
flags |= SUPPORT_SELECT_SOURCE
|
||||
flags |= MediaPlayerEntityFeature.SELECT_SOURCE
|
||||
|
||||
if SERVICE_PLAY_MEDIA in self._cmds:
|
||||
flags |= SUPPORT_PLAY_MEDIA
|
||||
flags |= MediaPlayerEntityFeature.PLAY_MEDIA
|
||||
|
||||
if SERVICE_CLEAR_PLAYLIST in self._cmds:
|
||||
flags |= SUPPORT_CLEAR_PLAYLIST
|
||||
flags |= MediaPlayerEntityFeature.CLEAR_PLAYLIST
|
||||
|
||||
if SERVICE_SHUFFLE_SET in self._cmds and ATTR_MEDIA_SHUFFLE in self._attrs:
|
||||
flags |= SUPPORT_SHUFFLE_SET
|
||||
flags |= MediaPlayerEntityFeature.SHUFFLE_SET
|
||||
|
||||
if SERVICE_REPEAT_SET in self._cmds and ATTR_MEDIA_REPEAT in self._attrs:
|
||||
flags |= SUPPORT_REPEAT_SET
|
||||
flags |= MediaPlayerEntityFeature.REPEAT_SET
|
||||
|
||||
if (
|
||||
SERVICE_SELECT_SOUND_MODE in self._cmds
|
||||
and ATTR_SOUND_MODE_LIST in self._attrs
|
||||
):
|
||||
flags |= SUPPORT_SELECT_SOUND_MODE
|
||||
flags |= MediaPlayerEntityFeature.SELECT_SOUND_MODE
|
||||
|
||||
return flags
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import requests
|
|||
from uvcclient import camera as uvc_camera, nvr
|
||||
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_PASSWORD, CONF_PORT, CONF_SSL
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
|
@ -115,7 +115,7 @@ class UnifiVideoCamera(Camera):
|
|||
channels = self._caminfo["channels"]
|
||||
for channel in channels:
|
||||
if channel["isRtspEnabled"]:
|
||||
return SUPPORT_STREAM
|
||||
return CameraEntityFeature.STREAM
|
||||
|
||||
return 0
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ from homeassistant import config as hass_config
|
|||
import homeassistant.components.input_number as input_number
|
||||
import homeassistant.components.input_select as input_select
|
||||
import homeassistant.components.media_player as media_player
|
||||
from homeassistant.components.media_player.const import MediaPlayerEntityFeature
|
||||
import homeassistant.components.switch as switch
|
||||
import homeassistant.components.universal.media_player as universal
|
||||
from homeassistant.const import (
|
||||
|
@ -696,22 +697,22 @@ async def test_supported_features_children_and_cmds(
|
|||
await ump.async_update()
|
||||
|
||||
check_flags = (
|
||||
universal.SUPPORT_TURN_ON
|
||||
| universal.SUPPORT_TURN_OFF
|
||||
| universal.SUPPORT_VOLUME_STEP
|
||||
| universal.SUPPORT_VOLUME_MUTE
|
||||
| universal.SUPPORT_SELECT_SOUND_MODE
|
||||
| universal.SUPPORT_SELECT_SOURCE
|
||||
| universal.SUPPORT_REPEAT_SET
|
||||
| universal.SUPPORT_SHUFFLE_SET
|
||||
| universal.SUPPORT_VOLUME_SET
|
||||
| universal.SUPPORT_PLAY
|
||||
| universal.SUPPORT_PAUSE
|
||||
| universal.SUPPORT_STOP
|
||||
| universal.SUPPORT_NEXT_TRACK
|
||||
| universal.SUPPORT_PREVIOUS_TRACK
|
||||
| universal.SUPPORT_PLAY_MEDIA
|
||||
| universal.SUPPORT_CLEAR_PLAYLIST
|
||||
MediaPlayerEntityFeature.TURN_ON
|
||||
| MediaPlayerEntityFeature.TURN_OFF
|
||||
| MediaPlayerEntityFeature.VOLUME_STEP
|
||||
| MediaPlayerEntityFeature.VOLUME_MUTE
|
||||
| MediaPlayerEntityFeature.SELECT_SOUND_MODE
|
||||
| MediaPlayerEntityFeature.SELECT_SOURCE
|
||||
| MediaPlayerEntityFeature.REPEAT_SET
|
||||
| MediaPlayerEntityFeature.SHUFFLE_SET
|
||||
| MediaPlayerEntityFeature.VOLUME_SET
|
||||
| MediaPlayerEntityFeature.PLAY
|
||||
| MediaPlayerEntityFeature.PAUSE
|
||||
| MediaPlayerEntityFeature.STOP
|
||||
| MediaPlayerEntityFeature.NEXT_TRACK
|
||||
| MediaPlayerEntityFeature.PREVIOUS_TRACK
|
||||
| MediaPlayerEntityFeature.PLAY_MEDIA
|
||||
| MediaPlayerEntityFeature.CLEAR_PLAYLIST
|
||||
)
|
||||
|
||||
assert check_flags == ump.supported_features
|
||||
|
@ -910,7 +911,7 @@ async def test_supported_features_play_pause(
|
|||
await hass.async_block_till_done()
|
||||
await ump.async_update()
|
||||
|
||||
check_flags = universal.SUPPORT_PLAY | universal.SUPPORT_PAUSE
|
||||
check_flags = MediaPlayerEntityFeature.PLAY | MediaPlayerEntityFeature.PAUSE
|
||||
|
||||
assert check_flags == ump.supported_features
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue