mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Pull track position from MPD status (#28579)
* Pull track position from MPD status() This allows the progress bar to work when using the media-control card in lovelace. * Actually commit flake8 fix! * Extra documentation. Mainly to trigger CI rerun. * Updated to use self._media_position
This commit is contained in:
parent
217b974cef
commit
5e3102b2d6
@ -37,6 +37,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -98,6 +99,8 @@ class MpdDevice(MediaPlayerDevice):
|
|||||||
self._is_connected = False
|
self._is_connected = False
|
||||||
self._muted = False
|
self._muted = False
|
||||||
self._muted_volume = 0
|
self._muted_volume = 0
|
||||||
|
self._media_position_updated_at = None
|
||||||
|
self._media_position = None
|
||||||
|
|
||||||
# set up MPD client
|
# set up MPD client
|
||||||
self._client = mpd.MPDClient()
|
self._client = mpd.MPDClient()
|
||||||
@ -130,6 +133,11 @@ class MpdDevice(MediaPlayerDevice):
|
|||||||
self._status = self._client.status()
|
self._status = self._client.status()
|
||||||
self._currentsong = self._client.currentsong()
|
self._currentsong = self._client.currentsong()
|
||||||
|
|
||||||
|
position = self._status["time"]
|
||||||
|
if self._media_position != position:
|
||||||
|
self._media_position_updated_at = dt_util.utcnow()
|
||||||
|
self._media_position = position
|
||||||
|
|
||||||
self._update_playlists()
|
self._update_playlists()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -188,6 +196,20 @@ class MpdDevice(MediaPlayerDevice):
|
|||||||
# Time does not exist for streams
|
# Time does not exist for streams
|
||||||
return self._currentsong.get("time")
|
return self._currentsong.get("time")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def media_position(self):
|
||||||
|
"""Position of current playing media in seconds.
|
||||||
|
|
||||||
|
This is returned as part of the mpd status rather than in the details
|
||||||
|
of the current song.
|
||||||
|
"""
|
||||||
|
return self._media_position
|
||||||
|
|
||||||
|
@property
|
||||||
|
def media_position_updated_at(self):
|
||||||
|
"""Last valid time of media position."""
|
||||||
|
return self._media_position_updated_at
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def media_title(self):
|
def media_title(self):
|
||||||
"""Return the title of current playing media."""
|
"""Return the title of current playing media."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user