mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 18:27:51 +00:00
Support playback of channel preset in philips_js (#86491)
* Correct invalid browse check * Support play_media of channel number * Use ChannelStep instead of Next/Previous
This commit is contained in:
parent
b7de185924
commit
9f5b1e58cb
@ -2,7 +2,7 @@
|
|||||||
"domain": "philips_js",
|
"domain": "philips_js",
|
||||||
"name": "Philips TV",
|
"name": "Philips TV",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/philips_js",
|
"documentation": "https://www.home-assistant.io/integrations/philips_js",
|
||||||
"requirements": ["ha-philipsjs==2.9.0"],
|
"requirements": ["ha-philipsjs==3.0.0"],
|
||||||
"codeowners": ["@elupus"],
|
"codeowners": ["@elupus"],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
|
@ -17,6 +17,7 @@ from homeassistant.components.media_player import (
|
|||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.trigger import PluggableAction
|
from homeassistant.helpers.trigger import PluggableAction
|
||||||
@ -166,11 +167,17 @@ class PhilipsTVMediaPlayer(
|
|||||||
|
|
||||||
async def async_media_previous_track(self) -> None:
|
async def async_media_previous_track(self) -> None:
|
||||||
"""Send rewind command."""
|
"""Send rewind command."""
|
||||||
|
if self._tv.channel_active:
|
||||||
|
await self._tv.sendKey("ChannelStepDown")
|
||||||
|
else:
|
||||||
await self._tv.sendKey("Previous")
|
await self._tv.sendKey("Previous")
|
||||||
await self._async_update_soon()
|
await self._async_update_soon()
|
||||||
|
|
||||||
async def async_media_next_track(self) -> None:
|
async def async_media_next_track(self) -> None:
|
||||||
"""Send fast forward command."""
|
"""Send fast forward command."""
|
||||||
|
if self._tv.channel_active:
|
||||||
|
await self._tv.sendKey("ChannelStepUp")
|
||||||
|
else:
|
||||||
await self._tv.sendKey("Next")
|
await self._tv.sendKey("Next")
|
||||||
await self._async_update_soon()
|
await self._async_update_soon()
|
||||||
|
|
||||||
@ -211,6 +218,22 @@ class PhilipsTVMediaPlayer(
|
|||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
async def async_play_media_channel(self, media_id: str):
|
||||||
|
"""Play a channel."""
|
||||||
|
list_id, _, channel_id = media_id.partition("/")
|
||||||
|
if channel_id:
|
||||||
|
await self._tv.setChannel(channel_id, list_id)
|
||||||
|
await self._async_update_soon()
|
||||||
|
return
|
||||||
|
|
||||||
|
for channel in self._tv.channels_current:
|
||||||
|
if channel.get("preset") == media_id:
|
||||||
|
await self._tv.setChannel(channel["ccid"], self._tv.channel_list_id)
|
||||||
|
await self._async_update_soon()
|
||||||
|
return
|
||||||
|
|
||||||
|
raise HomeAssistantError(f"Unable to find channel {media_id}")
|
||||||
|
|
||||||
async def async_play_media(
|
async def async_play_media(
|
||||||
self, media_type: MediaType | str, media_id: str, **kwargs: Any
|
self, media_type: MediaType | str, media_id: str, **kwargs: Any
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -218,34 +241,29 @@ class PhilipsTVMediaPlayer(
|
|||||||
_LOGGER.debug("Call play media type <%s>, Id <%s>", media_type, media_id)
|
_LOGGER.debug("Call play media type <%s>, Id <%s>", media_type, media_id)
|
||||||
|
|
||||||
if media_type == MediaType.CHANNEL:
|
if media_type == MediaType.CHANNEL:
|
||||||
list_id, _, channel_id = media_id.partition("/")
|
await self.async_play_media_channel(media_id)
|
||||||
if channel_id:
|
|
||||||
await self._tv.setChannel(channel_id, list_id)
|
|
||||||
await self._async_update_soon()
|
|
||||||
else:
|
|
||||||
_LOGGER.error("Unable to find channel <%s>", media_id)
|
|
||||||
elif media_type == MediaType.APP:
|
elif media_type == MediaType.APP:
|
||||||
if app := self._tv.applications.get(media_id):
|
if app := self._tv.applications.get(media_id):
|
||||||
await self._tv.setApplication(app["intent"])
|
await self._tv.setApplication(app["intent"])
|
||||||
await self._async_update_soon()
|
await self._async_update_soon()
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("Unable to find application <%s>", media_id)
|
raise HomeAssistantError(f"Unable to find application {media_id}")
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("Unsupported media type <%s>", media_type)
|
raise HomeAssistantError(f"Unsupported media type {media_type}")
|
||||||
|
|
||||||
async def async_browse_media_channels(self, expanded):
|
async def async_browse_media_channels(self, expanded: bool) -> BrowseMedia:
|
||||||
"""Return channel media objects."""
|
"""Return channel media objects."""
|
||||||
if expanded:
|
if expanded:
|
||||||
children = [
|
children = [
|
||||||
BrowseMedia(
|
BrowseMedia(
|
||||||
title=channel.get("name", f"Channel: {channel_id}"),
|
title=channel.get("name", f"Channel: {channel['ccid']}"),
|
||||||
media_class=MediaClass.CHANNEL,
|
media_class=MediaClass.CHANNEL,
|
||||||
media_content_id=f"alltv/{channel_id}",
|
media_content_id=f"{self._tv.channel_list_id}/{channel['ccid']}",
|
||||||
media_content_type=MediaType.CHANNEL,
|
media_content_type=MediaType.CHANNEL,
|
||||||
can_play=True,
|
can_play=True,
|
||||||
can_expand=False,
|
can_expand=False,
|
||||||
)
|
)
|
||||||
for channel_id, channel in self._tv.channels.items()
|
for channel in self._tv.channels_current
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
children = None
|
children = None
|
||||||
@ -261,10 +279,12 @@ class PhilipsTVMediaPlayer(
|
|||||||
children=children,
|
children=children,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_browse_media_favorites(self, list_id, expanded):
|
async def async_browse_media_favorites(
|
||||||
|
self, list_id: str, expanded: bool
|
||||||
|
) -> BrowseMedia:
|
||||||
"""Return channel media objects."""
|
"""Return channel media objects."""
|
||||||
if expanded:
|
if expanded:
|
||||||
favorites = await self._tv.getFavoriteList(list_id)
|
favorites = self._tv.favorite_lists.get(list_id)
|
||||||
if favorites:
|
if favorites:
|
||||||
|
|
||||||
def get_name(channel):
|
def get_name(channel):
|
||||||
@ -282,7 +302,7 @@ class PhilipsTVMediaPlayer(
|
|||||||
can_play=True,
|
can_play=True,
|
||||||
can_expand=False,
|
can_expand=False,
|
||||||
)
|
)
|
||||||
for channel in favorites
|
for channel in favorites.get("channels", [])
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
children = None
|
children = None
|
||||||
@ -377,10 +397,7 @@ class PhilipsTVMediaPlayer(
|
|||||||
if not self._tv.on:
|
if not self._tv.on:
|
||||||
raise BrowseError("Can't browse when tv is turned off")
|
raise BrowseError("Can't browse when tv is turned off")
|
||||||
|
|
||||||
if media_content_id is None:
|
if media_content_id is None or media_content_id == "":
|
||||||
raise BrowseError("Missing media content id")
|
|
||||||
|
|
||||||
if media_content_id in (None, ""):
|
|
||||||
return await self.async_browse_media_root()
|
return await self.async_browse_media_root()
|
||||||
path = media_content_id.partition("/")
|
path = media_content_id.partition("/")
|
||||||
if path[0] == "channels":
|
if path[0] == "channels":
|
||||||
|
@ -865,7 +865,7 @@ ha-av==10.0.0
|
|||||||
ha-ffmpeg==3.0.2
|
ha-ffmpeg==3.0.2
|
||||||
|
|
||||||
# homeassistant.components.philips_js
|
# homeassistant.components.philips_js
|
||||||
ha-philipsjs==2.9.0
|
ha-philipsjs==3.0.0
|
||||||
|
|
||||||
# homeassistant.components.habitica
|
# homeassistant.components.habitica
|
||||||
habitipy==0.2.0
|
habitipy==0.2.0
|
||||||
|
@ -660,7 +660,7 @@ ha-av==10.0.0
|
|||||||
ha-ffmpeg==3.0.2
|
ha-ffmpeg==3.0.2
|
||||||
|
|
||||||
# homeassistant.components.philips_js
|
# homeassistant.components.philips_js
|
||||||
ha-philipsjs==2.9.0
|
ha-philipsjs==3.0.0
|
||||||
|
|
||||||
# homeassistant.components.habitica
|
# homeassistant.components.habitica
|
||||||
habitipy==0.2.0
|
habitipy==0.2.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user