Support media position and media duration (will display progressbar in ui) (#8904)
parent
317bc10ccb
commit
e84ff61d4a
|
@ -23,6 +23,7 @@ from homeassistant.const import (
|
|||
STATE_PAUSED, STATE_PLAYING, STATE_UNKNOWN, CONF_PORT)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -154,6 +155,7 @@ class SqueezeBoxDevice(MediaPlayerDevice):
|
|||
self._id = player_id
|
||||
self._status = {}
|
||||
self._name = name
|
||||
self._last_update = None
|
||||
_LOGGER.debug("Creating SqueezeBox object: %s, %s", name, player_id)
|
||||
|
||||
@property
|
||||
|
@ -199,7 +201,7 @@ class SqueezeBoxDevice(MediaPlayerDevice):
|
|||
if response is False:
|
||||
return
|
||||
|
||||
self._status = response.copy()
|
||||
self._status = {}
|
||||
|
||||
try:
|
||||
self._status.update(response["playlist_loop"][0])
|
||||
|
@ -210,6 +212,9 @@ class SqueezeBoxDevice(MediaPlayerDevice):
|
|||
except KeyError:
|
||||
pass
|
||||
|
||||
self._status.update(response)
|
||||
self._last_update = utcnow()
|
||||
|
||||
@property
|
||||
def volume_level(self):
|
||||
"""Volume level of the media player (0..1)."""
|
||||
|
@ -239,6 +244,17 @@ class SqueezeBoxDevice(MediaPlayerDevice):
|
|||
if 'duration' in self._status:
|
||||
return int(float(self._status['duration']))
|
||||
|
||||
@property
|
||||
def media_position(self):
|
||||
"""Duration of current playing media in seconds."""
|
||||
if 'time' in self._status:
|
||||
return int(float(self._status['time']))
|
||||
|
||||
@property
|
||||
def media_position_updated_at(self):
|
||||
"""Last time status was updated."""
|
||||
return self._last_update
|
||||
|
||||
@property
|
||||
def media_image_url(self):
|
||||
"""Image url of current playing media."""
|
||||
|
|
Loading…
Reference in New Issue