mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Improve media-player typing (#78300)
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
This commit is contained in:
parent
55e59b778c
commit
9cb8d910ce
@ -135,8 +135,6 @@ from .const import ( # noqa: F401
|
|||||||
)
|
)
|
||||||
from .errors import BrowseError
|
from .errors import BrowseError
|
||||||
|
|
||||||
# mypy: allow-untyped-defs, no-check-untyped-defs
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||||
@ -221,7 +219,7 @@ ATTR_TO_PROPERTY = [
|
|||||||
|
|
||||||
|
|
||||||
@bind_hass
|
@bind_hass
|
||||||
def is_on(hass, entity_id=None):
|
def is_on(hass: HomeAssistant, entity_id: str | None = None) -> bool:
|
||||||
"""
|
"""
|
||||||
Return true if specified media player entity_id is on.
|
Return true if specified media player entity_id is on.
|
||||||
|
|
||||||
@ -372,7 +370,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Remove in Home Assistant 2022.9
|
# Remove in Home Assistant 2022.9
|
||||||
def _rewrite_enqueue(value):
|
def _rewrite_enqueue(value: dict[str, Any]) -> dict[str, Any]:
|
||||||
"""Rewrite the enqueue value."""
|
"""Rewrite the enqueue value."""
|
||||||
if ATTR_MEDIA_ENQUEUE not in value:
|
if ATTR_MEDIA_ENQUEUE not in value:
|
||||||
pass
|
pass
|
||||||
@ -1186,7 +1184,11 @@ class MediaPlayerImageView(HomeAssistantView):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
@websocket_api.async_response
|
@websocket_api.async_response
|
||||||
async def websocket_browse_media(hass, connection, msg):
|
async def websocket_browse_media(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
connection: websocket_api.connection.ActiveConnection,
|
||||||
|
msg: dict[str, Any],
|
||||||
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Browse media available to the media_player entity.
|
Browse media available to the media_player entity.
|
||||||
|
|
||||||
@ -1213,6 +1215,7 @@ async def websocket_browse_media(hass, connection, msg):
|
|||||||
try:
|
try:
|
||||||
payload = await player.async_browse_media(media_content_type, media_content_id)
|
payload = await player.async_browse_media(media_content_type, media_content_id)
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
|
assert player.platform
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"%s allows media browsing but its integration (%s) does not",
|
"%s allows media browsing but its integration (%s) does not",
|
||||||
player.entity_id,
|
player.entity_id,
|
||||||
@ -1234,11 +1237,12 @@ async def websocket_browse_media(hass, connection, msg):
|
|||||||
|
|
||||||
# For backwards compat
|
# For backwards compat
|
||||||
if isinstance(payload, BrowseMedia):
|
if isinstance(payload, BrowseMedia):
|
||||||
payload = payload.as_dict()
|
result = payload.as_dict()
|
||||||
else:
|
else:
|
||||||
|
result = payload # type: ignore[unreachable]
|
||||||
_LOGGER.warning("Browse Media should use new BrowseMedia class")
|
_LOGGER.warning("Browse Media should use new BrowseMedia class")
|
||||||
|
|
||||||
connection.send_result(msg["id"], payload)
|
connection.send_result(msg["id"], result)
|
||||||
|
|
||||||
|
|
||||||
async def async_fetch_image(
|
async def async_fetch_image(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user