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