mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +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 import PLATFORM_SCHEMA, MediaPlayerEntity
|
||||||
from homeassistant.components.media_player.const import (
|
from homeassistant.components.media_player.const import (
|
||||||
MEDIA_TYPE_CHANNEL,
|
MEDIA_TYPE_CHANNEL,
|
||||||
|
SUPPORT_BROWSE_MEDIA,
|
||||||
SUPPORT_NEXT_TRACK,
|
SUPPORT_NEXT_TRACK,
|
||||||
SUPPORT_PLAY_MEDIA,
|
SUPPORT_PLAY_MEDIA,
|
||||||
SUPPORT_PREVIOUS_TRACK,
|
SUPPORT_PREVIOUS_TRACK,
|
||||||
@ -18,6 +19,7 @@ from homeassistant.components.media_player.const import (
|
|||||||
SUPPORT_VOLUME_SET,
|
SUPPORT_VOLUME_SET,
|
||||||
SUPPORT_VOLUME_STEP,
|
SUPPORT_VOLUME_STEP,
|
||||||
)
|
)
|
||||||
|
from homeassistant.components.media_player.errors import BrowseError
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_API_VERSION,
|
CONF_API_VERSION,
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
@ -40,6 +42,7 @@ SUPPORT_PHILIPS_JS = (
|
|||||||
| SUPPORT_NEXT_TRACK
|
| SUPPORT_NEXT_TRACK
|
||||||
| SUPPORT_PREVIOUS_TRACK
|
| SUPPORT_PREVIOUS_TRACK
|
||||||
| SUPPORT_PLAY_MEDIA
|
| SUPPORT_PLAY_MEDIA
|
||||||
|
| SUPPORT_BROWSE_MEDIA
|
||||||
)
|
)
|
||||||
|
|
||||||
CONF_ON_ACTION = "turn_on_action"
|
CONF_ON_ACTION = "turn_on_action"
|
||||||
@ -146,38 +149,28 @@ class PhilipsTVMediaPlayer(MediaPlayerEntity):
|
|||||||
@property
|
@property
|
||||||
def source(self):
|
def source(self):
|
||||||
"""Return the current input source."""
|
"""Return the current input source."""
|
||||||
if self.media_content_type == MEDIA_TYPE_CHANNEL:
|
return self._sources.get(self._tv.source_id)
|
||||||
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
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_list(self):
|
def source_list(self):
|
||||||
"""List of available input sources."""
|
"""List of available input sources."""
|
||||||
complete = []
|
return list(self._sources.values())
|
||||||
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
|
|
||||||
|
|
||||||
def select_source(self, source):
|
def select_source(self, source):
|
||||||
"""Set the input source."""
|
"""Set the input source."""
|
||||||
data = source.split(PREFIX_SEPARATOR, 1)
|
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])
|
source_id = _inverted(self._sources).get(data[1])
|
||||||
if source_id:
|
if source_id:
|
||||||
self._tv.setSource(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])
|
channel_id = _inverted(self._channels).get(data[1])
|
||||||
if channel_id:
|
if channel_id:
|
||||||
self._tv.setChannel(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)
|
self._update_soon(DELAY_ACTION_DEFAULT)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -281,6 +274,29 @@ class PhilipsTVMediaPlayer(MediaPlayerEntity):
|
|||||||
else:
|
else:
|
||||||
_LOGGER.error("Unsupported media type <%s>", media_type)
|
_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):
|
def update(self):
|
||||||
"""Get the latest data and update device state."""
|
"""Get the latest data and update device state."""
|
||||||
self._tv.update()
|
self._tv.update()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user