2019-04-03 15:40:03 +00:00
|
|
|
"""Support for DLNA DMR (Device Media Renderer)."""
|
2018-08-05 12:41:18 +00:00
|
|
|
import asyncio
|
2018-11-07 12:48:51 +00:00
|
|
|
from datetime import timedelta
|
2018-08-05 12:41:18 +00:00
|
|
|
import functools
|
|
|
|
import logging
|
2019-03-05 15:48:44 +00:00
|
|
|
from typing import Optional
|
2018-08-05 12:41:18 +00:00
|
|
|
|
|
|
|
import aiohttp
|
|
|
|
import voluptuous as vol
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
from homeassistant.components.media_player import MediaPlayerDevice, PLATFORM_SCHEMA
|
2019-02-08 22:18:18 +00:00
|
|
|
from homeassistant.components.media_player.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
MEDIA_TYPE_CHANNEL,
|
|
|
|
MEDIA_TYPE_EPISODE,
|
|
|
|
MEDIA_TYPE_IMAGE,
|
|
|
|
MEDIA_TYPE_MOVIE,
|
|
|
|
MEDIA_TYPE_MUSIC,
|
|
|
|
MEDIA_TYPE_PLAYLIST,
|
|
|
|
MEDIA_TYPE_TVSHOW,
|
|
|
|
MEDIA_TYPE_VIDEO,
|
|
|
|
SUPPORT_NEXT_TRACK,
|
|
|
|
SUPPORT_PAUSE,
|
|
|
|
SUPPORT_PLAY,
|
|
|
|
SUPPORT_PLAY_MEDIA,
|
|
|
|
SUPPORT_PREVIOUS_TRACK,
|
|
|
|
SUPPORT_SEEK,
|
|
|
|
SUPPORT_STOP,
|
|
|
|
SUPPORT_VOLUME_MUTE,
|
|
|
|
SUPPORT_VOLUME_SET,
|
|
|
|
)
|
2018-08-05 12:41:18 +00:00
|
|
|
from homeassistant.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
CONF_NAME,
|
|
|
|
CONF_URL,
|
|
|
|
EVENT_HOMEASSISTANT_STOP,
|
|
|
|
STATE_IDLE,
|
|
|
|
STATE_OFF,
|
|
|
|
STATE_ON,
|
|
|
|
STATE_PAUSED,
|
|
|
|
STATE_PLAYING,
|
|
|
|
)
|
2018-08-05 12:41:18 +00:00
|
|
|
from homeassistant.exceptions import PlatformNotReady
|
|
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
2019-03-05 15:48:44 +00:00
|
|
|
from homeassistant.helpers.typing import HomeAssistantType
|
2018-09-09 12:26:06 +00:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
2019-09-19 06:39:09 +00:00
|
|
|
import homeassistant.util.dt as dt_util
|
2018-08-05 12:41:18 +00:00
|
|
|
from homeassistant.util import get_local_ip
|
|
|
|
|
2018-09-09 12:26:06 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2018-08-05 12:41:18 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
DLNA_DMR_DATA = "dlna_dmr"
|
2018-08-05 12:41:18 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
DEFAULT_NAME = "DLNA Digital Media Renderer"
|
2018-08-05 12:41:18 +00:00
|
|
|
DEFAULT_LISTEN_PORT = 8301
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
CONF_LISTEN_IP = "listen_ip"
|
|
|
|
CONF_LISTEN_PORT = "listen_port"
|
|
|
|
CONF_CALLBACK_URL_OVERRIDE = "callback_url_override"
|
2018-08-05 12:41:18 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|
|
|
{
|
|
|
|
vol.Required(CONF_URL): cv.string,
|
|
|
|
vol.Optional(CONF_LISTEN_IP): cv.string,
|
|
|
|
vol.Optional(CONF_LISTEN_PORT, default=DEFAULT_LISTEN_PORT): cv.port,
|
|
|
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
|
|
vol.Optional(CONF_CALLBACK_URL_OVERRIDE): cv.url,
|
|
|
|
}
|
|
|
|
)
|
2018-08-05 12:41:18 +00:00
|
|
|
|
|
|
|
HOME_ASSISTANT_UPNP_CLASS_MAPPING = {
|
2019-07-31 19:25:30 +00:00
|
|
|
MEDIA_TYPE_MUSIC: "object.item.audioItem",
|
|
|
|
MEDIA_TYPE_TVSHOW: "object.item.videoItem",
|
|
|
|
MEDIA_TYPE_MOVIE: "object.item.videoItem",
|
|
|
|
MEDIA_TYPE_VIDEO: "object.item.videoItem",
|
|
|
|
MEDIA_TYPE_EPISODE: "object.item.videoItem",
|
|
|
|
MEDIA_TYPE_CHANNEL: "object.item.videoItem",
|
|
|
|
MEDIA_TYPE_IMAGE: "object.item.imageItem",
|
|
|
|
MEDIA_TYPE_PLAYLIST: "object.item.playlist",
|
2018-08-05 12:41:18 +00:00
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
UPNP_CLASS_DEFAULT = "object.item"
|
2018-08-05 12:41:18 +00:00
|
|
|
HOME_ASSISTANT_UPNP_MIME_TYPE_MAPPING = {
|
2019-07-31 19:25:30 +00:00
|
|
|
MEDIA_TYPE_MUSIC: "audio/*",
|
|
|
|
MEDIA_TYPE_TVSHOW: "video/*",
|
|
|
|
MEDIA_TYPE_MOVIE: "video/*",
|
|
|
|
MEDIA_TYPE_VIDEO: "video/*",
|
|
|
|
MEDIA_TYPE_EPISODE: "video/*",
|
|
|
|
MEDIA_TYPE_CHANNEL: "video/*",
|
|
|
|
MEDIA_TYPE_IMAGE: "image/*",
|
|
|
|
MEDIA_TYPE_PLAYLIST: "playlist/*",
|
2018-08-05 12:41:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def catch_request_errors():
|
|
|
|
"""Catch asyncio.TimeoutError, aiohttp.ClientError errors."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2018-08-05 12:41:18 +00:00
|
|
|
def call_wrapper(func):
|
|
|
|
"""Call wrapper for decorator."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2018-08-05 12:41:18 +00:00
|
|
|
@functools.wraps(func)
|
|
|
|
def wrapper(self, *args, **kwargs):
|
|
|
|
"""Catch asyncio.TimeoutError, aiohttp.ClientError errors."""
|
|
|
|
try:
|
|
|
|
return func(self, *args, **kwargs)
|
|
|
|
except (asyncio.TimeoutError, aiohttp.ClientError):
|
|
|
|
_LOGGER.error("Error during call %s", func.__name__)
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
return call_wrapper
|
|
|
|
|
|
|
|
|
2019-03-05 15:48:44 +00:00
|
|
|
async def async_start_event_handler(
|
2019-07-31 19:25:30 +00:00
|
|
|
hass: HomeAssistantType,
|
|
|
|
server_host: str,
|
|
|
|
server_port: int,
|
|
|
|
requester,
|
|
|
|
callback_url_override: Optional[str] = None,
|
|
|
|
):
|
2018-08-05 12:41:18 +00:00
|
|
|
"""Register notify view."""
|
|
|
|
hass_data = hass.data[DLNA_DMR_DATA]
|
2019-07-31 19:25:30 +00:00
|
|
|
if "event_handler" in hass_data:
|
|
|
|
return hass_data["event_handler"]
|
2018-08-05 12:41:18 +00:00
|
|
|
|
|
|
|
# start event handler
|
|
|
|
from async_upnp_client.aiohttp import AiohttpNotifyServer
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2018-09-09 12:26:06 +00:00
|
|
|
server = AiohttpNotifyServer(
|
2019-03-05 15:48:44 +00:00
|
|
|
requester,
|
|
|
|
listen_port=server_port,
|
|
|
|
listen_host=server_host,
|
2019-07-31 19:25:30 +00:00
|
|
|
callback_url=callback_url_override,
|
|
|
|
)
|
2018-08-05 12:41:18 +00:00
|
|
|
await server.start_server()
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.info("UPNP/DLNA event handler listening, url: %s", server.callback_url)
|
|
|
|
hass_data["notify_server"] = server
|
|
|
|
hass_data["event_handler"] = server.event_handler
|
2018-08-05 12:41:18 +00:00
|
|
|
|
|
|
|
# register for graceful shutdown
|
|
|
|
async def async_stop_server(event):
|
|
|
|
"""Stop server."""
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Stopping UPNP/DLNA event handler")
|
2018-08-05 12:41:18 +00:00
|
|
|
await server.stop_server()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2018-08-05 12:41:18 +00:00
|
|
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_stop_server)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
return hass_data["event_handler"]
|
2018-08-05 12:41:18 +00:00
|
|
|
|
|
|
|
|
2018-09-09 12:26:06 +00:00
|
|
|
async def async_setup_platform(
|
2019-07-31 19:25:30 +00:00
|
|
|
hass: HomeAssistantType, config, async_add_entities, discovery_info=None
|
|
|
|
):
|
2018-08-05 12:41:18 +00:00
|
|
|
"""Set up DLNA DMR platform."""
|
|
|
|
if config.get(CONF_URL) is not None:
|
|
|
|
url = config[CONF_URL]
|
|
|
|
name = config.get(CONF_NAME)
|
|
|
|
elif discovery_info is not None:
|
2019-07-31 19:25:30 +00:00
|
|
|
url = discovery_info["ssdp_description"]
|
|
|
|
name = discovery_info.get("name")
|
2018-08-05 12:41:18 +00:00
|
|
|
|
|
|
|
if DLNA_DMR_DATA not in hass.data:
|
|
|
|
hass.data[DLNA_DMR_DATA] = {}
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
if "lock" not in hass.data[DLNA_DMR_DATA]:
|
|
|
|
hass.data[DLNA_DMR_DATA]["lock"] = asyncio.Lock()
|
2018-08-05 12:41:18 +00:00
|
|
|
|
|
|
|
# build upnp/aiohttp requester
|
|
|
|
from async_upnp_client.aiohttp import AiohttpSessionRequester
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2018-08-05 12:41:18 +00:00
|
|
|
session = async_get_clientsession(hass)
|
|
|
|
requester = AiohttpSessionRequester(session, True)
|
|
|
|
|
|
|
|
# ensure event handler has been started
|
2019-07-31 19:25:30 +00:00
|
|
|
with await hass.data[DLNA_DMR_DATA]["lock"]:
|
2018-08-05 12:41:18 +00:00
|
|
|
server_host = config.get(CONF_LISTEN_IP)
|
|
|
|
if server_host is None:
|
|
|
|
server_host = get_local_ip()
|
|
|
|
server_port = config.get(CONF_LISTEN_PORT, DEFAULT_LISTEN_PORT)
|
2019-03-05 15:48:44 +00:00
|
|
|
callback_url_override = config.get(CONF_CALLBACK_URL_OVERRIDE)
|
2018-09-09 12:26:06 +00:00
|
|
|
event_handler = await async_start_event_handler(
|
2019-07-31 19:25:30 +00:00
|
|
|
hass, server_host, server_port, requester, callback_url_override
|
|
|
|
)
|
2018-08-05 12:41:18 +00:00
|
|
|
|
|
|
|
# create upnp device
|
|
|
|
from async_upnp_client import UpnpFactory
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2018-08-05 12:41:18 +00:00
|
|
|
factory = UpnpFactory(requester, disable_state_variable_validation=True)
|
|
|
|
try:
|
|
|
|
upnp_device = await factory.async_create_device(url)
|
|
|
|
except (asyncio.TimeoutError, aiohttp.ClientError):
|
|
|
|
raise PlatformNotReady()
|
|
|
|
|
|
|
|
# wrap with DmrDevice
|
2019-01-19 17:08:53 +00:00
|
|
|
from async_upnp_client.profiles.dlna import DmrDevice
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2018-08-05 12:41:18 +00:00
|
|
|
dlna_device = DmrDevice(upnp_device, event_handler)
|
|
|
|
|
|
|
|
# create our own device
|
|
|
|
device = DlnaDmrDevice(dlna_device, name)
|
|
|
|
_LOGGER.debug("Adding device: %s", device)
|
2018-08-24 14:37:30 +00:00
|
|
|
async_add_entities([device], True)
|
2018-08-05 12:41:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DlnaDmrDevice(MediaPlayerDevice):
|
|
|
|
"""Representation of a DLNA DMR device."""
|
|
|
|
|
|
|
|
def __init__(self, dmr_device, name=None):
|
|
|
|
"""Initializer."""
|
|
|
|
self._device = dmr_device
|
|
|
|
self._name = name
|
|
|
|
|
|
|
|
self._available = False
|
|
|
|
self._subscription_renew_time = None
|
|
|
|
|
|
|
|
async def async_added_to_hass(self):
|
2018-08-24 08:28:43 +00:00
|
|
|
"""Handle addition."""
|
2018-08-05 12:41:18 +00:00
|
|
|
self._device.on_event = self._on_event
|
|
|
|
|
2018-09-09 12:26:06 +00:00
|
|
|
# Register unsubscribe on stop
|
2018-08-05 12:41:18 +00:00
|
|
|
bus = self.hass.bus
|
2019-07-31 19:25:30 +00:00
|
|
|
bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._async_on_hass_stop)
|
2018-08-05 12:41:18 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self):
|
|
|
|
"""Device is available."""
|
|
|
|
return self._available
|
|
|
|
|
|
|
|
async def _async_on_hass_stop(self, event):
|
|
|
|
"""Event handler on HASS stop."""
|
2019-07-31 19:25:30 +00:00
|
|
|
with await self.hass.data[DLNA_DMR_DATA]["lock"]:
|
2018-08-05 12:41:18 +00:00
|
|
|
await self._device.async_unsubscribe_services()
|
|
|
|
|
|
|
|
async def async_update(self):
|
|
|
|
"""Retrieve the latest data."""
|
|
|
|
was_available = self._available
|
|
|
|
|
|
|
|
try:
|
|
|
|
await self._device.async_update()
|
|
|
|
self._available = True
|
|
|
|
except (asyncio.TimeoutError, aiohttp.ClientError):
|
|
|
|
self._available = False
|
|
|
|
_LOGGER.debug("Device unavailable")
|
|
|
|
return
|
|
|
|
|
|
|
|
# do we need to (re-)subscribe?
|
2019-09-19 06:39:09 +00:00
|
|
|
now = dt_util.utcnow()
|
2019-07-31 19:25:30 +00:00
|
|
|
should_renew = (
|
|
|
|
self._subscription_renew_time and now >= self._subscription_renew_time
|
|
|
|
)
|
|
|
|
if should_renew or not was_available and self._available:
|
2018-08-05 12:41:18 +00:00
|
|
|
try:
|
|
|
|
timeout = await self._device.async_subscribe_services()
|
2019-09-19 06:39:09 +00:00
|
|
|
self._subscription_renew_time = dt_util.utcnow() + timeout / 2
|
2018-08-05 12:41:18 +00:00
|
|
|
except (asyncio.TimeoutError, aiohttp.ClientError):
|
|
|
|
self._available = False
|
|
|
|
_LOGGER.debug("Could not (re)subscribe")
|
|
|
|
|
|
|
|
def _on_event(self, service, state_variables):
|
|
|
|
"""State variable(s) changed, let home-assistant know."""
|
|
|
|
self.schedule_update_ha_state()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Flag media player features that are supported."""
|
|
|
|
supported_features = 0
|
|
|
|
|
|
|
|
if self._device.has_volume_level:
|
|
|
|
supported_features |= SUPPORT_VOLUME_SET
|
|
|
|
if self._device.has_volume_mute:
|
|
|
|
supported_features |= SUPPORT_VOLUME_MUTE
|
|
|
|
if self._device.has_play:
|
|
|
|
supported_features |= SUPPORT_PLAY
|
|
|
|
if self._device.has_pause:
|
|
|
|
supported_features |= SUPPORT_PAUSE
|
|
|
|
if self._device.has_stop:
|
|
|
|
supported_features |= SUPPORT_STOP
|
|
|
|
if self._device.has_previous:
|
|
|
|
supported_features |= SUPPORT_PREVIOUS_TRACK
|
|
|
|
if self._device.has_next:
|
|
|
|
supported_features |= SUPPORT_NEXT_TRACK
|
|
|
|
if self._device.has_play_media:
|
|
|
|
supported_features |= SUPPORT_PLAY_MEDIA
|
2018-11-07 12:48:51 +00:00
|
|
|
if self._device.has_seek_rel_time:
|
|
|
|
supported_features |= SUPPORT_SEEK
|
2018-08-05 12:41:18 +00:00
|
|
|
|
|
|
|
return supported_features
|
|
|
|
|
|
|
|
@property
|
|
|
|
def volume_level(self):
|
|
|
|
"""Volume level of the media player (0..1)."""
|
|
|
|
return self._device.volume_level
|
|
|
|
|
|
|
|
@catch_request_errors()
|
|
|
|
async def async_set_volume_level(self, volume):
|
|
|
|
"""Set volume level, range 0..1."""
|
|
|
|
await self._device.async_set_volume_level(volume)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_volume_muted(self):
|
|
|
|
"""Boolean if volume is currently muted."""
|
|
|
|
return self._device.is_volume_muted
|
|
|
|
|
|
|
|
@catch_request_errors()
|
|
|
|
async def async_mute_volume(self, mute):
|
|
|
|
"""Mute the volume."""
|
|
|
|
desired_mute = bool(mute)
|
|
|
|
await self._device.async_mute_volume(desired_mute)
|
|
|
|
|
|
|
|
@catch_request_errors()
|
|
|
|
async def async_media_pause(self):
|
|
|
|
"""Send pause command."""
|
|
|
|
if not self._device.can_pause:
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Cannot do Pause")
|
2018-08-05 12:41:18 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
await self._device.async_pause()
|
|
|
|
|
|
|
|
@catch_request_errors()
|
|
|
|
async def async_media_play(self):
|
|
|
|
"""Send play command."""
|
|
|
|
if not self._device.can_play:
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Cannot do Play")
|
2018-08-05 12:41:18 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
await self._device.async_play()
|
|
|
|
|
|
|
|
@catch_request_errors()
|
|
|
|
async def async_media_stop(self):
|
|
|
|
"""Send stop command."""
|
|
|
|
if not self._device.can_stop:
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Cannot do Stop")
|
2018-08-05 12:41:18 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
await self._device.async_stop()
|
|
|
|
|
2018-11-07 12:48:51 +00:00
|
|
|
@catch_request_errors()
|
|
|
|
async def async_media_seek(self, position):
|
|
|
|
"""Send seek command."""
|
|
|
|
if not self._device.can_seek_rel_time:
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Cannot do Seek/rel_time")
|
2018-11-07 12:48:51 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
time = timedelta(seconds=position)
|
|
|
|
await self._device.async_seek_rel_time(time)
|
|
|
|
|
2018-08-05 12:41:18 +00:00
|
|
|
@catch_request_errors()
|
|
|
|
async def async_play_media(self, media_type, media_id, **kwargs):
|
|
|
|
"""Play a piece of media."""
|
|
|
|
title = "Home Assistant"
|
2019-07-31 19:25:30 +00:00
|
|
|
mime_type = HOME_ASSISTANT_UPNP_MIME_TYPE_MAPPING.get(media_type, media_type)
|
|
|
|
upnp_class = HOME_ASSISTANT_UPNP_CLASS_MAPPING.get(
|
|
|
|
media_type, UPNP_CLASS_DEFAULT
|
|
|
|
)
|
2018-08-05 12:41:18 +00:00
|
|
|
|
2018-09-09 12:26:06 +00:00
|
|
|
# Stop current playing media
|
2018-08-05 12:41:18 +00:00
|
|
|
if self._device.can_stop:
|
|
|
|
await self.async_media_stop()
|
|
|
|
|
2018-11-07 12:48:51 +00:00
|
|
|
# Queue media
|
2018-09-09 12:26:06 +00:00
|
|
|
await self._device.async_set_transport_uri(
|
2019-07-31 19:25:30 +00:00
|
|
|
media_id, title, mime_type, upnp_class
|
|
|
|
)
|
2018-08-05 12:41:18 +00:00
|
|
|
await self._device.async_wait_for_can_play()
|
|
|
|
|
2018-09-09 12:26:06 +00:00
|
|
|
# If already playing, no need to call Play
|
2019-01-19 17:08:53 +00:00
|
|
|
from async_upnp_client.profiles.dlna import DeviceState
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2019-01-19 17:08:53 +00:00
|
|
|
if self._device.state == DeviceState.PLAYING:
|
2018-08-05 12:41:18 +00:00
|
|
|
return
|
|
|
|
|
2018-09-09 12:26:06 +00:00
|
|
|
# Play it
|
2018-08-05 12:41:18 +00:00
|
|
|
await self.async_media_play()
|
|
|
|
|
|
|
|
@catch_request_errors()
|
|
|
|
async def async_media_previous_track(self):
|
|
|
|
"""Send previous track command."""
|
|
|
|
if not self._device.can_previous:
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Cannot do Previous")
|
2018-08-05 12:41:18 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
await self._device.async_previous()
|
|
|
|
|
|
|
|
@catch_request_errors()
|
|
|
|
async def async_media_next_track(self):
|
|
|
|
"""Send next track command."""
|
|
|
|
if not self._device.can_next:
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Cannot do Next")
|
2018-08-05 12:41:18 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
await self._device.async_next()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def media_title(self):
|
|
|
|
"""Title of current playing media."""
|
|
|
|
return self._device.media_title
|
|
|
|
|
|
|
|
@property
|
|
|
|
def media_image_url(self):
|
|
|
|
"""Image url of current playing media."""
|
|
|
|
return self._device.media_image_url
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""State of the player."""
|
|
|
|
if not self._available:
|
|
|
|
return STATE_OFF
|
|
|
|
|
2019-01-19 17:08:53 +00:00
|
|
|
from async_upnp_client.profiles.dlna import DeviceState
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2018-08-05 12:41:18 +00:00
|
|
|
if self._device.state is None:
|
|
|
|
return STATE_ON
|
2019-01-19 17:08:53 +00:00
|
|
|
if self._device.state == DeviceState.PLAYING:
|
2018-08-05 12:41:18 +00:00
|
|
|
return STATE_PLAYING
|
2019-01-19 17:08:53 +00:00
|
|
|
if self._device.state == DeviceState.PAUSED:
|
2018-08-05 12:41:18 +00:00
|
|
|
return STATE_PAUSED
|
|
|
|
|
|
|
|
return STATE_IDLE
|
|
|
|
|
|
|
|
@property
|
|
|
|
def media_duration(self):
|
|
|
|
"""Duration of current playing media in seconds."""
|
|
|
|
return self._device.media_duration
|
|
|
|
|
|
|
|
@property
|
|
|
|
def media_position(self):
|
|
|
|
"""Position of current playing media in seconds."""
|
|
|
|
return self._device.media_position
|
|
|
|
|
|
|
|
@property
|
|
|
|
def media_position_updated_at(self):
|
|
|
|
"""When was the position of the current playing media valid.
|
|
|
|
|
|
|
|
Returns value from homeassistant.util.dt.utcnow().
|
|
|
|
"""
|
|
|
|
return self._device.media_position_updated_at
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self) -> str:
|
|
|
|
"""Return the name of the device."""
|
|
|
|
if self._name:
|
|
|
|
return self._name
|
|
|
|
return self._device.name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unique_id(self) -> str:
|
|
|
|
"""Return an unique ID."""
|
|
|
|
return self._device.udn
|