Skip to content

Commit

Permalink
Adjust type hints for MediaPlayerEntityFeature (#82258)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed Nov 17, 2022
1 parent 569e52c commit 18e30e7
Show file tree
Hide file tree
Showing 26 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/bluesound/media_player.py
Expand Up @@ -775,7 +775,7 @@ def source(self):
return None

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature | int:
"""Flag of media commands that are supported."""
if self._status is None:
return 0
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/cast/media_player.py
Expand Up @@ -899,7 +899,7 @@ def app_name(self):
return self._chromecast.app_display_name if self._chromecast else None

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature:
"""Flag media player features that are supported."""
support = (
MediaPlayerEntityFeature.PLAY_MEDIA
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/denon/media_player.py
Expand Up @@ -245,7 +245,7 @@ def media_title(self):
return self._mediainfo

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature:
"""Flag media player features that are supported."""
if self._mediasource in MEDIA_MODES.values():
return SUPPORT_DENON | SUPPORT_MEDIA_MODES
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/denonavr/media_player.py
Expand Up @@ -277,7 +277,7 @@ def sound_mode(self):
return self._receiver.sound_mode

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature:
"""Flag media player features that are supported."""
if self._receiver.input_func in self._receiver.netaudio_func_list:
return self._supported_features_base | SUPPORT_MEDIA_MODES
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/directv/media_player.py
Expand Up @@ -237,7 +237,7 @@ def source(self):
return self._program.channel

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature:
"""Flag media player features that are supported."""
return SUPPORT_DTV_CLIENT if self._is_client else SUPPORT_DTV

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/dlna_dmr/media_player.py
Expand Up @@ -478,7 +478,7 @@ def state(self) -> MediaPlayerState | None:
return MediaPlayerState.IDLE

@property
def supported_features(self) -> int:
def supported_features(self) -> MediaPlayerEntityFeature | int:
"""Flag media player features that are supported at this moment.
Supported features may change as the device enters different states.
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/dunehd/media_player.py
Expand Up @@ -19,7 +19,7 @@

CONF_SOURCES: Final = "sources"

DUNEHD_PLAYER_SUPPORT: Final[int] = (
DUNEHD_PLAYER_SUPPORT: Final[MediaPlayerEntityFeature] = (
MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.TURN_OFF
Expand Down Expand Up @@ -105,7 +105,7 @@ def is_volume_muted(self) -> bool:
return int(self._state.get("playback_mute", 0)) == 1

@property
def supported_features(self) -> int:
def supported_features(self) -> MediaPlayerEntityFeature:
"""Flag media player features that are supported."""
return DUNEHD_PLAYER_SUPPORT

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/emby/media_player.py
Expand Up @@ -284,7 +284,7 @@ def media_album_artist(self):
return self.device.media_album_artist

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature | int:
"""Flag media player features that are supported."""
if self.supports_remote_control:
return SUPPORT_EMBY
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/esphome/media_player.py
Expand Up @@ -83,7 +83,7 @@ def volume_level(self) -> float | None:
return self._state.volume

@property
def supported_features(self) -> int:
def supported_features(self) -> MediaPlayerEntityFeature:
"""Flag supported features."""
flags = (
MediaPlayerEntityFeature.PLAY_MEDIA
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/forked_daapd/media_player.py
Expand Up @@ -17,6 +17,7 @@
BrowseMedia,
MediaPlayerEnqueue,
MediaPlayerEntity,
MediaPlayerEntityFeature,
MediaPlayerState,
MediaType,
async_process_play_media_url,
Expand Down Expand Up @@ -236,7 +237,7 @@ async def async_set_volume_level(self, volume: float) -> None:
await self._api.set_volume(volume=volume * 100, output_id=self._output_id)

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature:
"""Flag media player features that are supported."""
return SUPPORTED_FEATURES_ZONE

Expand Down Expand Up @@ -558,7 +559,7 @@ def shuffle(self):
return self._player["shuffle"]

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature:
"""Flag media player features that are supported."""
return SUPPORTED_FEATURES

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hdmi_cec/media_player.py
Expand Up @@ -163,7 +163,7 @@ def update(self) -> None:
_LOGGER.warning("Unknown state: %s", device.status)

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature:
"""Flag media player features that are supported."""
if self.type_id == TYPE_RECORDER or self.type == TYPE_PLAYBACK:
return (
Expand Down
Expand Up @@ -80,7 +80,7 @@ def get_characteristic_types(self) -> list[str]:
]

@property
def supported_features(self) -> int:
def supported_features(self) -> MediaPlayerEntityFeature | int:
"""Flag media player features that are supported."""
features = 0

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/jellyfin/media_player.py
Expand Up @@ -198,7 +198,7 @@ def media_image_url(self) -> str | None:
return get_artwork_url(self.coordinator.api_client, self.now_playing, 150)

@property
def supported_features(self) -> int:
def supported_features(self) -> MediaPlayerEntityFeature | int:
"""Flag media player features that are supported."""
commands: list[str] = self.capabilities.get("SupportedCommands", [])
controllable = self.capabilities.get("SupportsMediaControl", False)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/lg_netcast/media_player.py
Expand Up @@ -197,7 +197,7 @@ def media_title(self):
return self._program_name

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature:
"""Flag media player features that are supported."""
if self._on_action_script:
return SUPPORT_LGTV | MediaPlayerEntityFeature.TURN_ON
Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/lookin/media_player.py
Expand Up @@ -82,7 +82,6 @@ def __init__(
) -> None:
"""Init the lookin media player."""
self._attr_device_class = device_class
self._attr_supported_features: int = 0
super().__init__(coordinator, uuid, device, lookin_data)
for function_name, feature in _FUNCTION_NAME_TO_FEATURE.items():
if function_name in self._function_names:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/media_player/__init__.py
Expand Up @@ -492,7 +492,7 @@ class MediaPlayerEntity(Entity):
_attr_source_list: list[str] | None = None
_attr_source: str | None = None
_attr_state: MediaPlayerState | str | None = None
_attr_supported_features: int = 0
_attr_supported_features: MediaPlayerEntityFeature | int = 0
_attr_volume_level: float | None = None

# Implement these for your media player
Expand Down Expand Up @@ -692,7 +692,7 @@ def group_members(self) -> list[str] | None:
return self._attr_group_members

@property
def supported_features(self) -> int:
def supported_features(self) -> MediaPlayerEntityFeature | int:
"""Flag media player features that are supported."""
return self._attr_supported_features

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/mpd/media_player.py
Expand Up @@ -338,7 +338,7 @@ def volume_level(self):
return None

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature | int:
"""Flag media player features that are supported."""
if self._status is None:
return 0
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/onkyo/media_player.py
Expand Up @@ -553,7 +553,7 @@ def update(self) -> None:
)

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature:
"""Return media player features that are supported."""
if self._supports_volume:
return SUPPORT_ONKYO
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/philips_js/media_player.py
Expand Up @@ -104,7 +104,7 @@ async def _async_update_soon(self):
await self.coordinator.async_request_refresh()

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature:
"""Flag media player features that are supported."""
supports = self._supports
if self.coordinator.turn_on or (
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/plex/media_player.py
Expand Up @@ -389,7 +389,7 @@ def media_episode(self):
return self.session.media_episode

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature:
"""Flag media player features that are supported."""
if self.device and "playback" in self._device_protocol_capabilities:
return (
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/universal/media_player.py
Expand Up @@ -453,9 +453,11 @@ def shuffle(self):
return self._override_or_child_attr(ATTR_MEDIA_SHUFFLE)

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature | int:
"""Flag media player features that are supported."""
flags = self._child_attr(ATTR_SUPPORTED_FEATURES) or 0
flags: MediaPlayerEntityFeature | int = (
self._child_attr(ATTR_SUPPORTED_FEATURES) or 0
)

if SERVICE_TURN_ON in self._cmds:
flags |= MediaPlayerEntityFeature.TURN_ON
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/webostv/media_player.py
Expand Up @@ -137,7 +137,7 @@ def __init__(
self._current_source = None
self._source_list: dict = {}

self._supported_features: int = 0
self._supported_features: MediaPlayerEntityFeature | int = 0
self._update_states()

async def async_added_to_hass(self) -> None:
Expand Down Expand Up @@ -314,7 +314,7 @@ async def async_update(self) -> None:
await self._client.connect()

@property
def supported_features(self) -> int:
def supported_features(self) -> MediaPlayerEntityFeature | int:
"""Flag media player features that are supported."""
if self._wrapper.turn_on:
return self._supported_features | MediaPlayerEntityFeature.TURN_ON
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/xbox/media_player.py
Expand Up @@ -107,7 +107,7 @@ def state(self):
return XBOX_STATE_MAP[status.power_state]

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature:
"""Flag media player features that are supported."""
if self.state not in [MediaPlayerState.PLAYING, MediaPlayerState.PAUSED]:
return (
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/yamaha/media_player.py
Expand Up @@ -311,7 +311,7 @@ def zone_id(self):
return f"{self.receiver.ctrl_url}:{self._zone}"

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature:
"""Flag media player features that are supported."""
supported_features = SUPPORT_YAMAHA

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/yamaha_musiccast/media_player.py
Expand Up @@ -424,7 +424,7 @@ def repeat(self):
)

@property
def supported_features(self):
def supported_features(self) -> MediaPlayerEntityFeature:
"""Flag media player features that are supported."""
supported_features = MUSIC_PLAYER_BASE_SUPPORT
zone = self.coordinator.data.zones[self._zone_id]
Expand Down
4 changes: 4 additions & 0 deletions pylint/plugins/hass_enforce_type_hints.py
Expand Up @@ -1788,6 +1788,10 @@ class ClassTypeHintMatch:
function_name="group_members",
return_type=["list[str]", None],
),
TypeHintMatch(
function_name="supported_features",
return_type=["MediaPlayerEntityFeature", "int"],
),
TypeHintMatch(
function_name="turn_on",
return_type=None,
Expand Down

0 comments on commit 18e30e7

Please sign in to comment.