Move dlna_dmr imports at top-level (#29082)

This commit is contained in:
Quentame 2019-11-26 00:37:19 +01:00 committed by Paulus Schoutsen
parent 5015993f30
commit 844eb6b8ef

View File

@ -6,9 +6,12 @@ import logging
from typing import Optional
import aiohttp
from async_upnp_client import UpnpFactory
from async_upnp_client.aiohttp import AiohttpNotifyServer, AiohttpSessionRequester
from async_upnp_client.profiles.dlna import DeviceState, DmrDevice
import voluptuous as vol
from homeassistant.components.media_player import MediaPlayerDevice, PLATFORM_SCHEMA
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerDevice
from homeassistant.components.media_player.const import (
MEDIA_TYPE_CHANNEL,
MEDIA_TYPE_EPISODE,
@ -40,10 +43,10 @@ from homeassistant.const import (
)
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.typing import HomeAssistantType
import homeassistant.helpers.config_validation as cv
import homeassistant.util.dt as dt_util
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util import get_local_ip
import homeassistant.util.dt as dt_util
_LOGGER = logging.getLogger(__name__)
@ -121,8 +124,6 @@ async def async_start_event_handler(
return hass_data["event_handler"]
# start event handler
from async_upnp_client.aiohttp import AiohttpNotifyServer
server = AiohttpNotifyServer(
requester,
listen_port=server_port,
@ -163,8 +164,6 @@ async def async_setup_platform(
hass.data[DLNA_DMR_DATA]["lock"] = asyncio.Lock()
# build upnp/aiohttp requester
from async_upnp_client.aiohttp import AiohttpSessionRequester
session = async_get_clientsession(hass)
requester = AiohttpSessionRequester(session, True)
@ -180,8 +179,6 @@ async def async_setup_platform(
)
# create upnp device
from async_upnp_client import UpnpFactory
factory = UpnpFactory(requester, disable_state_variable_validation=True)
try:
upnp_device = await factory.async_create_device(url)
@ -189,8 +186,6 @@ async def async_setup_platform(
raise PlatformNotReady()
# wrap with DmrDevice
from async_upnp_client.profiles.dlna import DmrDevice
dlna_device = DmrDevice(upnp_device, event_handler)
# create our own device
@ -361,8 +356,6 @@ class DlnaDmrDevice(MediaPlayerDevice):
await self._device.async_wait_for_can_play()
# If already playing, no need to call Play
from async_upnp_client.profiles.dlna import DeviceState
if self._device.state == DeviceState.PLAYING:
return
@ -403,8 +396,6 @@ class DlnaDmrDevice(MediaPlayerDevice):
if not self._available:
return STATE_OFF
from async_upnp_client.profiles.dlna import DeviceState
if self._device.state is None:
return STATE_ON
if self._device.state == DeviceState.PLAYING: