From bd313ea27a9d87c06493796f6a8a8540686af16d Mon Sep 17 00:00:00 2001 From: Samuel Spagl <46893256+samuelspagl@users.noreply.github.com> Date: Mon, 14 Oct 2024 21:46:14 +0200 Subject: [PATCH] Fix 'audiotrackdata' (#42) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## [0.4.1] Media Mystique: The Great Data Disappearing Act! ### Fixed - Made media data (*track title*, *artist*, *length*) optional to acoomodate soundbars that don't provide this information (🥲) ### Added - Add translations for the english translation file --- CHANGELOG.md | 10 ++ README.md | 17 +-- .../api_extension/SoundbarDevice.py | 33 ++--- .../samsung_soundbar/translations/de.json | 20 ++- .../samsung_soundbar/translations/en.json | 114 ++++++++++++++++-- 5 files changed, 151 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0274a9c..21a2afb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [0.4.1] Media Mystique: The Great Data Disappearing Act! + +### Fixed + +- Made media data (*track title*, *artist*, *length*) optional to acoomodate soundbars that don't provide this information (🥲) + +### Added + +- Add translations for the english translation file + ## [0.4.0] Started with an "ick", but is now packed with new features 💪 > ⚠️ Please read the following carefully: diff --git a/README.md b/README.md index d817d1f..9d7a95e 100644 --- a/README.md +++ b/README.md @@ -2,21 +2,8 @@ Welcome to YASSI, the Home Assistant integration designed to bring comprehensive control over your Samsung Soundbar into your smart home ecosystem. -> [!CAUTION] -> **Soundbar Integration Issues**: -> -> Samsung changed (un)intentionally? something in the SmartThings API. Therefore it is currently not possible to retrieve a status update for -> custom capabilities like *Soundmode, EQ, Woofer and Advanced Audio settings (Nightmode, Bassmode, Voice-enhancer). -> Other than this, the integration is working as expected. -> -> **I released a new beta version where you can select for which custom capability entities should be created. If one is disabled so is the update -> process, and therefore the error logs will disappear.** -> -> It is still possible to adjust all settings of the custom capabilties, therefore the beta version features service calls for each of those. -> For more and updated information please refer to [#26](https://github.com/samuelspagl/ha_samsung_soundbar/issues/26). -> -> Best Samuel ✌️ - +> [!NOTE] +> Please use service calls for setting the attribute of a custom capability instead of the entity. (See #43 for more information) **Table of Contents:** diff --git a/custom_components/samsung_soundbar/api_extension/SoundbarDevice.py b/custom_components/samsung_soundbar/api_extension/SoundbarDevice.py index ef4a641..0890751 100644 --- a/custom_components/samsung_soundbar/api_extension/SoundbarDevice.py +++ b/custom_components/samsung_soundbar/api_extension/SoundbarDevice.py @@ -72,18 +72,19 @@ class SoundbarDevice: 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"]) @@ -372,11 +373,15 @@ class SoundbarDevice: @property def media_duration(self) -> int | None: - return self.device.status.attributes.get("totalTime").value + attr = self.device.status.attributes.get("totalTime", None) + if attr: + return attr.value @property def media_position(self) -> int | None: - return self.device.status.attributes.get("elapsedTime").value + attr = self.device.status.attributes.get("elapsedTime", None) + if attr: + return attr.value async def media_play(self): await self.device.play(True) diff --git a/custom_components/samsung_soundbar/translations/de.json b/custom_components/samsung_soundbar/translations/de.json index f8c7aff..bb3b087 100644 --- a/custom_components/samsung_soundbar/translations/de.json +++ b/custom_components/samsung_soundbar/translations/de.json @@ -107,11 +107,27 @@ }, "set_speaker_level":{ "name": "Lautsprecher level verändern", - "description": "Verändere die Lautstärke der einzelnen Lautsprecher" + "description": "Verändere die Lautstärke der einzelnen Lautsprecher", + "fields":{ + "speaker_identifier": { + "name": "Lautsprecher", + "description": "Auszuwählender Lautsprecher" + }, + "level": { + "name": "Lautstärke Level", + "description": "Lautstärke Level zwischen -6 und 6." + } + } }, "set_rear_speaker_mode":{ "name": "Modus der hinteren Lautsprecher setzen", - "description": "Nutze deine Rücklautsprecher, als 'Vorder-' oder 'Rücklautsprecher'." + "description": "Nutze deine Rücklautsprecher, als 'Vorder-' oder 'Rücklautsprecher'.", + "fields":{ + "speaker_mode": { + "name": "Lautsprecher Modus", + "description": "Nutze den Lautsprecher als Front oder Rear Speaker." + } + } }, "set_active_voice_amplifier":{ "name": "Stimmenverstärker setzen", diff --git a/custom_components/samsung_soundbar/translations/en.json b/custom_components/samsung_soundbar/translations/en.json index c9f8aed..56a87ce 100644 --- a/custom_components/samsung_soundbar/translations/en.json +++ b/custom_components/samsung_soundbar/translations/en.json @@ -1,18 +1,18 @@ { - "config":{ - "step":{ - "user":{ + "config": { + "step": { + "user": { "data": { "api_key": "SmartThings API Token", "device_id": "Device ID", - "device_name":"Device Name", + "device_name": "Device Name", "device_volume": "Max Volume (int)" - }, - "description": "Please enter your credentials.", - "title": "Authentication" + }, + "description": "Please enter your credentials.", + "title": "Authentication" }, - "device":{ - "data" : { + "device": { + "data": { "settings_advanced_audio": "Enable 'Advanced Audio switches' capabilities (NightMode, BassMode, VoiceEnhancer)", "settings_eq": "Enable 'EQ selector' capabilities", "settings_soundmode": "Enable 'Soundmode selector' capabilities", @@ -21,8 +21,8 @@ "description": "Some soundbars have a different featureset than others. Please the features supported by your soundbar (visible in the SmartThings App).", "title": "Device Settings" }, - "reconfigure_confirm":{ - "data" : { + "reconfigure_confirm": { + "data": { "settings_advanced_audio": "Enable 'Advanced Audio switches' capabilities (NightMode, BassMode, VoiceEnhancer)", "settings_eq": "Enable 'EQ selector' capabilities", "settings_soundmode": "Enable 'Soundmode selector' capabilities", @@ -59,5 +59,95 @@ "Front": "Front" } } - } + }, + "services": { + "select_soundmode": { + "name": "Select Sound Mode", + "description": "Choose between 'Standard', 'Surround', 'Game', and 'Adaptive Sound'." + }, + "set_woofer_level": { + "name": "Set Subwoofer Level", + "description": "Change the volume of your subwoofer.", + "fields": { + "level": { + "name": "Volume Level", + "description": "Subwoofer level, from -12 to +6" + } + } + }, + "set_night_mode": { + "name": "Set Night Mode", + "description": "Turn 'Night Mode' on/off.", + "fields": { + "enabled": { + "name": "On/Off", + "description": "See name." + } + } + }, + "set_bass_enhancer": { + "name": "Set Bass Mode", + "description": "Turn 'Bass Mode' on/off.", + "fields": { + "enabled": { + "name": "On/Off", + "description": "See name." + } + } + }, + "set_voice_enhancer": { + "name": "Set Voice Enhancer", + "description": "Turn 'Voice Enhancer' on/off.", + "fields": { + "enabled": { + "name": "On/Off", + "description": "See name." + } + } + }, + "set_speaker_level": { + "name": "Change Speaker Level", + "description": "Change the volume of individual speakers.", + "fields":{ + "speaker_identifier": { + "name": "Speaker Identifier", + "description": "Identifier of the speaker." + }, + "level": { + "name": "Level", + "description": "Level of the Speaker from -6 to 6." + } + } + }, + "set_rear_speaker_mode": { + "name": "Set Rear Speaker Mode", + "description": "Use your rear speakers as 'Front' or 'Rear' speakers.", + "fields":{ + "speaker_mode": { + "name": "Speaker mode", + "description": "Weather the speaker are used as rear / front speakers." + } + } + }, + "set_active_voice_amplifier": { + "name": "Set Voice Amplifier", + "description": "Turn 'Voice Amplifier' on/off.", + "fields": { + "enabled": { + "name": "On/Off", + "description": "See name." + } + } + }, + "set_space_fit_sound": { + "name": "Set SpaceFitSound", + "description": "Turn 'SpaceFitSound' on/off.", + "fields": { + "enabled": { + "name": "On/Off", + "description": "See name." + } + } + } + } } \ No newline at end of file