Skip to content
Snippets Groups Projects
Commit 5e3102b2 authored by Niall Donegan's avatar Niall Donegan Committed by cgtobi
Browse files

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
parent 217b974c
No related branches found
No related tags found
No related merge requests found
......@@ -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."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment