Change http to auto for cast media image url (#38242)

* Change http to auto

* Update media_player.py

* Update test_media_player.py

* Update test_media_player.py

* Update test_media_player.py

* Update test_media_player.py

* Update test_media_player.py

* Update test_media_player.py

* Update test_media_player.py

* Update test_media_player.py

* Update test_media_player.py

* Format
This commit is contained in:
Kendell R 2020-08-06 08:21:45 -07:00 committed by GitHub
parent 988d3e9373
commit 0cdd47b014
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 1 deletions

View file

@ -602,7 +602,9 @@ class CastDevice(MediaPlayerEntity):
images = media_status.images
return images[0].url if images and images[0].url else None
return (
images[0].url.replace("http://", "//") if images and images[0].url else None
)
@property
def media_image_remotely_accessible(self) -> bool:

View file

@ -440,6 +440,45 @@ async def test_entity_media_states(hass: HomeAssistantType):
assert state.state == "unknown"
async def test_url_replace(hass: HomeAssistantType):
"""Test functionality of replacing URL for HTTPS."""
info = get_fake_chromecast_info()
full_info = attr.evolve(
info, model_name="google home", friendly_name="Speaker", uuid=FakeUUID
)
chromecast, entity = await async_setup_media_player_cast(hass, info)
entity._available = True
entity.schedule_update_ha_state()
await hass.async_block_till_done()
state = hass.states.get("media_player.speaker")
assert state is not None
assert state.name == "Speaker"
assert state.state == "unknown"
assert entity.unique_id == full_info.uuid
class FakeHTTPImage:
url = "http://example.com/test.png"
class FakeHTTPSImage:
url = "https://example.com/test.png"
media_status = MagicMock(images=[FakeHTTPImage()])
media_status.player_is_playing = True
entity.new_media_status(media_status)
await hass.async_block_till_done()
state = hass.states.get("media_player.speaker")
assert state.attributes.get("entity_picture") == "//example.com/test.png"
media_status.images = [FakeHTTPSImage()]
entity.new_media_status(media_status)
await hass.async_block_till_done()
state = hass.states.get("media_player.speaker")
assert state.attributes.get("entity_picture") == "https://example.com/test.png"
async def test_group_media_states(hass: HomeAssistantType):
"""Test media states are read from group if entity has no state."""
info = get_fake_chromecast_info()