From 11ed2d144421f101d6f75744eb5437908edc0c09 Mon Sep 17 00:00:00 2001 From: samuelspagl Date: Mon, 7 Oct 2024 14:29:22 +0200 Subject: [PATCH] Fix 'audiotrackdata' --- CHANGELOG.md | 7 ++++++ .../api_extension/SoundbarDevice.py | 25 ++++++++++--------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0274a9c..ae0dc58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [0.4.1] It seems some Soundbars don't like music + +### Fixed + +- As it seems that some soundbars don't have the 'audioTrackData' attribute + the update process now, only tries to look at the data if it is existing. + ## [0.4.0] Started with an "ick", but is now packed with new features 💪 > ⚠️ Please read the following carefully: diff --git a/custom_components/samsung_soundbar/api_extension/SoundbarDevice.py b/custom_components/samsung_soundbar/api_extension/SoundbarDevice.py index ef4a641..9750f33 100644 --- a/custom_components/samsung_soundbar/api_extension/SoundbarDevice.py +++ b/custom_components/samsung_soundbar/api_extension/SoundbarDevice.py @@ -72,18 +72,19 @@ async def update(self): await self._update_equalizer() async def _update_media(self): - self.__media_artist = self.device.status._attributes["audioTrackData"].value[ - "artist" - ] - self.__media_title = self.device.status._attributes["audioTrackData"].value[ - "title" - ] - if self.__media_title != self.__old_media_title: - self.__old_media_title = self.__media_title - self.__media_cover_url_update_time = datetime.datetime.now() - self.__media_cover_url = await self.get_song_title_artwork( - self.__media_artist, self.__media_title - ) + if "audioTrackData" in self.device.status._attributes: + self.__media_artist = self.device.status._attributes["audioTrackData"].value[ + "artist" + ] + self.__media_title = self.device.status._attributes["audioTrackData"].value[ + "title" + ] + if self.__media_title != self.__old_media_title: + self.__old_media_title = self.__media_title + self.__media_cover_url_update_time = datetime.datetime.now() + self.__media_cover_url = await self.get_song_title_artwork( + self.__media_artist, self.__media_title + ) async def _update_soundmode(self): await self.update_execution_data(["/sec/networkaudio/soundmode"])