From 1000d590d703321c82c9ddb085e7a2c224e6dd99 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Fri, 8 Jan 2021 15:06:37 +0100 Subject: [PATCH] Don't return image hashes when the mpd instance doesn't support it Fixes: #44948 --- homeassistant/components/mpd/media_player.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/mpd/media_player.py b/homeassistant/components/mpd/media_player.py index 1273b720dd8ef0..f60fa8c4f267aa 100644 --- a/homeassistant/components/mpd/media_player.py +++ b/homeassistant/components/mpd/media_player.py @@ -109,6 +109,8 @@ def __init__(self, server, port, password, name): self._media_position_updated_at = None self._media_position = None self._commands = None + self._can_albumart = False + self._can_readpicture = False # set up MPD client self._client = MPDClient() @@ -167,6 +169,10 @@ async def async_update(self): await self._connect() self._commands = list(await self._client.commands()) + # not all MPD implementations and versions support the `albumart` and `fetchpicture` commands + self._can_albumart = "albumart" in self._commands + self._can_readpicture = "readpicture" in self._commands + await self._fetch_status() except (mpd.ConnectionError, OSError, BrokenPipeError, ValueError) as error: # Cleanly disconnect in case connection is not in valid state @@ -258,6 +264,9 @@ def media_album_name(self): @property def media_image_hash(self): """Hash value for media image.""" + if not self._can_albumart and not self._can_readpicture: + return None + file = self._currentsong.get("file") if file: return hashlib.sha256(file.encode("utf-8")).hexdigest()[:16] @@ -270,14 +279,10 @@ async def async_get_media_image(self): if not file: return None, None - # not all MPD implementations and versions support the `albumart` and `fetchpicture` commands - can_albumart = "albumart" in self._commands - can_readpicture = "readpicture" in self._commands - response = None # read artwork embedded into the media file - if can_readpicture: + if self._can_readpicture: try: response = await self._client.readpicture(file) except mpd.CommandError as error: @@ -287,7 +292,7 @@ async def async_get_media_image(self): ) # read artwork contained in the media directory (cover.{jpg,png,tiff,bmp}) if none is embedded - if can_albumart and not response: + if self._can_albumart and not response: try: response = await self._client.albumart(file) except mpd.CommandError as error: