-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Add installed apps to samsungtv sources #66752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
62201c2
Add get_app_list to bridge
epenet fe434ab
Load app list on first state_on
epenet 388bc9d
Add optional key_type to send_key
epenet 7730a89
Add ability to select an app
epenet 111e446
Adjust tests
epenet 1b1ae1e
Improve coverage
epenet c340d39
Sort app list
epenet 04115ee
Remove useless return
epenet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
MediaPlayerEntity, | ||
) | ||
from homeassistant.components.media_player.const import ( | ||
MEDIA_TYPE_APP, | ||
MEDIA_TYPE_CHANNEL, | ||
SUPPORT_NEXT_TRACK, | ||
SUPPORT_PAUSE, | ||
|
@@ -89,6 +90,8 @@ async def async_setup_entry( | |
class SamsungTVDevice(MediaPlayerEntity): | ||
"""Representation of a Samsung TV.""" | ||
|
||
_attr_source_list: list[str] | ||
|
||
def __init__( | ||
self, | ||
bridge: SamsungTVLegacyBridge | SamsungTVWSBridge, | ||
|
@@ -109,6 +112,7 @@ def __init__( | |
self._attr_is_volume_muted: bool = False | ||
self._attr_device_class = MediaPlayerDeviceClass.TV | ||
self._attr_source_list = list(SOURCES) | ||
self._app_list: dict[str, str] | None = None | ||
|
||
if self._on_script or self._mac: | ||
self._attr_supported_features = SUPPORT_SAMSUNGTV | SUPPORT_TURN_ON | ||
|
@@ -158,12 +162,21 @@ def update(self) -> None: | |
else: | ||
self._attr_state = STATE_ON if self._bridge.is_on() else STATE_OFF | ||
|
||
def send_key(self, key: str) -> None: | ||
if self._attr_state == STATE_ON and self._app_list is None: | ||
self._app_list = {} # Ensure that we don't update it twice in parallel | ||
self.hass.async_add_job(self._update_app_list) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are not allowed to use the async api from sync context. Probably use |
||
|
||
def _update_app_list(self) -> None: | ||
self._app_list = self._bridge.get_app_list() | ||
if self._app_list is not None: | ||
self._attr_source_list.extend(self._app_list) | ||
MartinHjelmare marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def send_key(self, key: str, key_type: str | None = None) -> None: | ||
"""Send a key to the tv and handles exceptions.""" | ||
if self._power_off_in_progress() and key != "KEY_POWEROFF": | ||
LOGGER.info("TV is powering off, not sending command: %s", key) | ||
return | ||
self._bridge.send_key(key) | ||
self._bridge.send_key(key, key_type) | ||
|
||
def _power_off_in_progress(self) -> bool: | ||
return ( | ||
|
@@ -232,6 +245,10 @@ async def async_play_media( | |
self, media_type: str, media_id: str, **kwargs: Any | ||
) -> None: | ||
"""Support changing a channel.""" | ||
if media_type == MEDIA_TYPE_APP: | ||
await self.hass.async_add_executor_job(self.send_key, media_id, "run_app") | ||
return | ||
|
||
if media_type != MEDIA_TYPE_CHANNEL: | ||
LOGGER.error("Unsupported media type") | ||
return | ||
|
@@ -264,8 +281,12 @@ async def async_turn_on(self) -> None: | |
|
||
def select_source(self, source: str) -> None: | ||
"""Select input source.""" | ||
if source not in SOURCES: | ||
LOGGER.error("Unsupported source") | ||
if self._app_list and source in self._app_list: | ||
self.send_key(self._app_list[source], "run_app") | ||
return | ||
|
||
if source in SOURCES: | ||
self.send_key(SOURCES[source]) | ||
return | ||
|
||
self.send_key(SOURCES[source]) | ||
LOGGER.error("Unsupported source") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Constants for the samsungtv tests.""" | ||
SAMPLE_APP_LIST = [ | ||
{ | ||
"appId": "111299001912", | ||
"app_type": 2, | ||
"icon": "/opt/share/webappservice/apps_icon/FirstScreen/111299001912/250x250.png", | ||
"is_lock": 0, | ||
"name": "YouTube", | ||
}, | ||
{ | ||
"appId": "3201608010191", | ||
"app_type": 2, | ||
"icon": "/opt/share/webappservice/apps_icon/FirstScreen/3201608010191/250x250.png", | ||
"is_lock": 0, | ||
"name": "Deezer", | ||
}, | ||
{ | ||
"appId": "3201606009684", | ||
"app_type": 2, | ||
"icon": "/opt/share/webappservice/apps_icon/FirstScreen/3201606009684/250x250.png", | ||
"is_lock": 0, | ||
"name": "Spotify - Music and Podcasts", | ||
}, | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we overload the
_send_key
method to run apps ? The media player knows it's running an app and could maybe callrun_app
directly ?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is because the primary
send_key
method in the bridge has a retry mechanism that I didn't want to bypass.I pland to rename the method to make it more obvious (
send_key
tosend_command
) in a follow-up PR.core/homeassistant/components/samsungtv/bridge.py
Lines 141 to 145 in d6100ab