core/homeassistant/components/dlna_dmr/media_player.py

446 lines
14 KiB
Python
Raw Normal View History

"""Support for DLNA DMR (Device Media Renderer)."""
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
2018-08-05 12:41:18 +00:00
import asyncio
from datetime import timedelta
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
2018-08-05 12:41:18 +00:00
import functools
import logging
from typing import Optional
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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
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,
)
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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,
)
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
2018-08-05 12:41:18 +00:00
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.typing import HomeAssistantType
2018-09-09 12:26:06 +00:00
import homeassistant.helpers.config_validation as cv
import homeassistant.util.dt as dt_util
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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__)
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
2018-08-05 12:41:18 +00:00
2019-07-31 19:25:30 +00:00
DLNA_DMR_DATA = "dlna_dmr"
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
2018-08-05 12:41:18 +00:00
2019-07-31 19:25:30 +00:00
DEFAULT_NAME = "DLNA Digital Media Renderer"
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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"
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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,
}
)
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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",
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
2018-08-05 12:41:18 +00:00
}
2019-07-31 19:25:30 +00:00
UPNP_CLASS_DEFAULT = "object.item"
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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/*",
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
2018-08-05 12:41:18 +00:00
def call_wrapper(func):
"""Call wrapper for decorator."""
2019-07-31 19:25:30 +00:00
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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
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,
):
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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"]
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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(
requester,
listen_port=server_port,
listen_host=server_host,
2019-07-31 19:25:30 +00:00
callback_url=callback_url_override,
)
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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")
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
2018-08-05 12:41:18 +00:00
await server.stop_server()
2019-07-31 19:25:30 +00:00
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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"]
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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
):
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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")
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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()
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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"]:
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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)
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
)
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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
from async_upnp_client.profiles.dlna import DmrDevice
2019-07-31 19:25:30 +00:00
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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)
async_add_entities([device], True)
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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):
"""Handle addition."""
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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)
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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"]:
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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?
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:
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
2018-08-05 12:41:18 +00:00
try:
timeout = await self._device.async_subscribe_services()
self._subscription_renew_time = dt_util.utcnow() + timeout / 2
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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
if self._device.has_seek_rel_time:
supported_features |= SUPPORT_SEEK
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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")
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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")
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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")
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
2018-08-05 12:41:18 +00:00
return
await self._device.async_stop()
@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")
return
time = timedelta(seconds=position)
await self._device.async_seek_rel_time(time)
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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
)
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
2018-08-05 12:41:18 +00:00
2018-09-09 12:26:06 +00:00
# Stop current playing media
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
2018-08-05 12:41:18 +00:00
if self._device.can_stop:
await self.async_media_stop()
# 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
)
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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
from async_upnp_client.profiles.dlna import DeviceState
2019-07-31 19:25:30 +00:00
if self._device.state == DeviceState.PLAYING:
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
2018-08-05 12:41:18 +00:00
return
2018-09-09 12:26:06 +00:00
# Play it
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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")
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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")
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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
from async_upnp_client.profiles.dlna import DeviceState
2019-07-31 19:25:30 +00:00
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
2018-08-05 12:41:18 +00:00
if self._device.state is None:
return STATE_ON
if self._device.state == DeviceState.PLAYING:
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
2018-08-05 12:41:18 +00:00
return STATE_PLAYING
if self._device.state == DeviceState.PAUSED:
Add media_player.dlna_dmr component (#14749) * Add media_player.dlna_dmr component * PEP 492 * Move DIDL-template up * Remove max_volume-override option * Remove picky_device support * Use DEFAULT_NAME * Make supported_features static * Remove unneeded argument * Proper module-docstring * Add http dependency * Remove additional_configuration options, no longer used * Change default name to 'DLNA Digital Media Renderer' * Use python-didl-lite for DIDL-Lite-xml construction/parsing * Handle NOT_IMPLEMENTED for UPnP state variables RelativeTimePosition and CurrentMediaDuration * Use UPnP-UDN for unique_id * Proper handling of upnp events * Keeping flake8 happy * Update requirements_all.txt * Make UDN optional * Ensure NotifyView is started, before using it * Only subscribe to services we're interested in * Don't update state_variables if value has not been changed + minor refactoring * Improve play_media, follow flow of DLNA more closely * Hopefully fix ClientOSError problems * Flake8 fixes * Keep pylint happy * Catch errors and report gracefully * Update async_upnp_client to 0.11.0 * Don't be so noisy * Define/use constants for HTTP status codes * Add discovery entry for dlna_dmr * More robustness with regard to state variable not being set (yet) * Keep privates hidden * Handle NOT_IMPLEMENTED for CurrentTrackMetaData state variable * Fixes in async_upnp_client + renew UPnP subscriptions regularly * Not too eager * Refactor duplicate code to _current_transport_actions and improve parsing of actions * Support RC:1 to RC:3 and AVT:1 to AVT:3 * Moved DLNA-specifics to async_upnp_client.dlna.DmrDevice * Use our own HTTP server to listen for events. * More clear and explicit log message for easier troubleshooting * Follow changes by hass, fixes traceback * Fix not being able to do next * Changes after review by @MartinHjelmare * Linting * Use homeassistant.util.get_local_ip * Moved upnp event handling to async_upnp_client * Keeping pylint happy * Changes after review by @MartinHjelmare
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