Skip to content
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

Fix Android TV icon when screencap option is disabled #35710

Merged
merged 2 commits into from
May 27, 2020

Conversation

JeffLIrion
Copy link
Contributor

@JeffLIrion JeffLIrion commented May 16, 2020

Proposed change

If the screencap option is disabled, then the MediaPlayerEntity.media_image_hash should return None because an image was not fetched. This fixes an issue where the media player's icon is not displayed because it is overridden by a nonexistent entity picture.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

Copy link
Contributor

@elupus elupus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this isn't IO, wouldn't it be better to store timestamp in async_update() method? I'm mainly asking here to understand. As it is now you get different image hashes every call to this property. So from caching perspective this totally kills it.

@JeffLIrion
Copy link
Contributor Author

While this isn't IO, wouldn't it be better to store timestamp in async_update() method? I'm mainly asking here to understand. As it is now you get different image hashes every call to this property. So from caching perspective this totally kills it.

I don't know. I just wanted to fix the issue that HA tries to display an entity picture when there isn't one (because the screencap option is off), and as a result the icon is not displayed.

@JeffLIrion
Copy link
Contributor Author

@elupus to expand a bit on my previous response, the screencap functionality was introduced in #33232, and with it came the media_image_hash property. I'm not familiar with how HA handles fetching these images and caching, but looking at the MediaPlayerEntity.media_image_hash property it's clear that if there is no entity picture -- as is the case when the screencap option is disabled -- then that property should be None.

@JeffLIrion
Copy link
Contributor Author

I’ve tested this change and it works.

Could this be cherry-picked for the next release?

@bdraco
Copy link
Member

bdraco commented May 26, 2020

By returning the timestamp you are effectively disabling the caching.

Is there a way to tell when the image is updated?

@JeffLIrion
Copy link
Contributor Author

By returning the timestamp you are effectively disabling the caching.

Is there a way to tell when the image is updated?

That's a question for @i00. The screencap functionality was introduced in #33232.

I'm not familiar with how HA handles the images that the integration retrieves, I just know that if you have the screencap option disabled then the media_image_hash property should return None.

@bdraco
Copy link
Member

bdraco commented May 26, 2020

@JeffLIrion Would you please fill out what the Proposed change describing what this is fixing. I realize can figure it out from the linked issue, but thats not what we use when generating the release notes.

This also helps guide the reviewer as to what is changing here and give us an idea of the scope of the change.

Please remove the Breaking Change section

@bdraco bdraco added this to the 0.110.4 milestone May 26, 2020
@JeffLIrion
Copy link
Contributor Author

@bdraco done.

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should look into getting rid of the timestamp here in a new PR as the cache exists for a reason.

Its outside of scope for a bugfix though.

@bdraco bdraco merged commit 6a06d64 into home-assistant:dev May 27, 2020
@i00
Copy link
Contributor

i00 commented May 28, 2020

@bdraco ... how is the cache a good thing for something that continually changes?... There are at least 2 different media player integrations (I know of) that require no image caching... so maybe this should be able to be disabled within MediaPlayerEntity?

On another note, I have opened a frontend issue about the flickering (I use a custom media player card that does not flicker):
home-assistant/frontend#6067

kennedyshead pushed a commit to kennedyshead/home-assistant that referenced this pull request May 28, 2020
…#35710)

* Don't return a media image hash if the screencap config option is False

* 1-liner
@bdraco
Copy link
Member

bdraco commented May 28, 2020

@bdraco ... how is the cache a good thing for something that continually changes?... There are at least 2 different media player integrations (I know of) that require no image caching... so maybe this should be able to be disabled within MediaPlayerEntity?

On another note, I have opened a frontend issue about the flickering (I use a custom media player card that does not flicker):
home-assistant/frontend#6067

It looks like system was originally designed to display album artwork in #5754 and the hash gets generated here: https://github.com/postlund/pyatv/blob/master/pyatv/interface.py#L443

When we send a timestamp instead of a hash here its abusing the original design (not a problem until it is). It does work as you are expecting sans the flickering from the original design not expecting the update frequency or image size.

We should probably change media_player to better handle integrations that don't want caching.

balloob pushed a commit that referenced this pull request May 28, 2020
* Don't return a media image hash if the screencap config option is False

* 1-liner
@balloob balloob mentioned this pull request May 28, 2020
@i00
Copy link
Contributor

i00 commented May 29, 2020

We should probably change media_player to better handle integrations that don't want caching.

As I said 👍

It does work as you are expecting sans the flickering from the original design not expecting the update frequency or image size.

Yes ... but this also occurs when the song advances and still doesn't look that pleasant when this does occur; and should be fixed regardless in the media cards; and on the "circular" entity previews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AndroidTV: media_player entity has no icon when device is turned on
6 participants