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:
Niall Donegan 2019-12-25 10:09:03 +00:00 committed by cgtobi
parent 217b974cef
commit 5e3102b2d6

View file

@ -37,6 +37,7 @@ from homeassistant.const import (
)
import homeassistant.helpers.config_validation as cv
from homeassistant.util import Throttle
import homeassistant.util.dt as dt_util
_LOGGER = logging.getLogger(__name__)
@ -98,6 +99,8 @@ class MpdDevice(MediaPlayerDevice):
self._is_connected = False
self._muted = False
self._muted_volume = 0
self._media_position_updated_at = None
self._media_position = None
# set up MPD client
self._client = mpd.MPDClient()
@ -130,6 +133,11 @@ class MpdDevice(MediaPlayerDevice):
self._status = self._client.status()
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()
@property
@ -188,6 +196,20 @@ class MpdDevice(MediaPlayerDevice):
# Time does not exist for streams
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
def media_title(self):
"""Return the title of current playing media."""