mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Replace old source prefixing for channels with new media browser (#39596)
* Replace old source prefixing for channels with new media browser * Restore support to call select source with prefix * Drop warning log for deprecated call method
This commit is contained in:
parent
4885b22cb4
commit
1cb60dd5c7
@ -8,6 +8,7 @@ import voluptuous as vol
|
||||
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity
|
||||
from homeassistant.components.media_player.const import (
|
||||
MEDIA_TYPE_CHANNEL,
|
||||
SUPPORT_BROWSE_MEDIA,
|
||||
SUPPORT_NEXT_TRACK,
|
||||
SUPPORT_PLAY_MEDIA,
|
||||
SUPPORT_PREVIOUS_TRACK,
|
||||
@ -18,6 +19,7 @@ from homeassistant.components.media_player.const import (
|
||||
SUPPORT_VOLUME_SET,
|
||||
SUPPORT_VOLUME_STEP,
|
||||
)
|
||||
from homeassistant.components.media_player.errors import BrowseError
|
||||
from homeassistant.const import (
|
||||
CONF_API_VERSION,
|
||||
CONF_HOST,
|
||||
@ -40,6 +42,7 @@ SUPPORT_PHILIPS_JS = (
|
||||
| SUPPORT_NEXT_TRACK
|
||||
| SUPPORT_PREVIOUS_TRACK
|
||||
| SUPPORT_PLAY_MEDIA
|
||||
| SUPPORT_BROWSE_MEDIA
|
||||
)
|
||||
|
||||
CONF_ON_ACTION = "turn_on_action"
|
||||
@ -146,38 +149,28 @@ class PhilipsTVMediaPlayer(MediaPlayerEntity):
|
||||
@property
|
||||
def source(self):
|
||||
"""Return the current input source."""
|
||||
if self.media_content_type == MEDIA_TYPE_CHANNEL:
|
||||
name = self._channels.get(self._tv.channel_id)
|
||||
prefix = PREFIX_CHANNEL
|
||||
else:
|
||||
name = self._sources.get(self._tv.source_id)
|
||||
prefix = PREFIX_SOURCE
|
||||
|
||||
if name is None:
|
||||
return None
|
||||
return prefix + PREFIX_SEPARATOR + name
|
||||
return self._sources.get(self._tv.source_id)
|
||||
|
||||
@property
|
||||
def source_list(self):
|
||||
"""List of available input sources."""
|
||||
complete = []
|
||||
for source in self._sources.values():
|
||||
complete.append(PREFIX_SOURCE + PREFIX_SEPARATOR + source)
|
||||
for channel in self._channels.values():
|
||||
complete.append(PREFIX_CHANNEL + PREFIX_SEPARATOR + channel)
|
||||
return complete
|
||||
return list(self._sources.values())
|
||||
|
||||
def select_source(self, source):
|
||||
"""Set the input source."""
|
||||
data = source.split(PREFIX_SEPARATOR, 1)
|
||||
if data[0] == PREFIX_SOURCE:
|
||||
if data[0] == PREFIX_SOURCE: # Legacy way to set source
|
||||
source_id = _inverted(self._sources).get(data[1])
|
||||
if source_id:
|
||||
self._tv.setSource(source_id)
|
||||
elif data[0] == PREFIX_CHANNEL:
|
||||
elif data[0] == PREFIX_CHANNEL: # Legacy way to set channel
|
||||
channel_id = _inverted(self._channels).get(data[1])
|
||||
if channel_id:
|
||||
self._tv.setChannel(channel_id)
|
||||
else:
|
||||
source_id = _inverted(self._sources).get(source)
|
||||
if source_id:
|
||||
self._tv.setSource(source_id)
|
||||
self._update_soon(DELAY_ACTION_DEFAULT)
|
||||
|
||||
@property
|
||||
@ -281,6 +274,29 @@ class PhilipsTVMediaPlayer(MediaPlayerEntity):
|
||||
else:
|
||||
_LOGGER.error("Unsupported media type <%s>", media_type)
|
||||
|
||||
async def async_browse_media(self, media_content_type=None, media_content_id=None):
|
||||
"""Implement the websocket media browsing helper."""
|
||||
if media_content_id not in (None, ""):
|
||||
raise BrowseError(
|
||||
f"Media not found: {media_content_type} / {media_content_id}"
|
||||
)
|
||||
|
||||
return {
|
||||
"title": "Channels",
|
||||
"media_content_id": "",
|
||||
"media_content_type": "library",
|
||||
"can_play": False,
|
||||
"children": [
|
||||
{
|
||||
"title": channel,
|
||||
"media_content_id": channel,
|
||||
"media_content_type": MEDIA_TYPE_CHANNEL,
|
||||
"can_play": True,
|
||||
}
|
||||
for channel in self._channels.values()
|
||||
],
|
||||
}
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data and update device state."""
|
||||
self._tv.update()
|
||||
|
Loading…
x
Reference in New Issue
Block a user