mirror of
https://github.com/home-assistant/core.git
synced 2026-04-02 08:26:41 +01:00
LG Soundbar: Fix incorrect state and outdated track information (#165148)
This commit is contained in:
@@ -41,7 +41,7 @@ class LGDevice(MediaPlayerEntity):
|
||||
"""Representation of an LG soundbar device."""
|
||||
|
||||
_attr_should_poll = False
|
||||
_attr_state = MediaPlayerState.ON
|
||||
_attr_state = MediaPlayerState.OFF
|
||||
_attr_supported_features = (
|
||||
MediaPlayerEntityFeature.VOLUME_SET
|
||||
| MediaPlayerEntityFeature.VOLUME_MUTE
|
||||
@@ -79,6 +79,8 @@ class LGDevice(MediaPlayerEntity):
|
||||
self._treble = 0
|
||||
self._device = None
|
||||
self._support_play_control = False
|
||||
self._device_on = False
|
||||
self._stream_type = 0
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, unique_id)}, name=host
|
||||
)
|
||||
@@ -113,6 +115,7 @@ class LGDevice(MediaPlayerEntity):
|
||||
if "i_curr_func" in data:
|
||||
self._function = data["i_curr_func"]
|
||||
if "b_powerstatus" in data:
|
||||
self._device_on = data["b_powerstatus"]
|
||||
if data["b_powerstatus"]:
|
||||
self._attr_state = MediaPlayerState.ON
|
||||
else:
|
||||
@@ -157,17 +160,34 @@ class LGDevice(MediaPlayerEntity):
|
||||
|
||||
def _update_playinfo(self, data: dict[str, Any]) -> None:
|
||||
"""Update the player info."""
|
||||
if "i_stream_type" in data:
|
||||
if self._stream_type != data["i_stream_type"]:
|
||||
self._stream_type = data["i_stream_type"]
|
||||
# Ask device for current play info when stream type changed.
|
||||
self._device.get_play()
|
||||
if data["i_stream_type"] == 0:
|
||||
# If the stream type is 0 (aka the soundbar is used as an actual soundbar)
|
||||
# the last track info should be cleared and the state should only be on or off,
|
||||
# as all playing/paused are not applicable in this mode
|
||||
self._attr_media_image_url = None
|
||||
self._attr_media_artist = None
|
||||
self._attr_media_title = None
|
||||
if self._device_on:
|
||||
self._attr_state = MediaPlayerState.ON
|
||||
else:
|
||||
self._attr_state = MediaPlayerState.OFF
|
||||
if "i_play_ctrl" in data:
|
||||
if data["i_play_ctrl"] == 0:
|
||||
self._attr_state = MediaPlayerState.PLAYING
|
||||
else:
|
||||
self._attr_state = MediaPlayerState.PAUSED
|
||||
if self._device_on and self._stream_type != 0:
|
||||
if data["i_play_ctrl"] == 0:
|
||||
self._attr_state = MediaPlayerState.PLAYING
|
||||
else:
|
||||
self._attr_state = MediaPlayerState.PAUSED
|
||||
if "s_albumart" in data:
|
||||
self._attr_media_image_url = data["s_albumart"]
|
||||
self._attr_media_image_url = data["s_albumart"].strip() or None
|
||||
if "s_artist" in data:
|
||||
self._attr_media_artist = data["s_artist"]
|
||||
self._attr_media_artist = data["s_artist"].strip() or None
|
||||
if "s_title" in data:
|
||||
self._attr_media_title = data["s_title"]
|
||||
self._attr_media_title = data["s_title"].strip() or None
|
||||
if "b_support_play_ctrl" in data:
|
||||
self._support_play_control = data["b_support_play_ctrl"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user