From e50b59a56c5301bcb61034fddcb639b55bb66a10 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Fri, 27 Oct 2017 10:49:20 +0200 Subject: [PATCH] Reduce album art flickering in media player UI (#10163) * Add HTTP cache header to proxied media player images With the resource actually being cacheable, preemptively extend the cache buster key to prevent hash collisions. While at it, change the hash from md5 to sha256 for consistency with the access_token method. * Remove lint --- homeassistant/components/media_player/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index d12c634884f..f037dfb708e 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -12,7 +12,7 @@ import logging import os from random import SystemRandom -from aiohttp import web +from aiohttp import web, hdrs import async_timeout import voluptuous as vol @@ -490,9 +490,8 @@ class MediaPlayerDevice(Entity): def media_image_hash(self): """Hash value for media image.""" url = self.media_image_url - if url is not None: - return hashlib.md5(url.encode('utf-8')).hexdigest()[:5] + return hashlib.sha256(url.encode('utf-8')).hexdigest()[:16] return None @@ -966,4 +965,8 @@ class MediaPlayerImageView(HomeAssistantView): if data is None: return web.Response(status=500) - return web.Response(body=data, content_type=content_type) + headers = {hdrs.CACHE_CONTROL: 'max-age=3600'} + return web.Response( + body=data, + content_type=content_type, + headers=headers)